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.powermax.internal.message;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.powermax.internal.state.PowermaxState;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * A class for SETTINGS and SETTINGS_ITEM messages handling
26 * @author Laurent Garnier - Initial contribution
29 public class PowermaxSettingsMessage extends PowermaxBaseMessage {
31 private final Logger logger = LoggerFactory.getLogger(PowermaxSettingsMessage.class);
37 * the received message as a buffer of bytes
39 public PowermaxSettingsMessage(byte[] message) {
44 protected @Nullable PowermaxState handleMessageInternal(@Nullable PowermaxCommManager commManager) {
45 if (commManager == null) {
49 PowermaxState updatedState = commManager.createNewState();
51 byte[] message = getRawData();
52 int index = message[2] & 0x000000FF;
53 int page = message[3] & 0x000000FF;
56 debug("Page", page, Integer.toString(page));
57 debug("Index", index, Integer.toString(index));
59 if (getReceiveType() == PowermaxReceiveType.SETTINGS) {
60 length = message.length - 6;
61 updatedState.setUpdateSettings(Arrays.copyOfRange(message, 2, 2 + 2 + length));
62 } else if (getReceiveType() == PowermaxReceiveType.SETTINGS_ITEM) {
63 length = message[4] & 0x000000FF;
64 byte[] data = new byte[length + 2];
66 for (int j = 2; j <= 3; j++) {
67 data[i++] = message[j];
69 for (int j = 0; j < length; j++) {
70 data[i++] = message[j + 5];
72 updatedState.setUpdateSettings(data);
74 if (logger.isDebugEnabled()) {
75 logger.debug("Received Powermax setting page {} index {} length {}", String.format("%02X (%d)", page, page),
76 String.format("%02X (%d)", index, index), String.format("%02X (%d)", length, length));