]> git.basschouten.com Git - openhab-addons.git/blob
393a0d85f3212fc986bea467d0ceb5a3e9f6fe22
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Command used to get the Clean Filter Indicator status
26  *
27  * @author Benjamin Lafois - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public class GetCleanFilterIndicatorCommand extends BRC1HCommand {
32
33     private final Logger logger = LoggerFactory.getLogger(GetCleanFilterIndicatorCommand.class);
34
35     private @Nullable Boolean cleanFilterIndicator;
36
37     @Override
38     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
39             throws MadokaParsingException {
40
41         byte[] valueCleanFilterIndicator = mm.getValues().get(0x62).getRawValue();
42         if (valueCleanFilterIndicator == null || valueCleanFilterIndicator.length != 1) {
43             setState(State.FAILED);
44             throw new MadokaParsingException("Incorrect clean filter indicator value");
45         }
46
47         if ((valueCleanFilterIndicator[0] & 0x01) == 0x01) {
48             this.cleanFilterIndicator = true;
49         } else {
50             this.cleanFilterIndicator = false;
51         }
52
53         setState(State.SUCCEEDED);
54         executor.execute(() -> listener.receivedResponse(this));
55     }
56
57     public @Nullable Boolean getCleanFilterIndicator() {
58         return cleanFilterIndicator;
59     }
60
61     @Override
62     public byte[][] getRequest() {
63         return MadokaMessage.createRequest(this);
64     }
65
66     @Override
67     public int getCommandId() {
68         return 256;
69     }
70 }