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.model.commands;
15 import java.util.concurrent.Executor;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.util.HexUtils;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * This command is in charge of turning on or off the AC.
28 * @author Benjamin Lafois - Initial contribution
32 public class SetPowerstateCommand extends BRC1HCommand {
34 private final Logger logger = LoggerFactory.getLogger(SetPowerstateCommand.class);
36 private OnOffType powerState;
38 public SetPowerstateCommand(OnOffType powerState) {
39 this.powerState = powerState;
43 public byte[][] getRequest() {
44 MadokaValue mv = new MadokaValue(0x20, 1,
45 new byte[] { (byte) (this.powerState == OnOffType.ON ? 0x01 : 0x00) });
47 return MadokaMessage.createRequest(this, mv);
51 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
52 byte[] msg = mm.getRawMessage();
53 if (logger.isDebugEnabled() && msg != null) {
54 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
57 setState(State.SUCCEEDED);
58 executor.execute(() -> listener.receivedResponse(this));
62 public int getCommandId() {
66 public OnOffType getPowerState() {