1 """Base classes for Hydrawise entities."""
3 from __future__
import annotations
5 from pydrawise.schema
import Controller, Sensor, Zone
12 from .const
import DOMAIN, MANUFACTURER
13 from .coordinator
import HydrawiseDataUpdateCoordinator
17 """Entity class for Hydrawise devices."""
19 _attr_attribution =
"Data provided by hydrawise.com"
20 _attr_has_entity_name =
True
24 coordinator: HydrawiseDataUpdateCoordinator,
25 description: EntityDescription,
26 controller: Controller,
28 zone_id: int |
None =
None,
29 sensor_id: int |
None =
None,
31 """Initialize the Hydrawise entity."""
32 super().
__init__(coordinator=coordinator)
37 self.
_device_id_device_id =
str(zone_id)
if zone_id
is not None else str(controller.id)
40 identifiers={(DOMAIN, self.
_device_id_device_id)},
41 name=self.
zonezone.name
if zone_id
is not None else controller.name,
43 "Zone" if zone_id
is not None else controller.hardware.model.description
45 manufacturer=MANUFACTURER,
47 if zone_id
is not None or sensor_id
is not None:
53 """Return the entity zone."""
54 assert self.
zone_idzone_id
is not None
55 return self.coordinator.data.zones[self.
zone_idzone_id]
59 """Return the entity sensor."""
60 assert self.
sensor_idsensor_id
is not None
61 return self.coordinator.data.sensors[self.
sensor_idsensor_id]
64 """Update state attributes."""
69 """Get the latest data and updates the state."""
76 """Set the entity availability."""
77 return super().available
and self.
controllercontroller.online
None _handle_coordinator_update(self)
None __init__(self, HydrawiseDataUpdateCoordinator coordinator, EntityDescription description, Controller controller, *int|None zone_id=None, int|None sensor_id=None)