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.webservice.api;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.LinkedList;
21 import java.util.List;
22 import java.util.Optional;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.mielecloud.internal.webservice.api.json.Device;
27 import org.openhab.binding.mielecloud.internal.webservice.api.json.DeviceIdentLabel;
28 import org.openhab.binding.mielecloud.internal.webservice.api.json.DeviceType;
29 import org.openhab.binding.mielecloud.internal.webservice.api.json.DryingStep;
30 import org.openhab.binding.mielecloud.internal.webservice.api.json.EcoFeedback;
31 import org.openhab.binding.mielecloud.internal.webservice.api.json.EnergyConsumption;
32 import org.openhab.binding.mielecloud.internal.webservice.api.json.Ident;
33 import org.openhab.binding.mielecloud.internal.webservice.api.json.Light;
34 import org.openhab.binding.mielecloud.internal.webservice.api.json.PlateStep;
35 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramId;
36 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramPhase;
37 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramType;
38 import org.openhab.binding.mielecloud.internal.webservice.api.json.RemoteEnable;
39 import org.openhab.binding.mielecloud.internal.webservice.api.json.SpinningSpeed;
40 import org.openhab.binding.mielecloud.internal.webservice.api.json.State;
41 import org.openhab.binding.mielecloud.internal.webservice.api.json.StateType;
42 import org.openhab.binding.mielecloud.internal.webservice.api.json.Status;
43 import org.openhab.binding.mielecloud.internal.webservice.api.json.Temperature;
44 import org.openhab.binding.mielecloud.internal.webservice.api.json.Type;
45 import org.openhab.binding.mielecloud.internal.webservice.api.json.VentilationStep;
46 import org.openhab.binding.mielecloud.internal.webservice.api.json.WaterConsumption;
49 * @author Björn Lange - Initial contribution
50 * @author Benjamin Bolte - Add pre-heat finished, plate step, door state, door alarm and info state channels and map
51 * signal flags from API
52 * @author Björn Lange - Add elapsed time channel, robotic vacuum cleaner, eco feedback
55 public class DeviceStateTest {
56 private static final String DEVICE_IDENTIFIER = "mac-f83001f37d45ffff";
59 public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
61 Device device = mock(Device.class);
62 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
65 String deviceId = deviceState.getDeviceIdentifier();
68 assertEquals(DEVICE_IDENTIFIER, deviceId);
72 public void testReturnValuesWhenDeviceIsNull() {
74 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, null);
77 Optional<String> status = deviceState.getStatus();
78 Optional<Integer> statusRaw = deviceState.getStatusRaw();
79 Optional<StateType> stateType = deviceState.getStateType();
80 Optional<String> selectedProgram = deviceState.getSelectedProgram();
81 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
82 Optional<String> programPhase = deviceState.getProgramPhase();
83 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
84 Optional<String> dryingTarget = deviceState.getDryingTarget();
85 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
86 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
87 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
88 Optional<Integer> temperature = deviceState.getTemperature(0);
89 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
90 Optional<String> ventilationStep = deviceState.getVentilationStep();
91 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
92 Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
93 Optional<String> plateStep = deviceState.getPlateStep(0);
94 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
95 boolean hasError = deviceState.hasError();
96 boolean hasInfo = deviceState.hasInfo();
97 Optional<Boolean> doorState = deviceState.getDoorState();
98 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
99 Optional<String> type = deviceState.getType();
100 DeviceType rawType = deviceState.getRawType();
101 Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
103 Optional<String> deviceName = deviceState.getDeviceName();
104 Optional<String> fabNumber = deviceState.getFabNumber();
105 Optional<String> techType = deviceState.getTechType();
106 Optional<Integer> progress = deviceState.getProgress();
109 assertFalse(status.isPresent());
110 assertFalse(statusRaw.isPresent());
111 assertFalse(stateType.isPresent());
112 assertFalse(selectedProgram.isPresent());
113 assertFalse(selectedProgramId.isPresent());
114 assertFalse(programPhase.isPresent());
115 assertFalse(programPhaseRaw.isPresent());
116 assertFalse(dryingTarget.isPresent());
117 assertFalse(dryingTargetRaw.isPresent());
118 assertFalse(hasPreHeatFinished.isPresent());
119 assertFalse(targetTemperature.isPresent());
120 assertFalse(temperature.isPresent());
121 assertFalse(remoteControlEnabled.isPresent());
122 assertFalse(ventilationStep.isPresent());
123 assertFalse(ventilationStepRaw.isPresent());
124 assertFalse(plateStepCount.isPresent());
125 assertFalse(plateStep.isPresent());
126 assertFalse(plateStepRaw.isPresent());
127 assertFalse(hasError);
128 assertFalse(hasInfo);
129 assertFalse(doorState.isPresent());
130 assertFalse(doorAlarm.isPresent());
131 assertFalse(type.isPresent());
132 assertEquals(DeviceType.UNKNOWN, rawType);
133 assertFalse(deviceName.isPresent());
134 assertFalse(fabNumber.isPresent());
135 assertFalse(techType.isPresent());
136 assertFalse(progress.isPresent());
137 assertFalse(batteryLevel.isPresent());
141 public void testReturnValuesWhenStateIsNull() {
143 Device device = mock(Device.class);
144 when(device.getState()).thenReturn(Optional.empty());
145 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
148 Optional<String> status = deviceState.getStatus();
149 Optional<Integer> statusRaw = deviceState.getStatusRaw();
150 Optional<StateType> stateType = deviceState.getStateType();
151 Optional<String> selectedProgram = deviceState.getSelectedProgram();
152 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
153 Optional<String> programPhase = deviceState.getProgramPhase();
154 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
155 Optional<String> dryingTarget = deviceState.getDryingTarget();
156 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
157 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
158 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
159 Optional<Integer> temperature = deviceState.getTemperature(0);
160 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
161 Optional<Integer> progress = deviceState.getProgress();
162 Optional<String> ventilationStep = deviceState.getVentilationStep();
163 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
164 Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
165 Optional<String> plateStep = deviceState.getPlateStep(0);
166 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
167 Boolean hasError = deviceState.hasError();
168 Optional<Boolean> doorState = deviceState.getDoorState();
169 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
170 Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
173 assertFalse(status.isPresent());
174 assertFalse(statusRaw.isPresent());
175 assertFalse(stateType.isPresent());
176 assertFalse(selectedProgram.isPresent());
177 assertFalse(selectedProgramId.isPresent());
178 assertFalse(programPhase.isPresent());
179 assertFalse(programPhaseRaw.isPresent());
180 assertFalse(dryingTarget.isPresent());
181 assertFalse(dryingTargetRaw.isPresent());
182 assertFalse(hasPreHeatFinished.isPresent());
183 assertFalse(targetTemperature.isPresent());
184 assertFalse(temperature.isPresent());
185 assertFalse(remoteControlEnabled.isPresent());
186 assertFalse(progress.isPresent());
187 assertFalse(ventilationStep.isPresent());
188 assertFalse(ventilationStepRaw.isPresent());
189 assertFalse(plateStepCount.isPresent());
190 assertFalse(plateStep.isPresent());
191 assertFalse(plateStepRaw.isPresent());
192 assertFalse(hasError);
193 assertFalse(doorState.isPresent());
194 assertFalse(doorAlarm.isPresent());
195 assertFalse(batteryLevel.isPresent());
199 public void testReturnValuesWhenStatusIsEmpty() {
201 State state = mock(State.class);
202 when(state.getStatus()).thenReturn(Optional.empty());
204 Device device = mock(Device.class);
205 when(device.getState()).thenReturn(Optional.of(state));
206 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
209 Optional<String> status = deviceState.getStatus();
210 Optional<Integer> statusRaw = deviceState.getStatusRaw();
211 Optional<StateType> stateType = deviceState.getStateType();
214 assertFalse(status.isPresent());
215 assertFalse(statusRaw.isPresent());
216 assertFalse(stateType.isPresent());
220 public void testReturnValuesWhenStatusValuesAreEmpty() {
222 Status statusMock = mock(Status.class);
223 when(statusMock.getValueLocalized()).thenReturn(Optional.empty());
224 when(statusMock.getValueRaw()).thenReturn(Optional.empty());
226 State state = mock(State.class);
227 when(state.getStatus()).thenReturn(Optional.of(statusMock));
229 Device device = mock(Device.class);
230 when(device.getState()).thenReturn(Optional.of(state));
231 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
234 Optional<String> status = deviceState.getStatus();
235 Optional<Integer> statusRaw = deviceState.getStatusRaw();
236 Optional<StateType> stateType = deviceState.getStateType();
239 assertFalse(status.isPresent());
240 assertFalse(statusRaw.isPresent());
241 assertFalse(stateType.isPresent());
245 public void testReturnValuesWhenStatusValueLocalizedIsNotNull() {
247 Status statusMock = mock(Status.class);
248 when(statusMock.getValueLocalized()).thenReturn(Optional.of("Not connected"));
249 when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.NOT_CONNECTED.getCode()));
251 State state = mock(State.class);
252 when(state.getStatus()).thenReturn(Optional.of(statusMock));
254 Device device = mock(Device.class);
255 when(device.getState()).thenReturn(Optional.of(state));
256 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
259 String status = deviceState.getStatus().get();
260 int statusRaw = deviceState.getStatusRaw().get();
261 StateType stateType = deviceState.getStateType().get();
264 assertEquals("Not connected", status);
265 assertEquals(StateType.NOT_CONNECTED.getCode(), statusRaw);
266 assertEquals(StateType.NOT_CONNECTED, stateType);
270 public void testReturnValuesWhenStatusValueRawIsNotNull() {
272 Status statusMock = mock(Status.class);
273 when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.END_PROGRAMMED.getCode()));
275 State state = mock(State.class);
276 when(state.getStatus()).thenReturn(Optional.of(statusMock));
278 Device device = mock(Device.class);
279 when(device.getState()).thenReturn(Optional.of(state));
280 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
283 StateType stateType = deviceState.getStateType().get();
286 assertEquals(StateType.END_PROGRAMMED, stateType);
290 public void testReturnValuesWhenProgramTypeIsEmpty() {
292 State state = mock(State.class);
293 when(state.getProgramType()).thenReturn(Optional.empty());
295 Device device = mock(Device.class);
296 when(device.getState()).thenReturn(Optional.of(state));
297 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
300 Optional<String> selectedProgram = deviceState.getSelectedProgram();
301 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
304 assertFalse(selectedProgram.isPresent());
305 assertFalse(selectedProgramId.isPresent());
309 public void testReturnValuesWhenProgramTypeValueLocalizedIsEmpty() {
311 ProgramType programType = mock(ProgramType.class);
312 when(programType.getValueLocalized()).thenReturn(Optional.empty());
314 State state = mock(State.class);
315 when(state.getProgramType()).thenReturn(Optional.of(programType));
317 Device device = mock(Device.class);
318 when(device.getState()).thenReturn(Optional.of(state));
319 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
322 Optional<String> selectedProgram = deviceState.getSelectedProgram();
323 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
326 assertFalse(selectedProgram.isPresent());
327 assertFalse(selectedProgramId.isPresent());
331 public void testReturnValuesWhenProgramTypeValueLocalizedIsNotNull() {
333 ProgramId programId = mock(ProgramId.class);
334 when(programId.getValueRaw()).thenReturn(Optional.of(3L));
335 when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
337 State state = mock(State.class);
338 Status status = mock(Status.class);
339 Device device = mock(Device.class);
340 when(state.getStatus()).thenReturn(Optional.of(status));
341 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
342 when(state.getProgramId()).thenReturn(Optional.of(programId));
343 when(device.getState()).thenReturn(Optional.of(state));
344 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
347 String selectedProgram = deviceState.getSelectedProgram().get();
348 long selectedProgramId = deviceState.getSelectedProgramId().get();
351 assertEquals("Washing", selectedProgram);
352 assertEquals(3L, selectedProgramId);
356 public void testReturnValuesWhenProgramPhaseIsEmpty() {
358 State state = mock(State.class);
359 when(state.getProgramPhase()).thenReturn(Optional.empty());
361 Device device = mock(Device.class);
362 when(device.getState()).thenReturn(Optional.of(state));
363 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
366 Optional<String> programPhase = deviceState.getProgramPhase();
367 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
370 assertFalse(programPhase.isPresent());
371 assertFalse(programPhaseRaw.isPresent());
375 public void testReturnValuesWhenProgramPhaseValueLocalizedIsEmpty() {
377 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
378 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.empty());
380 State state = mock(State.class);
381 when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
383 Device device = mock(Device.class);
384 when(device.getState()).thenReturn(Optional.of(state));
385 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
388 Optional<String> programPhase = deviceState.getProgramPhase();
389 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
392 assertFalse(programPhase.isPresent());
393 assertFalse(programPhaseRaw.isPresent());
397 public void testReturnValuesWhenProgramPhaseValueLocalizedIsNotNull() {
399 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
400 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.of("Spülen"));
401 when(programPhaseMock.getValueRaw()).thenReturn(Optional.of(4));
403 State state = mock(State.class);
404 Status status = mock(Status.class);
405 Device device = mock(Device.class);
406 when(state.getStatus()).thenReturn(Optional.of(status));
407 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
408 when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
409 when(device.getState()).thenReturn(Optional.of(state));
410 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
413 String programPhase = deviceState.getProgramPhase().get();
414 int programPhaseRaw = deviceState.getProgramPhaseRaw().get();
417 assertEquals("Spülen", programPhase);
418 assertEquals(4, programPhaseRaw);
422 public void testReturnValuesWhenDryingStepIsEmpty() {
424 State state = mock(State.class);
425 when(state.getDryingStep()).thenReturn(Optional.empty());
427 Device device = mock(Device.class);
428 when(device.getState()).thenReturn(Optional.of(state));
429 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
432 Optional<String> dryingTarget = deviceState.getDryingTarget();
433 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
436 assertFalse(dryingTarget.isPresent());
437 assertFalse(dryingTargetRaw.isPresent());
441 public void testReturnValuesWhenDryingStepValueLocalizedIsEmpty() {
443 DryingStep dryingStep = mock(DryingStep.class);
444 when(dryingStep.getValueLocalized()).thenReturn(Optional.empty());
445 when(dryingStep.getValueRaw()).thenReturn(Optional.empty());
447 State state = mock(State.class);
448 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
450 Device device = mock(Device.class);
451 when(device.getState()).thenReturn(Optional.of(state));
452 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
455 Optional<String> dryingTarget = deviceState.getDryingTarget();
456 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
459 assertFalse(dryingTarget.isPresent());
460 assertFalse(dryingTargetRaw.isPresent());
464 public void testReturnValuesWhenDryingStepValueLocalizedIsNotNull() {
466 DryingStep dryingStep = mock(DryingStep.class);
467 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Hot"));
468 when(dryingStep.getValueRaw()).thenReturn(Optional.of(5));
470 State state = mock(State.class);
471 Device device = mock(Device.class);
472 Status status = mock(Status.class);
473 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
474 when(state.getStatus()).thenReturn(Optional.of(status));
475 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
476 when(device.getState()).thenReturn(Optional.of(state));
477 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
480 String dryingTarget = deviceState.getDryingTarget().get();
481 int dryingTargetRaw = deviceState.getDryingTargetRaw().get();
484 assertEquals("Hot", dryingTarget);
485 assertEquals(5, dryingTargetRaw);
489 public void testReturnValuesPreHeatFinishedWhenStateIsNotRunning() {
491 Temperature targetTemperature = mock(Temperature.class);
492 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(0));
493 Temperature currentTemperature = mock(Temperature.class);
494 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(0));
496 Status status = mock(Status.class);
497 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
499 State state = mock(State.class);
500 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
501 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
502 when(state.getStatus()).thenReturn(Optional.of(status));
504 Device device = mock(Device.class);
505 when(device.getState()).thenReturn(Optional.of(state));
507 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
510 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
513 assertFalse(hasPreHeatFinished.get());
517 public void testReturnValuesPreHeatFinishedWhenTargetTemperatureIsEmpty() {
519 Temperature targetTemperature = mock(Temperature.class);
520 when(targetTemperature.getValueLocalized()).thenReturn(Optional.empty());
521 Temperature currentTemperature = mock(Temperature.class);
522 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
524 Status status = mock(Status.class);
525 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
527 State state = mock(State.class);
528 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
529 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
530 when(state.getStatus()).thenReturn(Optional.of(status));
532 Device device = mock(Device.class);
533 when(device.getState()).thenReturn(Optional.of(state));
535 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
538 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
541 assertFalse(hasPreHeatFinished.isPresent());
545 public void testReturnValuesPreHeatFinishedWhenCurrentTemperatureIsEmpty() {
547 Temperature targetTemperature = mock(Temperature.class);
548 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
549 Temperature currentTemperature = mock(Temperature.class);
550 when(currentTemperature.getValueLocalized()).thenReturn(Optional.empty());
552 Status status = mock(Status.class);
553 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
555 State state = mock(State.class);
556 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
557 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
558 when(state.getStatus()).thenReturn(Optional.of(status));
560 Device device = mock(Device.class);
561 when(device.getState()).thenReturn(Optional.of(state));
563 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
566 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
569 assertFalse(hasPreHeatFinished.isPresent());
573 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasFinished() {
575 Temperature targetTemperature = mock(Temperature.class);
576 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
577 Temperature currentTemperature = mock(Temperature.class);
578 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
580 Status status = mock(Status.class);
581 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
583 State state = mock(State.class);
584 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
585 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
586 when(state.getStatus()).thenReturn(Optional.of(status));
588 Device device = mock(Device.class);
589 when(device.getState()).thenReturn(Optional.of(state));
591 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
594 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
597 assertTrue(hasPreHeatFinished.get());
601 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasNotFinished() {
603 Temperature targetTemperature = mock(Temperature.class);
604 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
605 Temperature currentTemperature = mock(Temperature.class);
606 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(179));
608 Status status = mock(Status.class);
609 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
611 State state = mock(State.class);
612 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
613 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
614 when(state.getStatus()).thenReturn(Optional.of(status));
616 Device device = mock(Device.class);
617 when(device.getState()).thenReturn(Optional.of(state));
619 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
622 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
625 assertFalse(hasPreHeatFinished.get());
629 public void testReturnValuesWhenTargetTemperatureIsEmpty() {
631 State state = mock(State.class);
632 when(state.getTargetTemperature()).thenReturn(Collections.emptyList());
634 Device device = mock(Device.class);
635 when(device.getState()).thenReturn(Optional.of(state));
636 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
639 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
642 assertFalse(targetTemperature.isPresent());
646 public void testReturnValuesWhenTargetTemperatureIndexIsOutOfRange() {
648 Status status = mock(Status.class);
649 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
651 State state = mock(State.class);
652 when(state.getTargetTemperature()).thenReturn(new LinkedList<>());
653 when(state.getStatus()).thenReturn(Optional.of(status));
655 Device device = mock(Device.class);
656 when(device.getState()).thenReturn(Optional.of(state));
657 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
660 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
663 assertFalse(targetTemperature.isPresent());
667 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsEmpty() {
669 Status status = mock(Status.class);
670 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
672 Temperature temperature = mock(Temperature.class);
673 when(temperature.getValueLocalized()).thenReturn(Optional.empty());
675 State state = mock(State.class);
676 when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
677 when(state.getStatus()).thenReturn(Optional.of(status));
679 Device device = mock(Device.class);
680 when(device.getState()).thenReturn(Optional.of(state));
681 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
684 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
687 assertFalse(targetTemperature.isPresent());
691 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsValid() {
693 Temperature temperature = mock(Temperature.class);
694 when(temperature.getValueLocalized()).thenReturn(Optional.of(20));
696 State state = mock(State.class);
697 Status status = mock(Status.class);
698 Device device = mock(Device.class);
699 when(state.getStatus()).thenReturn(Optional.of(status));
700 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
701 when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
702 when(device.getState()).thenReturn(Optional.of(state));
703 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
706 Integer targetTemperature = deviceState.getTargetTemperature(0).get();
709 assertEquals(Integer.valueOf(20), targetTemperature);
713 public void testReturnValuesWhenTemperatureIsEmpty() {
715 Status status = mock(Status.class);
716 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
718 State state = mock(State.class);
719 when(state.getTemperature()).thenReturn(Collections.emptyList());
720 when(state.getStatus()).thenReturn(Optional.of(status));
722 Device device = mock(Device.class);
723 when(device.getState()).thenReturn(Optional.of(state));
724 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
727 Optional<Integer> temperature = deviceState.getTemperature(0);
730 assertFalse(temperature.isPresent());
734 public void testReturnValuesWhenVentilationStepIsEmpty() {
736 State state = mock(State.class);
737 when(state.getVentilationStep()).thenReturn(Optional.empty());
739 Device device = mock(Device.class);
740 when(device.getState()).thenReturn(Optional.of(state));
741 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
744 Optional<String> ventilationStep = deviceState.getVentilationStep();
745 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
748 assertFalse(ventilationStep.isPresent());
749 assertFalse(ventilationStepRaw.isPresent());
753 public void testReturnValuesWhenTemperatureIndexIsOutOfRange() {
755 Status status = mock(Status.class);
756 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
758 State state = mock(State.class);
759 when(state.getTemperature()).thenReturn(new LinkedList<>());
760 when(state.getStatus()).thenReturn(Optional.of(status));
762 Device device = mock(Device.class);
763 when(device.getState()).thenReturn(Optional.of(state));
764 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
767 Optional<Integer> temperature = deviceState.getTemperature(-1);
770 assertFalse(temperature.isPresent());
774 public void testReturnValuesWhenTemperatureValueLocalizedIsEmpty() {
776 Status status = mock(Status.class);
777 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
779 Temperature temperatureMock = mock(Temperature.class);
780 when(temperatureMock.getValueLocalized()).thenReturn(Optional.empty());
782 State state = mock(State.class);
783 when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
784 when(state.getStatus()).thenReturn(Optional.of(status));
786 Device device = mock(Device.class);
787 when(device.getState()).thenReturn(Optional.of(state));
788 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
791 Optional<Integer> temperature = deviceState.getTemperature(0);
794 assertFalse(temperature.isPresent());
798 public void testReturnValuesWhenTemperatureValueLocalizedIsValid() {
800 Temperature temperatureMock = mock(Temperature.class);
801 when(temperatureMock.getValueLocalized()).thenReturn(Optional.of(10));
803 State state = mock(State.class);
804 Device device = mock(Device.class);
805 Status status = mock(Status.class);
806 when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
807 when(state.getStatus()).thenReturn(Optional.of(status));
808 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
809 when(device.getState()).thenReturn(Optional.of(state));
810 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
813 Integer temperature = deviceState.getTemperature(0).get();
816 assertEquals(Integer.valueOf(10), temperature);
820 public void testReturnValuesWhenPlatStepIndexIsOutOfRange() {
822 Status status = mock(Status.class);
823 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
825 State state = mock(State.class);
826 when(state.getPlateStep()).thenReturn(Collections.emptyList());
827 when(state.getStatus()).thenReturn(Optional.of(status));
829 Device device = mock(Device.class);
830 when(device.getState()).thenReturn(Optional.of(state));
831 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
834 int plateStepCount = deviceState.getPlateStepCount().get();
835 Optional<String> plateStep = deviceState.getPlateStep(0);
836 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
839 assertEquals(0, plateStepCount);
840 assertFalse(plateStep.isPresent());
841 assertFalse(plateStepRaw.isPresent());
845 public void testReturnValuesWhenPlateStepValueIsEmpty() {
847 Status status = mock(Status.class);
848 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
850 PlateStep plateStepMock = mock(PlateStep.class);
851 when(plateStepMock.getValueRaw()).thenReturn(Optional.empty());
852 when(plateStepMock.getValueLocalized()).thenReturn(Optional.empty());
854 State state = mock(State.class);
855 when(state.getPlateStep()).thenReturn(List.of(plateStepMock));
856 when(state.getStatus()).thenReturn(Optional.of(status));
858 Device device = mock(Device.class);
859 when(device.getState()).thenReturn(Optional.of(state));
860 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
863 int plateStepCount = deviceState.getPlateStepCount().get();
864 Optional<String> plateStep = deviceState.getPlateStep(0);
865 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
868 assertEquals(1, plateStepCount);
869 assertFalse(plateStep.isPresent());
870 assertFalse(plateStepRaw.isPresent());
874 public void testReturnValuesWhenPlateStepValueIsValid() {
876 PlateStep plateStepMock = mock(PlateStep.class);
877 when(plateStepMock.getValueRaw()).thenReturn(Optional.of(2));
878 when(plateStepMock.getValueLocalized()).thenReturn(Optional.of("1."));
880 State state = mock(State.class);
881 Status status = mock(Status.class);
882 Device device = mock(Device.class);
883 when(state.getStatus()).thenReturn(Optional.of(status));
884 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
885 when(state.getPlateStep()).thenReturn(Arrays.asList(plateStepMock));
886 when(device.getState()).thenReturn(Optional.of(state));
887 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
890 int plateStepCount = deviceState.getPlateStepCount().get();
891 String plateStep = deviceState.getPlateStep(0).get();
892 int plateStepRaw = deviceState.getPlateStepRaw(0).get();
895 assertEquals(1, plateStepCount);
896 assertEquals("1.", plateStep);
897 assertEquals(2, plateStepRaw);
901 public void testReturnValuesWhenRemainingTimeIsEmpty() {
903 State state = mock(State.class);
904 when(state.getRemainingTime()).thenReturn(Optional.empty());
905 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
907 Device device = mock(Device.class);
908 when(device.getState()).thenReturn(Optional.of(state));
909 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
912 Optional<Integer> progress = deviceState.getProgress();
915 assertFalse(progress.isPresent());
919 public void testReturnValuesWhenRemainingTimeSizeIsNotTwo() {
921 Status status = mock(Status.class);
922 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
924 State state = mock(State.class);
925 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(2)));
926 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
927 when(state.getStatus()).thenReturn(Optional.of(status));
929 Device device = mock(Device.class);
930 when(device.getState()).thenReturn(Optional.of(state));
931 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
934 Optional<Integer> progress = deviceState.getProgress();
937 assertFalse(progress.isPresent());
941 public void testReturnValuesWhenRemoteEnableIsEmpty() {
943 State state = mock(State.class);
944 when(state.getRemoteEnable()).thenReturn(Optional.empty());
946 Device device = mock(Device.class);
947 when(device.getState()).thenReturn(Optional.of(state));
948 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
951 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
954 assertFalse(remoteControlEnabled.isPresent());
958 public void testReturnValuesWhenFullRemoteControlIsEmpty() {
960 RemoteEnable remoteEnable = mock(RemoteEnable.class);
961 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.empty());
963 State state = mock(State.class);
964 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
966 Device device = mock(Device.class);
967 when(device.getState()).thenReturn(Optional.of(state));
968 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
971 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
974 assertFalse(remoteControlEnabled.isPresent());
978 public void testReturnValuesWhenFullRemoteControlIsNotNull() {
980 RemoteEnable remoteEnable = mock(RemoteEnable.class);
981 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.of(true));
983 State state = mock(State.class);
984 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
986 Device device = mock(Device.class);
987 when(device.getState()).thenReturn(Optional.of(state));
988 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
991 Boolean remoteControlEnabled = deviceState.isRemoteControlEnabled().get();
994 assertTrue(remoteControlEnabled);
998 public void testReturnValuesWhenElapsedTimeIsEmpty() {
1000 Status status = mock(Status.class);
1001 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1003 State state = mock(State.class);
1004 when(state.getElapsedTime()).thenReturn(Optional.empty());
1005 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1006 when(state.getStatus()).thenReturn(Optional.of(status));
1008 Device device = mock(Device.class);
1009 when(device.getState()).thenReturn(Optional.of(state));
1010 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1013 Optional<Integer> progress = deviceState.getProgress();
1016 assertFalse(progress.isPresent());
1020 public void testReturnValuesWhenElapsedTimeSizeIsNotTwo() {
1022 Status status = mock(Status.class);
1023 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1025 State state = mock(State.class);
1026 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0)));
1027 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1028 when(state.getStatus()).thenReturn(Optional.of(status));
1030 Device device = mock(Device.class);
1031 when(device.getState()).thenReturn(Optional.of(state));
1032 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1035 Optional<Integer> progress = deviceState.getProgress();
1038 assertFalse(progress.isPresent());
1042 public void testReturnValuesWhenElapsedTimeAndRemainingTimeIsZero() {
1044 Status status = mock(Status.class);
1045 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1047 State state = mock(State.class);
1048 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1049 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1050 when(state.getStatus()).thenReturn(Optional.of(status));
1052 Device device = mock(Device.class);
1053 when(device.getState()).thenReturn(Optional.of(state));
1054 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1057 Optional<Integer> progress = deviceState.getProgress();
1060 assertFalse(progress.isPresent());
1064 public void whenElapsedTimeIsNotPresentThenEmptyIsReturned() {
1066 Status status = mock(Status.class);
1067 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1069 State state = mock(State.class);
1070 when(state.getStatus()).thenReturn(Optional.of(status));
1071 when(state.getElapsedTime()).thenReturn(Optional.empty());
1073 Device device = mock(Device.class);
1074 when(device.getState()).thenReturn(Optional.of(state));
1076 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1079 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1082 assertFalse(elapsedTime.isPresent());
1086 public void whenElapsedTimeIsAnEmptyListThenEmptyIsReturned() {
1088 Status status = mock(Status.class);
1089 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1091 State state = mock(State.class);
1092 when(state.getStatus()).thenReturn(Optional.of(status));
1093 when(state.getElapsedTime()).thenReturn(Optional.of(Collections.emptyList()));
1095 Device device = mock(Device.class);
1096 when(device.getState()).thenReturn(Optional.of(state));
1098 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1101 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1104 assertFalse(elapsedTime.isPresent());
1108 public void whenElapsedTimeHasOnlyOneElementThenEmptyIsReturned() {
1110 Status status = mock(Status.class);
1111 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1113 State state = mock(State.class);
1114 when(state.getStatus()).thenReturn(Optional.of(status));
1115 when(state.getElapsedTime()).thenReturn(Optional.of(List.of(2)));
1117 Device device = mock(Device.class);
1118 when(device.getState()).thenReturn(Optional.of(state));
1120 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1123 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1126 assertFalse(elapsedTime.isPresent());
1130 public void whenElapsedTimeHasThreeElementsThenEmptyIsReturned() {
1132 Status status = mock(Status.class);
1133 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1135 State state = mock(State.class);
1136 when(state.getStatus()).thenReturn(Optional.of(status));
1137 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2, 3)));
1139 Device device = mock(Device.class);
1140 when(device.getState()).thenReturn(Optional.of(state));
1142 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1145 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1148 assertFalse(elapsedTime.isPresent());
1152 public void whenElapsedTimeHasTwoElementsThenTheTotalNumberOfSecondsIsReturned() {
1154 Status status = mock(Status.class);
1155 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1157 State state = mock(State.class);
1158 when(state.getStatus()).thenReturn(Optional.of(status));
1159 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1161 Device device = mock(Device.class);
1162 when(device.getState()).thenReturn(Optional.of(state));
1164 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1167 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1170 assertTrue(elapsedTime.isPresent());
1171 assertEquals(Integer.valueOf((60 + 2) * 60), elapsedTime.get());
1175 public void whenDeviceIsInOffStateThenElapsedTimeIsEmpty() {
1177 Status status = mock(Status.class);
1178 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1180 State state = mock(State.class);
1181 when(state.getStatus()).thenReturn(Optional.of(status));
1182 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1184 Device device = mock(Device.class);
1185 when(device.getState()).thenReturn(Optional.of(state));
1187 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1190 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1193 assertFalse(elapsedTime.isPresent());
1197 public void testReturnValuesWhenProgressIs50Percent() {
1199 State state = mock(State.class);
1200 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1201 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1203 Device device = mock(Device.class);
1204 Status status = mock(Status.class);
1205 when(state.getStatus()).thenReturn(Optional.of(status));
1206 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1207 when(device.getState()).thenReturn(Optional.of(state));
1208 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1211 Integer progress = deviceState.getProgress().get();
1214 assertEquals(Integer.valueOf(50), progress);
1218 public void testReturnValuesWhenProgressIs25Percent() {
1220 State state = mock(State.class);
1221 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 15)));
1222 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1224 Device device = mock(Device.class);
1225 Status status = mock(Status.class);
1226 when(state.getStatus()).thenReturn(Optional.of(status));
1227 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1228 when(device.getState()).thenReturn(Optional.of(state));
1229 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1232 Integer progress = deviceState.getProgress().get();
1235 assertEquals(Integer.valueOf(25), progress);
1239 public void testReturnValuesWhenProgressIs0Percent() {
1241 State state = mock(State.class);
1242 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1243 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1245 Device device = mock(Device.class);
1246 Status status = mock(Status.class);
1247 when(state.getStatus()).thenReturn(Optional.of(status));
1248 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1249 when(device.getState()).thenReturn(Optional.of(state));
1250 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1253 Integer progress = deviceState.getProgress().get();
1256 assertEquals(Integer.valueOf(0), progress);
1260 public void testReturnValuesWhenSignalDoorIsEmpty() {
1262 State state = mock(State.class);
1263 when(state.getSignalDoor()).thenReturn(Optional.empty());
1265 Status status = mock(Status.class);
1266 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1267 when(state.getStatus()).thenReturn(Optional.of(status));
1269 Device device = mock(Device.class);
1270 when(device.getState()).thenReturn(Optional.of(state));
1272 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1275 Optional<Boolean> doorState = deviceState.getDoorState();
1276 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1279 assertFalse(doorState.isPresent());
1280 assertFalse(doorAlarm.isPresent());
1284 public void testReturnValuesWhenSignalDoorIsTrue() {
1286 State state = mock(State.class);
1287 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1289 Status status = mock(Status.class);
1290 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1291 when(state.getStatus()).thenReturn(Optional.of(status));
1293 Device device = mock(Device.class);
1294 when(device.getState()).thenReturn(Optional.of(state));
1296 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1299 Optional<Boolean> doorState = deviceState.getDoorState();
1302 assertTrue(doorState.get());
1306 public void testReturnValuesWhenSignalDoorIsFalse() {
1308 State state = mock(State.class);
1309 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1311 Status status = mock(Status.class);
1312 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1313 when(state.getStatus()).thenReturn(Optional.of(status));
1315 Device device = mock(Device.class);
1316 when(device.getState()).thenReturn(Optional.of(state));
1318 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1321 Optional<Boolean> doorState = deviceState.getDoorState();
1324 assertFalse(doorState.get());
1328 public void testReturnValuesWhenSignalFailureIsEmpty() {
1330 State state = mock(State.class);
1331 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1332 when(state.getSignalFailure()).thenReturn(Optional.empty());
1334 Status status = mock(Status.class);
1335 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1336 when(state.getStatus()).thenReturn(Optional.of(status));
1338 Device device = mock(Device.class);
1339 when(device.getState()).thenReturn(Optional.of(state));
1341 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1344 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1347 assertFalse(doorAlarm.isPresent());
1351 public void testReturnValuesWhenDoorAlarmIsActive() {
1353 State state = mock(State.class);
1354 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1355 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1357 Status status = mock(Status.class);
1358 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1359 when(state.getStatus()).thenReturn(Optional.of(status));
1361 Device device = mock(Device.class);
1362 when(device.getState()).thenReturn(Optional.of(state));
1364 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1367 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1370 assertTrue(doorAlarm.get());
1374 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoDoorSignal() {
1376 State state = mock(State.class);
1377 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1378 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1380 Status status = mock(Status.class);
1381 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1382 when(state.getStatus()).thenReturn(Optional.of(status));
1384 Device device = mock(Device.class);
1385 when(device.getState()).thenReturn(Optional.of(state));
1387 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1390 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1393 assertFalse(doorAlarm.get());
1397 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoFailureSignal() {
1399 State state = mock(State.class);
1400 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1401 when(state.getSignalFailure()).thenReturn(Optional.of(false));
1403 Status status = mock(Status.class);
1404 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1405 when(state.getStatus()).thenReturn(Optional.of(status));
1407 Device device = mock(Device.class);
1408 when(device.getState()).thenReturn(Optional.of(state));
1410 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1413 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1416 assertFalse(doorAlarm.get());
1420 public void testReturnValuesWhenIdentIsEmpty() {
1422 Device device = mock(Device.class);
1423 when(device.getIdent()).thenReturn(Optional.empty());
1424 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1427 Optional<String> type = deviceState.getType();
1428 DeviceType rawType = deviceState.getRawType();
1429 Optional<String> deviceName = deviceState.getDeviceName();
1430 Optional<String> fabNumber = deviceState.getFabNumber();
1431 Optional<String> techType = deviceState.getTechType();
1434 assertFalse(type.isPresent());
1435 assertEquals(DeviceType.UNKNOWN, rawType);
1436 assertFalse(deviceName.isPresent());
1437 assertFalse(fabNumber.isPresent());
1438 assertFalse(techType.isPresent());
1442 public void testReturnValuesWhenTypeIsEmpty() {
1444 Ident ident = mock(Ident.class);
1445 when(ident.getType()).thenReturn(Optional.empty());
1447 Device device = mock(Device.class);
1448 when(device.getIdent()).thenReturn(Optional.of(ident));
1449 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1452 Optional<String> type = deviceState.getType();
1453 DeviceType rawType = deviceState.getRawType();
1456 assertFalse(type.isPresent());
1457 assertEquals(DeviceType.UNKNOWN, rawType);
1461 public void testReturnValuesWhenTypeValueLocalizedIsEmpty() {
1463 Type typeMock = mock(Type.class);
1464 when(typeMock.getValueLocalized()).thenReturn(Optional.empty());
1466 Ident ident = mock(Ident.class);
1467 when(ident.getType()).thenReturn(Optional.of(typeMock));
1469 Device device = mock(Device.class);
1470 when(device.getIdent()).thenReturn(Optional.of(ident));
1471 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1474 Optional<String> type = deviceState.getType();
1477 assertFalse(type.isPresent());
1481 public void testReturnValuesWhenTypeValueLocalizedIsNotNull() {
1483 Type typeMock = mock(Type.class);
1484 when(typeMock.getValueLocalized()).thenReturn(Optional.of("Hood"));
1486 Ident ident = mock(Ident.class);
1487 when(ident.getType()).thenReturn(Optional.of(typeMock));
1489 Device device = mock(Device.class);
1490 when(device.getIdent()).thenReturn(Optional.of(ident));
1491 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1494 String type = deviceState.getType().get();
1497 assertEquals("Hood", type);
1501 public void testReturnValuesWhenTypeValueRawIsNotNull() {
1503 Type typeMock = mock(Type.class);
1504 when(typeMock.getValueRaw()).thenReturn(DeviceType.COFFEE_SYSTEM);
1506 Ident ident = mock(Ident.class);
1507 when(ident.getType()).thenReturn(Optional.of(typeMock));
1509 Device device = mock(Device.class);
1510 when(device.getIdent()).thenReturn(Optional.of(ident));
1511 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1514 DeviceType rawType = deviceState.getRawType();
1517 assertEquals(DeviceType.COFFEE_SYSTEM, rawType);
1521 public void testReturnValuesWhenDeviceNameIsEmpty() {
1523 Ident ident = mock(Ident.class);
1524 when(ident.getDeviceName()).thenReturn(Optional.empty());
1526 Device device = mock(Device.class);
1527 when(device.getIdent()).thenReturn(Optional.of(ident));
1528 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1531 Optional<String> deviceName = deviceState.getDeviceName();
1534 assertFalse(deviceName.isPresent());
1538 public void testReturnValuesWhenDeviceNameIsEmptyString() {
1540 Ident ident = mock(Ident.class);
1541 when(ident.getDeviceName()).thenReturn(Optional.of(""));
1543 Device device = mock(Device.class);
1544 when(device.getIdent()).thenReturn(Optional.of(ident));
1545 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1548 Optional<String> deviceName = deviceState.getDeviceName();
1551 assertFalse(deviceName.isPresent());
1555 public void testReturnValuesWhenDeviceNameIsValid() {
1557 Ident ident = mock(Ident.class);
1558 when(ident.getDeviceName()).thenReturn(Optional.of("MyWashingMachine"));
1560 Device device = mock(Device.class);
1561 when(device.getIdent()).thenReturn(Optional.of(ident));
1562 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1565 Optional<String> deviceName = deviceState.getDeviceName();
1568 assertEquals(Optional.of("MyWashingMachine"), deviceName);
1572 public void testReturnValuesWhenFabNumberIsNotNull() {
1574 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1575 when(deviceIdentLabel.getFabNumber()).thenReturn(Optional.of("000061431659"));
1577 Ident ident = mock(Ident.class);
1578 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1580 Device device = mock(Device.class);
1581 when(device.getIdent()).thenReturn(Optional.of(ident));
1582 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1585 String fabNumber = deviceState.getFabNumber().get();
1588 assertEquals("000061431659", fabNumber);
1592 public void testReturnValuesWhenTechTypeIsNotNull() {
1594 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1595 when(deviceIdentLabel.getTechType()).thenReturn(Optional.of("XKM3100WEC"));
1597 Ident ident = mock(Ident.class);
1598 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1600 Device device = mock(Device.class);
1601 when(device.getIdent()).thenReturn(Optional.of(ident));
1602 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1605 String techType = deviceState.getTechType().get();
1608 assertEquals("XKM3100WEC", techType);
1612 public void whenDeviceIsInFailureStateThenItHasAnError() {
1614 Status status = mock(Status.class);
1615 when(status.getValueRaw()).thenReturn(Optional.of(StateType.FAILURE.getCode()));
1617 State state = mock(State.class);
1618 when(state.getStatus()).thenReturn(Optional.of(status));
1620 Device device = mock(Device.class);
1621 when(device.getState()).thenReturn(Optional.of(state));
1622 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1625 boolean hasError = deviceState.hasError();
1628 assertTrue(hasError);
1632 public void whenDeviceIsInRunningStateAndDoesNotSignalAFailureThenItHasNoError() {
1634 Status status = mock(Status.class);
1635 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1637 State state = mock(State.class);
1638 when(state.getStatus()).thenReturn(Optional.of(status));
1640 Device device = mock(Device.class);
1641 when(device.getState()).thenReturn(Optional.of(state));
1642 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1645 boolean hasError = deviceState.hasError();
1648 assertFalse(hasError);
1652 public void whenDeviceSignalsAFailureThenItHasAnError() {
1654 Status status = mock(Status.class);
1655 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1657 State state = mock(State.class);
1658 when(state.getStatus()).thenReturn(Optional.of(status));
1659 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1661 Device device = mock(Device.class);
1662 when(device.getState()).thenReturn(Optional.of(state));
1663 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1666 boolean hasError = deviceState.hasError();
1669 assertTrue(hasError);
1673 public void testReturnValuesForHasInfoWhenSignalInfoIsEmpty() {
1675 State state = mock(State.class);
1676 when(state.getSignalInfo()).thenReturn(Optional.empty());
1678 Status status = mock(Status.class);
1679 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1680 when(state.getStatus()).thenReturn(Optional.of(status));
1682 Device device = mock(Device.class);
1683 when(device.getState()).thenReturn(Optional.of(state));
1684 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1687 boolean hasInfo = deviceState.hasInfo();
1690 assertFalse(hasInfo);
1694 public void whenDeviceSignalsAnInfoThenItHasAnInfo() {
1696 State state = mock(State.class);
1697 when(state.getSignalInfo()).thenReturn(Optional.of(true));
1699 Status status = mock(Status.class);
1700 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1701 when(state.getStatus()).thenReturn(Optional.of(status));
1703 Device device = mock(Device.class);
1704 when(device.getState()).thenReturn(Optional.of(state));
1705 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1708 boolean hasInfo = deviceState.hasInfo();
1711 assertTrue(hasInfo);
1715 public void whenDeviceSignalsNoInfoThenItHasNoInfo() {
1717 State state = mock(State.class);
1718 when(state.getSignalInfo()).thenReturn(Optional.of(false));
1720 Status status = mock(Status.class);
1721 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1722 when(state.getStatus()).thenReturn(Optional.of(status));
1724 Device device = mock(Device.class);
1725 when(device.getState()).thenReturn(Optional.of(state));
1726 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1729 boolean hasInfo = deviceState.hasInfo();
1732 assertFalse(hasInfo);
1736 public void testReturnValuesForVentilationStep() {
1738 VentilationStep ventilationStepMock = mock(VentilationStep.class);
1739 when(ventilationStepMock.getValueLocalized()).thenReturn(Optional.of("Step 1"));
1740 when(ventilationStepMock.getValueRaw()).thenReturn(Optional.of(1));
1742 Status status = mock(Status.class);
1743 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1745 State state = mock(State.class);
1746 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStepMock));
1747 when(state.getStatus()).thenReturn(Optional.of(status));
1749 Device device = mock(Device.class);
1750 when(device.getState()).thenReturn(Optional.of(state));
1752 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1755 String ventilationStep = deviceState.getVentilationStep().get();
1756 int ventilationStepRaw = deviceState.getVentilationStepRaw().get();
1759 assertEquals("Step 1", ventilationStep);
1760 assertEquals(1, ventilationStepRaw);
1764 public void testProgramPhaseWhenDeviceIsInOffState() {
1766 ProgramPhase programPhase = mock(ProgramPhase.class);
1767 when(programPhase.getValueLocalized()).thenReturn(Optional.of("Washing"));
1768 when(programPhase.getValueRaw()).thenReturn(Optional.of(3));
1770 Status status = mock(Status.class);
1771 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1773 State state = mock(State.class);
1774 when(state.getProgramPhase()).thenReturn(Optional.of(programPhase));
1775 when(state.getStatus()).thenReturn(Optional.of(status));
1777 Device device = mock(Device.class);
1778 when(device.getState()).thenReturn(Optional.of(state));
1780 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1783 Optional<String> phase = deviceState.getProgramPhase();
1784 Optional<Integer> phaseRaw = deviceState.getProgramPhaseRaw();
1787 assertFalse(phase.isPresent());
1788 assertFalse(phaseRaw.isPresent());
1792 public void testDryingTargetWhenDeviceIsInOffState() {
1794 DryingStep dryingStep = mock(DryingStep.class);
1795 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Schranktrocken"));
1796 when(dryingStep.getValueRaw()).thenReturn(Optional.of(3));
1798 Status status = mock(Status.class);
1799 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1801 State state = mock(State.class);
1802 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
1803 when(state.getStatus()).thenReturn(Optional.of(status));
1805 Device device = mock(Device.class);
1806 when(device.getState()).thenReturn(Optional.of(state));
1808 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1811 Optional<String> dryingTarget = deviceState.getDryingTarget();
1812 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
1815 assertFalse(dryingTarget.isPresent());
1816 assertFalse(dryingTargetRaw.isPresent());
1820 public void testVentilationStepWhenDeviceIsInOffState() {
1822 VentilationStep ventilationStep = mock(VentilationStep.class);
1823 when(ventilationStep.getValueLocalized()).thenReturn(Optional.of("Stufe 1"));
1824 when(ventilationStep.getValueRaw()).thenReturn(Optional.of(1));
1826 Status status = mock(Status.class);
1827 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1829 State state = mock(State.class);
1830 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStep));
1831 when(state.getStatus()).thenReturn(Optional.of(status));
1833 Device device = mock(Device.class);
1834 when(device.getState()).thenReturn(Optional.of(state));
1836 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1839 Optional<String> step = deviceState.getVentilationStep();
1840 Optional<Integer> stepRaw = deviceState.getVentilationStepRaw();
1843 assertFalse(step.isPresent());
1844 assertFalse(stepRaw.isPresent());
1848 public void testReturnValuesWhenDeviceIsInOffState() {
1850 Device device = mock(Device.class);
1851 State state = mock(State.class);
1852 Status status = mock(Status.class);
1854 when(device.getState()).thenReturn(Optional.of(state));
1855 when(state.getStatus()).thenReturn(Optional.of(status));
1856 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1857 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1859 // Test SelectedProgram:
1860 ProgramId programId = mock(ProgramId.class);
1861 when(state.getProgramId()).thenReturn(Optional.of(programId));
1862 when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
1864 Optional<String> selectedProgram = deviceState.getSelectedProgram();
1866 assertFalse(selectedProgram.isPresent());
1868 // Test TargetTemperature:
1869 Temperature targetTemperatureMock = mock(Temperature.class);
1870 when(state.getTargetTemperature()).thenReturn(List.of(targetTemperatureMock));
1871 when(targetTemperatureMock.getValueLocalized()).thenReturn(Optional.of(200));
1873 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
1875 assertFalse(targetTemperature.isPresent());
1877 // Test Temperature:
1878 Temperature temperature = mock(Temperature.class);
1879 when(state.getTemperature()).thenReturn(List.of(temperature));
1880 when(temperature.getValueLocalized()).thenReturn(Optional.of(200));
1882 Optional<Integer> t = deviceState.getTemperature(0);
1884 assertFalse(t.isPresent());
1887 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 5)));
1888 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(1, 5)));
1890 Optional<Integer> progress = deviceState.getProgress();
1892 assertFalse(progress.isPresent());
1896 public void testWhenDeviceIsInOffStateThenGetSpinningSpeedReturnsNull() {
1898 Status status = mock(Status.class);
1899 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1901 SpinningSpeed spinningSpeed = mock(SpinningSpeed.class);
1902 when(spinningSpeed.getValueRaw()).thenReturn(Optional.of(800));
1903 when(spinningSpeed.getValueLocalized()).thenReturn(Optional.of("800"));
1904 when(spinningSpeed.getUnit()).thenReturn(Optional.of("rpm"));
1906 State state = mock(State.class);
1907 when(state.getStatus()).thenReturn(Optional.of(status));
1908 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeed));
1910 Device device = mock(Device.class);
1911 when(device.getState()).thenReturn(Optional.of(state));
1913 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1916 Optional<String> speed = deviceState.getSpinningSpeed();
1917 Optional<Integer> speedRaw = deviceState.getSpinningSpeedRaw();
1920 assertFalse(speed.isPresent());
1921 assertFalse(speedRaw.isPresent());
1925 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedIsEmpty() {
1927 Status status = mock(Status.class);
1928 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1930 State state = mock(State.class);
1931 when(state.getStatus()).thenReturn(Optional.of(status));
1932 when(state.getSpinningSpeed()).thenReturn(Optional.empty());
1934 Device device = mock(Device.class);
1935 when(device.getState()).thenReturn(Optional.of(state));
1937 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1940 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1941 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1944 assertFalse(spinningSpeed.isPresent());
1945 assertFalse(spinningSpeedRaw.isPresent());
1949 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedRawValueIsEmpty() {
1951 Status status = mock(Status.class);
1952 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1954 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1955 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.empty());
1956 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1958 State state = mock(State.class);
1959 when(state.getStatus()).thenReturn(Optional.of(status));
1960 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1962 Device device = mock(Device.class);
1963 when(device.getState()).thenReturn(Optional.of(state));
1965 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1968 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1969 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1972 assertFalse(spinningSpeed.isPresent());
1973 assertFalse(spinningSpeedRaw.isPresent());
1977 public void testGetSpinningSpeedReturnsValidValueWhenSpinningSpeedRawValueIsNotNull() {
1979 Status status = mock(Status.class);
1980 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1982 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1983 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.of(1200));
1984 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1986 State state = mock(State.class);
1987 when(state.getStatus()).thenReturn(Optional.of(status));
1988 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1990 Device device = mock(Device.class);
1991 when(device.getState()).thenReturn(Optional.of(state));
1993 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1996 String spinningSpeed = deviceState.getSpinningSpeed().get();
1997 int spinningSpeedRaw = deviceState.getSpinningSpeedRaw().get();
2000 assertEquals("1200", spinningSpeed);
2001 assertEquals(1200, spinningSpeedRaw);
2005 public void testGetLightStateWhenDeviceIsOff() {
2007 Status status = mock(Status.class);
2008 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
2010 State state = mock(State.class);
2011 when(state.getStatus()).thenReturn(Optional.of(status));
2013 Device device = mock(Device.class);
2014 when(device.getState()).thenReturn(Optional.of(state));
2016 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2019 Optional<Boolean> lightState = deviceState.getLightState();
2022 assertFalse(lightState.isPresent());
2026 public void testGetLightStateWhenLightIsUnknown() {
2028 Status status = mock(Status.class);
2029 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2031 State state = mock(State.class);
2032 when(state.getStatus()).thenReturn(Optional.of(status));
2033 when(state.getLight()).thenReturn(Light.UNKNOWN);
2035 Device device = mock(Device.class);
2036 when(device.getState()).thenReturn(Optional.of(state));
2038 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2041 Optional<Boolean> lightState = deviceState.getLightState();
2044 assertFalse(lightState.isPresent());
2048 public void testGetLightStateWhenLightIsEnabled() {
2050 Status status = mock(Status.class);
2051 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2053 State state = mock(State.class);
2054 when(state.getStatus()).thenReturn(Optional.of(status));
2055 when(state.getLight()).thenReturn(Light.ENABLE);
2057 Device device = mock(Device.class);
2058 when(device.getState()).thenReturn(Optional.of(state));
2060 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2063 Boolean lightState = deviceState.getLightState().get();
2066 assertEquals(Boolean.valueOf(true), lightState);
2070 public void testGetLightStateWhenLightIsDisabled() {
2072 Status status = mock(Status.class);
2073 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2075 State state = mock(State.class);
2076 when(state.getStatus()).thenReturn(Optional.of(status));
2077 when(state.getLight()).thenReturn(Light.DISABLE);
2079 Device device = mock(Device.class);
2080 when(device.getState()).thenReturn(Optional.of(state));
2082 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2085 Boolean lightState = deviceState.getLightState().get();
2088 assertEquals(Boolean.valueOf(false), lightState);
2092 public void testGetLightStateWhenLightIsNotSupported() {
2094 Status status = mock(Status.class);
2095 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2097 State state = mock(State.class);
2098 when(state.getStatus()).thenReturn(Optional.of(status));
2099 when(state.getLight()).thenReturn(Light.NOT_SUPPORTED);
2101 Device device = mock(Device.class);
2102 when(device.getState()).thenReturn(Optional.of(state));
2104 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2107 Optional<Boolean> lightState = deviceState.getLightState();
2110 assertFalse(lightState.isPresent());
2114 public void testGetCurrentWaterConsumptionWhenEcoFeedbackIsNotPresent() {
2116 Status status = mock(Status.class);
2117 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2119 State state = mock(State.class);
2120 when(state.getStatus()).thenReturn(Optional.of(status));
2121 when(state.getEcoFeedback()).thenReturn(Optional.empty());
2123 Device device = mock(Device.class);
2124 when(device.getState()).thenReturn(Optional.of(state));
2126 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2129 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2132 assertFalse(waterConsumption.isPresent());
2136 public void testGetCurrentWaterConsumptionWhenCurrentWaterConsumptionIsNotPresent() {
2138 Status status = mock(Status.class);
2139 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2141 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2142 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.empty());
2144 State state = mock(State.class);
2145 when(state.getStatus()).thenReturn(Optional.of(status));
2146 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2148 Device device = mock(Device.class);
2149 when(device.getState()).thenReturn(Optional.of(state));
2151 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2154 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2157 assertFalse(waterConsumption.isPresent());
2161 public void testGetCurrentWaterConsumptionWhenCurrentWaterConsumptionIsEmpty() {
2163 Status status = mock(Status.class);
2164 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2166 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2167 when(currentWaterConsumption.getUnit()).thenReturn(Optional.empty());
2168 when(currentWaterConsumption.getValue()).thenReturn(Optional.empty());
2170 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2171 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2173 State state = mock(State.class);
2174 when(state.getStatus()).thenReturn(Optional.of(status));
2175 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2177 Device device = mock(Device.class);
2178 when(device.getState()).thenReturn(Optional.of(state));
2180 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2183 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2186 assertFalse(waterConsumption.isPresent());
2190 public void testGetCurrentWaterConsumptionWhenValueIsNotPresent() {
2192 Status status = mock(Status.class);
2193 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2195 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2196 when(currentWaterConsumption.getUnit()).thenReturn(Optional.of("l"));
2197 when(currentWaterConsumption.getValue()).thenReturn(Optional.empty());
2199 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2200 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2202 State state = mock(State.class);
2203 when(state.getStatus()).thenReturn(Optional.of(status));
2204 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2206 Device device = mock(Device.class);
2207 when(device.getState()).thenReturn(Optional.of(state));
2209 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2212 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2215 assertFalse(waterConsumption.isPresent());
2219 public void testGetCurrentWaterConsumptionWhenUnitIsNotPresent() {
2221 Status status = mock(Status.class);
2222 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2224 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2225 when(currentWaterConsumption.getUnit()).thenReturn(Optional.empty());
2226 when(currentWaterConsumption.getValue()).thenReturn(Optional.of(0.5));
2228 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2229 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2231 State state = mock(State.class);
2232 when(state.getStatus()).thenReturn(Optional.of(status));
2233 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2235 Device device = mock(Device.class);
2236 when(device.getState()).thenReturn(Optional.of(state));
2238 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2241 Quantity waterConsumption = deviceState.getCurrentWaterConsumption().get();
2244 assertEquals(0.5, waterConsumption.getValue());
2245 assertFalse(waterConsumption.getUnit().isPresent());
2249 public void testGetCurrentWaterConsumption() {
2251 Status status = mock(Status.class);
2252 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2254 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2255 when(currentWaterConsumption.getUnit()).thenReturn(Optional.of("l"));
2256 when(currentWaterConsumption.getValue()).thenReturn(Optional.of(0.5));
2258 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2259 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2261 State state = mock(State.class);
2262 when(state.getStatus()).thenReturn(Optional.of(status));
2263 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2265 Device device = mock(Device.class);
2266 when(device.getState()).thenReturn(Optional.of(state));
2268 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2271 Quantity waterConsumption = deviceState.getCurrentWaterConsumption().get();
2274 assertEquals(0.5, waterConsumption.getValue());
2275 assertEquals(Optional.of("l"), waterConsumption.getUnit());
2279 public void testGetCurrentEnergyConsumptionWhenEcoFeedbackIsNotPresent() {
2281 Status status = mock(Status.class);
2282 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2284 State state = mock(State.class);
2285 when(state.getStatus()).thenReturn(Optional.of(status));
2286 when(state.getEcoFeedback()).thenReturn(Optional.empty());
2288 Device device = mock(Device.class);
2289 when(device.getState()).thenReturn(Optional.of(state));
2291 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2294 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2297 assertFalse(energyConsumption.isPresent());
2301 public void testGetCurrentEnergyConsumptionWhenCurrentEnergyConsumptionIsNotPresent() {
2303 Status status = mock(Status.class);
2304 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2306 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2307 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.empty());
2309 State state = mock(State.class);
2310 when(state.getStatus()).thenReturn(Optional.of(status));
2311 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2313 Device device = mock(Device.class);
2314 when(device.getState()).thenReturn(Optional.of(state));
2316 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2319 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2322 assertFalse(energyConsumption.isPresent());
2326 public void testGetCurrentEnergyConsumptionWhenCurrentEnergyConsumptionIsEmpty() {
2328 Status status = mock(Status.class);
2329 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2331 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2332 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.empty());
2333 when(currentEnergyConsumption.getValue()).thenReturn(Optional.empty());
2335 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2336 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2338 State state = mock(State.class);
2339 when(state.getStatus()).thenReturn(Optional.of(status));
2340 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2342 Device device = mock(Device.class);
2343 when(device.getState()).thenReturn(Optional.of(state));
2345 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2348 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2351 assertFalse(energyConsumption.isPresent());
2355 public void testGetCurrentEnergyConsumptionWhenValueIsNotPresent() {
2357 Status status = mock(Status.class);
2358 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2360 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2361 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.of("kWh"));
2362 when(currentEnergyConsumption.getValue()).thenReturn(Optional.empty());
2364 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2365 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2367 State state = mock(State.class);
2368 when(state.getStatus()).thenReturn(Optional.of(status));
2369 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2371 Device device = mock(Device.class);
2372 when(device.getState()).thenReturn(Optional.of(state));
2374 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2377 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2380 assertFalse(energyConsumption.isPresent());
2384 public void testGetCurrentEnergyConsumptionWhenUnitIsNotPresent() {
2386 Status status = mock(Status.class);
2387 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2389 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2390 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.empty());
2391 when(currentEnergyConsumption.getValue()).thenReturn(Optional.of(0.5));
2393 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2394 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2396 State state = mock(State.class);
2397 when(state.getStatus()).thenReturn(Optional.of(status));
2398 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2400 Device device = mock(Device.class);
2401 when(device.getState()).thenReturn(Optional.of(state));
2403 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2406 Quantity energyConsumption = deviceState.getCurrentEnergyConsumption().get();
2409 assertEquals(0.5, energyConsumption.getValue());
2410 assertFalse(energyConsumption.getUnit().isPresent());
2414 public void testGetCurrentEnergyConsumption() {
2416 Status status = mock(Status.class);
2417 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2419 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2420 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.of("kWh"));
2421 when(currentEnergyConsumption.getValue()).thenReturn(Optional.of(0.5));
2423 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2424 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2426 State state = mock(State.class);
2427 when(state.getStatus()).thenReturn(Optional.of(status));
2428 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2430 Device device = mock(Device.class);
2431 when(device.getState()).thenReturn(Optional.of(state));
2433 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2436 Quantity energyConsumption = deviceState.getCurrentEnergyConsumption().get();
2439 assertEquals(0.5, energyConsumption.getValue());
2440 assertEquals(Optional.of("kWh"), energyConsumption.getUnit());
2444 public void testGetBatteryLevel() {
2446 Status status = mock(Status.class);
2447 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2449 State state = mock(State.class);
2450 when(state.getStatus()).thenReturn(Optional.of(status));
2451 when(state.getBatteryLevel()).thenReturn(Optional.of(4));
2453 Device device = mock(Device.class);
2454 when(device.getState()).thenReturn(Optional.of(state));
2456 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2459 Integer batteryLevel = deviceState.getBatteryLevel().get();
2462 assertEquals(Integer.valueOf(4), batteryLevel);