]> git.basschouten.com Git - openhab-addons.git/blob
ffabd81fdfa76fa721ca296b7f4bbcf752fdf436
[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.util.HashMap;
18 import java.util.Map;
19
20 import javax.measure.quantity.Dimensionless;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.unit.Units;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
27
28 /**
29  * The {@link CoronaStatsCountry} class holds the internal data representation of each Country
30  *
31  * @author Johannes Ott - Initial contribution
32  */
33 @NonNullByDefault
34 public class CoronaStatsCases {
35     private int cases = -1;
36     private int todayCases = -1;
37     private int deaths = -1;
38     private int todayDeaths = -1;
39     private int recovered = -1;
40     private int active = -1;
41     private int critical = -1;
42
43     protected Map<String, State> getCaseChannelsStateMap() {
44         Map<String, State> map = new HashMap<>();
45
46         map.put(CHANNEL_CASES, parseToState(cases));
47         map.put(CHANNEL_NEW_CASES, parseToState(todayCases));
48         map.put(CHANNEL_DEATHS, parseToState(deaths));
49         map.put(CHANNEL_NEW_DEATHS, parseToState(todayDeaths));
50         map.put(CHANNEL_RECOVERED, parseToState(recovered));
51         map.put(CHANNEL_ACTIVE, parseToState(active));
52         map.put(CHANNEL_CRITICAL, parseToState(critical));
53
54         return map;
55     }
56
57     protected State parseToState(int count) {
58         if (count == -1) {
59             return UnDefType.NULL;
60         } else {
61             return new QuantityType<Dimensionless>(count, Units.ONE);
62         }
63     }
64 }