2 * Copyright (c) 2010-2020 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.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.InOrder;
24 import org.mockito.Mockito;
25 import org.openhab.binding.onewire.internal.OwException;
26 import org.openhab.binding.onewire.internal.device.EDS006x;
27 import org.openhab.binding.onewire.internal.device.OwSensorType;
28 import org.openhab.core.library.types.DecimalType;
29 import org.openhab.core.library.types.OnOffType;
30 import org.openhab.core.library.types.QuantityType;
33 * Tests cases for {@link EDS006x}.
35 * @author Jan N. Klug - Initial contribution
38 public class EDS006xTest extends DeviceTestParent<EDS006x> {
41 public void setupMocks() {
42 setupMocks(THING_TYPE_EDS_ENV, EDS006x.class);
44 addChannel(CHANNEL_TEMPERATURE, "Number:Temperature");
45 addChannel(CHANNEL_HUMIDITY, "Number:Dimensionless");
46 addChannel(CHANNEL_ABSOLUTE_HUMIDITY, "Number:Density");
47 addChannel(CHANNEL_DEWPOINT, "Number:Temperature");
48 addChannel(CHANNEL_LIGHT, "Number:Illuminance");
49 addChannel(CHANNEL_PRESSURE, "Number:Pressure");
53 public void temperatureChannel() {
54 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
55 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
58 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
59 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
61 testDevice.enableChannel(CHANNEL_TEMPERATURE);
62 testDevice.configureChannels();
63 testDevice.refresh(mockBridgeHandler, true);
65 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
66 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
68 inOrder.verifyNoMoreInteractions();
69 } catch (OwException e) {
70 Assert.fail("caught unexpected OwException");
75 public void humidityChannel() {
76 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
77 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
80 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
81 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
83 testDevice.enableChannel(CHANNEL_HUMIDITY);
84 testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
85 testDevice.enableChannel(CHANNEL_DEWPOINT);
86 testDevice.configureChannels();
87 testDevice.refresh(mockBridgeHandler, true);
89 inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
90 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
91 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
92 eq(new QuantityType<>("0.9381970824113001000 g/m³")));
93 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
94 eq(new QuantityType<>("-20.31395053870025 °C")));
96 inOrder.verifyNoMoreInteractions();
97 } catch (OwException e) {
98 Assert.fail("caught unexpected OwException");
103 public void pressureChannel() {
104 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
105 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
108 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
109 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
111 testDevice.enableChannel(CHANNEL_PRESSURE);
112 testDevice.configureChannels();
113 testDevice.refresh(mockBridgeHandler, true);
115 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
116 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_PRESSURE), eq(new QuantityType<>("2.0 mbar")));
118 inOrder.verifyNoMoreInteractions();
119 } catch (OwException e) {
120 Assert.fail("caught unexpected OwException");
125 public void lightChannel() {
126 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
127 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
130 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
131 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(100));
133 testDevice.enableChannel(CHANNEL_LIGHT);
134 testDevice.configureChannels();
135 testDevice.refresh(mockBridgeHandler, true);
137 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
138 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("100 lx")));
140 inOrder.verifyNoMoreInteractions();
141 } catch (OwException e) {
142 Assert.fail("caught unexpected OwException");
147 public void noChannel() {
148 final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
149 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
152 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
153 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
155 testDevice.configureChannels();
156 testDevice.refresh(mockBridgeHandler, true);
158 inOrder.verifyNoMoreInteractions();
159 } catch (OwException e) {
160 Assert.fail("caught unexpected OwException");