]> git.basschouten.com Git - openhab-addons.git/blob
de09c148bf68f65cf41166862d6a993bb0ce25fe
[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
22 /**
23  * This command returns the firmware version
24  *
25  * @author Benjamin Lafois - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class GetVersionCommand extends BRC1HCommand {
30
31     private @Nullable String remoteControllerVersion;
32     private @Nullable String communicationControllerVersion;
33
34     @Override
35     public byte[][] getRequest() {
36         return MadokaMessage.createRequest(this);
37     }
38
39     @Override
40     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
41             throws MadokaParsingException {
42         // In this method, we intentionally do not check for null values in mv45 and mv46. In case of null pointer
43         // access, it will be catched by the global exception and be reported as a Parsing Reponse exception.
44         byte[] mv45 = mm.getValues().get(0x45).getRawValue();
45         byte[] mv46 = mm.getValues().get(0x46).getRawValue();
46
47         if (mv45 == null || mv45.length != 3 || mv46 == null || mv46.length != 2) {
48             setState(State.FAILED);
49             throw new MadokaParsingException("Incorrect version value");
50         }
51
52         int remoteControllerMajor = mv45[0];
53         int remoteControllerMinor = mv45[1];
54         int remoteControllerRevision = mv45[2];
55         this.remoteControllerVersion = remoteControllerMajor + "." + remoteControllerMinor + "."
56                 + remoteControllerRevision;
57
58         int commControllerMajor = mv46[0];
59         int commControllerMinor = mv46[1];
60         this.communicationControllerVersion = commControllerMajor + "." + commControllerMinor;
61
62         setState(State.SUCCEEDED);
63         executor.execute(() -> listener.receivedResponse(this));
64     }
65
66     @Override
67     public int getCommandId() {
68         return 304;
69     }
70
71     public @Nullable String getRemoteControllerVersion() {
72         return remoteControllerVersion;
73     }
74
75     public @Nullable String getCommunicationControllerVersion() {
76         return communicationControllerVersion;
77     }
78 }