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.elroconnects.internal;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.core.thing.ThingTypeUID;
24 * The {@link ElroConnectsBindingConstants} class defines common constants, which are
25 * used across the whole binding.
27 * @author Mark Herwege - Initial contribution
30 public class ElroConnectsBindingConstants {
32 static final String BINDING_ID = "elroconnects";
34 // List of all Thing Type UIDs
35 public static final String TYPE_ACCOUNT = "account";
36 public static final ThingTypeUID THING_TYPE_ACCOUNT = new ThingTypeUID(BINDING_ID, TYPE_ACCOUNT);
38 public static final String TYPE_CONNECTOR = "connector";
39 public static final ThingTypeUID THING_TYPE_CONNECTOR = new ThingTypeUID(BINDING_ID, TYPE_CONNECTOR);
41 public static final String TYPE_SMOKEALARM = "smokealarm";
42 public static final String TYPE_COALARM = "coalarm";
43 public static final String TYPE_HEATALARM = "heatalarm";
44 public static final String TYPE_WATERALARM = "wateralarm";
45 public static final String TYPE_ENTRYSENSOR = "entrysensor";
46 public static final String TYPE_MOTIONSENSOR = "motionsensor";
47 public static final String TYPE_THSENSOR = "temperaturesensor";
48 public static final String TYPE_POWERSOCKET = "powersocket";
49 public static final ThingTypeUID THING_TYPE_SMOKEALARM = new ThingTypeUID(BINDING_ID, TYPE_SMOKEALARM);
50 public static final ThingTypeUID THING_TYPE_COALARM = new ThingTypeUID(BINDING_ID, TYPE_COALARM);
51 public static final ThingTypeUID THING_TYPE_HEATALARM = new ThingTypeUID(BINDING_ID, TYPE_HEATALARM);
52 public static final ThingTypeUID THING_TYPE_WATERALARM = new ThingTypeUID(BINDING_ID, TYPE_WATERALARM);
53 public static final ThingTypeUID THING_TYPE_ENTRYSENSOR = new ThingTypeUID(BINDING_ID, TYPE_ENTRYSENSOR);
54 public static final ThingTypeUID THING_TYPE_MOTIONSENSOR = new ThingTypeUID(BINDING_ID, TYPE_MOTIONSENSOR);
55 public static final ThingTypeUID THING_TYPE_THSENSOR = new ThingTypeUID(BINDING_ID, TYPE_THSENSOR);
56 public static final ThingTypeUID THING_TYPE_POWERSOCKET = new ThingTypeUID(BINDING_ID, TYPE_POWERSOCKET);
58 public static final Set<ThingTypeUID> SUPPORTED_ACCOUNT_TYPE_UIDS = Set.of(THING_TYPE_ACCOUNT);
59 public static final Set<ThingTypeUID> SUPPORTED_CONNECTOR_TYPES_UIDS = Set.of(THING_TYPE_CONNECTOR);
60 public static final Set<ThingTypeUID> SUPPORTED_DEVICE_TYPES_UIDS = Set.of(THING_TYPE_SMOKEALARM,
61 THING_TYPE_COALARM, THING_TYPE_HEATALARM, THING_TYPE_WATERALARM, THING_TYPE_ENTRYSENSOR,
62 THING_TYPE_MOTIONSENSOR, THING_TYPE_THSENSOR, THING_TYPE_POWERSOCKET);
63 public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Stream
64 .concat(SUPPORTED_ACCOUNT_TYPE_UIDS.stream(), SUPPORTED_CONNECTOR_TYPES_UIDS.stream())
65 .collect(Collectors.toSet());
66 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
67 .concat(SUPPORTED_BRIDGE_TYPES_UIDS.stream(), SUPPORTED_DEVICE_TYPES_UIDS.stream())
68 .collect(Collectors.toSet());
70 // List of all Channel ids
71 public static final String SCENE = "scene";
73 public static final String SIGNAL_STRENGTH = "signal";
74 public static final String BATTERY_LEVEL = "battery";
75 public static final String LOW_BATTERY = "lowBattery";
76 public static final String MUTE_ALARM = "muteAlarm";
77 public static final String TEST_ALARM = "testAlarm";
79 public static final String ENTRY = "entry";
80 public static final String MOTION = "motion";
82 public static final String POWER_STATE = "powerState";
84 public static final String TEMPERATURE = "temperature";
85 public static final String HUMIDITY = "humidity";
87 public static final String ALARM = "alarm";
88 public static final String SMOKE_ALARM = "smokeAlarm";
89 public static final String CO_ALARM = "coAlarm";
90 public static final String HEAT_ALARM = "heatAlarm";
91 public static final String WATER_ALARM = "waterAlarm";
92 public static final String ENTRY_ALARM = "entryAlarm";
93 public static final String MOTION_ALARM = "motionAlarm";
96 public static final String CONFIG_USERNAME = "username";
97 public static final String CONFIG_PASSWORD = "password";
98 public static final String CONFIG_CONNECTOR_ID = "connectorId";
99 public static final String CONFIG_IP_ADDRESS = "ipAddress";
100 public static final String CONFIG_REFRESH_INTERVAL_S = "refreshInterval";
101 public static final String CONFIG_LEGACY_FIRMWARE = "legacyFirmware";
102 public static final String CONFIG_DEVICE_ID = "deviceId";
103 public static final String CONFIG_DEVICE_TYPE = "deviceType";
105 // ELRO cmd constants
106 public static final int ELRO_DEVICE_CONTROL = 101;
107 public static final int ELRO_GET_DEVICE_NAME = 14;
108 public static final int ELRO_GET_DEVICE_STATUSES = 15;
109 public static final int ELRO_REC_DEVICE_NAME = 17;
110 public static final int ELRO_REC_DEVICE_STATUS = 119;
111 public static final int ELRO_SYNC_DEVICES = 29;
113 public static final int ELRO_DEVICE_JOIN = 2;
114 public static final int ELRO_DEVICE_CANCEL_JOIN = 7;
115 public static final int ELRO_DEVICE_REPLACE = 103;
116 public static final int ELRO_DEVICE_REMOVE = 104;
117 public static final int ELRO_DEVICE_RENAME = 105;
119 public static final int ELRO_SELECT_SCENE = 106;
120 public static final int ELRO_GET_SCENE = 18;
121 public static final int ELRO_REC_SCENE = 128;
122 public static final int ELRO_REC_SCENE_NAME = 126;
123 public static final int ELRO_REC_SCENE_TYPE = 127;
124 public static final int ELRO_SYNC_SCENES = 131;
126 public static final int ELRO_REC_ALARM = 25;
128 public static final int ELRO_IGNORE_YES_NO = 11;
130 // Older firmware uses different cmd message codes
131 public static final Map<Integer, Integer> ELRO_LEGACY_MESSAGES = Map.ofEntries(Map.entry(ELRO_DEVICE_CONTROL, 1),
132 Map.entry(ELRO_DEVICE_REPLACE, 3), Map.entry(ELRO_DEVICE_REMOVE, 4), Map.entry(ELRO_DEVICE_RENAME, 5),
133 Map.entry(ELRO_SELECT_SCENE, 6), Map.entry(ELRO_SYNC_SCENES, 31), Map.entry(ELRO_REC_DEVICE_STATUS, 19),
134 Map.entry(ELRO_REC_SCENE, 28), Map.entry(ELRO_REC_SCENE_NAME, 26), Map.entry(ELRO_REC_SCENE_TYPE, 27));
135 public static final Map<Integer, Integer> ELRO_NEW_MESSAGES = ELRO_LEGACY_MESSAGES.entrySet().stream()
136 .collect(Collectors.toUnmodifiableMap(Map.Entry::getValue, Map.Entry::getKey));
139 public enum ElroDeviceType {
152 public static final Map<ElroDeviceType, ThingTypeUID> THING_TYPE_MAP = Map.ofEntries(
153 Map.entry(ElroDeviceType.ENTRY_SENSOR, THING_TYPE_ENTRYSENSOR),
154 Map.entry(ElroDeviceType.CO_ALARM, THING_TYPE_COALARM),
155 Map.entry(ElroDeviceType.CXSM_ALARM, THING_TYPE_SMOKEALARM),
156 Map.entry(ElroDeviceType.MOTION_SENSOR, THING_TYPE_MOTIONSENSOR),
157 Map.entry(ElroDeviceType.SM_ALARM, THING_TYPE_SMOKEALARM),
158 Map.entry(ElroDeviceType.THERMAL_ALARM, THING_TYPE_HEATALARM),
159 Map.entry(ElroDeviceType.WT_ALARM, THING_TYPE_WATERALARM),
160 Map.entry(ElroDeviceType.TH_SENSOR, THING_TYPE_THSENSOR),
161 Map.entry(ElroDeviceType.POWERSOCKET, THING_TYPE_POWERSOCKET));
163 public static final Map<ElroDeviceType, String> TYPE_NAMES = Map.ofEntries(
164 Map.entry(ElroDeviceType.ENTRY_SENSOR, TYPE_ENTRYSENSOR), Map.entry(ElroDeviceType.CO_ALARM, TYPE_COALARM),
165 Map.entry(ElroDeviceType.CXSM_ALARM, TYPE_SMOKEALARM),
166 Map.entry(ElroDeviceType.MOTION_SENSOR, TYPE_MOTIONSENSOR),
167 Map.entry(ElroDeviceType.SM_ALARM, TYPE_SMOKEALARM),
168 Map.entry(ElroDeviceType.THERMAL_ALARM, TYPE_HEATALARM),
169 Map.entry(ElroDeviceType.WT_ALARM, TYPE_WATERALARM), Map.entry(ElroDeviceType.TH_SENSOR, TYPE_THSENSOR),
170 Map.entry(ElroDeviceType.POWERSOCKET, TYPE_POWERSOCKET));
172 public static final Set<String> T_ENTRY_SENSOR = Set.of("0101", "1101", "2101");
173 public static final Set<String> T_POWERSOCKET = Set.of("0200", "1200", "2200");
174 public static final Set<String> T_MOTION_SENSOR = Set.of("0100", "1100", "2100");
175 public static final Set<String> T_CO_ALARM = Set.of("0000", "1000", "2000", "0008", "1008", "2008", "000E", "100E",
177 public static final Set<String> T_SM_ALARM = Set.of("0001", "1001", "2001", "0009", "1009", "2009", "000F", "100F",
179 public static final Set<String> T_WT_ALARM = Set.of("0004", "1004", "2004", "000C", "100C", "200C", "0012", "1012",
181 public static final Set<String> T_TH_SENSOR = Set.of("0102", "1102", "2102");
182 public static final Set<String> T_CXSM_ALARM = Set.of("0005", "1109", "2109", "000D", "100D", "200D", "0013",
184 public static final Set<String> T_THERMAL_ALARM = Set.of("0003", "1003", "2003", "000B", "100B", "200B", "0011",
187 public static final Map<ElroDeviceType, Set<String>> DEVICE_TYPE_MAP = Map.ofEntries(
188 Map.entry(ElroDeviceType.ENTRY_SENSOR, T_ENTRY_SENSOR), Map.entry(ElroDeviceType.CO_ALARM, T_CO_ALARM),
189 Map.entry(ElroDeviceType.CXSM_ALARM, T_CXSM_ALARM),
190 Map.entry(ElroDeviceType.MOTION_SENSOR, T_MOTION_SENSOR), Map.entry(ElroDeviceType.SM_ALARM, T_SM_ALARM),
191 Map.entry(ElroDeviceType.POWERSOCKET, T_POWERSOCKET),
192 Map.entry(ElroDeviceType.THERMAL_ALARM, T_THERMAL_ALARM), Map.entry(ElroDeviceType.TH_SENSOR, T_TH_SENSOR),
193 Map.entry(ElroDeviceType.WT_ALARM, T_WT_ALARM));
195 public static final Map<String, ElroDeviceType> TYPE_MAP = DEVICE_TYPE_MAP.entrySet().stream()
196 .flatMap(e -> e.getValue().stream().map(v -> Map.entry(v, e.getKey())))
197 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
199 // ELRO device status
200 public enum ElroDeviceStatus {
210 // Listener threadname prefix
211 public static final String THREAD_NAME_PREFIX = "binding-";