2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands;
15 import java.util.concurrent.Executor;
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;
23 * This command returns the firmware version
25 * @author Benjamin Lafois - Initial contribution
29 public class GetVersionCommand extends BRC1HCommand {
31 private @Nullable String remoteControllerVersion;
32 private @Nullable String communicationControllerVersion;
35 public byte[][] getRequest() {
36 return MadokaMessage.createRequest(this);
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();
47 if (mv45 == null || mv45.length != 3 || mv46 == null || mv46.length != 2) {
48 setState(State.FAILED);
49 throw new MadokaParsingException("Incorrect version value");
52 int remoteControllerMajor = mv45[0];
53 int remoteControllerMinor = mv45[1];
54 int remoteControllerRevision = mv45[2];
55 this.remoteControllerVersion = remoteControllerMajor + "." + remoteControllerMinor + "."
56 + remoteControllerRevision;
58 int commControllerMajor = mv46[0];
59 int commControllerMinor = mv46[1];
60 this.communicationControllerVersion = commControllerMajor + "." + commControllerMinor;
62 setState(State.SUCCEEDED);
63 executor.execute(() -> listener.receivedResponse(this));
67 public int getCommandId() {
71 public @Nullable String getRemoteControllerVersion() {
72 return remoteControllerVersion;
75 public @Nullable String getCommunicationControllerVersion() {
76 return communicationControllerVersion;