2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.daikinmadoka.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.nio.ByteOrder;
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;
30 * @author blafois - Initial contribution
34 public class MadokaMessageTest {
37 public void testMessageBuildTemperature() {
38 byte[][] resp = new GetIndoorOutoorTemperatures().getRequest();
39 assertArrayEquals(resp[0], new byte[] { 0x00, 0x06, 0x00, 0x01, 0x10, 0x00, 0x00 });
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) },
52 public void testMessageBuildSize() {
53 byte[][] resp = MadokaMessage.createRequest(new GetIndoorOutoorTemperatures());
54 assertEquals(1, resp.length);
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]);
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);