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.MadokaParsingException;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
21 import org.openhab.core.library.types.PercentType;
22 import org.openhab.core.util.HexUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Command used to set the Blue Eye Brightness
29 * @author Benjamin Lafois - Initial contribution
33 public class SetEyeBrightnessCommand extends BRC1HCommand {
35 private final Logger logger = LoggerFactory.getLogger(SetEyeBrightnessCommand.class);
37 private PercentType eyeBrightness;
39 public SetEyeBrightnessCommand(PercentType eyeBrightness) {
40 this.eyeBrightness = eyeBrightness;
44 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
45 throws MadokaParsingException {
46 byte[] msg = mm.getRawMessage();
47 if (logger.isDebugEnabled() && msg != null) {
48 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
51 setState(State.SUCCEEDED);
52 executor.execute(() -> listener.receivedResponse(this));
56 public byte[][] getRequest() {
57 // The values accepted by the device are from 0 to 19 - integers
58 byte val = (byte) Math.round(eyeBrightness.intValue() * 0.19);
60 MadokaValue mv = new MadokaValue(0x33, 1, new byte[] { val });
61 return MadokaMessage.createRequest(this, mv);
65 public int getCommandId() {
69 public PercentType getEyeBrightness() {
75 * @param eyeBrightness a percentage - between 0 and 100
77 public void setEyeBrightness(PercentType eyeBrightness) {
78 this.eyeBrightness = eyeBrightness;