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;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
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;
24 * The {@link ElroConnectsDevice} is an abstract class representing all basic properties for ELRO Connects devices.
25 * Concrete subclasses will contain specific logic for each device type.
27 * @author Mark Herwege - Initial contribution
30 public abstract class ElroConnectsDevice {
32 // minimum data to create an instance of the class
33 protected int deviceId;
34 protected ElroConnectsBridgeHandler bridge;
36 protected volatile String deviceName = "";
37 protected volatile String deviceType = "";
38 protected volatile String deviceStatus = "";
40 protected volatile Map<String, ElroDeviceStatus> statusMap = Map.of();
43 * Create a new instance of a subclass of {@link ElroConnectsDevice}. These instances get created by an instance
44 * {@link ElroConnectsBridgeHandler}. The deviceId will be set on creation. Other fields will be set as and when the
45 * information is received from the K1 hub.
50 public ElroConnectsDevice(int deviceId, ElroConnectsBridgeHandler bridge) {
51 this.deviceId = deviceId;
56 * Get the current status of the device.
60 protected ElroDeviceStatus getStatus() {
61 String deviceStatus = this.deviceStatus;
62 ElroDeviceStatus elroStatus = ElroDeviceStatus.UNDEF;
64 if (deviceStatus.length() >= 6) {
65 elroStatus = statusMap.getOrDefault(deviceStatus.substring(4, 6), ElroDeviceStatus.UNDEF);
71 public void setDeviceName(String deviceName) {
72 this.deviceName = deviceName;
75 public void setDeviceType(String deviceType) {
76 this.deviceType = deviceType;
79 public void setDeviceStatus(String deviceStatus) {
80 this.deviceStatus = deviceStatus;
83 public String getDeviceName() {
87 public String getDeviceType() {
92 * Retrieve the {@link ElroConnectsDeviceHandler} for device.
94 * @return handler for the device.
96 protected @Nullable ElroConnectsDeviceHandler getHandler() {
97 return bridge.getDeviceHandler(deviceId);
101 * Update all {@link ElroConnectsDeviceHandler} channel states with information received from the device. This
102 * method needs to be implemented in the concrete subclass when any state updates are received from the device.
104 public abstract void updateState();
107 * Send alarm test message to the device. This method is called from the {@link ElroConnectsDeviceHandler}. The
108 * method needs to be implemented in the concrete subclass when test alarms are supported.
110 public abstract void testAlarm();
113 * Send alarm mute message to the device. This method is called from the {@link ElroConnectsDeviceHandler}. The
114 * method needs to be implemented in the concrete subclass when alarm muting is supported.
116 public abstract void muteAlarm();
119 * Send state switch message to the device. This method is called from the {@link ElroConnectsDeviceHandler}. The
120 * method needs to be implemented in the concrete subclass when switching the state on/off is supported.
122 public abstract void switchState(boolean state);