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.bluetooth.airthings;
15 import static org.junit.jupiter.api.Assertions.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.bluetooth.airthings.internal.AirthingsDataParser;
22 import org.openhab.binding.bluetooth.airthings.internal.AirthingsParserException;
25 * Tests {@link AirthingsParserTest}.
27 * @author Pauli Anttila - Initial contribution
30 public class AirthingsParserTest {
33 public void testWrongVersion() {
34 int[] data = { 5, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0, 0, 4, 20 };
35 assertThrows(AirthingsParserException.class, () -> AirthingsDataParser.parseWavePlusData(data));
39 public void testEmptyData() {
41 assertThrows(AirthingsParserException.class, () -> AirthingsDataParser.parseWavePlusData(data));
45 public void testWrongDataLen() throws AirthingsParserException {
46 int[] data = { 1, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0 };
47 assertThrows(AirthingsParserException.class, () -> AirthingsDataParser.parseWavePlusData(data));
51 public void testParsingPlus() throws AirthingsParserException {
52 int[] data = { 1, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0, 0, 4, 20 };
53 Map<String, Number> result = AirthingsDataParser.parseWavePlusData(data);
55 assertEquals(27.5, result.get(AirthingsDataParser.HUMIDITY));
56 assertEquals(681, result.get(AirthingsDataParser.CO2));
57 assertEquals(46, result.get(AirthingsDataParser.TVOC));
58 assertEquals(24.23, result.get(AirthingsDataParser.TEMPERATURE));
59 assertEquals(993.5, result.get(AirthingsDataParser.PRESSURE));
60 assertEquals(61, result.get(AirthingsDataParser.RADON_LONG_TERM_AVG));
61 assertEquals(122, result.get(AirthingsDataParser.RADON_SHORT_TERM_AVG));
65 public void testParsingMini() throws AirthingsParserException {
66 int[] data = { 12, 0, 248, 112, 201, 193, 136, 14, 150, 0, 1, 0, 217, 176, 14, 0, 255, 255, 255, 255 };
67 Map<String, Number> result = AirthingsDataParser.parseWaveMiniData(data);
69 assertEquals(37.2, result.get(AirthingsDataParser.HUMIDITY));
70 assertEquals(150, result.get(AirthingsDataParser.TVOC));
71 assertEquals(16.05, result.get(AirthingsDataParser.TEMPERATURE));