]> git.basschouten.com Git - openhab-addons.git/blob
93401d6be9ecb13411dd4bbb96366c7a8ece5781
[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  * This command returns the firmware version
25  *
26  * @author Benjamin Lafois - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public class GetVersionCommand extends BRC1HCommand {
31
32     private @Nullable String remoteControllerVersion;
33     private @Nullable String communicationControllerVersion;
34
35     @Override
36     public byte[][] getRequest() {
37         return MadokaMessage.createRequest(this);
38     }
39
40     @Override
41     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
42             throws MadokaParsingException {
43         MadokaValue mValue45 = mm.getValues().get(0x45);
44         MadokaValue mValue46 = mm.getValues().get(0x46);
45         if (mValue45 == null || mValue46 == null) {
46             String message = "version value is null when handling the response";
47             setState(State.FAILED);
48             throw new MadokaParsingException(message);
49         }
50
51         byte[] mv45 = mValue45.getRawValue();
52         byte[] mv46 = mValue46.getRawValue();
53
54         if (mv45 == null || mv45.length != 3 || mv46 == null || mv46.length != 2) {
55             setState(State.FAILED);
56             throw new MadokaParsingException("Incorrect version value");
57         }
58
59         int remoteControllerMajor = mv45[0];
60         int remoteControllerMinor = mv45[1];
61         int remoteControllerRevision = mv45[2];
62         this.remoteControllerVersion = remoteControllerMajor + "." + remoteControllerMinor + "."
63                 + remoteControllerRevision;
64
65         int commControllerMajor = mv46[0];
66         int commControllerMinor = mv46[1];
67         this.communicationControllerVersion = commControllerMajor + "." + commControllerMinor;
68
69         setState(State.SUCCEEDED);
70         try {
71             executor.execute(() -> listener.receivedResponse(this));
72         } catch (Exception e) {
73             setState(State.FAILED);
74             throw new MadokaParsingException(e);
75         }
76     }
77
78     @Override
79     public int getCommandId() {
80         return 304;
81     }
82
83     public @Nullable String getRemoteControllerVersion() {
84         return remoteControllerVersion;
85     }
86
87     public @Nullable String getCommunicationControllerVersion() {
88         return communicationControllerVersion;
89     }
90 }