2 * Copyright (c) 2010-2022 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.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
22 import org.openhab.core.library.types.PercentType;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Command used to get the blue Eye brightness level
29 * @author Benjamin Lafois - Initial contribution
33 public class GetEyeBrightnessCommand extends BRC1HCommand {
35 private final Logger logger = LoggerFactory.getLogger(GetEyeBrightnessCommand.class);
37 private @Nullable PercentType eyeBrightness;
40 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
41 throws MadokaParsingException {
42 byte[] bEyeBrightness = mm.getValues().get(0x33).getRawValue();
44 if (bEyeBrightness == null || bEyeBrightness == null) {
45 setState(State.FAILED);
46 throw new MadokaParsingException("Incorrect eye brightness value");
49 Integer iEyeBrightness = Integer.valueOf(bEyeBrightness[0]);
51 if (iEyeBrightness != null) {
52 // The values accepted by the device are from 0 to 19 - integers so conversion needed for Dimmer channel
53 eyeBrightness = new PercentType((int) Math.round(iEyeBrightness / 0.19));
56 logger.debug("Eye Brightness: {}", eyeBrightness);
58 setState(State.SUCCEEDED);
59 executor.execute(() -> listener.receivedResponse(this));
63 public byte[][] getRequest() {
64 // We can call the function without parameters - but it will return all the display parameters, which makes a 3
65 // chunks return message. As such, specifying requested value 0x33 (eyeBrightness)
66 MadokaValue mv = new MadokaValue(0x33, 1, new byte[] { (byte) 0x00 });
67 return MadokaMessage.createRequest(this, mv);
71 public int getCommandId() {
75 public @Nullable PercentType getEyeBrightness() {