]> git.basschouten.com Git - openhab-addons.git/blob
b4075c90936287da8c7cc826c98d87fb97ea002b
[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.deconz.internal.handler;
14
15 import static org.openhab.binding.deconz.internal.BindingConstants.*;
16
17 import java.io.IOException;
18 import java.util.List;
19 import java.util.Set;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.mockito.junit.jupiter.MockitoSettings;
26 import org.mockito.quality.Strictness;
27 import org.openhab.binding.deconz.internal.Util;
28 import org.openhab.core.library.types.DecimalType;
29 import org.openhab.core.library.types.OnOffType;
30 import org.openhab.core.library.types.OpenClosedType;
31 import org.openhab.core.library.types.QuantityType;
32 import org.openhab.core.library.types.StringType;
33 import org.openhab.core.types.UnDefType;
34
35 /**
36  * The {@link SensorThermostatThingHandlerTest} contains test classes for the {@link SensorThermostatThingHandler}
37  *
38  * @author Jan N. Klug - Initial contribution
39  */
40 @ExtendWith(MockitoExtension.class)
41 @MockitoSettings(strictness = Strictness.LENIENT)
42 @NonNullByDefault
43 public class SensorThermostatThingHandlerTest extends BaseDeconzThingHandlerTest {
44
45     @Test
46     public void testDanfoss() throws IOException {
47         createThing(THING_TYPE_THERMOSTAT, List.of(CHANNEL_HEATSETPOINT, CHANNEL_LAST_UPDATED, CHANNEL_TEMPERATURE,
48                 CHANNEL_TEMPERATURE_OFFSET, CHANNEL_THERMOSTAT_MODE), SensorThermostatThingHandler::new);
49
50         Set<TestParam> expected = Set.of(
51                 // standard channels
52                 new TestParam(CHANNEL_HEATSETPOINT, new QuantityType<>("21.00 °C")),
53                 new TestParam(CHANNEL_LAST_UPDATED, Util.convertTimestampToDateTime("2023-03-18T05:52:29.506")),
54                 new TestParam(CHANNEL_TEMPERATURE, new QuantityType<>("21.45 °C")),
55                 new TestParam(CHANNEL_TEMPERATURE_OFFSET, new QuantityType<>("0.0 °C")),
56                 new TestParam(CHANNEL_THERMOSTAT_MODE, new StringType("HEAT")),
57                 // battery
58                 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(41)),
59                 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
60                 // last seen
61                 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2023-03-18T05:58Z")),
62                 // dynamic channels
63                 new TestParam(CHANNEL_EXTERNAL_WINDOW_OPEN, OpenClosedType.CLOSED),
64                 new TestParam(CHANNEL_THERMOSTAT_LOCKED, OnOffType.OFF),
65                 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.OFF),
66                 new TestParam(CHANNEL_VALVE_POSITION, new QuantityType<>("1 %")),
67                 new TestParam(CHANNEL_WINDOW_OPEN, OpenClosedType.CLOSED));
68
69         assertThing("json/thermostat/danfoss.json", expected);
70     }
71
72     @Test
73     public void testNamron() throws IOException {
74         createThing(THING_TYPE_THERMOSTAT, List.of(CHANNEL_TEMPERATURE, CHANNEL_HEATSETPOINT, CHANNEL_THERMOSTAT_MODE,
75                 CHANNEL_TEMPERATURE_OFFSET, CHANNEL_LAST_UPDATED), SensorThermostatThingHandler::new);
76
77         Set<TestParam> expected = Set.of(
78                 // standard channels
79                 new TestParam(CHANNEL_HEATSETPOINT, new QuantityType<>("22.00 °C")),
80                 new TestParam(CHANNEL_LAST_UPDATED, Util.convertTimestampToDateTime("2023-03-18T18:10:39.296")),
81                 new TestParam(CHANNEL_TEMPERATURE, new QuantityType<>("20.39 °C")),
82                 new TestParam(CHANNEL_TEMPERATURE_OFFSET, new QuantityType<>("0.0 °C")),
83                 new TestParam(CHANNEL_THERMOSTAT_MODE, new StringType("OFF")),
84                 // last seen
85                 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2023-03-18T18:10Z")),
86                 // dynamic channels
87                 new TestParam(CHANNEL_THERMOSTAT_LOCKED, OnOffType.OFF),
88                 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.OFF));
89
90         assertThing("json/thermostat/namron_ZB_E1.json", expected);
91     }
92
93     @Test
94     public void testEurotronicValid() throws IOException {
95         createThing(THING_TYPE_THERMOSTAT, List.of(CHANNEL_HEATSETPOINT, CHANNEL_LAST_UPDATED, CHANNEL_TEMPERATURE,
96                 CHANNEL_TEMPERATURE_OFFSET, CHANNEL_THERMOSTAT_MODE), SensorThermostatThingHandler::new);
97
98         Set<TestParam> expected = Set.of(
99                 // standard channels
100                 new TestParam(CHANNEL_HEATSETPOINT, new QuantityType<>("25.00 °C")),
101                 new TestParam(CHANNEL_LAST_UPDATED, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
102                 new TestParam(CHANNEL_TEMPERATURE, new QuantityType<>("16.50 °C")),
103                 new TestParam(CHANNEL_TEMPERATURE_OFFSET, new QuantityType<>("0.0 °C")),
104                 new TestParam(CHANNEL_THERMOSTAT_MODE, new StringType("AUTO")),
105                 // battery
106                 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(85)),
107                 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
108                 // last seen
109                 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
110                 // dynamic channels
111                 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.ON),
112                 new TestParam(CHANNEL_VALVE_POSITION, new QuantityType<>("99 %")));
113
114         assertThing("json/thermostat/eurotronic.json", expected);
115     }
116
117     @Test
118     public void testEurotronicInvalid() throws IOException {
119         createThing(THING_TYPE_THERMOSTAT, List.of(CHANNEL_HEATSETPOINT, CHANNEL_LAST_UPDATED, CHANNEL_TEMPERATURE,
120                 CHANNEL_TEMPERATURE_OFFSET, CHANNEL_THERMOSTAT_MODE), SensorThermostatThingHandler::new);
121
122         Set<TestParam> expected = Set.of(
123                 // standard channels
124                 new TestParam(CHANNEL_HEATSETPOINT, new QuantityType<>("25.00 °C")),
125                 new TestParam(CHANNEL_LAST_UPDATED, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
126                 new TestParam(CHANNEL_TEMPERATURE, new QuantityType<>("16.50 °C")),
127                 new TestParam(CHANNEL_TEMPERATURE_OFFSET, new QuantityType<>("0.0 °C")),
128                 new TestParam(CHANNEL_THERMOSTAT_MODE, new StringType("AUTO")),
129                 // battery
130                 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(85)),
131                 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
132                 // last seen
133                 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
134                 // dynamic channels
135                 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.ON),
136                 new TestParam(CHANNEL_VALVE_POSITION, UnDefType.UNDEF));
137
138         assertThing("json/thermostat/eurotronic-invalid.json", expected);
139     }
140 }