]> git.basschouten.com Git - openhab-addons.git/blob
335de42dd7d4c37ce3b58d4989ad93cb93e68ea0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.boschshc.internal.devices.wallthermostat;
14
15 import static org.mockito.Mockito.verify;
16
17 import javax.measure.quantity.Dimensionless;
18 import javax.measure.quantity.Temperature;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandlerTest;
23 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.SIUnits;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.thing.ChannelUID;
28 import org.openhab.core.thing.ThingTypeUID;
29
30 import com.google.gson.JsonElement;
31 import com.google.gson.JsonParser;
32
33 /**
34  * Unit Tests for {@link WallThermostatHandler}.
35  *
36  * @author David Pace - Initial contribution
37  *
38  */
39 @NonNullByDefault
40 class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<WallThermostatHandler> {
41
42     @Override
43     protected WallThermostatHandler createFixture() {
44         return new WallThermostatHandler(getThing());
45     }
46
47     @Override
48     protected String getDeviceID() {
49         return "hdm:ZigBee:000d6f0016d1a193";
50     }
51
52     @Override
53     protected ThingTypeUID getThingTypeUID() {
54         return BoschSHCBindingConstants.THING_TYPE_WALL_THERMOSTAT;
55     }
56
57     @Test
58     void testUpdateChannelsTemperatureLevelService() {
59         JsonElement jsonObject = JsonParser.parseString("""
60                 {
61                    "@type": "temperatureLevelState",
62                    "temperature": 21.5
63                  }\
64                 """);
65         getFixture().processUpdate("TemperatureLevel", jsonObject);
66         verify(getCallback()).stateUpdated(
67                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
68                 new QuantityType<Temperature>(21.5, SIUnits.CELSIUS));
69     }
70
71     @Test
72     void testUpdateChannelsHumidityLevelService() {
73         JsonElement jsonObject = JsonParser
74                 .parseString("{\n" + "   \"@type\": \"humidityLevelState\",\n" + "   \"humidity\": 42.5\n" + " }");
75         getFixture().processUpdate("HumidityLevel", jsonObject);
76         verify(getCallback()).stateUpdated(
77                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_HUMIDITY),
78                 new QuantityType<Dimensionless>(42.5, Units.PERCENT));
79     }
80 }