]> git.basschouten.com Git - openhab-addons.git/blob
1625d7fb44f819783eb66f9ecdcfbfd380b7983c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.fineoffsetweatherstation.internal.service;
14
15 import java.time.ZoneOffset;
16 import java.util.List;
17
18 import org.assertj.core.api.Assertions;
19 import org.assertj.core.groups.Tuple;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.fineoffsetweatherstation.internal.domain.Command;
23 import org.openhab.binding.fineoffsetweatherstation.internal.domain.ConversionContext;
24 import org.openhab.binding.fineoffsetweatherstation.internal.domain.DebugDetails;
25 import org.openhab.binding.fineoffsetweatherstation.internal.domain.Protocol;
26 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.MeasuredValue;
27 import org.openhab.core.util.HexUtils;
28
29 /**
30  * @author Andreas Berger - Initial contribution
31  */
32 @NonNullByDefault
33 class FineOffsetDataParserTest {
34     @Test
35     void testLiveDataWH45() {
36         byte[] bytes = HexUtils.hexToBytes(
37                 "FFFF2700510100D306280827EF0927EF020045074F0A00150B00000C0000150000000016000117001900000E0000100000110021120000002113000005850D00007000D12E0060005A005B005502AE028F0633");
38         DebugDetails debugDetails = new DebugDetails(bytes, Command.CMD_GW1000_LIVEDATA, Protocol.DEFAULT);
39         List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(bytes,
40                 new ConversionContext(ZoneOffset.UTC), debugDetails);
41         Assertions.assertThat(data)
42                 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
43                 .containsExactly(new Tuple("temperature-indoor", "21.1 °C"), new Tuple("humidity-indoor", "40 %"),
44                         new Tuple("pressure-absolute", "1022.3 hPa"), new Tuple("pressure-relative", "1022.3 hPa"),
45                         new Tuple("temperature-outdoor", "6.9 °C"), new Tuple("humidity-outdoor", "79 %"),
46                         new Tuple("direction-wind", "21 °"), new Tuple("speed-wind", "0 m/s"),
47                         new Tuple("speed-gust", "0 m/s"), new Tuple("illumination", "0 lx"),
48                         new Tuple("irradiation-uv", "0.1 mW/m²"), new Tuple("uv-index", "0"),
49                         new Tuple("wind-max-day", "0 m/s"), new Tuple("rain-rate", "0 mm/h"),
50                         new Tuple("rain-day", "0 mm"), new Tuple("rain-week", "3.3 mm"),
51                         new Tuple("rain-month", "3.3 mm"), new Tuple("rain-year", "141.3 mm"),
52                         new Tuple("rain-event", "0 mm"), new Tuple("sensor-co2-temperature", "20.9 °C"),
53                         new Tuple("sensor-co2-humidity", "46 %"), new Tuple("sensor-co2-pm10", "9.6 µg/m³"),
54                         new Tuple("sensor-co2-pm10-24-hour-average", "9 µg/m³"),
55                         new Tuple("sensor-co2-pm25", "9.1 µg/m³"),
56                         new Tuple("sensor-co2-pm25-24-hour-average", "8.5 µg/m³"),
57                         new Tuple("sensor-co2-co2", "686 ppm"), new Tuple("sensor-co2-co2-24-hour-average", "655 ppm"));
58     }
59
60     @Test
61     void testLiveDataWH34AndWh45() {
62         byte[] bytes = HexUtils.hexToBytes(
63                 "FFFF2700540100CA063E0826EC0926EC02007A074C0A002F0B001F0C0023150000032016000017001A0086225558005A00620000000661654A5AF1601B1900266300884B7000CE3F001D00240016001E041A037B0695");
64         DebugDetails debugDetails = new DebugDetails(bytes, Command.CMD_GW1000_LIVEDATA, Protocol.DEFAULT);
65         List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(bytes,
66                 new ConversionContext(ZoneOffset.UTC), debugDetails);
67         Assertions.assertThat(data)
68                 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
69                 .containsExactly(new Tuple("temperature-indoor", "20.2 °C"), new Tuple("humidity-indoor", "62 %"),
70                         new Tuple("pressure-absolute", "996.4 hPa"), new Tuple("pressure-relative", "996.4 hPa"),
71                         new Tuple("temperature-outdoor", "12.2 °C"), new Tuple("humidity-outdoor", "76 %"),
72                         new Tuple("direction-wind", "47 °"), new Tuple("speed-wind", "3.1 m/s"),
73                         new Tuple("speed-gust", "3.5 m/s"), new Tuple("illumination", "80 lx"),
74                         new Tuple("irradiation-uv", "0 mW/m²"), new Tuple("uv-index", "0"),
75                         new Tuple("temperature-channel-1", "13.4 °C"), new Tuple("humidity-channel-1", "85 %"),
76                         new Tuple("water-leak-channel-1", "OFF"), new Tuple("water-leak-channel-3", "OFF"),
77                         new Tuple("lightning-counter", "6"),
78                         new Tuple("lightning-time", "2023-11-07T15:42:41.000+0000"),
79                         new Tuple("lightning-distance", "27 km"), new Tuple("wind-max-day", "3.8 m/s"),
80                         new Tuple("temperature-external-channel-1", "13.6 °C"),
81                         new Tuple("sensor-co2-temperature", "20.6 °C"), new Tuple("sensor-co2-humidity", "63 %"),
82                         new Tuple("sensor-co2-pm10", "2.9 µg/m³"),
83                         new Tuple("sensor-co2-pm10-24-hour-average", "3.6 µg/m³"),
84                         new Tuple("sensor-co2-pm25", "2.2 µg/m³"),
85                         new Tuple("sensor-co2-pm25-24-hour-average", "3 µg/m³"),
86                         new Tuple("sensor-co2-co2", "1050 ppm"),
87                         new Tuple("sensor-co2-co2-24-hour-average", "891 ppm"));
88     }
89
90     @Test
91     void testLiveDataELV() {
92         byte[] data = HexUtils.hexToBytes(
93                 "FFFF0B00500401010B0201120300620401120501120629072108254B09254B0A01480B00040C000A0E000000001000000021110000002E120000014F130000100714000012FD15000B4BB816086917056D35");
94         DebugDetails debugDetails = new DebugDetails(data, Command.CMD_WS980_LIVEDATA, Protocol.ELV);
95         List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.ELV).getMeasuredValues(data,
96                 new ConversionContext(ZoneOffset.UTC), debugDetails);
97         Assertions.assertThat(measuredValues)
98                 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
99                 .containsExactly(new Tuple("temperature-indoor", "26.7 °C"),
100                         new Tuple("temperature-outdoor", "27.4 °C"), new Tuple("temperature-dew-point", "9.8 °C"),
101                         new Tuple("temperature-wind-chill", "27.4 °C"), new Tuple("temperature-heat-index", "27.4 °C"),
102                         new Tuple("humidity-indoor", "41 %"), new Tuple("humidity-outdoor", "33 %"),
103                         new Tuple("pressure-absolute", "954.7 hPa"), new Tuple("pressure-relative", "954.7 hPa"),
104                         new Tuple("direction-wind", "328 °"), new Tuple("speed-wind", "0.4 m/s"),
105                         new Tuple("speed-gust", "1 m/s"), new Tuple("rain-rate", "0 mm/h"),
106                         new Tuple("rain-day", "3.3 mm"), new Tuple("rain-week", "4.6 mm"),
107                         new Tuple("rain-month", "33.5 mm"), new Tuple("rain-year", "410.3 mm"),
108                         new Tuple("rain-total", "486.1 mm"), new Tuple("illumination", "74028 lx"),
109                         new Tuple("irradiation-uv", "215.3 mW/m²"), new Tuple("uv-index", "5"));
110     }
111
112     @Test
113     void testRainData() {
114         byte[] data = HexUtils
115                 .hexToBytes("FFFF5700290E000010000000001100000024120000003113000005030D00000F0064880000017A017B0030");
116         DebugDetails debugDetails = new DebugDetails(data, Command.CMD_READ_RAIN, Protocol.DEFAULT);
117         List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.DEFAULT).getRainData(data,
118                 new ConversionContext(ZoneOffset.UTC), debugDetails);
119         Assertions.assertThat(measuredValues)
120                 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
121                 .containsExactly(new Tuple("rain-rate", "0 mm/h"), new Tuple("rain-day", "0 mm"),
122                         new Tuple("rain-week", "3.6 mm"), new Tuple("rain-month", "4.9 mm"),
123                         new Tuple("rain-year", "128.3 mm"), new Tuple("rain-event", "0 mm"),
124                         new Tuple("rain-hour", "10 mm"));
125     }
126
127     @Test
128     void testRainDataW90() {
129         byte[] data = HexUtils.hexToBytes(
130                 "FFFF5700398000008300000009840000000985000000C786000000C7810000870064006400640064006400640064006400640064880900007A02BF");
131         Assertions.assertThat(Command.CMD_READ_RAIN.isResponseValid(data)).isTrue();
132         DebugDetails debugDetails = new DebugDetails(data, Command.CMD_READ_RAIN, Protocol.DEFAULT);
133         List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.DEFAULT).getRainData(data,
134                 new ConversionContext(ZoneOffset.UTC), debugDetails);
135         Assertions.assertThat(measuredValues)
136                 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
137                 .containsExactly(new Tuple("piezo-rain-rate", "0 mm/h"), new Tuple("piezo-rain-day", "0.9 mm"),
138                         new Tuple("piezo-rain-week", "0.9 mm"), new Tuple("piezo-rain-month", "19.9 mm"),
139                         new Tuple("piezo-rain-year", "19.9 mm"), new Tuple("piezo-rain-event", "0 mm"));
140     }
141
142     @Test
143     void testFirmware() {
144         byte[] data = HexUtils.hexToBytes("FFFF501511456173795765617468657256312E362E3400");
145         String firmware = new FineOffsetDataParser(Protocol.ELV).getFirmwareVersion(data);
146         Assertions.assertThat(firmware).isEqualTo("EasyWeatherV1.6.4");
147     }
148 }