]> git.basschouten.com Git - openhab-addons.git/blob
664047b9014c999c7876bdb43086d8300ad022a6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.shelly.internal.discovery;
14
15 import static org.openhab.binding.shelly.internal.ShellyBindingConstants.BINDING_ID;
16 import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*;
17 import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
18
19 import java.util.LinkedHashMap;
20 import java.util.Map;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.openhab.core.thing.ThingUID;
25
26 /**
27  * The {@link ShellyThingCreator} maps the device id into the thing type id
28  *
29  * @author Markus Michels - Initial contribution
30  */
31 @NonNullByDefault
32 public class ShellyThingCreator {
33     // Device Types
34     public static final String SHELLYDT_1 = "SHSW-1";
35     public static final String SHELLYDT_1PM = "SHSW-PM";
36     public static final String SHELLYDT_1L = "SHSW-L";
37     public static final String SHELLYDT_SHPLG = "SHPLG-1";
38     public static final String SHELLYDT_SHPLG_S = "SHPLG-S";
39     public static final String SHELLYDT_SHPLG_U1 = "SHPLG-U1";
40     public static final String SHELLYDT_SHELLY2 = "SHSW-21";
41     public static final String SHELLYDT_SHELLY25 = "SHSW-25";
42     public static final String SHELLYDT_SHPRO = "SHSW-44";
43     public static final String SHELLYDT_EM = "SHEM";
44     public static final String SHELLYDT_3EM = "SHEM-3";
45     public static final String SHELLYDT_HT = "SHHT-1";
46     public static final String SHELLYDT_DW = "SHDW-1";
47     public static final String SHELLYDT_DW2 = "SHDW-2";
48     public static final String SHELLYDT_SENSE = "SHSEN-1";
49     public static final String SHELLYDT_MOTION = "SHMOS-01";
50     public static final String SHELLYDT_MOTION2 = "SHMOS-02";
51     public static final String SHELLYDT_GAS = "SHGS-1";
52     public static final String SHELLYDT_DIMMER = "SHDM-1";
53     public static final String SHELLYDT_DIMMER2 = "SHDM-2";
54     public static final String SHELLYDT_IX3 = "SHIX3-1";
55     public static final String SHELLYDT_BULB = "SHBLB-1";
56     public static final String SHELLYDT_DUO = "SHBDUO-1";
57     public static final String SHELLYDT_DUORGBW = "SHCB-1";
58     public static final String SHELLYDT_VINTAGE = "SHVIN-1";
59     public static final String SHELLYDT_RGBW2 = "SHRGBW2";
60     public static final String SHELLYDT_BUTTON1 = "SHBTN-1";
61     public static final String SHELLYDT_BUTTON2 = "SHBTN-2";
62     public static final String SHELLYDT_UNI = "SHUNI-1";
63     public static final String SHELLYDT_TRV = "SHTRV-01";
64
65     // Shelly Plus Series
66     public static final String SHELLYDT_PLUS1 = "SNSW-001X16EU";
67     public static final String SHELLYDT_PLUS1PM = "SNSW-001P16EU";
68     public static final String SHELLYDT_PLUS1UL = "SNSW-001X15UL";
69     public static final String SHELLYDT_PLUS1PMUL = "SNSW-001P15UL";
70     public static final String SHELLYDT_PLUS2PM_RELAY = "SNSW-002P16EU-relay";
71     public static final String SHELLYDT_PLUS2PM_ROLLER = "SNSW-002P16EU-roller";
72     public static final String SHELLYDT_PLUS2PM_RELAY_2 = "SNSW-102P16EU-relay";
73     public static final String SHELLYDT_PLUS2PM_ROLLER_2 = "SNSW-102P16EU-roller";
74     public static final String SHELLYDT_PLUSPLUGS = "SNPL-00112EU";
75     public static final String SHELLYDT_PLUSPLUGIT = "SNPL-00110IT";
76     public static final String SHELLYDT_PLUSPLUGUK = "SNPL-00112UK";
77     public static final String SHELLYDT_PLUSPLUGUS = "SNPL-00116US";
78     public static final String SHELLYDT_PLUSI4 = "SNSN-0024X";
79     public static final String SHELLYDT_PLUSI4DC = "SNSN-0D24X";
80     public static final String SHELLYDT_PLUSHT = "SNSN-0013A";
81     public static final String SHELLYDT_PLUSSMOKE = "SNSN-0031Z";
82
83     // Shelly Pro Series
84     public static final String SHELLYDT_PRO1 = "SPSW-001XE16EU";
85     public static final String SHELLYDT_PRO1_2 = "SPSW-101XE16EU";
86     public static final String SHELLYDT_PRO1_3 = "SPSW-201XE16EU";
87     public static final String SHELLYDT_PRO1PM = "SPSW-001PE16EU";
88     public static final String SHELLYDT_PRO1PM_2 = "SPSW-101PE16EU";
89     public static final String SHELLYDT_PRO1PM_3 = "SPSW-201PE16EU";
90     public static final String SHELLYDT_PRO2_RELAY = "SPSW-002XE16EU-relay";
91     public static final String SHELLYDT_PRO2_RELAY_2 = "SPSW-102XE16EU-relay";
92     public static final String SHELLYDT_PRO2_RELAY_3 = "SPSW-202XE16EU-relay";
93     public static final String SHELLYDT_PRO2PM_RELAY = "SPSW-002PE16EU-relay";
94     public static final String SHELLYDT_PRO2PM_ROLLER = "SPSW-002PE16EU-roller";
95     public static final String SHELLYDT_PRO2PM_RELAY_2 = "SPSW-102PE16EU-relay";
96     public static final String SHELLYDT_PRO2PM_ROLLER_2 = "SPSW-102PE16EU-roller";
97     public static final String SHELLYDT_PRO2PM_RELAY_3 = "SPSW-202PE16EU-relay";
98     public static final String SHELLYDT_PRO2PM_ROLLER_3 = "SPSW-202PE16EU-roller";
99     public static final String SHELLYDT_PRO3 = "SPSW-003XE16EU";
100     public static final String SHELLYDT_PRO3EM = "SPEM-003CEBEU";
101     public static final String SHELLYDT_PRO4PM = "SPSW-004PE16EU";
102     public static final String SHELLYDT_PRO4PM_2 = "SPSW-104PE16EU";
103
104     // Shelly BLU Series
105     public static final String SHELLYDT_BLUBUTTON = "SBBT";
106     public static final String SHELLYDT_BLUDW = "SBDW";
107
108     // Thing names
109     public static final String THING_TYPE_SHELLY1_STR = "shelly1";
110     public static final String THING_TYPE_SHELLY1L_STR = "shelly1l";
111     public static final String THING_TYPE_SHELLY1PM_STR = "shelly1pm";
112     public static final String THING_TYPE_SHELLYEM_STR = "shellyem";
113     public static final String THING_TYPE_SHELLY3EM_STR = "shellyem3"; // bad: misspelled product name, it's 3EM
114     public static final String THING_TYPE_SHELLY2_PREFIX = "shellyswitch";
115     public static final String THING_TYPE_SHELLY2_RELAY_STR = "shelly2-relay";
116     public static final String THING_TYPE_SHELLY2_ROLLER_STR = "shelly2-roller";
117     public static final String THING_TYPE_SHELLY25_PREFIX = "shellyswitch25";
118     public static final String THING_TYPE_SHELLY25_RELAY_STR = "shelly25-relay";
119     public static final String THING_TYPE_SHELLY25_ROLLER_STR = "shelly25-roller";
120     public static final String THING_TYPE_SHELLY4PRO_STR = "shelly4pro";
121     public static final String THING_TYPE_SHELLYPLUG_STR = "shellyplug";
122     public static final String THING_TYPE_SHELLYPLUGS_STR = "shellyplugs";
123     public static final String THING_TYPE_SHELLYPLUGU1_STR = "shellyplugu1"; // Shely Plug US
124     public static final String THING_TYPE_SHELLYDIMMER_STR = "shellydimmer";
125     public static final String THING_TYPE_SHELLYDIMMER2_STR = "shellydimmer2";
126     public static final String THING_TYPE_SHELLYIX3_STR = "shellyix3";
127     public static final String THING_TYPE_SHELLYBULB_STR = "shellybulb";
128     public static final String THING_TYPE_SHELLYDUO_STR = "shellybulbduo";
129     public static final String THING_TYPE_SHELLYVINTAGE_STR = "shellyvintage";
130     public static final String THING_TYPE_SHELLYRGBW2_PREFIX = "shellyrgbw2";
131     public static final String THING_TYPE_SHELLYRGBW2_COLOR_STR = THING_TYPE_SHELLYRGBW2_PREFIX + "-color";
132     public static final String THING_TYPE_SHELLYRGBW2_WHITE_STR = THING_TYPE_SHELLYRGBW2_PREFIX + "-white";
133     public static final String THING_TYPE_SHELLYDUORGBW_STR = "shellycolorbulb";
134     public static final String THING_TYPE_SHELLYHT_STR = "shellyht";
135     public static final String THING_TYPE_SHELLYSMOKE_STR = "shellysmoke";
136     public static final String THING_TYPE_SHELLYGAS_STR = "shellygas";
137     public static final String THING_TYPE_SHELLYFLOOD_STR = "shellyflood";
138     public static final String THING_TYPE_SHELLYDOORWIN_STR = "shellydw";
139     public static final String THING_TYPE_SHELLYDOORWIN2_STR = "shellydw2";
140     public static final String THING_TYPE_SHELLYEYE_STR = "shellyseye";
141     public static final String THING_TYPE_SHELLYSENSE_STR = "shellysense";
142     public static final String THING_TYPE_SHELLYTRV_STR = "shellytrv";
143     public static final String THING_TYPE_SHELLYMOTION_STR = "shellymotion";
144     public static final String THING_TYPE_SHELLYMOTION2_STR = "shellymotion2";
145     public static final String THING_TYPE_SHELLYBUTTON1_STR = "shellybutton1";
146     public static final String THING_TYPE_SHELLYBUTTON2_STR = "shellybutton2";
147     public static final String THING_TYPE_SHELLYUNI_STR = "shellyuni";
148
149     // Shelly Plus Seriens
150     public static final String THING_TYPE_SHELLYPLUS1_STR = "shellyplus1";
151     public static final String THING_TYPE_SHELLYPLUS1PM_STR = "shellyplus1pm";
152     public static final String THING_TYPE_SHELLYPLUS2PM_RELAY_STR = "shellyplus2pm-relay";
153     public static final String THING_TYPE_SHELLYPLUS2PM_ROLLER_STR = "shellyplus2pm-roller";
154     public static final String THING_TYPE_SHELLYPLUSI4_STR = "shellyplusi4";
155     public static final String THING_TYPE_SHELLYPLUSI4DC_STR = "shellyplusi4dc";
156     public static final String THING_TYPE_SHELLYPLUSHT_STR = "shellyplusht";
157     public static final String THING_TYPE_SHELLYPLUSSMOKE_STR = "shellyplussmoke";
158     public static final String THING_TYPE_SHELLYPLUSPLUGS_STR = "shellyplusplug";
159     public static final String THING_TYPE_SHELLYPLUSPLUGUS_STR = "shellyplusplugus";
160
161     // Shelly Pro Series
162     public static final String THING_TYPE_SHELLYPRO1_STR = "shellypro1";
163     public static final String THING_TYPE_SHELLYPRO1PM_STR = "shellypro1pm";
164     public static final String THING_TYPE_SHELLYPRO2_RELAY_STR = "shellypro2-relay";
165     public static final String THING_TYPE_SHELLYPRO2PM_RELAY_STR = "shellypro2pm-relay";
166     public static final String THING_TYPE_SHELLYPRO2PM_ROLLER_STR = "shellypro2pm-roller";
167     public static final String THING_TYPE_SHELLYPRO3_STR = "shellypro3";
168     public static final String THING_TYPE_SHELLYPRO3EM_STR = "shellypro3em";
169     public static final String THING_TYPE_SHELLYPRO4PM_STR = "shellypro4pm";
170
171     // Shelly BLU Series
172     public static final String THING_TYPE_SHELLYBLU_PREFIX = "shellyblu";
173     public static final String THING_TYPE_SHELLYBLUBUTTON_STR = THING_TYPE_SHELLYBLU_PREFIX + "button";
174     public static final String THING_TYPE_SHELLYBLUDW_STR = THING_TYPE_SHELLYBLU_PREFIX + "dw";
175
176     // Password protected or unknown device
177     public static final String THING_TYPE_SHELLYPROTECTED_STR = "shellydevice";
178     public static final String THING_TYPE_SHELLYUNKNOWN_STR = "shellyunknown";
179
180     // List of all Thing Type UIDs
181     public static final ThingTypeUID THING_TYPE_SHELLY1 = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLY1_STR);
182     public static final ThingTypeUID THING_TYPE_SHELLY1L = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLY1L_STR);
183     public static final ThingTypeUID THING_TYPE_SHELLY1PM = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLY1PM_STR);
184     public static final ThingTypeUID THING_TYPE_SHELLYEM = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYEM_STR);
185     public static final ThingTypeUID THING_TYPE_SHELLY3EM = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLY3EM_STR);
186     public static final ThingTypeUID THING_TYPE_SHELLY2_RELAY = new ThingTypeUID(BINDING_ID,
187             THING_TYPE_SHELLY2_RELAY_STR);
188     public static final ThingTypeUID THING_TYPE_SHELLY2_ROLLER = new ThingTypeUID(BINDING_ID,
189             THING_TYPE_SHELLY2_ROLLER_STR);
190     public static final ThingTypeUID THING_TYPE_SHELLY25_RELAY = new ThingTypeUID(BINDING_ID,
191             THING_TYPE_SHELLY25_RELAY_STR);
192     public static final ThingTypeUID THING_TYPE_SHELLY25_ROLLER = new ThingTypeUID(BINDING_ID,
193             THING_TYPE_SHELLY25_ROLLER_STR);
194     public static final ThingTypeUID THING_TYPE_SHELLY4PRO = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLY4PRO_STR);
195     public static final ThingTypeUID THING_TYPE_SHELLYPLUG = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUG_STR);
196     public static final ThingTypeUID THING_TYPE_SHELLYPLUGS = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUGS_STR);
197     public static final ThingTypeUID THING_TYPE_SHELLYPLUGU1 = new ThingTypeUID(BINDING_ID,
198             THING_TYPE_SHELLYPLUGU1_STR);
199     public static final ThingTypeUID THING_TYPE_SHELLYUNI = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYUNI_STR);
200     public static final ThingTypeUID THING_TYPE_SHELLYDIMMER = new ThingTypeUID(BINDING_ID,
201             THING_TYPE_SHELLYDIMMER_STR);
202     public static final ThingTypeUID THING_TYPE_SHELLYDIMMER2 = new ThingTypeUID(BINDING_ID,
203             THING_TYPE_SHELLYDIMMER2_STR);
204     public static final ThingTypeUID THING_TYPE_SHELLYIX3 = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYIX3_STR);
205     public static final ThingTypeUID THING_TYPE_SHELLYBULB = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYBULB_STR);
206     public static final ThingTypeUID THING_TYPE_SHELLYDUO = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYDUO_STR);
207     public static final ThingTypeUID THING_TYPE_SHELLYVINTAGE = new ThingTypeUID(BINDING_ID,
208             THING_TYPE_SHELLYVINTAGE_STR);
209     public static final ThingTypeUID THING_TYPE_SHELLYDUORGBW = new ThingTypeUID(BINDING_ID,
210             THING_TYPE_SHELLYDUORGBW_STR);
211     public static final ThingTypeUID THING_TYPE_SHELLYHT = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYHT_STR);
212     public static final ThingTypeUID THING_TYPE_SHELLYSENSE = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYSENSE_STR);
213     public static final ThingTypeUID THING_TYPE_SHELLYSMOKE = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYSMOKE_STR);
214     public static final ThingTypeUID THING_TYPE_SHELLYGAS = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYGAS_STR);
215     public static final ThingTypeUID THING_TYPE_SHELLYFLOOD = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYFLOOD_STR);
216     public static final ThingTypeUID THING_TYPE_SHELLYDOORWIN = new ThingTypeUID(BINDING_ID,
217             THING_TYPE_SHELLYDOORWIN_STR);
218     public static final ThingTypeUID THING_TYPE_SHELLYDOORWIN2 = new ThingTypeUID(BINDING_ID,
219             THING_TYPE_SHELLYDOORWIN2_STR);
220     public static final ThingTypeUID THING_TYPE_SHELLYTRV = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYTRV_STR);
221     public static final ThingTypeUID THING_TYPE_SHELLYBUTTON1 = new ThingTypeUID(BINDING_ID,
222             THING_TYPE_SHELLYBUTTON1_STR);
223     public static final ThingTypeUID THING_TYPE_SHELLYBUTTON2 = new ThingTypeUID(BINDING_ID,
224             THING_TYPE_SHELLYBUTTON2_STR);
225     public static final ThingTypeUID THING_TYPE_SHELLYEYE = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYEYE_STR);
226     public static final ThingTypeUID THING_TYPE_SHELLMOTION = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYMOTION_STR);
227     public static final ThingTypeUID THING_TYPE_SHELLYRGBW2_COLOR = new ThingTypeUID(BINDING_ID,
228             THING_TYPE_SHELLYRGBW2_COLOR_STR);
229     public static final ThingTypeUID THING_TYPE_SHELLYRGBW2_WHITE = new ThingTypeUID(BINDING_ID,
230             THING_TYPE_SHELLYRGBW2_WHITE_STR);
231     public static final ThingTypeUID THING_TYPE_SHELLYPROTECTED = new ThingTypeUID(BINDING_ID,
232             THING_TYPE_SHELLYPROTECTED_STR);
233     public static final ThingTypeUID THING_TYPE_SHELLYUNKNOWN = new ThingTypeUID(BINDING_ID,
234             THING_TYPE_SHELLYUNKNOWN_STR);
235
236     // Shelly Plus/Pro
237     public static final ThingTypeUID THING_TYPE_SHELLYPLUS1 = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUS1_STR);
238     public static final ThingTypeUID THING_TYPE_SHELLYPLUS1PM = new ThingTypeUID(BINDING_ID,
239             THING_TYPE_SHELLYPLUS1PM_STR);
240     public static final ThingTypeUID THING_TYPE_SHELLYPLUS2PM_RELAY = new ThingTypeUID(BINDING_ID,
241             THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
242     public static final ThingTypeUID THING_TYPE_SHELLYPLUS2PM_ROLLER = new ThingTypeUID(BINDING_ID,
243             THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
244     public static final ThingTypeUID THING_TYPE_SHELLYPLUSI4 = new ThingTypeUID(BINDING_ID,
245             THING_TYPE_SHELLYPLUSI4_STR);
246     public static final ThingTypeUID THING_TYPE_SHELLYPLUSI4DC = new ThingTypeUID(BINDING_ID,
247             THING_TYPE_SHELLYPLUSI4DC_STR);
248     public static final ThingTypeUID THING_TYPE_SHELLYPLUSHT = new ThingTypeUID(BINDING_ID,
249             THING_TYPE_SHELLYPLUSHT_STR);
250     public static final ThingTypeUID THING_TYPE_SHELLYPLUSSMOKE = new ThingTypeUID(BINDING_ID,
251             THING_TYPE_SHELLYPLUSSMOKE_STR);
252     public static final ThingTypeUID THING_TYPE_SHELLYPLUSPLUGS = new ThingTypeUID(BINDING_ID,
253             THING_TYPE_SHELLYPLUSPLUGS_STR);
254     public static final ThingTypeUID THING_TYPE_SHELLYPLUSPLUGUS = new ThingTypeUID(BINDING_ID,
255             THING_TYPE_SHELLYPLUSPLUGUS_STR);
256     public static final ThingTypeUID THING_TYPE_SHELLYPRO1 = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPRO1_STR);
257     public static final ThingTypeUID THING_TYPE_SHELLYPRO1PM = new ThingTypeUID(BINDING_ID,
258             THING_TYPE_SHELLYPRO1PM_STR);
259     public static final ThingTypeUID THING_TYPE_SHELLYPRO2_RELAY = new ThingTypeUID(BINDING_ID,
260             THING_TYPE_SHELLYPRO2_RELAY_STR);
261     public static final ThingTypeUID THING_TYPE_SHELLYPRO2PM_RELAY = new ThingTypeUID(BINDING_ID,
262             THING_TYPE_SHELLYPRO2PM_RELAY_STR);
263     public static final ThingTypeUID THING_TYPE_SHELLYPRO2PM_ROLLER = new ThingTypeUID(BINDING_ID,
264             THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
265     public static final ThingTypeUID THING_TYPE_SHELLYPRO3 = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPRO3_STR);
266     public static final ThingTypeUID THING_TYPE_SHELLYPRO3EM = new ThingTypeUID(BINDING_ID,
267             THING_TYPE_SHELLYPRO3EM_STR);
268     public static final ThingTypeUID THING_TYPE_SHELLYPRO4PM = new ThingTypeUID(BINDING_ID,
269             THING_TYPE_SHELLYPRO4PM_STR);
270
271     // Shelly Blu series
272     public static final ThingTypeUID THING_TYPE_SHELLYBLUBUTTON = new ThingTypeUID(BINDING_ID,
273             THING_TYPE_SHELLYBLUBUTTON_STR);
274     public static final ThingTypeUID THING_TYPE_SHELLYBLUDW = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYBLUDW_STR);
275
276     private static final Map<String, String> THING_TYPE_MAPPING = new LinkedHashMap<>();
277     static {
278         // mapping by device type id
279         THING_TYPE_MAPPING.put(SHELLYDT_1PM, THING_TYPE_SHELLY1PM_STR);
280         THING_TYPE_MAPPING.put(SHELLYDT_1L, THING_TYPE_SHELLY1L_STR);
281         THING_TYPE_MAPPING.put(SHELLYDT_1, THING_TYPE_SHELLY1_STR);
282         THING_TYPE_MAPPING.put(SHELLYDT_3EM, THING_TYPE_SHELLY3EM_STR);
283         THING_TYPE_MAPPING.put(SHELLYDT_EM, THING_TYPE_SHELLYEM_STR);
284         THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_S, THING_TYPE_SHELLYPLUGS_STR);
285         THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_U1, THING_TYPE_SHELLYPLUGU1_STR);
286         THING_TYPE_MAPPING.put(SHELLYDT_GAS, THING_TYPE_SHELLYGAS_STR);
287         THING_TYPE_MAPPING.put(SHELLYDT_DW, THING_TYPE_SHELLYDOORWIN_STR);
288         THING_TYPE_MAPPING.put(SHELLYDT_DW2, THING_TYPE_SHELLYDOORWIN2_STR);
289         THING_TYPE_MAPPING.put(SHELLYDT_DUO, THING_TYPE_SHELLYDUO_STR);
290         THING_TYPE_MAPPING.put(SHELLYDT_DUORGBW, THING_TYPE_SHELLYDUORGBW_STR);
291         THING_TYPE_MAPPING.put(SHELLYDT_BULB, THING_TYPE_SHELLYBULB_STR);
292         THING_TYPE_MAPPING.put(SHELLYDT_VINTAGE, THING_TYPE_SHELLYVINTAGE_STR);
293         THING_TYPE_MAPPING.put(SHELLYDT_DIMMER, THING_TYPE_SHELLYDIMMER_STR);
294         THING_TYPE_MAPPING.put(SHELLYDT_DIMMER2, THING_TYPE_SHELLYDIMMER2_STR);
295         THING_TYPE_MAPPING.put(SHELLYDT_IX3, THING_TYPE_SHELLYIX3_STR);
296         THING_TYPE_MAPPING.put(SHELLYDT_BUTTON1, THING_TYPE_SHELLYBUTTON1_STR);
297         THING_TYPE_MAPPING.put(SHELLYDT_BUTTON2, THING_TYPE_SHELLYBUTTON2_STR);
298         THING_TYPE_MAPPING.put(SHELLYDT_UNI, THING_TYPE_SHELLYUNI_STR);
299         THING_TYPE_MAPPING.put(SHELLYDT_HT, THING_TYPE_SHELLYHT_STR);
300         THING_TYPE_MAPPING.put(SHELLYDT_TRV, THING_TYPE_SHELLYTRV_STR);
301         THING_TYPE_MAPPING.put(SHELLYDT_MOTION, THING_TYPE_SHELLYMOTION_STR);
302
303         // Plus Series
304         THING_TYPE_MAPPING.put(SHELLYDT_PLUS1, THING_TYPE_SHELLYPLUS1_STR);
305         THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PM, THING_TYPE_SHELLYPLUS1PM_STR);
306         THING_TYPE_MAPPING.put(SHELLYDT_PLUS1UL, THING_TYPE_SHELLYPLUS1_STR);
307         THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PMUL, THING_TYPE_SHELLYPLUS1PM_STR);
308         THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
309         THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
310         THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY_2, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
311         THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER_2, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
312         THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGS, THING_TYPE_SHELLYPLUSPLUGS_STR);
313         THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGIT, THING_TYPE_SHELLYPLUSPLUGS_STR);
314         THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUK, THING_TYPE_SHELLYPLUSPLUGS_STR);
315         THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUS, THING_TYPE_SHELLYPLUSPLUGUS_STR);
316         THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4DC, THING_TYPE_SHELLYPLUSI4DC_STR);
317         THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4, THING_TYPE_SHELLYPLUSI4_STR);
318         THING_TYPE_MAPPING.put(SHELLYDT_PLUSHT, THING_TYPE_SHELLYPLUSHT_STR);
319         THING_TYPE_MAPPING.put(SHELLYDT_PLUSSMOKE, THING_TYPE_SHELLYPLUSSMOKE_STR);
320
321         // Pro Series
322         THING_TYPE_MAPPING.put(SHELLYDT_PRO1, THING_TYPE_SHELLYPRO1_STR);
323         THING_TYPE_MAPPING.put(SHELLYDT_PRO1_2, THING_TYPE_SHELLYPRO1_STR);
324         THING_TYPE_MAPPING.put(SHELLYDT_PRO1_3, THING_TYPE_SHELLYPRO1_STR);
325         THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM, THING_TYPE_SHELLYPRO1PM_STR);
326         THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_2, THING_TYPE_SHELLYPRO1PM_STR);
327         THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_3, THING_TYPE_SHELLYPRO1PM_STR);
328         THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY, THING_TYPE_SHELLYPRO2_RELAY_STR);
329         THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_2, THING_TYPE_SHELLYPRO2_RELAY_STR);
330         THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_3, THING_TYPE_SHELLYPRO2_RELAY_STR);
331         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
332         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_2, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
333         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_3, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
334         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
335         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_2, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
336         THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_3, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
337         THING_TYPE_MAPPING.put(SHELLYDT_PRO3, THING_TYPE_SHELLYPRO3_STR);
338         THING_TYPE_MAPPING.put(SHELLYDT_PRO3EM, THING_TYPE_SHELLYPRO3EM_STR);
339         THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM, THING_TYPE_SHELLYPRO4PM_STR);
340         THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM_2, THING_TYPE_SHELLYPRO4PM_STR);
341
342         // Blu Series
343         THING_TYPE_MAPPING.put(SHELLYDT_BLUBUTTON, THING_TYPE_SHELLYBLUBUTTON_STR);
344         THING_TYPE_MAPPING.put(SHELLYDT_BLUDW, THING_TYPE_SHELLYBLUDW_STR);
345
346         // mapping by thing type
347         THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1_STR, THING_TYPE_SHELLY1_STR);
348         THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PM_STR, THING_TYPE_SHELLY1PM_STR);
349         THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1L_STR, THING_TYPE_SHELLY1L_STR);
350         THING_TYPE_MAPPING.put(THING_TYPE_SHELLY3EM_STR, THING_TYPE_SHELLY3EM_STR);
351         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEM_STR, THING_TYPE_SHELLYEM_STR);
352         THING_TYPE_MAPPING.put(THING_TYPE_SHELLY4PRO_STR, THING_TYPE_SHELLY4PRO_STR);
353         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER2_STR, THING_TYPE_SHELLYDIMMER2_STR);
354         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER_STR, THING_TYPE_SHELLYDIMMER_STR);
355         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYIX3_STR, THING_TYPE_SHELLYIX3_STR);
356         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUORGBW_STR, THING_TYPE_SHELLYDUORGBW_STR);
357         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR);
358         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYVINTAGE_STR, THING_TYPE_SHELLYVINTAGE_STR);
359         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBULB_STR, THING_TYPE_SHELLYBULB_STR);
360         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR);
361         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYHT_STR, THING_TYPE_SHELLYHT_STR);
362         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSMOKE_STR, THING_TYPE_SHELLYSMOKE_STR);
363         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYGAS_STR, THING_TYPE_SHELLYGAS_STR);
364         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYFLOOD_STR, THING_TYPE_SHELLYFLOOD_STR);
365         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYTRV_STR, THING_TYPE_SHELLYTRV_STR);
366         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN_STR, THING_TYPE_SHELLYDOORWIN_STR);
367         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN2_STR, THING_TYPE_SHELLYDOORWIN2_STR);
368         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSENSE_STR, THING_TYPE_SHELLYSENSE_STR);
369         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEYE_STR, THING_TYPE_SHELLYEYE_STR);
370         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON1_STR, THING_TYPE_SHELLYBUTTON1_STR);
371         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON2_STR, THING_TYPE_SHELLYBUTTON2_STR);
372         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYUNI_STR, THING_TYPE_SHELLYUNI_STR);
373         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMOTION2_STR, THING_TYPE_SHELLYMOTION_STR);
374
375         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR);
376         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1_STR, THING_TYPE_SHELLYPLUS1_STR);
377         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR);
378         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
379         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
380         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
381         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
382         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGS_STR, THING_TYPE_SHELLYPLUSPLUGS_STR);
383         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGUS_STR, THING_TYPE_SHELLYPLUSPLUGUS_STR);
384         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4DC_STR, THING_TYPE_SHELLYPLUSI4DC_STR);
385         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4_STR, THING_TYPE_SHELLYPLUSI4_STR);
386         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSHT_STR, THING_TYPE_SHELLYPLUSHT_STR);
387         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSSMOKE_STR, THING_TYPE_SHELLYPLUSSMOKE_STR);
388
389         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1_STR, THING_TYPE_SHELLYPRO1_STR);
390         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1PM_STR, THING_TYPE_SHELLYPRO1PM_STR);
391         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_RELAY_STR, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
392         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_ROLLER_STR, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
393         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2_RELAY_STR, THING_TYPE_SHELLYPRO2_RELAY_STR);
394         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3EM_STR, THING_TYPE_SHELLYPRO3EM_STR);
395         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3_STR, THING_TYPE_SHELLYPRO3_STR);
396         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO4PM_STR, THING_TYPE_SHELLYPRO4PM_STR);
397
398         THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROTECTED_STR, THING_TYPE_SHELLYPROTECTED_STR);
399     }
400
401     public static ThingUID getThingUID(String serviceName, String deviceType, String mode, boolean unknown) {
402         String devid = substringAfterLast(serviceName, "-");
403         if (devid.isEmpty()) {
404             throw new IllegalArgumentException("serviceName has improper format: " + serviceName);
405         }
406         return new ThingUID(!unknown ? getThingTypeUID(serviceName, deviceType, mode)
407                 : getThingTypeUID(THING_TYPE_SHELLYPROTECTED_STR + "-" + devid, deviceType, mode), devid);
408     }
409
410     public static ThingTypeUID getThingTypeUID(String serviceName, String deviceType, String mode) {
411         return new ThingTypeUID(BINDING_ID, getThingType(serviceName, deviceType, mode));
412     }
413
414     public static ThingTypeUID getUnknownTTUID() {
415         return new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPROTECTED_STR);
416     }
417
418     public static String getThingType(String hostname, String deviceType, String mode) {
419         if (THING_TYPE_SHELLYPROTECTED_STR.equals(hostname)) {
420             return THING_TYPE_SHELLYPROTECTED_STR;
421         }
422         String name = hostname.toLowerCase();
423         String type = substringBefore(name, "-").toLowerCase();
424         String devid = substringAfterLast(name, "-");
425         if (devid.isEmpty() || type.isEmpty()) {
426             throw new IllegalArgumentException("Invalid device name format: " + hostname);
427         }
428
429         // First check for special handling
430         if (name.startsWith(THING_TYPE_SHELLY25_PREFIX)) { // Shelly v2.5
431             return mode.equals(SHELLY_MODE_RELAY) ? THING_TYPE_SHELLY25_RELAY_STR : THING_TYPE_SHELLY25_ROLLER_STR;
432         }
433         if (name.startsWith(THING_TYPE_SHELLY2_PREFIX)) { // Shelly v2
434             return mode.equals(SHELLY_MODE_RELAY) ? THING_TYPE_SHELLY2_RELAY_STR : THING_TYPE_SHELLY2_ROLLER_STR;
435         }
436         if (name.startsWith(THING_TYPE_SHELLYPLUG_STR)) {
437             // shellyplug-s needs to be mapped to shellyplugs to follow the schema
438             // for the thing types: <thing type>-<mode>
439             if (name.startsWith(THING_TYPE_SHELLYPLUGS_STR) || name.contains("-s")) {
440                 return THING_TYPE_SHELLYPLUGS_STR;
441             }
442             if (name.startsWith(THING_TYPE_SHELLYPLUGU1_STR)) {
443                 return THING_TYPE_SHELLYPLUGU1_STR;
444             }
445             return THING_TYPE_SHELLYPLUG_STR;
446         }
447         if (name.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX)) {
448             return mode.equals(SHELLY_MODE_COLOR) ? THING_TYPE_SHELLYRGBW2_COLOR_STR : THING_TYPE_SHELLYRGBW2_WHITE_STR;
449         }
450         if (name.startsWith(THING_TYPE_SHELLYMOTION_STR)) {
451             // depending on firmware release the Motion advertises under shellymotion-xxx or shellymotionsensor-xxxx
452             return THING_TYPE_SHELLYMOTION_STR;
453         }
454
455         // Check general mapping
456         if (!deviceType.isEmpty()) {
457             String res = THING_TYPE_MAPPING.get(deviceType); // by device type
458             if (res != null) {
459                 return res;
460             }
461
462             String dt = mode.equals(SHELLY_MODE_RELAY) || mode.equals(SHELLY_MODE_ROLLER) ? deviceType + "-" + mode
463                     : deviceType;
464             res = THING_TYPE_MAPPING.get(dt); // <DT>-relay / <DT>-roller
465             if (res != null) {
466                 return res;
467             }
468         }
469
470         String res = THING_TYPE_MAPPING.get(type);
471         if (res != null) {
472             return res;
473         }
474         return THING_TYPE_SHELLYUNKNOWN_STR;
475     }
476 }