]> git.basschouten.com Git - openhab-addons.git/blob
05911dd539ec062c7613afdae28188eda6559a16
[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.boschshc.internal.devices.climatecontrol;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
18
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeoutException;
21
22 import javax.measure.quantity.Temperature;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.junit.jupiter.api.Test;
26 import org.mockito.ArgumentCaptor;
27 import org.mockito.Captor;
28 import org.openhab.binding.boschshc.internal.devices.AbstractBoschSHCDeviceHandlerTest;
29 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
30 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
31 import org.openhab.binding.boschshc.internal.services.roomclimatecontrol.dto.RoomClimateControlServiceState;
32 import org.openhab.core.library.types.QuantityType;
33 import org.openhab.core.library.unit.SIUnits;
34 import org.openhab.core.thing.ChannelUID;
35 import org.openhab.core.thing.ThingTypeUID;
36
37 import com.google.gson.JsonElement;
38 import com.google.gson.JsonParser;
39
40 /**
41  * Unit tests for {@link ClimateControlHandler}.
42  *
43  * @author David Pace - Initial contribution
44  *
45  */
46 @NonNullByDefault
47 class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ClimateControlHandler> {
48
49     private @Captor @NonNullByDefault({}) ArgumentCaptor<RoomClimateControlServiceState> roomClimateControlServiceStateCaptor;
50
51     @Override
52     protected String getDeviceID() {
53         return "hdm:ZigBee:abcd6fc012ad25b1";
54     }
55
56     @Override
57     protected ClimateControlHandler createFixture() {
58         return new ClimateControlHandler(getThing());
59     }
60
61     @Override
62     protected ThingTypeUID getThingTypeUID() {
63         return BoschSHCBindingConstants.THING_TYPE_CLIMATE_CONTROL;
64     }
65
66     @Test
67     void testHandleCommandRoomClimateControlService()
68             throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
69         QuantityType<Temperature> temperature = new QuantityType<>(21.5, SIUnits.CELSIUS);
70         getFixture().handleCommand(
71                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SETPOINT_TEMPERATURE),
72                 temperature);
73         verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("RoomClimateControl"),
74                 roomClimateControlServiceStateCaptor.capture());
75         RoomClimateControlServiceState state = roomClimateControlServiceStateCaptor.getValue();
76         assertEquals(temperature, state.getSetpointTemperatureState());
77     }
78
79     @Test
80     void testUpdateChannelsTemperatureLevelService() {
81         JsonElement jsonObject = JsonParser.parseString("""
82                 {
83                    "@type": "temperatureLevelState",
84                    "temperature": 21.5
85                  }\
86                 """);
87         getFixture().processUpdate("TemperatureLevel", jsonObject);
88         verify(getCallback()).stateUpdated(
89                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
90                 new QuantityType<Temperature>(21.5, SIUnits.CELSIUS));
91     }
92
93     @Test
94     void testUpdateChannelsRoomClimateControlService() {
95         JsonElement jsonObject = JsonParser.parseString("""
96                 {
97                    "@type": "climateControlState",
98                    "setpointTemperature": 21.5
99                  }\
100                 """);
101         getFixture().processUpdate("RoomClimateControl", jsonObject);
102         verify(getCallback()).stateUpdated(
103                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SETPOINT_TEMPERATURE),
104                 new QuantityType<Temperature>(21.5, SIUnits.CELSIUS));
105     }
106 }