1 """Support for Streamlabs Water Monitor Usage."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
11 SensorEntityDescription,
19 from .
import StreamlabsCoordinator
20 from .const
import DOMAIN
21 from .coordinator
import StreamlabsData
22 from .entity
import StreamlabsWaterEntity
25 @dataclass(frozen=True, kw_only=True)
27 """Streamlabs sensor entity description."""
29 value_fn: Callable[[StreamlabsData], StateType]
32 SENSORS: tuple[StreamlabsWaterSensorEntityDescription, ...] = (
35 translation_key=
"daily_usage",
36 native_unit_of_measurement=UnitOfVolume.GALLONS,
37 device_class=SensorDeviceClass.WATER,
38 suggested_display_precision=1,
39 value_fn=
lambda data: data.daily_usage,
43 translation_key=
"monthly_usage",
44 native_unit_of_measurement=UnitOfVolume.GALLONS,
45 device_class=SensorDeviceClass.WATER,
46 suggested_display_precision=1,
47 value_fn=
lambda data: data.monthly_usage,
51 translation_key=
"yearly_usage",
52 native_unit_of_measurement=UnitOfVolume.GALLONS,
53 device_class=SensorDeviceClass.WATER,
54 suggested_display_precision=1,
55 value_fn=
lambda data: data.yearly_usage,
63 async_add_entities: AddEntitiesCallback,
65 """Set up Streamlabs water sensor from a config entry."""
66 coordinator = hass.data[DOMAIN][entry.entry_id]
70 for location_id
in coordinator.data
71 for entity_description
in SENSORS
76 """Monitors the daily water usage."""
78 entity_description: StreamlabsWaterSensorEntityDescription
82 coordinator: StreamlabsCoordinator,
84 entity_description: StreamlabsWaterSensorEntityDescription,
86 """Initialize the daily water usage device."""
87 super().
__init__(coordinator, location_id, entity_description.key)
92 """Return the current daily usage."""
StreamlabsData location_data(self)
None __init__(self, StreamlabsCoordinator coordinator, str location_id, StreamlabsWaterSensorEntityDescription entity_description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)