From 625088b61a8837f4d2a9bf0678ab9248f2f6f606 Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Sun, 12 May 2024 00:43:36 +0200 Subject: [PATCH] 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; }