From 3f925692f5dd1a054fabca19ab2c5b6176b9784b Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Mon, 2 Jun 2025 21:16:05 +0200 Subject: [PATCH] [shelly] Refactor `ShellyThingCreator` (#18729) * Remove duplicated mappings Signed-off-by: Jacob Laursen --- .../ShellyBasicDiscoveryService.java | 6 +- .../discovery/ShellyDiscoveryParticipant.java | 2 +- .../discovery/ShellyThingCreator.java | 440 +++++++++--------- .../discovery/ShellyThingCreatorTest.java | 46 +- 4 files changed, 249 insertions(+), 245 deletions(-) diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java index 6a083ce5ee0..783a12868c8 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java @@ -83,7 +83,7 @@ public class ShellyBasicDiscoveryService extends AbstractDiscoveryService { public void discoveredResult(ThingTypeUID tuid, String model, String serviceName, String address, Map properties) { - ThingUID uid = ShellyThingCreator.getThingUID(serviceName, model, "", true); + ThingUID uid = ShellyThingCreator.getThingUIDForUnknown(serviceName, model, ""); logger.debug("Adding discovered thing with id {}", uid.toString()); properties.put(PROPERTY_MAC_ADDRESS, address); String thingLabel = "Shelly BLU " + model + " (" + serviceName + ")"; @@ -148,12 +148,12 @@ public class ShellyBasicDiscoveryService extends AbstractDiscoveryService { properties = ShellyBaseHandler.fillDeviceProperties(profile); // get thing type from device name - thingUID = ShellyThingCreator.getThingUID(name, model, mode, false); + thingUID = ShellyThingCreator.getThingUID(name, model, mode); } catch (ShellyApiException e) { ShellyApiResult result = e.getApiResult(); if (result.isHttpAccessUnauthorized()) { // create shellyunknown thing - will be changed during thing initialization with valid credentials - thingUID = ShellyThingCreator.getThingUID(name, model, mode, true); + thingUID = ShellyThingCreator.getThingUIDForUnknown(name, model, mode); } } catch (IllegalArgumentException | IOException e) { // maybe some format description was buggy logger.debug("Discovery: Unable to discover thing", e); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyDiscoveryParticipant.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyDiscoveryParticipant.java index 6221d471d7f..94459b6ceba 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyDiscoveryParticipant.java @@ -150,6 +150,6 @@ public class ShellyDiscoveryParticipant implements MDNSDiscoveryParticipant { logger.debug("Not a " + VENDOR + " device!"); return null; } - return ShellyThingCreator.getThingUID(serviceName, "", "", false); + return ShellyThingCreator.getThingUID(serviceName); } } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java index b1fc1de547a..65956bbd93b 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreator.java @@ -16,7 +16,6 @@ import static org.openhab.binding.shelly.internal.ShellyBindingConstants.BINDING import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -373,273 +372,278 @@ public class ShellyThingCreator { public static final ThingTypeUID THING_TYPE_SHELLYBLUHT = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYBLUHT_STR); public static final ThingTypeUID THING_TYPE_SHELLYBLUGW = new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYBLUGW_STR); - private static final Map THING_TYPE_MAPPING = new LinkedHashMap<>(); - static { - // mapping by device type id - THING_TYPE_MAPPING.put(SHELLYDT_1PM, THING_TYPE_SHELLY1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_1L, THING_TYPE_SHELLY1L_STR); - THING_TYPE_MAPPING.put(SHELLYDT_1, THING_TYPE_SHELLY1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_SHPRO, THING_TYPE_SHELLY4PRO_STR); - THING_TYPE_MAPPING.put(SHELLYDT_4PRO, THING_TYPE_SHELLY4PRO_STR); - THING_TYPE_MAPPING.put(SHELLYDT_3EM, THING_TYPE_SHELLY3EM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_EM, THING_TYPE_SHELLYEM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_S, THING_TYPE_SHELLYPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_U1, THING_TYPE_SHELLYPLUGU1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_GAS, THING_TYPE_SHELLYGAS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DW, THING_TYPE_SHELLYDOORWIN_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DW2, THING_TYPE_SHELLYDOORWIN2_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DUO, THING_TYPE_SHELLYDUO_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DUORGBW, THING_TYPE_SHELLYDUORGBW_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BULB, THING_TYPE_SHELLYBULB_STR); - THING_TYPE_MAPPING.put(SHELLYDT_VINTAGE, THING_TYPE_SHELLYVINTAGE_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DIMMER, THING_TYPE_SHELLYDIMMER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_DIMMER2, THING_TYPE_SHELLYDIMMER2_STR); - THING_TYPE_MAPPING.put(SHELLYDT_IX3, THING_TYPE_SHELLYIX3_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BUTTON1, THING_TYPE_SHELLYBUTTON1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BUTTON2, THING_TYPE_SHELLYBUTTON2_STR); - THING_TYPE_MAPPING.put(SHELLYDT_UNI, THING_TYPE_SHELLYUNI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_HT, THING_TYPE_SHELLYHT_STR); - THING_TYPE_MAPPING.put(SHELLYDT_TRV, THING_TYPE_SHELLYTRV_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MOTION, THING_TYPE_SHELLYMOTION_STR); + private static final Map THING_TYPE_BY_DEVICE_TYPE = Map.ofEntries( + Map.entry(SHELLYDT_1PM, THING_TYPE_SHELLY1PM_STR), // + Map.entry(SHELLYDT_1L, THING_TYPE_SHELLY1L_STR), // + Map.entry(SHELLYDT_1, THING_TYPE_SHELLY1_STR), // + Map.entry(SHELLYDT_SHPRO, THING_TYPE_SHELLY4PRO_STR), // + Map.entry(SHELLYDT_4PRO, THING_TYPE_SHELLY4PRO_STR), // + Map.entry(SHELLYDT_3EM, THING_TYPE_SHELLY3EM_STR), // + Map.entry(SHELLYDT_EM, THING_TYPE_SHELLYEM_STR), // + Map.entry(SHELLYDT_SHPLG_S, THING_TYPE_SHELLYPLUGS_STR), + Map.entry(SHELLYDT_SHPLG_U1, THING_TYPE_SHELLYPLUGU1_STR), + Map.entry(SHELLYDT_GAS, THING_TYPE_SHELLYGAS_STR), // + Map.entry(SHELLYDT_DW, THING_TYPE_SHELLYDOORWIN_STR), + Map.entry(SHELLYDT_DW2, THING_TYPE_SHELLYDOORWIN2_STR), // + Map.entry(SHELLYDT_DUO, THING_TYPE_SHELLYDUO_STR), + Map.entry(SHELLYDT_DUORGBW, THING_TYPE_SHELLYDUORGBW_STR), + Map.entry(SHELLYDT_BULB, THING_TYPE_SHELLYBULB_STR), + Map.entry(SHELLYDT_VINTAGE, THING_TYPE_SHELLYVINTAGE_STR), + Map.entry(SHELLYDT_DIMMER, THING_TYPE_SHELLYDIMMER_STR), + Map.entry(SHELLYDT_DIMMER2, THING_TYPE_SHELLYDIMMER2_STR), + Map.entry(SHELLYDT_IX3, THING_TYPE_SHELLYIX3_STR), + Map.entry(SHELLYDT_BUTTON1, THING_TYPE_SHELLYBUTTON1_STR), + Map.entry(SHELLYDT_BUTTON2, THING_TYPE_SHELLYBUTTON2_STR), + Map.entry(SHELLYDT_UNI, THING_TYPE_SHELLYUNI_STR), // + Map.entry(SHELLYDT_HT, THING_TYPE_SHELLYHT_STR), // + Map.entry(SHELLYDT_TRV, THING_TYPE_SHELLYTRV_STR), // + Map.entry(SHELLYDT_MOTION, THING_TYPE_SHELLYMOTION_STR), - // Plus Series - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1G3, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1G4, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1UL, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PM, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PMG3, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PMG4, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PMUL, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY_2, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER_2, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMUL_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMUL_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMG3_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PMG3_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGS, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGS_2, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGIT, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUK, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUS, THING_TYPE_SHELLYPLUSPLUGUS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGSG3, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4, THING_TYPE_SHELLYPLUSI4_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4G3, THING_TYPE_SHELLYPLUSI4_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4DC, THING_TYPE_SHELLYPLUSI4DC_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSHT, THING_TYPE_SHELLYPLUSHT_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSHTG3, THING_TYPE_SHELLYPLUSHTG3_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSSMOKE, THING_TYPE_SHELLYPLUSSMOKE_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSUNI, THING_TYPE_SHELLYPLUSUNI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMERUS, THING_TYPE_SHELLYPLUSDIMMERUS_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMER10V, THING_TYPE_SHELLYPLUSDIMMER10V_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMER0110VG3, THING_TYPE_SHELLYPLUSDIMMER10V_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PLUSRGBWPM, THING_TYPE_SHELLYPLUSRGBWPM_STR); + // Plus Series + Map.entry(SHELLYDT_PLUS1, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(SHELLYDT_PLUS1G3, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(SHELLYDT_PLUS1G4, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(SHELLYDT_PLUS1UL, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(SHELLYDT_PLUS1PM, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(SHELLYDT_PLUS1PMG3, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(SHELLYDT_PLUS1PMG4, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(SHELLYDT_PLUS1PMUL, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(SHELLYDT_PLUS2PM_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + Map.entry(SHELLYDT_PLUS2PM_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + Map.entry(SHELLYDT_PLUS2PM_RELAY_2, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + Map.entry(SHELLYDT_PLUS2PM_ROLLER_2, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + Map.entry(SHELLYDT_PLUS2PMUL_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + Map.entry(SHELLYDT_PLUS2PMUL_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + Map.entry(SHELLYDT_PLUS2PMG3_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + Map.entry(SHELLYDT_PLUS2PMG3_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + Map.entry(SHELLYDT_PLUSPLUGS, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(SHELLYDT_PLUSPLUGS_2, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(SHELLYDT_PLUSPLUGIT, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(SHELLYDT_PLUSPLUGUK, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(SHELLYDT_PLUSPLUGUS, THING_TYPE_SHELLYPLUSPLUGUS_STR), + Map.entry(SHELLYDT_PLUSPLUGSG3, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(SHELLYDT_PLUSI4, THING_TYPE_SHELLYPLUSI4_STR), + Map.entry(SHELLYDT_PLUSI4G3, THING_TYPE_SHELLYPLUSI4_STR), + Map.entry(SHELLYDT_PLUSI4DC, THING_TYPE_SHELLYPLUSI4DC_STR), + Map.entry(SHELLYDT_PLUSHT, THING_TYPE_SHELLYPLUSHT_STR), + Map.entry(SHELLYDT_PLUSHTG3, THING_TYPE_SHELLYPLUSHTG3_STR), + Map.entry(SHELLYDT_PLUSSMOKE, THING_TYPE_SHELLYPLUSSMOKE_STR), + Map.entry(SHELLYDT_PLUSUNI, THING_TYPE_SHELLYPLUSUNI_STR), + Map.entry(SHELLYDT_PLUSDIMMERUS, THING_TYPE_SHELLYPLUSDIMMERUS_STR), + Map.entry(SHELLYDT_PLUSDIMMER10V, THING_TYPE_SHELLYPLUSDIMMER10V_STR), + Map.entry(SHELLYDT_PLUSDIMMER0110VG3, THING_TYPE_SHELLYPLUSDIMMER10V_STR), + Map.entry(SHELLYDT_PLUSRGBWPM, THING_TYPE_SHELLYPLUSRGBWPM_STR), - // Plus Mini Series - THING_TYPE_MAPPING.put(SHELLYDT_MINI1, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG3_1, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG4_1, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIPM, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG3_PM, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG4_PM, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINI1PM, THING_TYPE_SHELLY1PMMINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG3_1PM, THING_TYPE_SHELLY1PMMINI_STR); - THING_TYPE_MAPPING.put(SHELLYDT_MINIG4_1PM, THING_TYPE_SHELLY1PMMINI_STR); + // Plus Mini Series + Map.entry(SHELLYDT_MINI1, THING_TYPE_SHELLY1MINI_STR), + Map.entry(SHELLYDT_MINIG3_1, THING_TYPE_SHELLY1MINI_STR), + Map.entry(SHELLYDT_MINIG4_1, THING_TYPE_SHELLY1MINI_STR), + Map.entry(SHELLYDT_MINIPM, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(SHELLYDT_MINIG3_PM, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(SHELLYDT_MINIG4_PM, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(SHELLYDT_MINI1PM, THING_TYPE_SHELLY1PMMINI_STR), + Map.entry(SHELLYDT_MINIG3_1PM, THING_TYPE_SHELLY1PMMINI_STR), + Map.entry(SHELLYDT_MINIG4_1PM, THING_TYPE_SHELLY1PMMINI_STR), - // Pro Series - THING_TYPE_MAPPING.put(SHELLYDT_PRO1, THING_TYPE_SHELLYPRO1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1_2, THING_TYPE_SHELLYPRO1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1_3, THING_TYPE_SHELLYPRO1_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM, THING_TYPE_SHELLYPRO1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_2, THING_TYPE_SHELLYPRO1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_3, THING_TYPE_SHELLYPRO1PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO1CB, THING_TYPE_SHELLYPRO1CB_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY, THING_TYPE_SHELLYPRO2_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_2, THING_TYPE_SHELLYPRO2_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_3, THING_TYPE_SHELLYPRO2_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY, THING_TYPE_SHELLYPRO2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_2, THING_TYPE_SHELLYPRO2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_3, THING_TYPE_SHELLYPRO2PM_RELAY_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER, THING_TYPE_SHELLYPRO2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_2, THING_TYPE_SHELLYPRO2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_3, THING_TYPE_SHELLYPRO2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO3, THING_TYPE_SHELLYPRO3_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PROEM50, THING_TYPE_SHELLYPROEM50_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO3EM, THING_TYPE_SHELLYPRO3EM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM, THING_TYPE_SHELLYPRO4PM_STR); - THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM_2, THING_TYPE_SHELLYPRO4PM_STR); + // Pro Series + Map.entry(SHELLYDT_PRO1, THING_TYPE_SHELLYPRO1_STR), // + Map.entry(SHELLYDT_PRO1_2, THING_TYPE_SHELLYPRO1_STR), + Map.entry(SHELLYDT_PRO1_3, THING_TYPE_SHELLYPRO1_STR), + Map.entry(SHELLYDT_PRO1PM, THING_TYPE_SHELLYPRO1PM_STR), + Map.entry(SHELLYDT_PRO1PM_2, THING_TYPE_SHELLYPRO1PM_STR), + Map.entry(SHELLYDT_PRO1PM_3, THING_TYPE_SHELLYPRO1PM_STR), + Map.entry(SHELLYDT_PRO1CB, THING_TYPE_SHELLYPRO1CB_STR), + Map.entry(SHELLYDT_PRO2_RELAY, THING_TYPE_SHELLYPRO2_RELAY_STR), + Map.entry(SHELLYDT_PRO2_RELAY_2, THING_TYPE_SHELLYPRO2_RELAY_STR), + Map.entry(SHELLYDT_PRO2_RELAY_3, THING_TYPE_SHELLYPRO2_RELAY_STR), + Map.entry(SHELLYDT_PRO2PM_RELAY, THING_TYPE_SHELLYPRO2PM_RELAY_STR), + Map.entry(SHELLYDT_PRO2PM_RELAY_2, THING_TYPE_SHELLYPRO2PM_RELAY_STR), + Map.entry(SHELLYDT_PRO2PM_RELAY_3, THING_TYPE_SHELLYPRO2PM_RELAY_STR), + Map.entry(SHELLYDT_PRO2PM_ROLLER, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), + Map.entry(SHELLYDT_PRO2PM_ROLLER_2, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), + Map.entry(SHELLYDT_PRO2PM_ROLLER_3, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), + Map.entry(SHELLYDT_PRO3, THING_TYPE_SHELLYPRO3_STR), + Map.entry(SHELLYDT_PROEM50, THING_TYPE_SHELLYPROEM50_STR), + Map.entry(SHELLYDT_PRO3EM, THING_TYPE_SHELLYPRO3EM_STR), + Map.entry(SHELLYDT_PRO4PM, THING_TYPE_SHELLYPRO4PM_STR), + Map.entry(SHELLYDT_PRO4PM_2, THING_TYPE_SHELLYPRO4PM_STR), - // BLU Series - THING_TYPE_MAPPING.put(SHELLYDT_BLUBUTTON, THING_TYPE_SHELLYBLUBUTTON_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BLUDW, THING_TYPE_SHELLYBLUDW_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BLUMOTION, THING_TYPE_SHELLYBLUMOTION_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BLUHT, THING_TYPE_SHELLYBLUHT_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BLUGW, THING_TYPE_SHELLYBLUGW_STR); - THING_TYPE_MAPPING.put(SHELLYDT_BLUGWG3, THING_TYPE_SHELLYBLUGW_STR); + // BLU Series + Map.entry(SHELLYDT_BLUBUTTON, THING_TYPE_SHELLYBLUBUTTON_STR), + Map.entry(SHELLYDT_BLUDW, THING_TYPE_SHELLYBLUDW_STR), + Map.entry(SHELLYDT_BLUMOTION, THING_TYPE_SHELLYBLUMOTION_STR), + Map.entry(SHELLYDT_BLUHT, THING_TYPE_SHELLYBLUHT_STR), + Map.entry(SHELLYDT_BLUGW, THING_TYPE_SHELLYBLUGW_STR), + Map.entry(SHELLYDT_BLUGWG3, THING_TYPE_SHELLYBLUGW_STR), - // Wall displays - THING_TYPE_MAPPING.put(SHELLYDT_PLUSWALLDISPLAY, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR); + // Wall displays + Map.entry(SHELLYDT_PLUSWALLDISPLAY, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR)); - // mapping by thing type - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1_STR, THING_TYPE_SHELLY1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PM_STR, THING_TYPE_SHELLY1PM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1L_STR, THING_TYPE_SHELLY1L_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY3EM_STR, THING_TYPE_SHELLY3EM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEM_STR, THING_TYPE_SHELLYEM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY4PRO_STR, THING_TYPE_SHELLY4PRO_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER2_STR, THING_TYPE_SHELLYDIMMER2_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER_STR, THING_TYPE_SHELLYDIMMER_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYIX3_STR, THING_TYPE_SHELLYIX3_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUORGBW_STR, THING_TYPE_SHELLYDUORGBW_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYVINTAGE_STR, THING_TYPE_SHELLYVINTAGE_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBULB_STR, THING_TYPE_SHELLYBULB_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYHT_STR, THING_TYPE_SHELLYHT_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSMOKE_STR, THING_TYPE_SHELLYSMOKE_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYGAS_STR, THING_TYPE_SHELLYGAS_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYFLOOD_STR, THING_TYPE_SHELLYFLOOD_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYTRV_STR, THING_TYPE_SHELLYTRV_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN_STR, THING_TYPE_SHELLYDOORWIN_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN2_STR, THING_TYPE_SHELLYDOORWIN2_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSENSE_STR, THING_TYPE_SHELLYSENSE_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEYE_STR, THING_TYPE_SHELLYEYE_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON1_STR, THING_TYPE_SHELLYBUTTON1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON2_STR, THING_TYPE_SHELLYBUTTON2_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYUNI_STR, THING_TYPE_SHELLYUNI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMOTION2_STR, THING_TYPE_SHELLYMOTION_STR); + private static final Map THING_TYPE_MAPPING = Map.ofEntries( + Map.entry(THING_TYPE_SHELLY1_STR, THING_TYPE_SHELLY1_STR), + Map.entry(THING_TYPE_SHELLY1PM_STR, THING_TYPE_SHELLY1PM_STR), + Map.entry(THING_TYPE_SHELLY1L_STR, THING_TYPE_SHELLY1L_STR), + Map.entry(THING_TYPE_SHELLY3EM_STR, THING_TYPE_SHELLY3EM_STR), + Map.entry(THING_TYPE_SHELLYEM_STR, THING_TYPE_SHELLYEM_STR), + Map.entry(THING_TYPE_SHELLY4PRO_STR, THING_TYPE_SHELLY4PRO_STR), + Map.entry(THING_TYPE_SHELLYDIMMER2_STR, THING_TYPE_SHELLYDIMMER2_STR), + Map.entry(THING_TYPE_SHELLYDIMMER_STR, THING_TYPE_SHELLYDIMMER_STR), + Map.entry(THING_TYPE_SHELLYIX3_STR, THING_TYPE_SHELLYIX3_STR), + Map.entry(THING_TYPE_SHELLYDUORGBW_STR, THING_TYPE_SHELLYDUORGBW_STR), + Map.entry(THING_TYPE_SHELLYVINTAGE_STR, THING_TYPE_SHELLYVINTAGE_STR), + Map.entry(THING_TYPE_SHELLYBULB_STR, THING_TYPE_SHELLYBULB_STR), + Map.entry(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR), + Map.entry(THING_TYPE_SHELLYHT_STR, THING_TYPE_SHELLYHT_STR), + Map.entry(THING_TYPE_SHELLYSMOKE_STR, THING_TYPE_SHELLYSMOKE_STR), + Map.entry(THING_TYPE_SHELLYGAS_STR, THING_TYPE_SHELLYGAS_STR), + Map.entry(THING_TYPE_SHELLYFLOOD_STR, THING_TYPE_SHELLYFLOOD_STR), + Map.entry(THING_TYPE_SHELLYTRV_STR, THING_TYPE_SHELLYTRV_STR), + Map.entry(THING_TYPE_SHELLYDOORWIN_STR, THING_TYPE_SHELLYDOORWIN_STR), + Map.entry(THING_TYPE_SHELLYDOORWIN2_STR, THING_TYPE_SHELLYDOORWIN2_STR), + Map.entry(THING_TYPE_SHELLYSENSE_STR, THING_TYPE_SHELLYSENSE_STR), + Map.entry(THING_TYPE_SHELLYEYE_STR, THING_TYPE_SHELLYEYE_STR), + Map.entry(THING_TYPE_SHELLYBUTTON1_STR, THING_TYPE_SHELLYBUTTON1_STR), + Map.entry(THING_TYPE_SHELLYBUTTON2_STR, THING_TYPE_SHELLYBUTTON2_STR), + Map.entry(THING_TYPE_SHELLYUNI_STR, THING_TYPE_SHELLYUNI_STR), + Map.entry(THING_TYPE_SHELLYMOTION2_STR, THING_TYPE_SHELLYMOTION_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1_STR, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1G3_STR, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1G4_STR, THING_TYPE_SHELLYPLUS1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PMG3_STR, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PMG4_STR, THING_TYPE_SHELLYPLUS1PM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGS_STR, THING_TYPE_SHELLYPLUSPLUGS_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGUS_STR, THING_TYPE_SHELLYPLUSPLUGUS_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4_STR, THING_TYPE_SHELLYPLUSI4_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4G3_STR, THING_TYPE_SHELLYPLUSI4_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4DC_STR, THING_TYPE_SHELLYPLUSI4DC_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSHT_STR, THING_TYPE_SHELLYPLUSHT_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSSMOKE_STR, THING_TYPE_SHELLYPLUSSMOKE_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSUNI_STR, THING_TYPE_SHELLYPLUSUNI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMERUS_STR, THING_TYPE_SHELLYPLUSDIMMERUS_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMER10V_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMER0110VG3_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSRGBWPM_STR, THING_TYPE_SHELLYPLUSRGBWPM_STR); + Map.entry(THING_TYPE_SHELLYPLUS1_STR, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(THING_TYPE_SHELLYPLUS1G3_STR, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(THING_TYPE_SHELLYPLUS1G4_STR, THING_TYPE_SHELLYPLUS1_STR), + Map.entry(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(THING_TYPE_SHELLYPLUS1PMG3_STR, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(THING_TYPE_SHELLYPLUS1PMG4_STR, THING_TYPE_SHELLYPLUS1PM_STR), + Map.entry(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + Map.entry(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + Map.entry(THING_TYPE_SHELLYPLUSPLUGS_STR, THING_TYPE_SHELLYPLUSPLUGS_STR), + Map.entry(THING_TYPE_SHELLYPLUSPLUGUS_STR, THING_TYPE_SHELLYPLUSPLUGUS_STR), + Map.entry(THING_TYPE_SHELLYPLUSI4_STR, THING_TYPE_SHELLYPLUSI4_STR), + Map.entry(THING_TYPE_SHELLYPLUSI4G3_STR, THING_TYPE_SHELLYPLUSI4_STR), + Map.entry(THING_TYPE_SHELLYPLUSI4DC_STR, THING_TYPE_SHELLYPLUSI4DC_STR), + Map.entry(THING_TYPE_SHELLYPLUSHT_STR, THING_TYPE_SHELLYPLUSHT_STR), + Map.entry(THING_TYPE_SHELLYPLUSSMOKE_STR, THING_TYPE_SHELLYPLUSSMOKE_STR), + Map.entry(THING_TYPE_SHELLYPLUSUNI_STR, THING_TYPE_SHELLYPLUSUNI_STR), + Map.entry(THING_TYPE_SHELLYPLUSDIMMERUS_STR, THING_TYPE_SHELLYPLUSDIMMERUS_STR), + Map.entry(THING_TYPE_SHELLYPLUSDIMMER10V_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR), + Map.entry(THING_TYPE_SHELLYPLUSDIMMER0110VG3_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR), + Map.entry(THING_TYPE_SHELLYPLUSRGBWPM_STR, THING_TYPE_SHELLYPLUSRGBWPM_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSWALLDISPLAY_STR, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR); + Map.entry(THING_TYPE_SHELLYPLUSWALLDISPLAY_STR, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1MINI_STR, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMINI1G3_STR, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMINI1G4_STR, THING_TYPE_SHELLY1MINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPMMINI_STR, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPMMINIG3_STR, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPMMINIG4_STR, THING_TYPE_SHELLYPMMINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PMMINI_STR, THING_TYPE_SHELLY1PMMINI_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PMMINIG3_STR, THING_TYPE_SHELLY1PMMINIG3_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PMMINIG4_STR, THING_TYPE_SHELLY1PMMINIG3_STR); + Map.entry(THING_TYPE_SHELLY1MINI_STR, THING_TYPE_SHELLY1MINI_STR), + Map.entry(THING_TYPE_SHELLYMINI1G3_STR, THING_TYPE_SHELLY1MINI_STR), + Map.entry(THING_TYPE_SHELLYMINI1G4_STR, THING_TYPE_SHELLY1MINI_STR), + Map.entry(THING_TYPE_SHELLYPMMINI_STR, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(THING_TYPE_SHELLYPMMINIG3_STR, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(THING_TYPE_SHELLYPMMINIG4_STR, THING_TYPE_SHELLYPMMINI_STR), + Map.entry(THING_TYPE_SHELLY1PMMINI_STR, THING_TYPE_SHELLY1PMMINI_STR), + Map.entry(THING_TYPE_SHELLY1PMMINIG3_STR, THING_TYPE_SHELLY1PMMINIG3_STR), + Map.entry(THING_TYPE_SHELLY1PMMINIG4_STR, THING_TYPE_SHELLY1PMMINIG3_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1_STR, THING_TYPE_SHELLYPRO1_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1PM_STR, THING_TYPE_SHELLYPRO1PM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1CB_STR, THING_TYPE_SHELLYPRO1CB_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_RELAY_STR, THING_TYPE_SHELLYPRO2PM_RELAY_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_ROLLER_STR, THING_TYPE_SHELLYPRO2PM_ROLLER_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2_RELAY_STR, THING_TYPE_SHELLYPRO2_RELAY_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROEM50_STR, THING_TYPE_SHELLYPROEM50_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3EM_STR, THING_TYPE_SHELLYPRO3EM_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3_STR, THING_TYPE_SHELLYPRO3_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO4PM_STR, THING_TYPE_SHELLYPRO4PM_STR); + Map.entry(THING_TYPE_SHELLYPRO1_STR, THING_TYPE_SHELLYPRO1_STR), + Map.entry(THING_TYPE_SHELLYPRO1PM_STR, THING_TYPE_SHELLYPRO1PM_STR), + Map.entry(THING_TYPE_SHELLYPRO1CB_STR, THING_TYPE_SHELLYPRO1CB_STR), + Map.entry(THING_TYPE_SHELLYPRO2PM_RELAY_STR, THING_TYPE_SHELLYPRO2PM_RELAY_STR), + Map.entry(THING_TYPE_SHELLYPRO2PM_ROLLER_STR, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), + Map.entry(THING_TYPE_SHELLYPRO2_RELAY_STR, THING_TYPE_SHELLYPRO2_RELAY_STR), + Map.entry(THING_TYPE_SHELLYPROEM50_STR, THING_TYPE_SHELLYPROEM50_STR), + Map.entry(THING_TYPE_SHELLYPRO3EM_STR, THING_TYPE_SHELLYPRO3EM_STR), + Map.entry(THING_TYPE_SHELLYPRO3_STR, THING_TYPE_SHELLYPRO3_STR), + Map.entry(THING_TYPE_SHELLYPRO4PM_STR, THING_TYPE_SHELLYPRO4PM_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUBUTTON_STR, THING_TYPE_SHELLYBLUBUTTON_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUDW_STR, THING_TYPE_SHELLYBLUDW_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUMOTION_STR, THING_TYPE_SHELLYBLUMOTION_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUHT_STR, THING_TYPE_SHELLYBLUHT_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUGW_STR, THING_TYPE_SHELLYBLUGW_STR); - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBLUGWG3_STR, THING_TYPE_SHELLYBLUGW_STR); + Map.entry(THING_TYPE_SHELLYBLUBUTTON_STR, THING_TYPE_SHELLYBLUBUTTON_STR), + Map.entry(THING_TYPE_SHELLYBLUDW_STR, THING_TYPE_SHELLYBLUDW_STR), + Map.entry(THING_TYPE_SHELLYBLUMOTION_STR, THING_TYPE_SHELLYBLUMOTION_STR), + Map.entry(THING_TYPE_SHELLYBLUHT_STR, THING_TYPE_SHELLYBLUHT_STR), + Map.entry(THING_TYPE_SHELLYBLUGW_STR, THING_TYPE_SHELLYBLUGW_STR), + Map.entry(THING_TYPE_SHELLYBLUGWG3_STR, THING_TYPE_SHELLYBLUGW_STR), - THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROTECTED_STR, THING_TYPE_SHELLYPROTECTED_STR); + Map.entry(THING_TYPE_SHELLYPROTECTED_STR, THING_TYPE_SHELLYPROTECTED_STR)); + + public static ThingUID getThingUID(String serviceName) { + return getThingUID(serviceName, "", ""); } - public static ThingUID getThingUID(String serviceName, String deviceType, String mode, boolean unknown) { - String devid = substringAfterLast(serviceName, "-"); - if (devid.isEmpty()) { - throw new IllegalArgumentException("serviceName has improper format: " + serviceName); - } - return new ThingUID(!unknown ? getThingTypeUID(serviceName, deviceType, mode) - : getThingTypeUID(THING_TYPE_SHELLYPROTECTED_STR + "-" + devid, deviceType, mode), devid); + public static ThingUID getThingUID(String serviceName, String deviceType, String mode) { + String deviceId = getDeviceIdOrThrow(serviceName); + return new ThingUID(getThingTypeUID(serviceName, deviceType, mode), deviceId); + } + + public static ThingUID getThingUIDForUnknown(String serviceName, String deviceType, String mode) { + String deviceId = getDeviceIdOrThrow(serviceName); + return new ThingUID(getThingTypeUID(THING_TYPE_SHELLYPROTECTED_STR + "-" + deviceId, deviceType, mode), + deviceId); } public static ThingTypeUID getThingTypeUID(String serviceName, String deviceType, String mode) { - return new ThingTypeUID(BINDING_ID, getThingType(serviceName, deviceType, mode)); + return new ThingTypeUID(BINDING_ID, getThingTypeID(serviceName, deviceType, mode)); } - public static ThingTypeUID getUnknownTTUID() { - return new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPROTECTED_STR); + private static String getDeviceIdOrThrow(String serviceName) { + String deviceId = substringAfterLast(serviceName, "-"); + if (deviceId.isEmpty()) { + throw new IllegalArgumentException("Invalid serviceName format: " + serviceName); + } + return deviceId; } - public static String getThingType(String hostname, String deviceType, String mode) { - if (THING_TYPE_SHELLYPROTECTED_STR.equals(hostname)) { + private static String getThingTypeID(String serviceName, String deviceType, String mode) { + if (THING_TYPE_SHELLYPROTECTED_STR.equals(serviceName)) { return THING_TYPE_SHELLYPROTECTED_STR; } - String name = hostname.toLowerCase(); - String type = substringBefore(name, "-").toLowerCase(); - String devid = substringAfterLast(name, "-"); - if (devid.isEmpty() || type.isEmpty()) { - throw new IllegalArgumentException("Invalid device name format: " + hostname); + String serviceNameLowerCase = serviceName.toLowerCase(); + String type = substringBefore(serviceNameLowerCase, "-"); + if (type.isEmpty()) { + throw new IllegalArgumentException("Invalid serviceName format: " + serviceName); } // First check for special handling - if (name.startsWith(THING_TYPE_SHELLY25_PREFIX)) { // Shelly v2.5 - return mode.equals(SHELLY_MODE_RELAY) ? THING_TYPE_SHELLY25_RELAY_STR : THING_TYPE_SHELLY25_ROLLER_STR; + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLY25_PREFIX)) { // Shelly v2.5 + return getRelayOrRollerType(THING_TYPE_SHELLY25_RELAY_STR, THING_TYPE_SHELLY25_ROLLER_STR, mode); } - if (name.startsWith(THING_TYPE_SHELLY2_PREFIX)) { // Shelly v2 - return mode.equals(SHELLY_MODE_RELAY) ? THING_TYPE_SHELLY2_RELAY_STR : THING_TYPE_SHELLY2_ROLLER_STR; + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLY2_PREFIX)) { // Shelly v2 + return getRelayOrRollerType(THING_TYPE_SHELLY2_RELAY_STR, THING_TYPE_SHELLY2_ROLLER_STR, mode); } - if (name.startsWith(THING_TYPE_SHELLYPLUG_STR)) { + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLYPLUG_STR)) { // shellyplug-s needs to be mapped to shellyplugs to follow the schema // for the thing types: - - if (name.startsWith(THING_TYPE_SHELLYPLUGS_STR) || name.contains("-s")) { + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLYPLUGS_STR) || serviceNameLowerCase.contains("-s")) { return THING_TYPE_SHELLYPLUGS_STR; } - if (name.startsWith(THING_TYPE_SHELLYPLUGU1_STR)) { + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLYPLUGU1_STR)) { return THING_TYPE_SHELLYPLUGU1_STR; } return THING_TYPE_SHELLYPLUG_STR; } - if (name.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX)) { - return mode.equals(SHELLY_MODE_COLOR) ? THING_TYPE_SHELLYRGBW2_COLOR_STR : THING_TYPE_SHELLYRGBW2_WHITE_STR; + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLYRGBW2_PREFIX)) { + return SHELLY_MODE_COLOR.equals(mode) ? THING_TYPE_SHELLYRGBW2_COLOR_STR : THING_TYPE_SHELLYRGBW2_WHITE_STR; } - if (name.startsWith(THING_TYPE_SHELLYMOTION_STR)) { + if (serviceNameLowerCase.startsWith(THING_TYPE_SHELLYMOTION_STR)) { // depending on firmware release the Motion advertises under shellymotion-xxx or shellymotionsensor-xxxx return THING_TYPE_SHELLYMOTION_STR; } - // Check general mapping if (!deviceType.isEmpty()) { - String res = THING_TYPE_MAPPING.get(deviceType); // by device type + String res = THING_TYPE_BY_DEVICE_TYPE.get(deviceType); if (res != null) { return res; } - String dt = mode.equals(SHELLY_MODE_RELAY) || mode.equals(SHELLY_MODE_ROLLER) ? deviceType + "-" + mode - : deviceType; - res = THING_TYPE_MAPPING.get(dt); //
-relay /
-roller + String key = switch (mode) { + //
-relay /
-roller + case SHELLY_MODE_RELAY, SHELLY_MODE_ROLLER -> deviceType + "-" + mode; + default -> deviceType; + }; + res = THING_TYPE_BY_DEVICE_TYPE.get(key); if (res != null) { return res; } } - String res = THING_TYPE_MAPPING.get(type); - if (res != null) { - return res; - } - return THING_TYPE_SHELLYUNKNOWN_STR; + return THING_TYPE_MAPPING.getOrDefault(type, THING_TYPE_SHELLYUNKNOWN_STR); + } + + private static String getRelayOrRollerType(String relayType, String rollerType, String mode) { + return SHELLY_MODE_RELAY.equals(mode) ? relayType : rollerType; } } diff --git a/bundles/org.openhab.binding.shelly/src/test/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreatorTest.java b/bundles/org.openhab.binding.shelly/src/test/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreatorTest.java index 8d9876d5614..94a9bab4538 100644 --- a/bundles/org.openhab.binding.shelly/src/test/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreatorTest.java +++ b/bundles/org.openhab.binding.shelly/src/test/java/org/openhab/binding/shelly/internal/discovery/ShellyThingCreatorTest.java @@ -15,6 +15,7 @@ package org.openhab.binding.shelly.internal.discovery; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*; import static org.openhab.binding.shelly.internal.discovery.ShellyThingCreator.*; import java.util.Set; @@ -25,7 +26,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.openhab.binding.shelly.internal.ShellyBindingConstants; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingUID; @@ -43,7 +43,7 @@ public class ShellyThingCreatorTest { @MethodSource("provideTestCasesForGetThingUIDThrowsForInvalidServiceName") void getThingUIDThrowsForInvalidServiceName(String serviceName) { assertThrows(IllegalArgumentException.class, () -> { - ShellyThingCreator.getThingUID(serviceName, "", "", false); + ShellyThingCreator.getThingUID(serviceName); }); } @@ -52,9 +52,9 @@ public class ShellyThingCreatorTest { } @Test - void getThingUIDReturnsThingUidForUnknown() { - ThingUID actual = ShellyThingCreator.getThingUID("johndoe-" + DEVICE_ID, "", "", true); - ThingUID expected = new ThingUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPROTECTED_STR, DEVICE_ID); + void getThingUIDForUnknownReturnsThingUidForUnknown() { + ThingUID actual = ShellyThingCreator.getThingUIDForUnknown("johndoe-" + DEVICE_ID, "", ""); + ThingUID expected = new ThingUID(BINDING_ID, THING_TYPE_SHELLYPROTECTED_STR, DEVICE_ID); assertThat(actual, is(equalTo(expected))); } @@ -63,13 +63,13 @@ public class ShellyThingCreatorTest { @MethodSource("provideTestCasesForGetThingUIDReturnsThingUidAccordingToRuleset") void getThingUIDReturnsThingUidAccordingToRuleset(String serviceName, String deviceType, String mode, String expectedThingTypeId) { - ThingUID actual = ShellyThingCreator.getThingUID(serviceName, deviceType, mode, false); - ThingUID expected = new ThingUID(ShellyBindingConstants.BINDING_ID, expectedThingTypeId, DEVICE_ID); - ThingTypeUID expectedThingTypeUid = new ThingTypeUID(ShellyBindingConstants.BINDING_ID, expectedThingTypeId); + ThingUID actual = ShellyThingCreator.getThingUID(serviceName, deviceType, mode); + ThingUID expected = new ThingUID(BINDING_ID, expectedThingTypeId, DEVICE_ID); + ThingTypeUID expectedThingTypeUid = new ThingTypeUID(BINDING_ID, expectedThingTypeId); assertThat("serviceName: " + serviceName + "; deviceType: " + deviceType + "; mode: " + mode, actual, is(equalTo(expected))); - assertThat(ShellyBindingConstants.SUPPORTED_THING_TYPES_UIDS, hasItem(expectedThingTypeUid)); + assertThat(SUPPORTED_THING_TYPES_UIDS, hasItem(expectedThingTypeUid)); } private static Stream provideTestCasesForGetThingUIDReturnsThingUidAccordingToRuleset() { @@ -99,12 +99,12 @@ public class ShellyThingCreatorTest { @ParameterizedTest @MethodSource("provideTestCasesForGetThingUIDReturnsThingUidByDeviceType") void getThingUIDReturnsThingUidByDeviceType(String deviceType, String mode, String expectedThingTypeId) { - ThingUID actual = ShellyThingCreator.getThingUID("x-" + DEVICE_ID, deviceType, mode, false); - ThingUID expected = new ThingUID(ShellyBindingConstants.BINDING_ID, expectedThingTypeId, DEVICE_ID); - ThingTypeUID expectedThingTypeUid = new ThingTypeUID(ShellyBindingConstants.BINDING_ID, expectedThingTypeId); + ThingUID actual = ShellyThingCreator.getThingUID("x-" + DEVICE_ID, deviceType, mode); + ThingUID expected = new ThingUID(BINDING_ID, expectedThingTypeId, DEVICE_ID); + ThingTypeUID expectedThingTypeUid = new ThingTypeUID(BINDING_ID, expectedThingTypeId); assertThat("deviceType: " + deviceType + "; mode: " + mode, actual, is(equalTo(expected))); - assertThat(ShellyBindingConstants.SUPPORTED_THING_TYPES_UIDS, hasItem(expectedThingTypeUid)); + assertThat(SUPPORTED_THING_TYPES_UIDS, hasItem(expectedThingTypeUid)); } private static Stream provideTestCasesForGetThingUIDReturnsThingUidByDeviceType() { @@ -204,19 +204,19 @@ public class ShellyThingCreatorTest { Set excludedThingTypeUids = Set.of(THING_TYPE_SHELLYBLUDW, THING_TYPE_SHELLYBLUMOTION, THING_TYPE_SHELLYBLUHT, THING_TYPE_SHELLYBLUGW, THING_TYPE_SHELLYBLUBUTTON, THING_TYPE_SHELLY2_RELAY, THING_TYPE_SHELLY2_ROLLER, THING_TYPE_SHELLY25_ROLLER, THING_TYPE_SHELLY25_RELAY, - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPLUSHTG3_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPRO2_RELAY_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYPRO2PM_RELAY_STR), - new ThingTypeUID(ShellyBindingConstants.BINDING_ID, THING_TYPE_SHELLYRGBW2_COLOR_STR)); + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUSHTG3_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUS2PM_RELAY_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPRO2_RELAY_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPRO2PM_ROLLER_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYPRO2PM_RELAY_STR), + new ThingTypeUID(BINDING_ID, THING_TYPE_SHELLYRGBW2_COLOR_STR)); - for (ThingTypeUID supportedThingTypeUid : ShellyBindingConstants.SUPPORTED_THING_TYPES_UIDS.stream() + for (ThingTypeUID supportedThingTypeUid : SUPPORTED_THING_TYPES_UIDS.stream() .filter(uid -> !excludedThingTypeUids.contains(uid)).toList()) { String thingTypeId = supportedThingTypeUid.getId(); - ThingUID actualThingUid = ShellyThingCreator.getThingUID(thingTypeId + "-" + DEVICE_ID, "", "", false); - ThingUID expectedThingUid = new ThingUID(ShellyBindingConstants.BINDING_ID, thingTypeId, DEVICE_ID); + ThingUID actualThingUid = ShellyThingCreator.getThingUID(thingTypeId + "-" + DEVICE_ID); + ThingUID expectedThingUid = new ThingUID(BINDING_ID, thingTypeId, DEVICE_ID); assertThat(actualThingUid, is(equalTo(expectedThingUid))); } }