]> git.basschouten.com Git - openhab-addons.git/blob
22b6614e564e506a5d1972a4bc3e6fa521c3a292
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.max.internal.message;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.time.ZoneId;
18 import java.time.ZonedDateTime;
19 import java.util.Date;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.max.internal.Utils;
24
25 /**
26  * Tests cases for {@link HMessage}.
27  *
28  * @author Marcel Verpaalen - Initial contribution
29  */
30 @NonNullByDefault
31 public class HMessageTest {
32
33     public static final String RAW_DATA = "H:KEQ0565026,0b5951,0113,00000000,4eed6795,01,32,12080a,070f,03,0000";
34
35     private final HMessage message = new HMessage(RAW_DATA);
36
37     @Test
38     public void getMessageTypeTest() {
39         MessageType messageType = ((Message) message).getType();
40         assertEquals(MessageType.H, messageType);
41     }
42
43     @Test
44     public void getRFAddressTest() {
45         String rfAddress = message.getRFAddress();
46         assertEquals("0b5951", rfAddress);
47     }
48
49     @Test
50     public void getFirmwareTest() {
51         String firmware = message.getFirmwareVersion();
52         assertEquals("01.13", firmware);
53     }
54
55     @Test
56     public void getConnectionIdTest() {
57         String connectionId = message.getConnectionId();
58         assertEquals("4eed6795", connectionId);
59     }
60
61     @Test
62     public void getCubeTimeStateTest() {
63         String cubeTimeState = message.getCubeTimeState();
64         assertEquals("03", cubeTimeState);
65     }
66
67     @Test
68     public void testParseDateTime() {
69         String[] tokens = RAW_DATA.split(Message.DELIMETER);
70
71         String hexDate = tokens[7];
72         String hexTime = tokens[8];
73
74         int year = Utils.fromHex(hexDate.substring(0, 2));
75         int month = Utils.fromHex(hexDate.substring(2, 4));
76         int dayOfMonth = Utils.fromHex(hexDate.substring(4, 6));
77         assertEquals(18, year);
78         assertEquals(8, month);
79         assertEquals(10, dayOfMonth);
80
81         int hours = Utils.fromHex(hexTime.substring(0, 2));
82         int minutes = Utils.fromHex(hexTime.substring(2, 4));
83         assertEquals(7, hours);
84         assertEquals(15, minutes);
85     }
86
87     @Test
88     public void testGetDateTime() {
89         Date dateTime = message.getDateTime();
90         assertEquals(Date.from(ZonedDateTime.of(2018, 8, 10, 7, 15, 0, 0, ZoneId.systemDefault()).toInstant()),
91                 dateTime);
92     }
93
94     @Test
95     public void getNTPCounterTest() {
96         String ntpCounter = message.getNTPCounter();
97         assertEquals("0", ntpCounter);
98     }
99
100     @Test
101     public void getSerialNumberTest() {
102         String serialNumber = message.getSerialNumber();
103         assertEquals("KEQ0565026", serialNumber);
104     }
105 }