2 * Copyright (c) 2010-2023 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;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
24 * This command returns the firmware version
26 * @author Benjamin Lafois - Initial contribution
30 public class GetVersionCommand extends BRC1HCommand {
32 private @Nullable String remoteControllerVersion;
33 private @Nullable String communicationControllerVersion;
36 public byte[][] getRequest() {
37 return MadokaMessage.createRequest(this);
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);
51 byte[] mv45 = mValue45.getRawValue();
52 byte[] mv46 = mValue46.getRawValue();
54 if (mv45 == null || mv45.length != 3 || mv46 == null || mv46.length != 2) {
55 setState(State.FAILED);
56 throw new MadokaParsingException("Incorrect version value");
59 int remoteControllerMajor = mv45[0];
60 int remoteControllerMinor = mv45[1];
61 int remoteControllerRevision = mv45[2];
62 this.remoteControllerVersion = remoteControllerMajor + "." + remoteControllerMinor + "."
63 + remoteControllerRevision;
65 int commControllerMajor = mv46[0];
66 int commControllerMinor = mv46[1];
67 this.communicationControllerVersion = commControllerMajor + "." + commControllerMinor;
69 setState(State.SUCCEEDED);
71 executor.execute(() -> listener.receivedResponse(this));
72 } catch (Exception e) {
73 setState(State.FAILED);
74 throw new MadokaParsingException(e);
79 public int getCommandId() {
83 public @Nullable String getRemoteControllerVersion() {
84 return remoteControllerVersion;
87 public @Nullable String getCommunicationControllerVersion() {
88 return communicationControllerVersion;