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.fineoffsetweatherstation.internal.service;
15 import java.time.ZoneOffset;
16 import java.util.List;
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.Protocol;
25 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.MeasuredValue;
26 import org.openhab.core.util.HexUtils;
29 * @author Andreas Berger - Initial contribution
32 class FineOffsetDataParserTest {
34 void testLiveDataWH45() {
35 List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(HexUtils.hexToBytes(
36 "FFFF2700510100D306280827EF0927EF020045074F0A00150B00000C0000150000000016000117001900000E0000100000110021120000002113000005850D00007000D12E0060005A005B005502AE028F0633"),
37 new ConversionContext(ZoneOffset.UTC));
38 Assertions.assertThat(data)
39 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
40 .containsExactly(new Tuple("temperature-indoor", "21.1 °C"), new Tuple("humidity-indoor", "40 %"),
41 new Tuple("pressure-absolute", "1022.3 hPa"), new Tuple("pressure-relative", "1022.3 hPa"),
42 new Tuple("temperature-outdoor", "6.9 °C"), new Tuple("humidity-outdoor", "79 %"),
43 new Tuple("direction-wind", "21 °"), new Tuple("speed-wind", "0 m/s"),
44 new Tuple("speed-gust", "0 m/s"), new Tuple("illumination", "0 lx"),
45 new Tuple("irradiation-uv", "0.1 mW/m²"), new Tuple("uv-index", "0"),
46 new Tuple("wind-max-day", "0 m/s"), new Tuple("rain-rate", "0 mm/h"),
47 new Tuple("rain-day", "0 mm"), new Tuple("rain-week", "3.3 mm"),
48 new Tuple("rain-month", "3.3 mm"), new Tuple("rain-year", "141.3 mm"),
49 new Tuple("rain-event", "0 mm"), new Tuple("sensor-co2-temperature", "20.9 °C"),
50 new Tuple("sensor-co2-humidity", "46 %"), new Tuple("sensor-co2-pm10", "9.6 µg/m³"),
51 new Tuple("sensor-co2-pm10-24-hour-average", "9 µg/m³"),
52 new Tuple("sensor-co2-pm25", "9.1 µg/m³"),
53 new Tuple("sensor-co2-pm25-24-hour-average", "8.5 µg/m³"),
54 new Tuple("sensor-co2-co2", "686 ppm"), new Tuple("sensor-co2-co2-24-hour-average", "655 ppm"));
58 void testLiveDataELV() {
59 byte[] data = HexUtils.hexToBytes(
60 "FFFF0B00500401010B0201120300620401120501120629072108254B09254B0A01480B00040C000A0E000000001000000021110000002E120000014F130000100714000012FD15000B4BB816086917056D35");
61 List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.ELV).getMeasuredValues(data,
62 new ConversionContext(ZoneOffset.UTC));
63 Assertions.assertThat(measuredValues)
64 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
65 .containsExactly(new Tuple("temperature-indoor", "26.7 °C"),
66 new Tuple("temperature-outdoor", "27.4 °C"), new Tuple("temperature-dew-point", "9.8 °C"),
67 new Tuple("temperature-wind-chill", "27.4 °C"), new Tuple("temperature-heat-index", "27.4 °C"),
68 new Tuple("humidity-indoor", "41 %"), new Tuple("humidity-outdoor", "33 %"),
69 new Tuple("pressure-absolute", "954.7 hPa"), new Tuple("pressure-relative", "954.7 hPa"),
70 new Tuple("direction-wind", "328 °"), new Tuple("speed-wind", "0.4 m/s"),
71 new Tuple("speed-gust", "1 m/s"), new Tuple("rain-rate", "0 mm/h"),
72 new Tuple("rain-day", "3.3 mm"), new Tuple("rain-week", "4.6 mm"),
73 new Tuple("rain-month", "33.5 mm"), new Tuple("rain-year", "410.3 mm"),
74 new Tuple("rain-total", "486.1 mm"), new Tuple("illumination", "74028 lx"),
75 new Tuple("irradiation-uv", "215.3 mW/m²"), new Tuple("uv-index", "5"));
80 byte[] data = HexUtils
81 .hexToBytes("FFFF5700290E000010000000001100000024120000003113000005030D00000F0064880000017A017B0030");
82 List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.DEFAULT).getRainData(data,
83 new ConversionContext(ZoneOffset.UTC));
84 Assertions.assertThat(measuredValues)
85 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
86 .containsExactly(new Tuple("rain-rate", "0 mm/h"), new Tuple("rain-day", "0 mm"),
87 new Tuple("rain-week", "3.6 mm"), new Tuple("rain-month", "4.9 mm"),
88 new Tuple("rain-year", "128.3 mm"), new Tuple("rain-event", "0 mm"),
89 new Tuple("rain-hour", "10 mm"));
93 void testRainDataW90() {
94 byte[] data = HexUtils.hexToBytes(
95 "FFFF5700398000008300000009840000000985000000C786000000C7810000870064006400640064006400640064006400640064880900007A02BF");
96 Assertions.assertThat(Command.CMD_READ_RAIN.isResponseValid(data)).isTrue();
97 List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.DEFAULT).getRainData(data,
98 new ConversionContext(ZoneOffset.UTC));
99 Assertions.assertThat(measuredValues)
100 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
101 .containsExactly(new Tuple("piezo-rain-rate", "0 mm/h"), new Tuple("piezo-rain-day", "0.9 mm"),
102 new Tuple("piezo-rain-week", "0.9 mm"), new Tuple("piezo-rain-month", "19.9 mm"),
103 new Tuple("piezo-rain-year", "19.9 mm"), new Tuple("piezo-rain-event", "0 mm"));
107 void testFirmware() {
108 byte[] data = HexUtils.hexToBytes("FFFF501511456173795765617468657256312E362E3400");
109 String firmware = new FineOffsetDataParser(Protocol.ELV).getFirmwareVersion(data);
110 Assertions.assertThat(firmware).isEqualTo("EasyWeatherV1.6.4");