]> git.basschouten.com Git - openhab-addons.git/blob
128f7bc76ce4efbb6eb8f05f206bc5953537191a
[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.bluetooth.daikinmadoka.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.nio.ByteOrder;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.GetIndoorOutoorTemperatures;
24 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.GetOperationHoursCommand;
25 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetPowerstateCommand;
26 import org.openhab.core.library.types.OnOffType;
27
28 /**
29  *
30  * @author blafois - Initial contribution
31  *
32  */
33 @NonNullByDefault
34 public class MadokaMessageTest {
35
36     @Test
37     public void testMessageBuildTemperature() {
38         byte[][] resp = new GetIndoorOutoorTemperatures().getRequest();
39         assertArrayEquals(resp[0], new byte[] { 0x00, 0x06, 0x00, 0x01, 0x10, 0x00, 0x00 });
40     }
41
42     @Test
43     public void testMessageBuildSetPower() {
44         boolean powered = true;
45         MadokaValue mv = new MadokaValue(0x20, 1, new byte[] { 1 });
46         byte[][] resp = MadokaMessage.createRequest(new SetPowerstateCommand(OnOffType.ON), mv);
47         assertArrayEquals(new byte[] { 0x00, 0x07, 0x00, 0x40, 0x20, 0x20, 0x01, (byte) (powered ? 0x01 : 0x00) },
48                 resp[0]);
49     }
50
51     @Test
52     public void testMessageBuildSize() {
53         byte[][] resp = MadokaMessage.createRequest(new GetIndoorOutoorTemperatures());
54         assertEquals(1, resp.length);
55     }
56
57     @Test
58     public void testOperationHoursCommand() {
59         byte[][] resp = new GetOperationHoursCommand().getRequest();
60         assertEquals(2, resp.length);
61         assertArrayEquals(new byte[] { 0x00, 0x19, 0x00, 0x01, 0x12, 0x02, 0x01, 0x00, 0x40, 0x00, 0x41, 0x00, 0x42,
62                 0x00, 0x43, 0x00, 0x44, 0x00, 0x45, 0x00 }, resp[0]);
63         assertArrayEquals(new byte[] { 0x01, 0x46, 0x00, 0x47, 0x00, 0x48, 0x00 }, resp[1]);
64     }
65
66     @Test
67     public void testParseOperationHours() {
68         MadokaValue mv = new MadokaValue(0, 4, new byte[] { (byte) 0xF4, 0x03, 0x00, 0x00 });
69         Long v = mv.getComputedValue(ByteOrder.LITTLE_ENDIAN);
70         assertEquals(1012, v);
71     }
72 }