]> git.basschouten.com Git - openhab-addons.git/blob
76ec79d67dc813e0175d3e331c48b003f723367d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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 import org.eclipse.jdt.annotation.Nullable;
23
24 /**
25  * The {@link AirQualityJsonData} is responsible for storing
26  * the "data" node from the waqi.org JSON response
27  *
28  * @author Kuba Wolanin - Initial contribution
29  */
30 @NonNullByDefault
31 public class AirQualityJsonData {
32
33     private int aqi;
34     private int idx;
35
36     private @NonNullByDefault({}) AirQualityJsonTime time;
37     private @NonNullByDefault({}) AirQualityJsonCity city;
38     private List<Attribute> attributions = new ArrayList<>();
39     private Map<String, @Nullable AirQualityValue> iaqi = new HashMap<>();
40     private String dominentpol = "";
41
42     /**
43      * Air Quality Index
44      *
45      * @return {Integer}
46      */
47     public int getAqi() {
48         return aqi;
49     }
50
51     /**
52      * Measuring Station ID
53      *
54      * @return {Integer}
55      */
56     public int getStationId() {
57         return idx;
58     }
59
60     /**
61      * Receives "time" node from the "data" object in JSON response
62      *
63      * @return {AirQualityJsonTime}
64      */
65     public AirQualityJsonTime getTime() {
66         return time;
67     }
68
69     /**
70      * Receives "city" node from the "data" object in JSON response
71      *
72      * @return {AirQualityJsonCity}
73      */
74     public AirQualityJsonCity getCity() {
75         return city;
76     }
77
78     /**
79      * Collects a list of attributions (vendors making data available)
80      * and transforms it into readable string.
81      * Currently displayed in Thing Status description when ONLINE
82      *
83      * @return {String}
84      */
85     public String getAttributions() {
86         String attributionsString = attributions.stream().map(Attribute::getName).collect(Collectors.joining(", "));
87         return "Attributions : " + attributionsString;
88     }
89
90     public String getDominentPol() {
91         return dominentpol;
92     }
93
94     public double getIaqiValue(String key) {
95         AirQualityValue result = iaqi.get(key);
96         if (result != null) {
97             return result.getValue();
98         }
99         return -1;
100     }
101 }