]> git.basschouten.com Git - openhab-addons.git/blob
82364c6e43e5ab44b68d0b02432b55be0268e360
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.api.dto;
14
15 import java.util.List;
16 import java.util.Map;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.airquality.internal.api.Pollutant;
21
22 /**
23  * The {@link AirQualityData} is responsible for storing
24  * the "data" node from the waqi.org JSON response
25  *
26  * @author Kuba Wolanin - Initial contribution
27  */
28 @NonNullByDefault
29 public class AirQualityData {
30     private int aqi;
31     private int idx;
32
33     private @NonNullByDefault({}) AirQualityTime time;
34     private @NonNullByDefault({}) AirQualityCity city;
35     private List<Attribution> attributions = List.of();
36     private Map<String, AirQualityValue> iaqi = Map.of();
37     private String dominentpol = "";
38
39     /**
40      * Air Quality Index
41      *
42      * @return {Integer}
43      */
44     public int getAqi() {
45         return aqi;
46     }
47
48     /**
49      * Measuring Station ID
50      *
51      * @return {Integer}
52      */
53     public int getStationId() {
54         return idx;
55     }
56
57     /**
58      * Receives "time" node from the "data" object in JSON response
59      *
60      * @return {AirQualityJsonTime}
61      */
62     public AirQualityTime getTime() {
63         return time;
64     }
65
66     /**
67      * Receives "city" node from the "data" object in JSON response
68      *
69      * @return {AirQualityJsonCity}
70      */
71     public AirQualityCity getCity() {
72         return city;
73     }
74
75     /**
76      * Collects a list of attributions (vendors making data available)
77      * and transforms it into readable string.
78      *
79      * @return {String}
80      */
81     public String getAttributions() {
82         return attributions.stream().map(Attribution::getName).collect(Collectors.joining(", "));
83     }
84
85     public String getDominentPol() {
86         return dominentpol;
87     }
88
89     public double getIaqiValue(String key) {
90         AirQualityValue result = iaqi.get(key);
91         return result != null ? result.getValue() : -1;
92     }
93
94     public double getIaqiValue(Pollutant pollutant) {
95         return getIaqiValue(pollutant.name().toLowerCase());
96     }
97 }