mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Add Shelly totalWorkTime as Lamp life (Shelly Air) (#43112)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
d7e5d1bfaf
commit
cdc53329d0
@ -19,3 +19,6 @@ SLEEP_PERIOD_MULTIPLIER = 1.2
|
|||||||
|
|
||||||
# Multiplier used to calculate the "update_interval" for non-sleeping devices.
|
# Multiplier used to calculate the "update_interval" for non-sleeping devices.
|
||||||
UPDATE_PERIOD_MULTIPLIER = 2.2
|
UPDATE_PERIOD_MULTIPLIER = 2.2
|
||||||
|
|
||||||
|
# Shelly Air - Maximum work hours before lamp replacement
|
||||||
|
SHAIR_MAX_WORK_HOURS = 9000
|
||||||
|
@ -119,6 +119,7 @@ class BlockAttributeDescription:
|
|||||||
|
|
||||||
name: str
|
name: str
|
||||||
# Callable = lambda attr_info: unit
|
# Callable = lambda attr_info: unit
|
||||||
|
icon: Optional[str] = None
|
||||||
unit: Union[None, str, Callable[[dict], str]] = None
|
unit: Union[None, str, Callable[[dict], str]] = None
|
||||||
value: Callable[[Any], Any] = lambda val: val
|
value: Callable[[Any], Any] = lambda val: val
|
||||||
device_class: Optional[str] = None
|
device_class: Optional[str] = None
|
||||||
@ -254,6 +255,11 @@ class ShellyBlockAttributeEntity(ShellyBlockEntity, entity.Entity):
|
|||||||
"""Device class of sensor."""
|
"""Device class of sensor."""
|
||||||
return self.description.device_class
|
return self.description.device_class
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Icon of sensor."""
|
||||||
|
return self.description.icon
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Available."""
|
"""Available."""
|
||||||
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||||||
VOLT,
|
VOLT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .const import SHAIR_MAX_WORK_HOURS
|
||||||
from .entity import (
|
from .entity import (
|
||||||
BlockAttributeDescription,
|
BlockAttributeDescription,
|
||||||
RestAttributeDescription,
|
RestAttributeDescription,
|
||||||
@ -144,6 +145,15 @@ SENSORS = {
|
|||||||
device_class=sensor.DEVICE_CLASS_ILLUMINANCE,
|
device_class=sensor.DEVICE_CLASS_ILLUMINANCE,
|
||||||
),
|
),
|
||||||
("sensor", "tilt"): BlockAttributeDescription(name="tilt", unit=DEGREE),
|
("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 = {
|
REST_SENSORS = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user