]> git.basschouten.com Git - openhab-addons.git/blob
12418645864b559ad5be4682b2557bebfcc48781
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands;
14
15 import java.util.concurrent.Executor;
16
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;
25
26 /**
27  * Command used to set the Blue Eye Brightness
28  *
29  * @author Benjamin Lafois - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class SetEyeBrightnessCommand extends BRC1HCommand {
34
35     private final Logger logger = LoggerFactory.getLogger(SetEyeBrightnessCommand.class);
36
37     private PercentType eyeBrightness;
38
39     public SetEyeBrightnessCommand(PercentType eyeBrightness) {
40         this.eyeBrightness = eyeBrightness;
41     }
42
43     @Override
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));
49         }
50
51         setState(State.SUCCEEDED);
52         executor.execute(() -> listener.receivedResponse(this));
53     }
54
55     @Override
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);
59
60         MadokaValue mv = new MadokaValue(0x33, 1, new byte[] { val });
61         return MadokaMessage.createRequest(this, mv);
62     }
63
64     @Override
65     public int getCommandId() {
66         return 17154;
67     }
68
69     public PercentType getEyeBrightness() {
70         return eyeBrightness;
71     }
72
73     /**
74      *
75      * @param eyeBrightness a percentage - between 0 and 100
76      */
77     public void setEyeBrightness(PercentType eyeBrightness) {
78         this.eyeBrightness = eyeBrightness;
79     }
80 }