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.mielecloud.internal.handler;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.ArgumentMatchers.anyInt;
17 import static org.mockito.Mockito.*;
18 import static org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants.Channels.*;
19 import static org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants.HOB_DEVICE_THING_UID;
21 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants;
26 import org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants;
27 import org.openhab.binding.mielecloud.internal.webservice.api.DeviceState;
28 import org.openhab.binding.mielecloud.internal.webservice.api.json.StateType;
29 import org.openhab.core.library.types.DecimalType;
30 import org.openhab.core.library.types.OnOffType;
31 import org.openhab.core.library.types.StringType;
34 * @author Björn Lange - Initial contribution
35 * @author Benjamin Bolte - Add plate step
36 * @author Benjamin Bolte - Add info state channel and map signal flags from API tests
39 public class HobDeviceThingHandlerTest extends AbstractMieleThingHandlerTest {
41 protected AbstractMieleThingHandler setUpThingHandler() {
42 return createThingHandler(MieleCloudBindingConstants.THING_TYPE_HOB, HOB_DEVICE_THING_UID,
43 HobDeviceThingHandler.class, MieleCloudBindingIntegrationTestConstants.SERIAL_NUMBER, "0");
47 public void testChannelUpdatesForNullValues() throws Exception {
49 setUpBridgeAndThing();
51 DeviceState deviceState = mock(DeviceState.class);
52 when(deviceState.getDeviceIdentifier()).thenReturn(HOB_DEVICE_THING_UID.getId());
53 when(deviceState.getStateType()).thenReturn(Optional.empty());
54 when(deviceState.isRemoteControlEnabled()).thenReturn(Optional.empty());
55 when(deviceState.getStatus()).thenReturn(Optional.empty());
56 when(deviceState.getStatusRaw()).thenReturn(Optional.empty());
57 when(deviceState.getPlateStep(anyInt())).thenReturn(Optional.empty());
58 when(deviceState.getPlateStepRaw(anyInt())).thenReturn(Optional.empty());
61 getBridgeHandler().onDeviceStateUpdated(deviceState);
65 assertEquals(NULL_VALUE_STATE, getChannelState(OPERATION_STATE));
66 assertEquals(NULL_VALUE_STATE, getChannelState(OPERATION_STATE_RAW));
67 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_1_POWER_STEP));
68 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_1_POWER_STEP_RAW));
69 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_2_POWER_STEP));
70 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_2_POWER_STEP_RAW));
71 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_3_POWER_STEP));
72 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_3_POWER_STEP_RAW));
73 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_4_POWER_STEP));
74 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_4_POWER_STEP_RAW));
75 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_5_POWER_STEP));
76 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_5_POWER_STEP_RAW));
77 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_6_POWER_STEP));
78 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_6_POWER_STEP_RAW));
83 public void testChannelUpdatesForValidValues() throws Exception {
85 setUpBridgeAndThing();
87 DeviceState deviceState = mock(DeviceState.class);
88 when(deviceState.getDeviceIdentifier()).thenReturn(HOB_DEVICE_THING_UID.getId());
89 when(deviceState.getStateType()).thenReturn(Optional.of(StateType.RUNNING));
90 when(deviceState.isRemoteControlEnabled()).thenReturn(Optional.of(false));
91 when(deviceState.getStatus()).thenReturn(Optional.of("Running"));
92 when(deviceState.getStatusRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
93 when(deviceState.hasError()).thenReturn(false);
94 when(deviceState.hasInfo()).thenReturn(true);
95 when(deviceState.getPlateStep(0)).thenReturn(Optional.of("1."));
96 when(deviceState.getPlateStepRaw(0)).thenReturn(Optional.of(2));
97 when(deviceState.getPlateStep(1)).thenReturn(Optional.empty());
98 when(deviceState.getPlateStep(2)).thenReturn(Optional.empty());
99 when(deviceState.getPlateStep(3)).thenReturn(Optional.empty());
100 when(deviceState.getPlateStep(4)).thenReturn(Optional.empty());
101 when(deviceState.getPlateStep(5)).thenReturn(Optional.empty());
104 getBridgeHandler().onDeviceStateUpdated(deviceState);
107 waitForAssert(() -> {
108 assertEquals(new StringType("Running"), getChannelState(OPERATION_STATE));
109 assertEquals(new DecimalType(StateType.RUNNING.getCode()), getChannelState(OPERATION_STATE_RAW));
110 assertEquals(OnOffType.OFF, getChannelState(ERROR_STATE));
111 assertEquals(OnOffType.ON, getChannelState(INFO_STATE));
112 assertEquals(new StringType("1."), getChannelState(PLATE_1_POWER_STEP));
113 assertEquals(new DecimalType(2), getChannelState(PLATE_1_POWER_STEP_RAW));
114 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_2_POWER_STEP));
115 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_2_POWER_STEP_RAW));
116 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_3_POWER_STEP));
117 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_3_POWER_STEP_RAW));
118 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_4_POWER_STEP));
119 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_4_POWER_STEP_RAW));
120 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_5_POWER_STEP));
121 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_5_POWER_STEP_RAW));
122 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_6_POWER_STEP));
123 assertEquals(NULL_VALUE_STATE, getChannelState(PLATE_6_POWER_STEP_RAW));