]> git.basschouten.com Git - openhab-addons.git/blob
2732783e4d683ba8859c6120daa0589b82b2b298
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.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.MadokaProperties.FanSpeed;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Command used to set the FAN speed for all modes (auto/cool/heat...)
27  *
28  * @author Benjamin Lafois - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class GetFanspeedCommand extends BRC1HCommand {
33
34     private final Logger logger = LoggerFactory.getLogger(GetFanspeedCommand.class);
35
36     private @Nullable FanSpeed coolingFanSpeed;
37     private @Nullable FanSpeed heatingFanSpeed;
38
39     @Override
40     public byte[][] getRequest() {
41         return MadokaMessage.createRequest(this);
42     }
43
44     @Override
45     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
46             throws MadokaParsingException {
47
48         byte[] valueCoolingFanSpeed = mm.getValues().get(0x20).getRawValue();
49         byte[] valueHeatingFanSpeed = mm.getValues().get(0x21).getRawValue();
50
51         if (valueCoolingFanSpeed == null || valueHeatingFanSpeed == null) {
52             setState(State.FAILED);
53             throw new MadokaParsingException("Incorrect cooling or heating fan speed value");
54         }
55
56         this.coolingFanSpeed = FanSpeed.valueOf(valueCoolingFanSpeed[0]);
57         this.heatingFanSpeed = FanSpeed.valueOf(valueHeatingFanSpeed[0]);
58
59         logger.debug("coolingFanSpeed: {}", coolingFanSpeed);
60         logger.debug("heatingFanSpeed: {}", heatingFanSpeed);
61
62         setState(State.SUCCEEDED);
63         executor.execute(() -> listener.receivedResponse(this));
64     }
65
66     @Override
67     public int getCommandId() {
68         return 80;
69     }
70
71     public @Nullable FanSpeed getCoolingFanSpeed() {
72         return coolingFanSpeed;
73     }
74
75     public @Nullable FanSpeed getHeatingFanSpeed() {
76         return heatingFanSpeed;
77     }
78 }