2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.deconz.internal.handler;
15 import static org.openhab.binding.deconz.internal.BindingConstants.*;
17 import java.io.IOException;
18 import java.util.List;
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;
36 * The {@link SensorThermostatThingHandlerTest} contains test classes for the {@link SensorThermostatThingHandler}
38 * @author Jan N. Klug - Initial contribution
40 @ExtendWith(MockitoExtension.class)
41 @MockitoSettings(strictness = Strictness.LENIENT)
43 public class SensorThermostatThingHandlerTest extends BaseDeconzThingHandlerTest {
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);
50 Set<TestParam> expected = Set.of(
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")),
58 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(41)),
59 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
61 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2023-03-18T05:58Z")),
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));
69 assertThing("json/thermostat/danfoss.json", expected);
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);
77 Set<TestParam> expected = Set.of(
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")),
85 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2023-03-18T18:10Z")),
87 new TestParam(CHANNEL_THERMOSTAT_LOCKED, OnOffType.OFF),
88 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.OFF));
90 assertThing("json/thermostat/namron_ZB_E1.json", expected);
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);
98 Set<TestParam> expected = Set.of(
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")),
106 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(85)),
107 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
109 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
111 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.ON),
112 new TestParam(CHANNEL_VALVE_POSITION, new QuantityType<>("99 %")));
114 assertThing("json/thermostat/eurotronic.json", expected);
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);
122 Set<TestParam> expected = Set.of(
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")),
130 new TestParam(CHANNEL_BATTERY_LEVEL, new DecimalType(85)),
131 new TestParam(CHANNEL_BATTERY_LOW, OnOffType.OFF),
133 new TestParam(CHANNEL_LAST_SEEN, Util.convertTimestampToDateTime("2020-05-31T20:24:55.819")),
135 new TestParam(CHANNEL_THERMOSTAT_ON, OnOffType.ON),
136 new TestParam(CHANNEL_VALVE_POSITION, UnDefType.UNDEF));
138 assertThing("json/thermostat/eurotronic-invalid.json", expected);