]> git.basschouten.com Git - openhab-addons.git/blob
67c84f98e5eb59f9686f1a172b3741d0a1271d8f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.bluetooth.airthings;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Map;
18
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;
23
24 /**
25  * Tests {@link AirthingsParserTest}.
26  *
27  * @author Pauli Anttila - Initial contribution
28  */
29 @NonNullByDefault
30 public class AirthingsParserTest {
31
32     @Test
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));
36     }
37
38     @Test
39     public void testEmptyData() {
40         int[] data = {};
41         assertThrows(AirthingsParserException.class, () -> AirthingsDataParser.parseWavePlusData(data));
42     }
43
44     @Test
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));
48     }
49
50     @Test
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);
54
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));
62     }
63
64     @Test
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);
68
69         assertEquals(37.2, result.get(AirthingsDataParser.HUMIDITY));
70         assertEquals(150, result.get(AirthingsDataParser.TVOC));
71         assertEquals(16.05, result.get(AirthingsDataParser.TEMPERATURE));
72     }
73 }