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.onewire.device;
15 import static org.mockito.ArgumentMatchers.*;
16 import static org.mockito.Mockito.times;
17 import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.mockito.InOrder;
23 import org.mockito.Mockito;
24 import org.openhab.binding.onewire.internal.OwException;
25 import org.openhab.binding.onewire.internal.device.EDS006x;
26 import org.openhab.binding.onewire.internal.device.OwSensorType;
27 import org.openhab.core.library.types.DecimalType;
28 import org.openhab.core.library.types.OnOffType;
29 import org.openhab.core.library.types.QuantityType;
32 * Tests cases for {@link EDS006x}.
34 * @author Jan N. Klug - Initial contribution
37 public class EDS006xTest extends DeviceTestParent<EDS006x> {
40 public void setupMocks() {
41 setupMocks(THING_TYPE_EDS_ENV, EDS006x.class);
43 addChannel(CHANNEL_TEMPERATURE, "Number:Temperature");
44 addChannel(CHANNEL_HUMIDITY, "Number:Dimensionless");
45 addChannel(CHANNEL_ABSOLUTE_HUMIDITY, "Number:Density");
46 addChannel(CHANNEL_DEWPOINT, "Number:Temperature");
47 addChannel(CHANNEL_LIGHT, "Number:Illuminance");
48 addChannel(CHANNEL_PRESSURE, "Number:Pressure");
52 public void temperatureChannel() throws OwException {
53 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
54 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
56 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
57 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
59 testDevice.enableChannel(CHANNEL_TEMPERATURE);
60 testDevice.configureChannels();
61 testDevice.refresh(mockBridgeHandler, true);
63 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
64 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
66 inOrder.verifyNoMoreInteractions();
70 public void humidityChannel() throws OwException {
71 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
72 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
74 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
75 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
77 testDevice.enableChannel(CHANNEL_HUMIDITY);
78 testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
79 testDevice.enableChannel(CHANNEL_DEWPOINT);
80 testDevice.configureChannels();
81 testDevice.refresh(mockBridgeHandler, true);
83 inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
84 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
85 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
86 eq(new QuantityType<>("0.9381970824113001000 g/m³")));
87 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
88 eq(new QuantityType<>("-20.31395053870025 °C")));
90 inOrder.verifyNoMoreInteractions();
94 public void pressureChannel() throws OwException {
95 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
96 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
98 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
99 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
101 testDevice.enableChannel(CHANNEL_PRESSURE);
102 testDevice.configureChannels();
103 testDevice.refresh(mockBridgeHandler, true);
105 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
106 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_PRESSURE), eq(new QuantityType<>("2.0 mbar")));
108 inOrder.verifyNoMoreInteractions();
112 public void lightChannel() throws OwException {
113 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
114 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
116 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
117 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(100));
119 testDevice.enableChannel(CHANNEL_LIGHT);
120 testDevice.configureChannels();
121 testDevice.refresh(mockBridgeHandler, true);
123 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
124 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("100 lx")));
126 inOrder.verifyNoMoreInteractions();
130 public void noChannel() throws OwException {
131 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
132 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
134 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
135 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
137 testDevice.configureChannels();
138 testDevice.refresh(mockBridgeHandler, true);
140 inOrder.verifyNoMoreInteractions();