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