]> git.basschouten.com Git - openhab-addons.git/blob
50371818b31cd1c787aa304e4e3062421d6d8bb7
[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.dwdpollenflug.internal.dto;
14
15 import static org.openhab.binding.dwdpollenflug.internal.DWDPollenflugBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.Map;
20
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;
25
26 import com.google.gson.annotations.SerializedName;
27
28 /**
29  * The {@link DWDRegion} class holds the internal data representation of each Region
30  *
31  * @author Johannes Ott - Initial contribution
32  */
33 @NonNullByDefault
34 public class DWDRegion {
35     @SerializedName("region_id")
36     public int regionID = 0;
37
38     @SerializedName("region_name")
39     public String regionName = "";
40
41     @SerializedName("partregion_id")
42     public int partRegionID = 0;
43
44     @SerializedName("partregion_name")
45     public String partRegionName = "";
46
47     @SerializedName("Pollen")
48     private @Nullable Map<String, DWDPollentypeJSON> pollen;
49
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);
55     }
56
57     public int getRegionID() {
58         if (partRegionID > 0) {
59             return partRegionID;
60         }
61         return regionID;
62     }
63
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));
73             });
74
75             return Collections.unmodifiableMap(map);
76         }
77
78         return Collections.emptyMap();
79     }
80 }