]> git.basschouten.com Git - openhab-addons.git/blob
a6670fb8cca7a737e2ee3211f7f21d982788ad9e
[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.coronastats.internal.dto;
14
15 import static org.openhab.binding.coronastats.internal.CoronaStatsBindingConstants.*;
16
17 import java.time.ZoneId;
18 import java.time.ZonedDateTime;
19 import java.util.Collections;
20 import java.util.Date;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.openhab.core.library.types.DateTimeType;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  * The {@link CoronaStatsCountry} class holds the internal data representation of each Country
31  *
32  * @author Johannes Ott - Initial contribution
33  */
34 @NonNullByDefault
35 public class CoronaStatsCountry extends CoronaStatsCases {
36     private String country = "";
37     private String countryCode = "";
38     private int tests = -1;
39     private long updated = -1;
40
41     public String getCountryCode() {
42         return countryCode;
43     }
44
45     public Map<String, String> getProperties() {
46         Map<String, String> map = new HashMap<>();
47         map.put(PROPERTY_COUNTRY, country);
48         return Collections.unmodifiableMap(map);
49     }
50
51     public Map<String, State> getChannelsStateMap() {
52         Map<String, State> map = super.getCaseChannelsStateMap();
53
54         map.put(CHANNEL_TESTS, parseToState(tests));
55
56         if (updated == -1) {
57             map.put(CHANNEL_UPDATED, UnDefType.NULL);
58         } else {
59             Date date = new Date(updated);
60             ZonedDateTime zoned = ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
61             map.put(CHANNEL_UPDATED, new DateTimeType(zoned));
62         }
63
64         return Collections.unmodifiableMap(map);
65     }
66 }