From e232bdc0827c06ab03c61a4675c1ddcd6f02f9d5 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Fri, 15 Oct 2021 05:02:37 +0300 Subject: [PATCH] Add Shelly "installed version" extra state attribute to Gen2 firmware update sensor (#57722) --- homeassistant/components/shelly/binary_sensor.py | 3 ++- homeassistant/components/shelly/entity.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 6ebea1456a1..d7e4983df77 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -153,8 +153,9 @@ RPC_SENSORS: Final = { name="Firmware Update", device_class=DEVICE_CLASS_UPDATE, default_enabled=False, - extra_state_attributes=lambda status: { + extra_state_attributes=lambda status, shelly: { "latest_stable_version": status.get("stable", {"version": ""})["version"], + "installed_version": shelly["ver"], "beta_version": status.get("beta", {"version": ""})["version"], }, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index db00e68c976..0a610545180 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -255,7 +255,7 @@ class RpcAttributeDescription: default_enabled: bool = True available: Callable[[dict], bool] | None = None removal_condition: Callable[[dict, str], bool] | None = None - extra_state_attributes: Callable[[dict], dict | None] | None = None + extra_state_attributes: Callable[[dict, dict], dict | None] | None = None entity_category: str | None = None @@ -608,8 +608,11 @@ class ShellyRpcAttributeEntity(ShellyRpcEntity, entity.Entity): if self.description.extra_state_attributes is None: return None + assert self.wrapper.device.shelly + return self.description.extra_state_attributes( - self.wrapper.device.status[self.key][self.sub_key] + self.wrapper.device.status[self.key][self.sub_key], + self.wrapper.device.shelly, ) @property