[shelly] Fix Shelly Plus 2PM discovery in Roller/Cover mode (#18790)

Signed-off-by: Markus Michels <markus7017@gmail.com>
pull/18793/head
Markus Michels 2025-06-11 02:17:46 -04:00 committed by GitHub
parent 686f5e1001
commit fd1236081d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 19 deletions

View File

@ -148,8 +148,11 @@ public class Shelly2ApiClient extends ShellyHttpClient {
SHELLY2_RSTATE_CALIB, SHELLY2_RSTATE_CALIB); // Gen2-only
protected static final Map<String, String> 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<String, String> 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;
}

View File

@ -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";

View File

@ -211,19 +211,17 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
List<ShellySettingsRoller> 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;
}

View File

@ -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();
}

View File

@ -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

View File

@ -34,8 +34,8 @@
</thing-type>
<thing-type id="shellyplus2pm-relay">
<label>ShellyPlus 2 Relay</label>
<description>@text/thing-type.shelly.shellyplus2-relay.description</description>
<label>ShellyPlus 2PM Relay</label>
<description>@text/thing-type.shelly.shellyplus2pm-relay.description</description>
<semantic-equipment-tag>ControlDevice</semantic-equipment-tag>
<channel-groups>
<channel-group id="relay1" typeId="relayChannel">