]> git.basschouten.com Git - openhab-addons.git/blob
8bd65ee0f2acd96923aac4198ea4bbfddcf0e9e0
[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.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.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Command used to set the FAN speed for all modes (auto/cool/heat...)
28  *
29  * @author Benjamin Lafois - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class GetFanspeedCommand extends BRC1HCommand {
34
35     private final Logger logger = LoggerFactory.getLogger(GetFanspeedCommand.class);
36
37     private @Nullable FanSpeed coolingFanSpeed;
38     private @Nullable FanSpeed heatingFanSpeed;
39
40     @Override
41     public byte[][] getRequest() {
42         return MadokaMessage.createRequest(this);
43     }
44
45     @Override
46     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
47             throws MadokaParsingException {
48         MadokaValue coolValue = mm.getValues().get(0x20);
49         MadokaValue heatValue = mm.getValues().get(0x21);
50         if (heatValue == null || coolValue == null) {
51             String message = "heating or cooling fan speed is null when handling the response";
52             setState(State.FAILED);
53             throw new MadokaParsingException(message);
54         }
55
56         byte[] valueCoolingFanSpeed = coolValue.getRawValue();
57         byte[] valueHeatingFanSpeed = heatValue.getRawValue();
58
59         if (valueCoolingFanSpeed == null || valueHeatingFanSpeed == null) {
60             setState(State.FAILED);
61             throw new MadokaParsingException("Incorrect cooling or heating fan speed value");
62         }
63
64         this.coolingFanSpeed = FanSpeed.valueOf(valueCoolingFanSpeed[0]);
65         this.heatingFanSpeed = FanSpeed.valueOf(valueHeatingFanSpeed[0]);
66
67         logger.debug("coolingFanSpeed: {}", coolingFanSpeed);
68         logger.debug("heatingFanSpeed: {}", heatingFanSpeed);
69
70         setState(State.SUCCEEDED);
71
72         try {
73             executor.execute(() -> listener.receivedResponse(this));
74         } catch (Exception e) {
75             setState(State.FAILED);
76             throw new MadokaParsingException(e);
77         }
78     }
79
80     @Override
81     public int getCommandId() {
82         return 80;
83     }
84
85     public @Nullable FanSpeed getCoolingFanSpeed() {
86         return coolingFanSpeed;
87     }
88
89     public @Nullable FanSpeed getHeatingFanSpeed() {
90         return heatingFanSpeed;
91     }
92 }