]> git.basschouten.com Git - openhab-addons.git/blob
6b2f760a2aed73616f102d78c6e91d0734b5c840
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.Assert.assertEquals;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.Test;
19 import org.openhab.binding.bluetooth.airthings.internal.AirthingsParserException;
20 import org.openhab.binding.bluetooth.airthings.internal.AirthingsWavePlusDataParser;
21
22 /**
23  * Tests {@link AirthingsWavePlusParserTest}.
24  *
25  * @author Pauli Anttila - Initial contribution
26  */
27 @NonNullByDefault
28 public class AirthingsWavePlusParserTest {
29
30     @Test(expected = AirthingsParserException.class)
31     public void testWrongVersion() throws AirthingsParserException {
32         int[] data = { 5, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0, 0, 4, 20 };
33         new AirthingsWavePlusDataParser(data);
34     }
35
36     @Test(expected = AirthingsParserException.class)
37     public void testEmptyData() throws AirthingsParserException {
38         int[] data = {};
39         new AirthingsWavePlusDataParser(data);
40     }
41
42     @Test(expected = AirthingsParserException.class)
43     public void testWrongDataLen() throws AirthingsParserException {
44         int[] data = { 1, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0 };
45         new AirthingsWavePlusDataParser(data);
46     }
47
48     @Test
49     public void testParsing() throws AirthingsParserException {
50         int[] data = { 1, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0, 0, 4, 20 };
51         AirthingsWavePlusDataParser parser = new AirthingsWavePlusDataParser(data);
52
53         assertEquals(27.5, parser.getHumidity(), 0.01);
54         assertEquals(681, parser.getCo2());
55         assertEquals(46, parser.getTvoc());
56         assertEquals(24.23, parser.getTemperature(), 0.01);
57         assertEquals(993.5, parser.getPressure(), 0.01);
58         assertEquals(61, parser.getRadonLongTermAvg());
59         assertEquals(122, parser.getRadonShortTermAvg());
60     }
61 }