]> git.basschouten.com Git - openhab-addons.git/blob
ddd6c4cad27202ec3713a286c3e25340a09d9f54
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.types.State;
25 import org.openhab.core.types.UnDefType;
26
27 import tec.uom.se.AbstractUnit;
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 CoronaStatsCases {
36     private int cases = -1;
37     private int todayCases = -1;
38     private int deaths = -1;
39     private int todayDeaths = -1;
40     private int recovered = -1;
41     private int active = -1;
42     private int critical = -1;
43
44     protected Map<String, State> getCaseChannelsStateMap() {
45         Map<String, State> map = new HashMap<>();
46
47         map.put(CHANNEL_CASES, parseToState(cases));
48         map.put(CHANNEL_NEW_CASES, parseToState(todayCases));
49         map.put(CHANNEL_DEATHS, parseToState(deaths));
50         map.put(CHANNEL_NEW_DEATHS, parseToState(todayDeaths));
51         map.put(CHANNEL_RECOVERED, parseToState(recovered));
52         map.put(CHANNEL_ACTIVE, parseToState(active));
53         map.put(CHANNEL_CRITICAL, parseToState(critical));
54
55         return map;
56     }
57
58     protected State parseToState(int count) {
59         if (count == -1) {
60             return UnDefType.NULL;
61         } else {
62             return new QuantityType<Dimensionless>(count, AbstractUnit.ONE);
63         }
64     }
65 }