diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 4f771a9cc46..00f63ea7411 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -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"}, + ], ), } diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index d0e51e8cc12..047c3d9d66a 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -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 diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 10eacff7068..c9ef3f55adb 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -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