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 d2f3086ec8f..c96d3842ffb 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 @@ -148,8 +148,11 @@ public class Shelly2ApiClient extends ShellyHttpClient { SHELLY2_RSTATE_CALIB, SHELLY2_RSTATE_CALIB); // Gen2-only protected static final Map MAP_PROFILE = Map.of(// - SHELLY_CLASS_RELAY, SHELLY2_PROFILE_RELAY, // - SHELLY_CLASS_ROLLER, SHELLY2_PROFILE_COVER); + SHELLY2_PROFILE_RELAY, SHELLY_CLASS_RELAY, // + SHELLY2_PROFILE_COVER, SHELLY_CLASS_ROLLER, // + SHELLY2_PROFILE_LIGHT, SHELLY_MODE_WHITE, // + SHELLY2_PROFILE_RGB, SHELLY_MODE_COLOR, // + SHELLY2_PROFILE_RGBW, SHELLY_MODE_COLOR); protected @Nullable ArrayList<@Nullable ShellySettingsRelay> fillRelaySettings(ShellyDeviceProfile profile, Shelly2GetConfigResult dc) { @@ -627,7 +630,7 @@ public class Shelly2ApiClient extends ShellyHttpClient { if (cs.moveStartedAt != null) { rs.duration = (int) (now() - cs.moveStartedAt.longValue()); } - if (cs.temperature != null && cs.temperature.tC > getDouble(status.temperature)) { + if (cs.temperature != null && getDouble(cs.temperature.tC) > getDouble(status.temperature)) { if (status.tmp == null) { status.tmp = new ShellySensorTmp(); } @@ -936,10 +939,14 @@ public class Shelly2ApiClient extends ShellyHttpClient { } protected String mapValue(Map map, @Nullable String key) { - String value; - boolean known = key != null && !key.isEmpty() && map.containsKey(key); - value = known ? getString(map.get(key)) : ""; - logger.trace("{}: API value {} was mapped to {}", thingName, key, known ? value : "UNKNOWN"); + String safeKey = getString(key); + if (safeKey.isEmpty() || !map.containsKey(safeKey)) { + logger.warn("{}: Unknown API value '{}' (map data={}), please create an issue on GitHub", thingName, + safeKey, map); + return ""; + } + String value = getString(map.get(safeKey)); + logger.trace("{}: API value '{}' was mapped to '{}'", thingName, safeKey, value); return value; } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java index 96abddf49a6..2eccae963ca 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java @@ -89,6 +89,9 @@ public class Shelly2ApiJsonDTO { // Component types public static final String SHELLY2_PROFILE_RELAY = "switch"; public static final String SHELLY2_PROFILE_COVER = "cover"; + public static final String SHELLY2_PROFILE_LIGHT = "light"; + public static final String SHELLY2_PROFILE_RGB = "rgb"; + public static final String SHELLY2_PROFILE_RGBW = "rgbw"; // Button types/modes public static final String SHELLY2_BTNT_MOMENTARY = "momentary"; 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 6069e6daec4..7ecdb8f45f7 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 @@ -211,19 +211,17 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac List rollers = profile.settings.rollers; profile.numRollers = rollers != null ? rollers.size() : 0; - profile.hasRelays = profile.numRelays > 0 || profile.numRollers > 0; - if (getString(profile.device.mode).isEmpty() && profile.hasRelays) { - profile.device.mode = profile.isRoller ? SHELLY_CLASS_ROLLER : SHELLY_CLASS_RELAY; - } ShellySettingsDevice device = profile.device; - if (config.serviceName.isEmpty()) { + if (config.serviceName.isBlank()) { config.serviceName = getString(profile.device.hostname); + logger.debug("{}: {} is used as serviceName", thingName, config.serviceName); } - profile.settings.fw = device.fw; + profile.settings.fw = getString(device.fw); profile.fwDate = substringBefore(substringBefore(device.fw, "/"), "-"); - profile.fwVersion = profile.status.update.oldVersion = ShellyDeviceProfile.extractFwVersion(device.fw); + profile.fwVersion = profile.status.update.oldVersion = ShellyDeviceProfile + .extractFwVersion(profile.settings.fw); profile.status.hasUpdate = profile.status.update.hasUpdate = false; if (dc.eth != null) { @@ -798,7 +796,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac info.mac = getString(device.mac); info.auth = getBool(device.auth); info.gen = getInteger(device.gen); - info.mode = mapValue(MAP_PROFILE, device.profile); + info.mode = mapValue(MAP_PROFILE, getString(device.profile)); return info; } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java index 783a12868c8..de5526d44ab 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/discovery/ShellyBasicDiscoveryService.java @@ -137,7 +137,7 @@ public class ShellyBasicDiscoveryService extends AbstractDiscoveryService { name = devInfo.hostname; } if (devInfo.name != null) { - deviceName = devInfo.name; + deviceName = getString(devInfo.name); } thingType = substringBeforeLast(name, "-"); @@ -176,6 +176,7 @@ public class ShellyBasicDiscoveryService extends AbstractDiscoveryService { String thingLabel = deviceName.isEmpty() ? name + " - " + ipAddress : deviceName + " (" + name + "@" + ipAddress + ")"; + logger.debug("{}: Adding Thing to Inbox (type {}, model {}, mode={})", name, thingType, model, mode); return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(thingLabel) .withRepresentationProperty(PROPERTY_SERVICE_NAME).build(); } 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 0a868d54cb1..0865b6669c5 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 @@ -92,7 +92,7 @@ thing-type.shelly.shellyplusrgbw.description = Shelly Plus RGBW PM - LED Control # Plus Devices thing-type.shelly.shellyplus1.description = Shelly Plus 1 (Single Relay Switch) thing-type.shelly.shellyplus1pm.description = Shelly Plus 1PM - Single Relay Switch with Power Meter -thing-type.shelly.shellyplus2-relay.description = Shelly Plus 2PM - Dual Relay Switch with Power Meter +thing-type.shelly.shellyplus2pm-relay.description = Shelly Plus 2PM - Dual Relay Switch with Power Meter thing-type.shelly.shellyplus2pm-roller.description = Shelly Plus 2PM - Roller Control with Power Meter thing-type.shelly.shellyplusplug.description = Shelly Plus Plug S/IT/UK/US . Outlet with Power Meter thing-type.shelly.shellyplusi4.description = Shelly Plus i4 - 4xInput Device diff --git a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_relay.xml b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_relay.xml index 88a65c41e5e..7c53c486504 100644 --- a/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_relay.xml +++ b/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_relay.xml @@ -34,8 +34,8 @@ - - @text/thing-type.shelly.shellyplus2-relay.description + + @text/thing-type.shelly.shellyplus2pm-relay.description ControlDevice