Add shelly installed firmware info (#43221)
This commit is contained in:
parent
0bf9734af1
commit
3dbfd2cb70
3 changed files with 20 additions and 17 deletions
|
@ -64,7 +64,10 @@ REST_SENSORS = {
|
|||
icon="mdi:update",
|
||||
default_enabled=False,
|
||||
path="update/has_update",
|
||||
attributes={"description": "available version:", "path": "update/new_version"},
|
||||
attributes=[
|
||||
{"description": "latest_stable_version", "path": "update/new_version"},
|
||||
{"description": "installed_version", "path": "update/old_version"},
|
||||
],
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -297,17 +297,20 @@ class ShellyRestAttributeEntity(update_coordinator.CoordinatorEntity):
|
|||
return f"{self.wrapper.mac}-{self.description.path}"
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
def device_state_attributes(self) -> dict:
|
||||
"""Return the state attributes."""
|
||||
|
||||
if self._attributes is None:
|
||||
return None
|
||||
|
||||
_description = self._attributes.get("description")
|
||||
_attribute_value = get_rest_value_from_path(
|
||||
self.wrapper.device.status,
|
||||
self.description.device_class,
|
||||
self._attributes.get("path"),
|
||||
)
|
||||
attributes = dict()
|
||||
for attrib in self._attributes:
|
||||
description = attrib.get("description")
|
||||
attribute_value = get_rest_value_from_path(
|
||||
self.wrapper.device.status,
|
||||
self.description.device_class,
|
||||
attrib.get("path"),
|
||||
)
|
||||
attributes[description] = attribute_value
|
||||
|
||||
return {_description: _attribute_value}
|
||||
return attributes
|
||||
|
|
|
@ -85,14 +85,11 @@ def get_rest_value_from_path(status, device_class, path: str):
|
|||
"""Parser for REST path from device status."""
|
||||
|
||||
if "/" not in path:
|
||||
_attribute_value = status[path]
|
||||
attribute_value = status[path]
|
||||
else:
|
||||
_attribute_value = status[path.split("/")[0]][path.split("/")[1]]
|
||||
attribute_value = status[path.split("/")[0]][path.split("/")[1]]
|
||||
if device_class == DEVICE_CLASS_TIMESTAMP:
|
||||
last_boot = datetime.utcnow() - timedelta(seconds=_attribute_value)
|
||||
_attribute_value = last_boot.replace(microsecond=0).isoformat()
|
||||
last_boot = datetime.utcnow() - timedelta(seconds=attribute_value)
|
||||
attribute_value = last_boot.replace(microsecond=0).isoformat()
|
||||
|
||||
if "new_version" in path:
|
||||
_attribute_value = _attribute_value.split("/")[1].split("@")[0]
|
||||
|
||||
return _attribute_value
|
||||
return attribute_value
|
||||
|
|
Loading…
Add table
Reference in a new issue