]> git.basschouten.com Git - openhab-addons.git/blob
6ebd8890d8ee820f92bf4df1e71eb1c122b22ab1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.airquality.internal.json;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.stream.Collectors;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22
23 /**
24  * The {@link AirQualityJsonData} is responsible for storing
25  * the "data" node from the waqi.org JSON response
26  *
27  * @author Kuba Wolanin - Initial contribution
28  */
29 @NonNullByDefault
30 public class AirQualityJsonData {
31
32     private int aqi;
33     private int idx;
34
35     private @NonNullByDefault({}) AirQualityJsonTime time;
36     private @NonNullByDefault({}) AirQualityJsonCity city;
37     private List<Attribute> attributions = new ArrayList<>();
38     private Map<String, AirQualityValue> iaqi = new HashMap<>();
39     private String dominentpol = "";
40
41     /**
42      * Air Quality Index
43      *
44      * @return {Integer}
45      */
46     public int getAqi() {
47         return aqi;
48     }
49
50     /**
51      * Measuring Station ID
52      *
53      * @return {Integer}
54      */
55     public int getStationId() {
56         return idx;
57     }
58
59     /**
60      * Receives "time" node from the "data" object in JSON response
61      *
62      * @return {AirQualityJsonTime}
63      */
64     public AirQualityJsonTime getTime() {
65         return time;
66     }
67
68     /**
69      * Receives "city" node from the "data" object in JSON response
70      *
71      * @return {AirQualityJsonCity}
72      */
73     public AirQualityJsonCity getCity() {
74         return city;
75     }
76
77     /**
78      * Collects a list of attributions (vendors making data available)
79      * and transforms it into readable string.
80      * Currently displayed in Thing Status description when ONLINE
81      *
82      * @return {String}
83      */
84     public String getAttributions() {
85         String attributionsString = attributions.stream().map(Attribute::getName).collect(Collectors.joining(", "));
86         return "Attributions : " + attributionsString;
87     }
88
89     public String getDominentPol() {
90         return dominentpol;
91     }
92
93     public double getIaqiValue(String key) {
94         AirQualityValue result = iaqi.get(key);
95         if (result != null) {
96             return result.getValue();
97         }
98         return -1;
99     }
100 }