]> git.basschouten.com Git - openhab-addons.git/blob
86dc3120bf0a13977969c692ea442357423d45b1
[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 public 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     public 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     public void testUpdateChannelsTemperatureLevelService() {
81         JsonElement jsonObject = JsonParser.parseString(
82                 "{\n" + "   \"@type\": \"temperatureLevelState\",\n" + "   \"temperature\": 21.5\n" + " }");
83         getFixture().processUpdate("TemperatureLevel", jsonObject);
84         verify(getCallback()).stateUpdated(
85                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
86                 new QuantityType<Temperature>(21.5, SIUnits.CELSIUS));
87     }
88
89     @Test
90     public void testUpdateChannelsRoomClimateControlService() {
91         JsonElement jsonObject = JsonParser.parseString(
92                 "{\n" + "   \"@type\": \"climateControlState\",\n" + "   \"setpointTemperature\": 21.5\n" + " }");
93         getFixture().processUpdate("RoomClimateControl", jsonObject);
94         verify(getCallback()).stateUpdated(
95                 new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SETPOINT_TEMPERATURE),
96                 new QuantityType<Temperature>(21.5, SIUnits.CELSIUS));
97     }
98 }