]> git.basschouten.com Git - openhab-addons.git/blob
c5a3bf3256310b9ab29350c333f832a1beaddff6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.elroconnects.internal.devices;
14
15 import java.util.Map;
16
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;
22
23 /**
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.
26  *
27  * @author Mark Herwege - Initial contribution
28  */
29 @NonNullByDefault
30 public abstract class ElroConnectsDevice {
31
32     // minimum data to create an instance of the class
33     protected int deviceId;
34     protected ElroConnectsBridgeHandler bridge;
35
36     protected volatile String deviceName = "";
37     protected volatile String deviceType = "";
38     protected volatile String deviceStatus = "";
39
40     protected volatile Map<String, ElroDeviceStatus> statusMap = Map.of();
41
42     /**
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.
46      *
47      * @param deviceId
48      * @param bridge
49      */
50     public ElroConnectsDevice(int deviceId, ElroConnectsBridgeHandler bridge) {
51         this.deviceId = deviceId;
52         this.bridge = bridge;
53     }
54
55     /**
56      * Get the current status of the device.
57      *
58      * @return status
59      */
60     protected ElroDeviceStatus getStatus() {
61         String deviceStatus = this.deviceStatus;
62         ElroDeviceStatus elroStatus = ElroDeviceStatus.UNDEF;
63
64         if (deviceStatus.length() >= 6) {
65             elroStatus = statusMap.getOrDefault(deviceStatus.substring(4, 6), ElroDeviceStatus.UNDEF);
66         }
67
68         return elroStatus;
69     }
70
71     public void setDeviceName(String deviceName) {
72         this.deviceName = deviceName;
73     }
74
75     public void setDeviceType(String deviceType) {
76         this.deviceType = deviceType;
77     }
78
79     public void setDeviceStatus(String deviceStatus) {
80         this.deviceStatus = deviceStatus;
81     }
82
83     public String getDeviceName() {
84         return deviceName;
85     }
86
87     public String getDeviceType() {
88         return deviceType;
89     }
90
91     /**
92      * Retrieve the {@link ElroConnectsDeviceHandler} for device.
93      *
94      * @return handler for the device.
95      */
96     protected @Nullable ElroConnectsDeviceHandler getHandler() {
97         return bridge.getDeviceHandler(deviceId);
98     }
99
100     /**
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.
103      */
104     public abstract void updateState();
105
106     /**
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.
109      */
110     public abstract void testAlarm();
111
112     /**
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.
115      */
116     public abstract void muteAlarm();
117
118     /**
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.
121      */
122     public abstract void switchState(boolean state);
123 }