2 * Copyright (c) 2010-2022 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.elroconnects.internal.devices;
15 import static org.openhab.binding.elroconnects.internal.ElroConnectsBindingConstants.*;
16 import static org.openhab.core.library.unit.SIUnits.CELSIUS;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.elroconnects.internal.ElroConnectsBindingConstants.ElroDeviceStatus;
20 import org.openhab.binding.elroconnects.internal.handler.ElroConnectsBridgeHandler;
21 import org.openhab.binding.elroconnects.internal.handler.ElroConnectsDeviceHandler;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.thing.ThingStatusDetail;
28 import org.openhab.core.types.UnDefType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link ElroConnectsDeviceTemperatureSensor} is representing an ELRO Connects temperature and humidity sensor
36 * @author Mark Herwege - Initial contribution
39 public class ElroConnectsDeviceTemperatureSensor extends ElroConnectsDevice {
41 private final Logger logger = LoggerFactory.getLogger(ElroConnectsDeviceTemperatureSensor.class);
43 public ElroConnectsDeviceTemperatureSensor(int deviceId, ElroConnectsBridgeHandler bridge) {
44 super(deviceId, bridge);
48 public void updateState() {
49 ElroConnectsDeviceHandler handler = getHandler();
50 if (handler == null) {
54 ElroDeviceStatus elroStatus = ElroDeviceStatus.NORMAL;
58 String deviceStatus = this.deviceStatus;
59 if (deviceStatus.length() >= 8) {
60 batteryLevel = Integer.parseInt(deviceStatus.substring(2, 4), 16);
61 temperature = Byte.parseByte(deviceStatus.substring(4, 6), 16);
62 humidity = Integer.parseInt(deviceStatus.substring(6, 8));
64 elroStatus = ElroDeviceStatus.FAULT;
65 logger.debug("Could not decode device status: {}", deviceStatus);
70 handler.updateState(BATTERY_LEVEL, UnDefType.UNDEF);
71 handler.updateState(LOW_BATTERY, UnDefType.UNDEF);
72 handler.updateState(TEMPERATURE, UnDefType.UNDEF);
73 handler.updateState(HUMIDITY, UnDefType.UNDEF);
74 handler.updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device " + deviceId + " has a fault");
77 handler.updateState(BATTERY_LEVEL, new DecimalType(batteryLevel));
78 handler.updateState(LOW_BATTERY, (batteryLevel < 15) ? OnOffType.ON : OnOffType.OFF);
79 handler.updateState(TEMPERATURE, new QuantityType<>(temperature, CELSIUS));
80 handler.updateState(HUMIDITY, new QuantityType<>(humidity, Units.PERCENT));
81 handler.updateStatus(ThingStatus.ONLINE);
86 public void testAlarm() {
91 public void muteAlarm() {
96 public void switchState(boolean state) {