From d85399f06cae40eb83f587e5b7212b14198eb1d1 Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Sat, 11 May 2024 23:55:29 +0200 Subject: [PATCH 1/4] fixes ##16736, #16734, #16542, #16709, #16735 Signed-off-by: Markus Michels --- .../binding/shelly/internal/api/ShellyApiInterface.java | 2 +- .../binding/shelly/internal/api1/Shelly1HttpApi.java | 2 +- .../binding/shelly/internal/api2/Shelly2ApiRpc.java | 2 +- .../shelly/internal/discovery/ShellyThingCreator.java | 2 +- .../shelly/internal/handler/ShellyBaseHandler.java | 7 ++++++- .../src/main/resources/OH-INF/config/config2.xml | 2 +- .../src/main/resources/scripts/oh-blu-scanner.js | 8 +++++--- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java index 72333350e9839..bad011bd2e82e 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiInterface.java @@ -84,7 +84,7 @@ ShellyDeviceProfile getDeviceProfile(String thingType, @Nullable ShellySettingsD void setValveMode(int id, boolean auto) throws ShellyApiException; - void setValveTemperature(int valveId, int value) throws ShellyApiException; + void setValveTemperature(int valveId, double value) throws ShellyApiException; void setValveProfile(int valveId, int value) throws ShellyApiException; diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1HttpApi.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1HttpApi.java index 0151e29679f0f..a83f22d2510c1 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1HttpApi.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api1/Shelly1HttpApi.java @@ -272,7 +272,7 @@ public void setSleepTime(int value) throws ShellyApiException { } @Override - public void setValveTemperature(int valveId, int value) throws ShellyApiException { + public void setValveTemperature(int valveId, double value) throws ShellyApiException { httpRequest("/thermostat/" + valveId + "?target_t_enabled=1&target_t=" + value); } 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 3e9d5a223cf03..1c3a3c47e2188 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 @@ -1099,7 +1099,7 @@ public void setValvePosition(int valveId, double value) throws ShellyApiExceptio } @Override - public void setValveTemperature(int valveId, int value) throws ShellyApiException { + public void setValveTemperature(int valveId, double value) throws ShellyApiException { throw new ShellyApiException("API call not implemented"); } 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 3945c4472a288..c956b172e476a 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 @@ -82,7 +82,7 @@ public class ShellyThingCreator { public static final String SHELLYDT_PLUSSMOKE = "SNSN-0031Z"; public static final String SHELLYDT_PLUSUNI = "SNSN-0043X"; public static final String SHELLYDT_PLUSDIMMERUS = "SNDM-0013US"; - public static final String SHELLYDT_PLUSDIMMER10V = "SNGW-0A11WW010"; + public static final String SHELLYDT_PLUSDIMMER10V = "SNDM-00100WW"; public static final String SHELLYDT_PLUSWALLDISPLAY = "SAWD-0A1XX10EU1"; // Shelly Pro Series 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 7090ba8ccadbf..0091ef93d6c9a 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 @@ -45,6 +45,7 @@ import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO; import org.openhab.binding.shelly.internal.api1.Shelly1CoapServer; import org.openhab.binding.shelly.internal.api1.Shelly1HttpApi; +import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO; import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2APClientList.Shelly2APClient; import org.openhab.binding.shelly.internal.api2.Shelly2ApiRpc; import org.openhab.binding.shelly.internal.api2.ShellyBluApi; @@ -463,7 +464,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { break; case CHANNEL_CONTROL_SETTEMP: logger.debug("{}: Set temperature to {}", thingName, command); - api.setValveTemperature(0, getNumber(command).intValue()); + api.setValveTemperature(0, getNumber(command).doubleValue()); break; case CHANNEL_CONTROL_POSITION: logger.debug("{}: Set position to {}", thingName, command); @@ -821,6 +822,10 @@ public void postEvent(String event, boolean force) { case SHELLY_WAKEUPT_POWERON: case SHELLY_WAKEUPT_EXT_POWER: case SHELLY_WAKEUPT_UNKNOWN: + case Shelly2ApiJsonDTO.SHELLY2_EVENT_OTASTART: + case Shelly2ApiJsonDTO.SHELLY2_EVENT_OTAPROGRESS: + case Shelly2ApiJsonDTO.SHELLY2_EVENT_OTADONE: + case SHELLY_EVENT_ROLLER_CALIB: logger.debug("{}: {}", thingName, messages.get("event.filtered", event)); case ALARM_TYPE_NONE: break; diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/config/config2.xml b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/config/config2.xml index 24fbbef7511fc..e24c68d7c5090 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/config/config2.xml +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/config/config2.xml @@ -29,7 +29,7 @@ @text/thing-type.config.shelly.enableRangeExtender.description - true + false diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js b/bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js index d5c670efa502a..9d774ec240fe6 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js +++ b/bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js @@ -1,7 +1,7 @@ /* * This script uses the BLE scan functionality in scripting to pass scan results to openHAB * Supported BLU Devices: BLU Button 1, BLU Door/Window, BLU Motion, BLU H&T - * Version 0.3 + * Version 0.4 */ let ALLTERCO_DEVICE_NAME_PREFIX = ["SBBT", "SBDW", "SBMO", "SBHT"]; @@ -33,15 +33,17 @@ BTH[0x05] = { n: "Illuminance", t: uint24, f: 0.01 }; BTH[0x08] = { n: "Dewpoint", t: int16, f: 0.01 }; BTH[0x12] = { n: "Co2", t: uint16 }; BTH[0x14] = { n: "Moisture16", t: uint16, f: 0.01 }; -BTH[0x14] = { n: "Moisture8", t: uint8 }; BTH[0x1a] = { n: "Door", t: uint8 }; BTH[0x20] = { n: "Moisture", t: uint8 }; BTH[0x21] = { n: "Motion", t: uint8 }; BTH[0x2d] = { n: "Window", t: uint8 }; +BTH[0x2e] = { n: "Humidity", t: uint8 }; +BTH[0x2f] = { n: "Moisture8", t: uint8 }; BTH[0x3a] = { n: "Button", t: uint8 }; BTH[0x3f] = { n: "Rotation", t: int16, f: 0.1 }; BTH[0x43] = { n: "Current", t: uint16, f: 0.1 }; -BTH[0x43] = { n: "UVIndex", t: uint8 }; +BTH[0x45] = { n: "Temperature", t: int16, f: 0.1 }; +BTH[0x46] = { n: "UVIndex", t: uint8 }; BTH[0x51] = { n: "Acceleration", t: uint16, f: 0.1 }; function getByteSize(type) { From 568630e2d375d24ab26ab619abc3b4fcd559f3df Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Sun, 12 May 2024 00:43:04 +0200 Subject: [PATCH 2/4] fix for #16655 Devices cannot be added via DNS anymore Signed-off-by: Markus Michels --- .../binding/shelly/internal/handler/ShellyRelayHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyRelayHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyRelayHandler.java index 395cb4cf56c78..d45c95a15545e 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyRelayHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyRelayHandler.java @@ -298,7 +298,7 @@ private void createRelayChannels(ShellySettingsRelay relay, int idx) { private void createRollerChannels(ShellyRollerStatus roller) { if (!areChannelsCreated()) { - updateChannelDefinitions(ShellyChannelDefinitions.createRollerChannels(getThing(), roller)); + updateChannelDefinitions(ShellyChannelDefinitions.createRollerChannels(getThing(), profile, roller)); } } From 625088b61a8837f4d2a9bf0678ab9248f2f6f606 Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Sun, 12 May 2024 00:43:36 +0200 Subject: [PATCH 3/4] fix for #16724 Addon channels not discovered when in cover mode with Shelly Plus 2PM Signed-off-by: Markus Michels --- .../internal/handler/ShellyBaseHandler.java | 2 +- .../provider/ShellyChannelDefinitions.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) 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 0091ef93d6c9a..86669e87d04e3 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 @@ -1008,7 +1008,7 @@ protected boolean initializeThingConfig() { String saddr = addr.getHostAddress(); if (!ip.equals(saddr)) { logger.debug("{}: hostname {} resolved to IP address {}", thingName, config.deviceIp, saddr); - config.deviceIp = saddr + (port.isEmpty() ? ip : ip + ":" + port); + config.deviceIp = saddr + (port.isEmpty() ? "" : ":" + port); } } catch (UnknownHostException e) { logger.debug("{}: Unable to resolve hostname {}", thingName, config.deviceIp); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java index b2ba9c94a2506..a8e9f0aa3c035 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/provider/ShellyChannelDefinitions.java @@ -369,6 +369,13 @@ public static Map createRelayChannels(final Thing thing, final addChannel(thing, add, rs.autoOff != null, group, CHANNEL_TIMER_AUTOOFF); } + addAddonChannels(thing, profile, idx, add); + + return add; + } + + private static void addAddonChannels(final Thing thing, final ShellyDeviceProfile profile, int idx, + Map add) { // Shelly 1/1PM and Plus 1/1PM Addon boolean addon = profile.settings.extSwitch != null && profile.settings.extSwitch.input0 != null && idx == getInteger(profile.settings.extSwitch.input0.relayNum); @@ -385,11 +392,10 @@ public static Map createRelayChannels(final Thing thing, final } addChannel(thing, add, profile.status.extHumidity != null && profile.status.extHumidity.sensor1 != null, CHGR_SENSOR, CHANNEL_ESENSOR_HUMIDITY); + addChannel(thing, add, profile.status.extVoltage != null, CHGR_SENSOR, CHANNEL_ESENSOR_VOLTAGE); addChannel(thing, add, profile.status.extDigitalInput != null, CHGR_SENSOR, CHANNEL_ESENSOR_DIGITALINPUT); addChannel(thing, add, profile.status.extAnalogInput != null, CHGR_SENSOR, CHANNEL_ESENSOR_ANALOGINPUT); - - return add; } public static Map createDimmerChannels(final Thing thing, final ShellyDeviceProfile profile, @@ -458,7 +464,8 @@ public static Map createInputChannels(final Thing thing, final return add; } - public static Map createRollerChannels(Thing thing, final ShellyRollerStatus roller) { + public static Map createRollerChannels(final Thing thing, final ShellyDeviceProfile profile, + final ShellyRollerStatus roller) { Map add = new LinkedHashMap<>(); addChannel(thing, add, true, CHGR_ROLLER, CHANNEL_ROL_CONTROL_CONTROL); addChannel(thing, add, true, CHGR_ROLLER, CHANNEL_ROL_CONTROL_STATE); @@ -474,6 +481,9 @@ public static Map createRollerChannels(Thing thing, final Shell addChannel(thing, add, roller.currentPos != null, CHGR_ROLLER, CHANNEL_ROL_CONTROL_FAV); } } + + addAddonChannels(thing, profile, 0, add); + return add; } From 850e03efa02189568aa3df83f87d6402dfadfda2 Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Fri, 24 May 2024 20:37:21 +0200 Subject: [PATCH 4/4] fixes ##16750, #16724 Signed-off-by: Markus Michels --- .../shelly/internal/api2/Shelly2ApiRpc.java | 4 +- .../internal/handler/ShellyComponents.java | 53 ++++++++++--------- 2 files changed, 31 insertions(+), 26 deletions(-) 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 1c3a3c47e2188..ce629307be284 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 @@ -15,7 +15,7 @@ import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*; import static org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.*; import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*; -import static org.openhab.binding.shelly.internal.discovery.ShellyThingCreator.THING_TYPE_SHELLYPRO2_RELAY_STR; +import static org.openhab.binding.shelly.internal.discovery.ShellyThingCreator.*; import static org.openhab.binding.shelly.internal.util.ShellyUtils.*; import java.io.BufferedReader; @@ -259,6 +259,8 @@ public ShellyDeviceProfile getDeviceProfile(String thingType, @Nullable ShellySe // Mini PM has 1 meter, but no relay if (thingType.equals(THING_TYPE_SHELLYPRO2_RELAY_STR)) { profile.numMeters = 0; + } else if (thingType.equals(THING_TYPE_SHELLYPRO3EM_STR)) { + profile.numMeters = 3; } else if (dc.pm10 != null) { profile.numMeters = 1; } else if (dc.em0 != null) { 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 1d5a0cc133234..95f00e6539701 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 @@ -123,31 +123,6 @@ public static boolean updateRelay(ShellyBaseHandler thingHandler, ShellySettings getOpenClosed(getInteger(status.extSwitch.input0.input) == 1)); } } - if (status.extTemperature != null) { - // Shelly 1/1PM support up to 3 external sensors - // for whatever reason those are not represented as an array, but 3 elements - updated |= updateTempChannel(status.extTemperature.sensor1, thingHandler, CHANNEL_ESENSOR_TEMP1); - updated |= updateTempChannel(status.extTemperature.sensor2, thingHandler, CHANNEL_ESENSOR_TEMP2); - updated |= updateTempChannel(status.extTemperature.sensor3, thingHandler, CHANNEL_ESENSOR_TEMP3); - updated |= updateTempChannel(status.extTemperature.sensor4, thingHandler, CHANNEL_ESENSOR_TEMP4); - updated |= updateTempChannel(status.extTemperature.sensor5, thingHandler, CHANNEL_ESENSOR_TEMP5); - } - if ((status.extHumidity != null) && (status.extHumidity.sensor1 != null)) { - updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_HUMIDITY, - toQuantityType(getDouble(status.extHumidity.sensor1.hum), DIGITS_PERCENT, Units.PERCENT)); - } - if ((status.extVoltage != null) && (status.extVoltage.sensor1 != null)) { - updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_VOLTAGE, - toQuantityType(getDouble(status.extVoltage.sensor1.voltage), 4, Units.VOLT)); - } - if ((status.extDigitalInput != null) && (status.extDigitalInput.sensor1 != null)) { - updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_DIGITALINPUT, - getOnOff(status.extDigitalInput.sensor1.state)); - } - if ((status.extAnalogInput != null) && (status.extAnalogInput.sensor1 != null)) { - updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_ANALOGINPUT, toQuantityType( - getDouble(status.extAnalogInput.sensor1.percent), DIGITS_PERCENT, Units.PERCENT)); - } // Update Auto-ON/OFF timer updated |= thingHandler.updateChannel(groupName, CHANNEL_TIMER_AUTOON, @@ -556,6 +531,34 @@ public static boolean updateSensors(ShellyThingInterface thingHandler, ShellySet thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_LAST_UPDATE, getTimestamp()); } } + + // Update Add-On channeƶs + if (status.extTemperature != null) { + // Shelly 1/1PM support up to 3 external sensors + // for whatever reason those are not represented as an array, but 3 elements + updated |= updateTempChannel(status.extTemperature.sensor1, thingHandler, CHANNEL_ESENSOR_TEMP1); + updated |= updateTempChannel(status.extTemperature.sensor2, thingHandler, CHANNEL_ESENSOR_TEMP2); + updated |= updateTempChannel(status.extTemperature.sensor3, thingHandler, CHANNEL_ESENSOR_TEMP3); + updated |= updateTempChannel(status.extTemperature.sensor4, thingHandler, CHANNEL_ESENSOR_TEMP4); + updated |= updateTempChannel(status.extTemperature.sensor5, thingHandler, CHANNEL_ESENSOR_TEMP5); + } + if ((status.extHumidity != null) && (status.extHumidity.sensor1 != null)) { + updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_HUMIDITY, + toQuantityType(getDouble(status.extHumidity.sensor1.hum), DIGITS_PERCENT, Units.PERCENT)); + } + if ((status.extVoltage != null) && (status.extVoltage.sensor1 != null)) { + updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_VOLTAGE, + toQuantityType(getDouble(status.extVoltage.sensor1.voltage), 4, Units.VOLT)); + } + if ((status.extDigitalInput != null) && (status.extDigitalInput.sensor1 != null)) { + updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_DIGITALINPUT, + getOnOff(status.extDigitalInput.sensor1.state)); + } + if ((status.extAnalogInput != null) && (status.extAnalogInput.sensor1 != null)) { + updated |= thingHandler.updateChannel(CHANNEL_GROUP_SENSOR, CHANNEL_ESENSOR_ANALOGINPUT, + toQuantityType(getDouble(status.extAnalogInput.sensor1.percent), DIGITS_PERCENT, Units.PERCENT)); + } + return updated; }