diff --git a/homeassistant/components/shelly/const.py b/homeassistant/components/shelly/const.py index d058a8c4588..36ab095f616 100644 --- a/homeassistant/components/shelly/const.py +++ b/homeassistant/components/shelly/const.py @@ -19,3 +19,6 @@ SLEEP_PERIOD_MULTIPLIER = 1.2 # Multiplier used to calculate the "update_interval" for non-sleeping devices. UPDATE_PERIOD_MULTIPLIER = 2.2 + +# Shelly Air - Maximum work hours before lamp replacement +SHAIR_MAX_WORK_HOURS = 9000 diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index 75070403c2c..d8d4725624d 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -119,6 +119,7 @@ class BlockAttributeDescription: name: str # Callable = lambda attr_info: unit + icon: Optional[str] = None unit: Union[None, str, Callable[[dict], str]] = None value: Callable[[Any], Any] = lambda val: val device_class: Optional[str] = None @@ -254,6 +255,11 @@ class ShellyBlockAttributeEntity(ShellyBlockEntity, entity.Entity): """Device class of sensor.""" return self.description.device_class + @property + def icon(self): + """Icon of sensor.""" + return self.description.icon + @property def available(self): """Available.""" diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index a9a2e8d8d6b..d73d7b5c2d4 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -12,6 +12,7 @@ from homeassistant.const import ( VOLT, ) +from .const import SHAIR_MAX_WORK_HOURS from .entity import ( BlockAttributeDescription, RestAttributeDescription, @@ -144,6 +145,15 @@ SENSORS = { device_class=sensor.DEVICE_CLASS_ILLUMINANCE, ), ("sensor", "tilt"): BlockAttributeDescription(name="tilt", unit=DEGREE), + ("relay", "totalWorkTime"): BlockAttributeDescription( + name="Lamp life", + unit=PERCENTAGE, + icon="mdi:progress-wrench", + value=lambda value: round(100 - (value / 3600 / SHAIR_MAX_WORK_HOURS), 1), + device_state_attributes=lambda block: { + "Operational hours": round(block.totalWorkTime / 3600, 1) + }, + ), } REST_SENSORS = {