2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.airquality.internal.api.dto;
15 import java.util.List;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.airquality.internal.api.Pollutant;
25 * The {@link AirQualityData} is responsible for storing
26 * the "data" node from the waqi.org JSON response
28 * @author Kuba Wolanin - Initial contribution
31 public class AirQualityData extends ResponseRoot {
36 private @Nullable AirQualityTime time;
37 private @Nullable AirQualityCity city;
38 private List<Attribution> attributions = List.of();
39 private Map<String, AirQualityValue> iaqi = Map.of();
40 private String dominentpol = "";
52 * Measuring Station ID
56 public int getStationId() {
61 * Receives "time" node from the "data" object in JSON response
63 * @return {AirQualityJsonTime}
65 public Optional<AirQualityTime> getTime() {
66 return Optional.ofNullable(time);
70 * Receives "city" node from the "data" object in JSON response
72 * @return {AirQualityJsonCity}
74 public Optional<AirQualityCity> getCity() {
75 return Optional.ofNullable(city);
79 * Collects a list of attributions (vendors making data available)
80 * and transforms it into readable string.
84 public String getAttributions() {
85 return attributions.stream().map(Attribution::getName).collect(Collectors.joining(", "));
88 public String getDominentPol() {
92 public double getIaqiValue(String key) {
93 AirQualityValue result = iaqi.get(key);
94 return result != null ? result.getValue() : -1;
97 public double getIaqiValue(Pollutant pollutant) {
98 return getIaqiValue(pollutant.name().toLowerCase());