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.dwdpollenflug.internal.dto;
15 import static org.openhab.binding.dwdpollenflug.internal.DWDPollenflugBindingConstants.*;
17 import java.util.Collections;
18 import java.util.HashMap;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.library.types.StringType;
24 import org.openhab.core.types.State;
26 import com.google.gson.annotations.SerializedName;
29 * The {@link DWDRegion} class holds the internal data representation of each Region
31 * @author Johannes Ott - Initial contribution
34 public class DWDRegion {
35 @SerializedName("region_id")
36 public int regionID = 0;
38 @SerializedName("region_name")
39 public String regionName = "";
41 @SerializedName("partregion_id")
42 public int partRegionID = 0;
44 @SerializedName("partregion_name")
45 public String partRegionName = "";
47 @SerializedName("Pollen")
48 private @Nullable Map<String, DWDPollentypeJSON> pollen;
50 public Map<String, String> getProperties() {
51 Map<String, String> map = new HashMap<>();
52 map.put(PROPERTY_REGION_NAME, regionName);
53 map.put(PROPERTY_PARTREGION_NAME, partRegionName);
54 return Collections.unmodifiableMap(map);
57 public int getRegionID() {
58 if (partRegionID > 0) {
64 public Map<String, State> getChannelsStateMap() {
65 final Map<String, DWDPollentypeJSON> localPollen = pollen;
66 if (localPollen != null) {
67 Map<String, State> map = new HashMap<>();
68 localPollen.forEach((k, jsonType) -> {
69 final String pollenType = DWDPollenflugPollen.valueOf(k.toUpperCase()).getChannelName();
70 map.put(pollenType + "#" + CHANNEL_TODAY, new StringType(jsonType.today));
71 map.put(pollenType + "#" + CHANNEL_TOMORROW, new StringType(jsonType.tomorrow));
72 map.put(pollenType + "#" + CHANNEL_DAYAFTER_TO, new StringType(jsonType.dayAfterTomorrow));
75 return Collections.unmodifiableMap(map);
78 return Collections.emptyMap();