2 * Copyright (c) 2010-2021 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.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;
32 public class MadokaMessageTest {
35 public void testMessageBuildTemperature() {
36 byte[][] resp = new GetIndoorOutoorTemperatures().getRequest();
37 assertArrayEquals(resp[0], new byte[] { 0x00, 0x06, 0x00, 0x01, 0x10, 0x00, 0x00 });
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);
46 new byte[] { 0x00, 0x07, 0x00, 0x40, 0x20, 0x20, 0x01, (byte) (powered == true ? 0x01 : 0x00) },
51 public void testMessageBuildSize() {
52 byte[][] resp = MadokaMessage.createRequest(new GetIndoorOutoorTemperatures());
53 assertEquals(1, resp.length);
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]);
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);