From: Markus Michels Date: Tue, 9 Jul 2024 05:36:21 +0000 (+0200) Subject: [shelly] Revise fix for Gen1 initialization problem for manually created Things ... X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=7755681749a4e14b1aeb86da478e0629cb9e55f4;p=openhab-addons.git [shelly] Revise fix for Gen1 initialization problem for manually created Things (#17011) * Fixes #16990 - Gen1 nbo longer initializes when defined in .things Signed-off-by: Markus Michels Co-authored-by: Jacob Laursen --- diff --git a/bundles/org.openhab.binding.shelly/README.md b/bundles/org.openhab.binding.shelly/README.md index 4f3aa479d0..1be0b89c9a 100644 --- a/bundles/org.openhab.binding.shelly/README.md +++ b/bundles/org.openhab.binding.shelly/README.md @@ -74,7 +74,6 @@ The binding provides the same feature set across all devices as good as possible | shellybutton2 | Shelly Button 2 | SHBTN-2 | | shellysense | Shelly Motion and IR Controller | SHSEN-1 | | shellytrv | Shelly TRV | SHTRV-01 | -| shellydevice | A password protected Shelly device or an unknown type | | ### Generation 2 Plus series @@ -87,7 +86,7 @@ The binding provides the same feature set across all devices as good as possible | shellyplusplug | Shelly Plug-S | SNPL-00112EU | | shellyplusplug | Shelly Plug-IT | SNPL-00110IT | | shellyplusplug | Shelly Plug-UK | SNPL-00112UK | -| shellyplusplug | Shelly Plug-US | SNPL-00116US | +| shellyplusplugus | Shelly Plug-US | SNPL-00116US | | shellyplusi4 | Shelly Plus i4 with 4x AC input | SNSN-0024X | | shellyplusi4dc | Shelly Plus i4 with 4x DC input | SNSN-0D24X | | shellyplusht | Shelly Plus HT with temperature + humidity sensor | SNSN-0013A | @@ -95,6 +94,7 @@ The binding provides the same feature set across all devices as good as possible | shellyplussmoke | Shelly Plus Smoke sensor | SNSN-0031Z | | shellypluswdus | Shelly Plus Wall Dimmer US | SNDM-0013US | | shellywalldisplay | Shelly Plus Wall Display | SAWD-0A1XX10EU1 | +| shellyblugw | SHelly BLU Gateway | SNGW-BT01 | ### Generation 2 Plus Mini series (incl. Gen 3) @@ -115,6 +115,7 @@ The binding provides the same feature set across all devices as good as possible | shellypro2pm-roller | Shelly Pro 2 PM with 2x relay + power meter, roller mode | SPSW-002PE16EU, SPSW-102PE16EU, SPSW-202PE16EU | | shellypro3 | Shelly Pro 3 with 3x relay (dry contacts) | SPSW-003XE16EU | | shellypro3em | Shelly Pro 3 with 3 integrated power meters | SPEM-003CEBEU | +| shellyproem50 | Shelly Pro EM50 with 3 integrated power meters | SPEM-002CEBEU50 | | shellypro4pm | Shelly Pro 4 PM with 4x relay + power meter | SPSW-004PE16EU, SPSW-104PE16EU | ### Shelly BLU @@ -126,6 +127,13 @@ The binding provides the same feature set across all devices as good as possible | shellyblumotion | Shelly BLU Motion | SBMO | | shellybluht | Shelly BLU H&T | SBMO | +### Special Thing Types + +| thing-type | Model | Vendor ID | +| ----------------- | ------------------------------------------------------ | --------- | +| shellydevice | A password protected Shelly device or an unknown type | | +| shellyunknown | An unknown Shelly device / model has been detected | | + ## Binding Configuration The binding has the following configuration options: @@ -1551,6 +1559,10 @@ See notes on discovery of Shelly BLU devices above. | battery | batteryLevel | Number | yes | Battery Level in % | | | lowBattery | Switch | yes | Low battery alert (< 20%) | +## Shelly BLU Gateway (thing-type: shellyblugw) + +There are no additional channels beside the device group. + ## Shelly Wall Displays | Group | Channel | Type | read-only | Description | diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java index 3149bac5aa..162b85e046 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java @@ -405,7 +405,8 @@ public class ShellyDeviceProfile { public static boolean isGeneration2(String thingType) { return thingType.startsWith("shellyplus") || thingType.startsWith("shellypro") || thingType.contains("mini") - || (thingType.startsWith("shelly") && thingType.contains("g3")) || isBluSeries(thingType); + || thingType.startsWith("shellywall") || (thingType.startsWith("shelly") && thingType.contains("g3")) + || isBluSeries(thingType); } public static boolean isBluSeries(String thingType) { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java index 3b440dbe63..c9b854f785 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java @@ -205,7 +205,6 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac } ShellySettingsDevice device = profile.device; - profile.isGen2 = device.gen == 2; if (config.serviceName.isEmpty()) { config.serviceName = getString(profile.device.hostname); } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java index a8ab8cfe03..d83fa16278 100755 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java @@ -153,13 +153,17 @@ public abstract class ShellyBaseHandler extends BaseThingHandler this.config = getConfigAs(ShellyThingConfiguration.class); this.httpClient = httpClient; - Map properties = thing.getProperties(); - String gen = getString(properties.get(PROPERTY_DEV_GEN)); + // Create thing handler depending on device generation String thingType = getThingType(); blu = ShellyDeviceProfile.isBluSeries(thingType); - gen2 = "2".equals(gen) || "3".equals(gen) || blu || ShellyDeviceProfile.isGeneration2(thingType); - this.api = !blu ? !gen2 ? new Shelly1HttpApi(thingName, this) : new Shelly2ApiRpc(thingName, thingTable, this) - : new ShellyBluApi(thingName, thingTable, this); + gen2 = ShellyDeviceProfile.isGeneration2(thingType); + if (blu) { + this.api = new ShellyBluApi(thingName, thingTable, this); + } else if (gen2) { + this.api = new Shelly2ApiRpc(thingName, thingTable, this); + } else { + this.api = new Shelly1HttpApi(thingName, this); + } if (gen2) { config.eventsCoIoT = false; }