From a6f9adf6ece09182cb89b339697c8edee4301bc4 Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Thu, 18 Jan 2024 16:05:22 -0500 Subject: [PATCH] Fix stack overflow when an unknown CoAP Id is detected; Fix innerTemp (#16240) channel creation for Gen2 devices not having this; Fix sensor initialization on wakeup; Fix missingf temperature5 description; add missing relay definition for shellywalldisplay; Some README fixes --- bundles/org.openhab.binding.shelly/README.md | 28 +++++++++++-------- .../internal/api1/Shelly1CoIoTVersion2.java | 3 ++ .../internal/api1/Shelly1CoapHandler.java | 12 +++----- .../internal/api2/Shelly2ApiClient.java | 3 -- .../internal/handler/ShellyBaseHandler.java | 10 ++++--- .../internal/handler/ShellyComponents.java | 2 +- .../shelly/internal/util/ShellyUtils.java | 2 +- .../resources/OH-INF/i18n/shelly.properties | 2 +- .../OH-INF/thing/shellyGen2_sensor.xml | 1 + 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/bundles/org.openhab.binding.shelly/README.md b/bundles/org.openhab.binding.shelly/README.md index d007aecebb813..813f60237d99d 100644 --- a/bundles/org.openhab.binding.shelly/README.md +++ b/bundles/org.openhab.binding.shelly/README.md @@ -96,12 +96,12 @@ The binding provides the same feature set across all devices as good as possible | shellywalldisplay | Shelly Plus Wall Display | SAWD-0A1XX10EU1 | ### Generation 2 Plus Mini series + | thing-type | Model | Vendor ID | | -------------------- | -------------------------------------------------------- | ---------------------------- | -| shellymini1 | Shelly Plus 1 Mini with 1x relay | SNSW-001X16EU | -| shellymini1pm | Shelly Plus 1PM Mini with 1x relay + power meter | SNPM-001PCEU16 | -| shellyminipm | Shelly Plus PM Mini with 1x power meter | SNSW-001P8EU | - +| shellymini1 | Shelly Plus 1 Mini with 1x relay | SNSW-001X8EU | +| shellymini1pm | Shelly Plus 1PM Mini with 1x relay + power meter | SNSW-001P8EU | +| shellyminipm | Shelly Plus PM Mini with 1x power meter | SNPM-001PCEU16 | ### Generation 2 Pro series @@ -402,14 +402,18 @@ A new alarm will be triggered on a new condition or every 5 minutes if the condi ### Non-battery powered devices -| Event Type | Description | -| ----------- | --------------------------------------------------------------------------------- | -| RESTARTED | The device has been restarted. This could be an indicator for a firmware problem. | -| WEAK_SIGNAL | An alarm is triggered when RSSI is < -80, which indicates an unstable connection. | -| OVER_TEMP | The device is overheating, check installation and housing. | -| OVER_LOAD | An over load condition has been detected, e.g. from the roller motor. | -| OVER_POWER | Maximum allowed power was exceeded. The relay was turned off. | -| LOAD_ERROR | Device reported a load problem, so far Dimmer only. | +| Event Type | Description | +| ------------ | --------------------------------------------------------------------------------- | +| RESTARTED | The device has been restarted. This could be an indicator for a firmware problem. | +| WEAK_SIGNAL | An alarm is triggered when RSSI is < -80, which indicates an unstable connection. | +| OVERTEMP | The device is overheating, check installation and housing. | +| OVERLOAD | An over load condition has been detected, e.g. from the roller motor. | +| OVERPOWER | Maximum allowed power was exceeded. The relay was turned off. | +| LOAD_ERROR | Device reported a load problem. | +| SENSOR_ERROR | Device reported a sensor problem. | +| VALVE_ERROR | Device reported a problem with the valve. | +| VIBRATION | Device reported vibration. | +| LOW_BATTERY | Device reported low battery. | ### Sensors diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTVersion2.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTVersion2.java index 7e1eef50ff463..fc29530369599 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTVersion2.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoIoTVersion2.java @@ -142,6 +142,9 @@ public boolean handleStatusUpdate(List sensorUpdates, CoIotDescrSen processed = true; switch (sen.id) { + case "6": // 3EM: neutralCurrent + break; + case "3106": // L, luminosity, lux, U32, -1 case "3110": // S, luminosityLevel, dark/twilight/bright, "unknown"=unknown case "3111": // B, battery, 0-100%, unknown -1 diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java index d933736be941c..9ab5e29c39bb7 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1CoapHandler.java @@ -359,16 +359,12 @@ private void handleDeviceDescription(String devId, String payload) throws Shelly valid &= addSensor(descr.sen.get(i)); } } - coiot.completeMissingSensorDefinition(sensorMap); - if (!valid) { - logger.debug( - "{}: Incompatible device description detected for CoIoT version {} (id length mismatch), discarding!", - thingName, coiot.getVersion()); - - discover(); - return; + logger.debug("{}: WARNING: Incompatible device description detected for CoIoT version {}!", thingName, + coiot.getVersion()); } + + coiot.completeMissingSensorDefinition(sensorMap); // fix incomplete format } catch (JsonSyntaxException e) { logger.warn("{}: Unable to parse CoAP Device Description! JSON={}", thingName, payload); } catch (NullPointerException | IllegalArgumentException e) { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java index 651fb195302b8..6ca8d4c11a243 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java @@ -239,9 +239,6 @@ private boolean updateRelayStatus(ShellySettingsStatus status, @Nullable Shelly2 int duration = (int) (now() - rs.timerStartetAt); sr.timerRemaining = duration; } - if (status.tmp == null) { - status.tmp = new ShellySensorTmp(); - } if (rs.temperature != null) { if (status.tmp == null) { status.tmp = new ShellySensorTmp(); 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 a413fc59aa262..4e0a4a1f14152 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 @@ -293,8 +293,10 @@ public boolean initializeThing() throws ShellyApiException { return false; } - updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.CONFIGURATION_PENDING, - messages.get("status.unknown.initializing")); + if (profile.alwaysOn || !profile.isInitialized()) { + updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.CONFIGURATION_PENDING, + messages.get("status.unknown.initializing")); + } // Gen 1 only: Setup CoAP listener to we get the CoAP message, which triggers initialization even the thing // could not be fully initialized here. In this case the CoAP messages triggers auto-initialization (like the @@ -513,7 +515,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } private double getNumber(Command command) { - if (command instanceof QuantityType quantityCommand) { + if (command instanceof QuantityType quantityCommand) { return quantityCommand.doubleValue(); } if (command instanceof DecimalType decimalCommand) { @@ -1279,7 +1281,7 @@ public State getChannelValue(String group, String channel) { public double getChannelDouble(String group, String channel) { State value = getChannelValue(group, channel); if (value != UnDefType.NULL) { - if (value instanceof QuantityType quantityCommand) { + if (value instanceof QuantityType quantityCommand) { return quantityCommand.toBigDecimal().doubleValue(); } if (value instanceof DecimalType decimalCommand) { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java index 6f862adc4636d..fe6e70a5cd92f 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java @@ -534,7 +534,7 @@ public static boolean updateSensors(ShellyThingInterface thingHandler, ShellySet updated |= thingHandler.updateInputs(status); if (updated) { - thingHandler.updateChannel(profile.getControlGroup(0), CHANNEL_LAST_UPDATE, getTimestamp()); + thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_LAST_UPDATE, getTimestamp()); } } return updated; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/util/ShellyUtils.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/util/ShellyUtils.java index e54b5f2693e09..5a4a82676676b 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/util/ShellyUtils.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/util/ShellyUtils.java @@ -239,7 +239,7 @@ public static Double getNumber(Command command) throws IllegalArgumentException if (command instanceof DecimalType decimalCommand) { return decimalCommand.doubleValue(); } - if (command instanceof QuantityType quantityCommand) { + if (command instanceof QuantityType quantityCommand) { return quantityCommand.doubleValue(); } throw new IllegalArgumentException("Unable to convert number"); diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties index 2c2801bfcbc34..9479788749880 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties @@ -246,7 +246,7 @@ channel-type.shelly.temperature3.description = Temperature of external Sensor #3 channel-type.shelly.temperature4.label = Temperature 4 channel-type.shelly.temperature4.description = Temperature of external Sensor #4 channel-type.shelly.temperature5.label = Temperature 5 -channel-type.shelly.temperature6.description = Temperature of external Sensor #5 +channel-type.shelly.temperature5.description = Temperature of external Sensor #5 channel-type.shelly.targetTemp.label = Target Temperature channel-type.shelly.targetTemp.description = Target Temperature in �C to be reached in auto-temperature mode channel-type.shelly.humidity.label = Humidity diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_sensor.xml b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_sensor.xml index 482379537fef9..1d84911bed81b 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_sensor.xml +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_sensor.xml @@ -38,6 +38,7 @@ Sensor +