Add Shelly "installed version" extra state attribute to Gen2 firmware update sensor (#57722)

pull/57747/head
Shay Levy 2021-10-15 05:02:37 +03:00 committed by GitHub
parent eed9f67402
commit e232bdc082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

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

View File

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