1 """Integration with the Rachio Iro sprinkler system controller."""
3 from abc
import abstractmethod
8 BinarySensorDeviceClass,
18 DOMAIN
as DOMAIN_RACHIO,
22 KEY_RAIN_SENSOR_TRIPPED,
28 SIGNAL_RACHIO_CONTROLLER_UPDATE,
29 SIGNAL_RACHIO_RAIN_SENSOR_UPDATE,
32 from .coordinator
import RachioUpdateCoordinator
33 from .device
import RachioPerson
34 from .entity
import RachioDevice, RachioHoseTimerEntity
35 from .webhooks
import (
39 SUBTYPE_RAIN_SENSOR_DETECTION_OFF,
40 SUBTYPE_RAIN_SENSOR_DETECTION_ON,
43 _LOGGER = logging.getLogger(__name__)
48 config_entry: ConfigEntry,
49 async_add_entities: AddEntitiesCallback,
51 """Set up the Rachio binary sensors."""
52 entities = await hass.async_add_executor_job(_create_entities, hass, config_entry)
57 entities: list[Entity] = []
58 person: RachioPerson = hass.data[DOMAIN_RACHIO][config_entry.entry_id]
59 for controller
in person.controllers:
64 for base_station
in person.base_stations
65 for valve
in base_station.status_coordinator.data.values()
71 """Represent a binary sensor that reflects a Rachio state."""
73 _attr_has_entity_name =
True
77 """Determine whether an update event applies to this device."""
78 if args[0][KEY_DEVICE_ID] != self.
_controller_controller.controller_id:
87 """Handle an update to the state of this sensor."""
90 class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
91 """Represent a binary sensor that reflects if the controller is online."""
93 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
97 """Return a unique id for this entity."""
98 return f
"{self._controller.controller_id}-online"
102 """Handle an update to the state of this sensor."""
103 if args[0][0][KEY_SUBTYPE]
in (SUBTYPE_ONLINE, SUBTYPE_COLD_REBOOT):
105 elif args[0][0][KEY_SUBTYPE] == SUBTYPE_OFFLINE:
111 """Subscribe to updates."""
117 SIGNAL_RACHIO_CONTROLLER_UPDATE,
124 """Represent a binary sensor that reflects the status of the rain sensor."""
126 _attr_device_class = BinarySensorDeviceClass.MOISTURE
127 _attr_translation_key =
"rain"
131 """Return a unique id for this entity."""
132 return f
"{self._controller.controller_id}-rain_sensor"
136 """Handle an update to the state of this sensor."""
137 if args[0][0][KEY_SUBTYPE] == SUBTYPE_RAIN_SENSOR_DETECTION_ON:
139 elif args[0][0][KEY_SUBTYPE] == SUBTYPE_RAIN_SENSOR_DETECTION_OFF:
145 """Subscribe to updates."""
151 SIGNAL_RACHIO_RAIN_SENSOR_UPDATE,
158 """Represents a battery sensor for a smart hose timer."""
160 _attr_device_class = BinarySensorDeviceClass.BATTERY
163 self, data: dict[str, Any], coordinator: RachioUpdateCoordinator
165 """Initialize a smart hose timer battery sensor."""
171 """Handle updated coordinator data."""
172 data = self.coordinator.data[self.
idid]
None _async_handle_any_update(self, *args, **kwargs)
None _async_handle_update(self, *args, **kwargs)
None _async_handle_update(self, *args, **kwargs)
None async_added_to_hass(self)
None __init__(self, dict[str, Any] data, RachioUpdateCoordinator coordinator)
None _async_handle_update(self, *args, **kwargs)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[Entity] _create_entities(HomeAssistant hass, ConfigEntry config_entry)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)