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.stream.Collectors;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.airquality.internal.api.Pollutant;
23 * The {@link AirQualityData} is responsible for storing
24 * the "data" node from the waqi.org JSON response
26 * @author Kuba Wolanin - Initial contribution
29 public class AirQualityData {
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 = "";
49 * Measuring Station ID
53 public int getStationId() {
58 * Receives "time" node from the "data" object in JSON response
60 * @return {AirQualityJsonTime}
62 public AirQualityTime getTime() {
67 * Receives "city" node from the "data" object in JSON response
69 * @return {AirQualityJsonCity}
71 public AirQualityCity getCity() {
76 * Collects a list of attributions (vendors making data available)
77 * and transforms it into readable string.
81 public String getAttributions() {
82 return attributions.stream().map(Attribution::getName).collect(Collectors.joining(", "));
85 public String getDominentPol() {
89 public double getIaqiValue(String key) {
90 AirQualityValue result = iaqi.get(key);
91 return result != null ? result.getValue() : -1;
94 public double getIaqiValue(Pollutant pollutant) {
95 return getIaqiValue(pollutant.name().toLowerCase());