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.boschshc.internal.devices.climatecontrol;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeoutException;
22 import javax.measure.quantity.Temperature;
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;
37 import com.google.gson.JsonElement;
38 import com.google.gson.JsonParser;
41 * Unit tests for {@link ClimateControlHandler}.
43 * @author David Pace - Initial contribution
47 class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<ClimateControlHandler> {
49 private @Captor @NonNullByDefault({}) ArgumentCaptor<RoomClimateControlServiceState> roomClimateControlServiceStateCaptor;
52 protected String getDeviceID() {
53 return "hdm:ZigBee:abcd6fc012ad25b1";
57 protected ClimateControlHandler createFixture() {
58 return new ClimateControlHandler(getThing());
62 protected ThingTypeUID getThingTypeUID() {
63 return BoschSHCBindingConstants.THING_TYPE_CLIMATE_CONTROL;
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),
73 verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("RoomClimateControl"),
74 roomClimateControlServiceStateCaptor.capture());
75 RoomClimateControlServiceState state = roomClimateControlServiceStateCaptor.getValue();
76 assertEquals(temperature, state.getSetpointTemperatureState());
80 void testUpdateChannelsTemperatureLevelService() {
81 JsonElement jsonObject = JsonParser.parseString("""
83 "@type": "temperatureLevelState",
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));
94 void testUpdateChannelsRoomClimateControlService() {
95 JsonElement jsonObject = JsonParser.parseString("""
97 "@type": "climateControlState",
98 "setpointTemperature": 21.5
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));