2 * Copyright (c) 2010-2022 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.bouncycastle.util.encoders.Hex;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
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;
28 * @author Andreas Berger - Initial contribution
31 class FineOffsetDataParserTest {
33 void testLiveDataWH45() {
34 List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(Hex.decode(
35 "FFFF2700510100D306280827EF0927EF020045074F0A00150B00000C0000150000000016000117001900000E0000100000110021120000002113000005850D00007000D12E0060005A005B005502AE028F0633"),
36 new ConversionContext(ZoneOffset.UTC));
37 Assertions.assertThat(data)
38 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
39 .containsExactly(new Tuple("temperature-indoor", "21.1 °C"), new Tuple("humidity-indoor", "40 %"),
40 new Tuple("pressure-absolute", "1022.3 hPa"), new Tuple("pressure-relative", "1022.3 hPa"),
41 new Tuple("temperature-outdoor", "6.9 °C"), new Tuple("humidity-outdoor", "79 %"),
42 new Tuple("direction-wind", "21 °"), new Tuple("speed-wind", "0 m/s"),
43 new Tuple("speed-gust", "0 m/s"), new Tuple("illumination", "0 lx"),
44 new Tuple("irradiation-uv", "0.1 mW/m²"), new Tuple("uv-index", "0"),
45 new Tuple("wind-max-day", "0 m/s"), new Tuple("rain-rate", "0 mm/h"),
46 new Tuple("rain-day", "0 mm"), new Tuple("rain-week", "3.3 mm"),
47 new Tuple("rain-month", "3.3 mm"), new Tuple("rain-year", "141.3 mm"),
48 new Tuple("rain-event", "0 mm"), new Tuple("sensor-co2-temperature", "20.9 °C"),
49 new Tuple("sensor-co2-humidity", "46 %"), new Tuple("sensor-co2-pm10", "9.6 µg/m³"),
50 new Tuple("sensor-co2-pm10-24-hour-average", "9 µg/m³"),
51 new Tuple("sensor-co2-pm25", "9.1 µg/m³"),
52 new Tuple("sensor-co2-pm25-24-hour-average", "8.5 µg/m³"),
53 new Tuple("sensor-co2-co2", "686 ppm"), new Tuple("sensor-co2-co2-24-hour-average", "655 ppm"));
57 void testLiveDataELV() {
58 byte[] data = Hex.decode(
59 "FFFF0B00500401010B0201120300620401120501120629072108254B09254B0A01480B00040C000A0E000000001000000021110000002E120000014F130000100714000012FD15000B4BB816086917056D35");
60 List<MeasuredValue> measuredValues = new FineOffsetDataParser(Protocol.ELV).getMeasuredValues(data,
61 new ConversionContext(ZoneOffset.UTC));
62 Assertions.assertThat(measuredValues)
63 .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
64 .containsExactly(new Tuple("temperature-indoor", "26.7 °C"),
65 new Tuple("temperature-outdoor", "27.4 °C"), new Tuple("temperature-dew-point", "9.8 °C"),
66 new Tuple("temperature-wind-chill", "27.4 °C"), new Tuple("temperature-heat-index", "27.4 °C"),
67 new Tuple("humidity-indoor", "41 %"), new Tuple("humidity-outdoor", "33 %"),
68 new Tuple("pressure-absolute", "954.7 hPa"), new Tuple("pressure-relative", "954.7 hPa"),
69 new Tuple("direction-wind", "328 °"), new Tuple("speed-wind", "0.4 m/s"),
70 new Tuple("speed-gust", "1 m/s"), new Tuple("rain-rate", "0 mm/h"),
71 new Tuple("rain-day", "3.3 mm"), new Tuple("rain-week", "4.6 mm"),
72 new Tuple("rain-month", "33.5 mm"), new Tuple("rain-year", "410.3 mm"),
73 new Tuple("rain-total", "486.1 mm"), new Tuple("illumination", "74028 lx"),
74 new Tuple("irradiation-uv", "215.3 mW/m²"), new Tuple("uv-index", "5"));
79 byte[] data = Hex.decode("FFFF501511456173795765617468657256312E362E3400");
80 String firmware = new FineOffsetDataParser(Protocol.ELV).getFirmwareVersion(data);
81 Assertions.assertThat(firmware).isEqualTo("EasyWeatherV1.6.4");