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.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 MadokaValue mValue = mm.getValues().get(0x33);
44 String message = "eye brightness is null when handling the response";
45 setState(State.FAILED);
46 throw new MadokaParsingException(message);
49 byte[] bEyeBrightness = mValue.getRawValue();
50 if (bEyeBrightness == null) {
51 setState(State.FAILED);
52 throw new MadokaParsingException("Incorrect eye brightness value");
55 Integer iEyeBrightness = Integer.valueOf(bEyeBrightness[0]);
56 // The values accepted by the device are from 0 to 19 - integers so conversion needed for Dimmer channel
57 eyeBrightness = new PercentType((int) Math.round(iEyeBrightness / 0.19));
59 logger.debug("Eye Brightness: {}", eyeBrightness);
61 setState(State.SUCCEEDED);
63 executor.execute(() -> listener.receivedResponse(this));
64 } catch (Exception e) {
65 setState(State.FAILED);
66 throw new MadokaParsingException(e);
71 public byte[][] getRequest() {
72 // We can call the function without parameters - but it will return all the display parameters, which makes a 3
73 // chunks return message. As such, specifying requested value 0x33 (eyeBrightness)
74 MadokaValue mv = new MadokaValue(0x33, 1, new byte[] { (byte) 0x00 });
75 return MadokaMessage.createRequest(this, mv);
79 public int getCommandId() {
83 public @Nullable PercentType getEyeBrightness() {