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",
|
icon="mdi:update",
|
||||||
default_enabled=False,
|
default_enabled=False,
|
||||||
path="update/has_update",
|
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}"
|
return f"{self.wrapper.mac}-{self.description.path}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self) -> dict:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|
||||||
if self._attributes is None:
|
if self._attributes is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_description = self._attributes.get("description")
|
attributes = dict()
|
||||||
_attribute_value = get_rest_value_from_path(
|
for attrib in self._attributes:
|
||||||
self.wrapper.device.status,
|
description = attrib.get("description")
|
||||||
self.description.device_class,
|
attribute_value = get_rest_value_from_path(
|
||||||
self._attributes.get("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."""
|
"""Parser for REST path from device status."""
|
||||||
|
|
||||||
if "/" not in path:
|
if "/" not in path:
|
||||||
_attribute_value = status[path]
|
attribute_value = status[path]
|
||||||
else:
|
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:
|
if device_class == DEVICE_CLASS_TIMESTAMP:
|
||||||
last_boot = datetime.utcnow() - timedelta(seconds=_attribute_value)
|
last_boot = datetime.utcnow() - timedelta(seconds=attribute_value)
|
||||||
_attribute_value = last_boot.replace(microsecond=0).isoformat()
|
attribute_value = last_boot.replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
if "new_version" in path:
|
return attribute_value
|
||||||
_attribute_value = _attribute_value.split("/")[1].split("@")[0]
|
|
||||||
|
|
||||||
return _attribute_value
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue