Add Shelly totalWorkTime as Lamp life (Shelly Air) (#43112)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Simone Chemelli 2020-11-12 10:38:53 +01:00 committed by GitHub
parent d7e5d1bfaf
commit cdc53329d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View file

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

View file

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

View file

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