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.satel.internal.command;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.satel.internal.event.EventDispatcher;
17 import org.openhab.binding.satel.internal.event.ZoneTemperatureEvent;
18 import org.openhab.binding.satel.internal.protocol.SatelMessage;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Command class for command that reads temperature in a zone.
25 * @author Krzysztof Goworek - Initial contribution
28 public class ReadZoneTemperature extends SatelCommandBase {
30 private final Logger logger = LoggerFactory.getLogger(this.getClass());
32 public static final byte COMMAND_CODE = (byte) 0x7d;
35 * Creates new command class instance to read temperature in given zone.
37 * @param zoneNbr zone number, 1 ... 256
39 public ReadZoneTemperature(int zoneNbr) {
40 super(COMMAND_CODE, new byte[] { (byte) (zoneNbr == 256 ? 0 : zoneNbr) });
44 * Returns zone temperature (Celsius degrees).
46 * @return zone temperature
48 public float getTemperature() {
49 final byte[] payload = getResponse().getPayload();
50 int temp = ((payload[1] & 0xff) << 8) + (payload[2] & 0xff);
51 return (temp - 110) / 2.0f;
55 protected boolean isResponseValid(SatelMessage response) {
57 if (response.getPayload().length != 3) {
58 logger.debug("Invalid payload length: {}", response.getPayload().length);
65 protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
66 // dispatch temperature event
67 int zoneNbr = getResponse().getPayload()[0];
68 eventDispatcher.dispatchEvent(new ZoneTemperatureEvent(zoneNbr == 0 ? 256 : zoneNbr, getTemperature()));