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