Skip to content

Commit 1e671d5

Browse files
markus7017jlaur
authored andcommitted
[shelly] Revise fix for Gen1 initialization problem for manually created Things (openhab#17011)
* Fixes openhab#16990 - Gen1 nbo longer initializes when defined in .things Signed-off-by: Markus Michels <[email protected]> Co-authored-by: Jacob Laursen <[email protected]>
1 parent 1ce8aed commit 1e671d5

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

bundles/org.openhab.binding.shelly/README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ The binding provides the same feature set across all devices as good as possible
7474
| shellybutton2 | Shelly Button 2 | SHBTN-2 |
7575
| shellysense | Shelly Motion and IR Controller | SHSEN-1 |
7676
| shellytrv | Shelly TRV | SHTRV-01 |
77-
| shellydevice | A password protected Shelly device or an unknown type | |
7877

7978
### Generation 2 Plus series
8079

@@ -87,14 +86,15 @@ The binding provides the same feature set across all devices as good as possible
8786
| shellyplusplug | Shelly Plug-S | SNPL-00112EU |
8887
| shellyplusplug | Shelly Plug-IT | SNPL-00110IT |
8988
| shellyplusplug | Shelly Plug-UK | SNPL-00112UK |
90-
| shellyplusplug | Shelly Plug-US | SNPL-00116US |
89+
| shellyplusplugus | Shelly Plug-US | SNPL-00116US |
9190
| shellyplusi4 | Shelly Plus i4 with 4x AC input | SNSN-0024X |
9291
| shellyplusi4dc | Shelly Plus i4 with 4x DC input | SNSN-0D24X |
9392
| shellyplusht | Shelly Plus HT with temperature + humidity sensor | SNSN-0013A |
9493
| shellyhtg3 | Shelly Plus HT Gen 3 with temperature + humidity sensor | S3SN-0U12A |
9594
| shellyplussmoke | Shelly Plus Smoke sensor | SNSN-0031Z |
9695
| shellypluswdus | Shelly Plus Wall Dimmer US | SNDM-0013US |
9796
| shellywalldisplay | Shelly Plus Wall Display | SAWD-0A1XX10EU1 |
97+
| shellyblugw | SHelly BLU Gateway | SNGW-BT01 |
9898

9999
### Generation 2 Plus Mini series (incl. Gen 3)
100100

@@ -115,6 +115,7 @@ The binding provides the same feature set across all devices as good as possible
115115
| shellypro2pm-roller | Shelly Pro 2 PM with 2x relay + power meter, roller mode | SPSW-002PE16EU, SPSW-102PE16EU, SPSW-202PE16EU |
116116
| shellypro3 | Shelly Pro 3 with 3x relay (dry contacts) | SPSW-003XE16EU |
117117
| shellypro3em | Shelly Pro 3 with 3 integrated power meters | SPEM-003CEBEU |
118+
| shellyproem50 | Shelly Pro EM50 with 3 integrated power meters | SPEM-002CEBEU50 |
118119
| shellypro4pm | Shelly Pro 4 PM with 4x relay + power meter | SPSW-004PE16EU, SPSW-104PE16EU |
119120

120121
### Shelly BLU
@@ -126,6 +127,13 @@ The binding provides the same feature set across all devices as good as possible
126127
| shellyblumotion | Shelly BLU Motion | SBMO |
127128
| shellybluht | Shelly BLU H&T | SBMO |
128129

130+
### Special Thing Types
131+
132+
| thing-type | Model | Vendor ID |
133+
| ----------------- | ------------------------------------------------------ | --------- |
134+
| shellydevice | A password protected Shelly device or an unknown type | |
135+
| shellyunknown | An unknown Shelly device / model has been detected | |
136+
129137
## Binding Configuration
130138

131139
The binding has the following configuration options:
@@ -1551,6 +1559,10 @@ See notes on discovery of Shelly BLU devices above.
15511559
| battery | batteryLevel | Number | yes | Battery Level in % |
15521560
| | lowBattery | Switch | yes | Low battery alert (< 20%) |
15531561

1562+
## Shelly BLU Gateway (thing-type: shellyblugw)
1563+
1564+
There are no additional channels beside the device group.
1565+
15541566
## Shelly Wall Displays
15551567

15561568
| Group | Channel | Type | read-only | Description |

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ public static String extractFwVersion(@Nullable String version) {
405405

406406
public static boolean isGeneration2(String thingType) {
407407
return thingType.startsWith("shellyplus") || thingType.startsWith("shellypro") || thingType.contains("mini")
408-
|| (thingType.startsWith("shelly") && thingType.contains("g3")) || isBluSeries(thingType);
408+
|| thingType.startsWith("shellywall") || (thingType.startsWith("shelly") && thingType.contains("g3"))
409+
|| isBluSeries(thingType);
409410
}
410411

411412
public static boolean isBluSeries(String thingType) {

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ public ShellyDeviceProfile getDeviceProfile(String thingType, @Nullable ShellySe
205205
}
206206

207207
ShellySettingsDevice device = profile.device;
208-
profile.isGen2 = device.gen == 2;
209208
if (config.serviceName.isEmpty()) {
210209
config.serviceName = getString(profile.device.hostname);
211210
}

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,17 @@ public ShellyBaseHandler(final Thing thing, final ShellyTranslationProvider tran
153153
this.config = getConfigAs(ShellyThingConfiguration.class);
154154
this.httpClient = httpClient;
155155

156-
Map<String, String> properties = thing.getProperties();
157-
String gen = getString(properties.get(PROPERTY_DEV_GEN));
156+
// Create thing handler depending on device generation
158157
String thingType = getThingType();
159158
blu = ShellyDeviceProfile.isBluSeries(thingType);
160-
gen2 = "2".equals(gen) || "3".equals(gen) || blu || ShellyDeviceProfile.isGeneration2(thingType);
161-
this.api = !blu ? !gen2 ? new Shelly1HttpApi(thingName, this) : new Shelly2ApiRpc(thingName, thingTable, this)
162-
: new ShellyBluApi(thingName, thingTable, this);
159+
gen2 = ShellyDeviceProfile.isGeneration2(thingType);
160+
if (blu) {
161+
this.api = new ShellyBluApi(thingName, thingTable, this);
162+
} else if (gen2) {
163+
this.api = new Shelly2ApiRpc(thingName, thingTable, this);
164+
} else {
165+
this.api = new Shelly1HttpApi(thingName, this);
166+
}
163167
if (gen2) {
164168
config.eventsCoIoT = false;
165169
}

0 commit comments

Comments
 (0)