1 """Support for Rain Bird Irrigation system LNK Wi-Fi Module."""
3 from __future__
import annotations
7 from pyrainbird.exceptions
import RainbirdApiException, RainbirdDeviceBusyException
8 import voluptuous
as vol
19 from .const
import ATTR_DURATION, CONF_IMPORTED_NAMES, DOMAIN, MANUFACTURER
20 from .coordinator
import RainbirdUpdateCoordinator
21 from .types
import RainbirdConfigEntry
23 _LOGGER = logging.getLogger(__name__)
25 SERVICE_START_IRRIGATION =
"start_irrigation"
27 SERVICE_SCHEMA_IRRIGATION: VolDictType = {
28 vol.Required(ATTR_DURATION): cv.positive_float,
34 config_entry: RainbirdConfigEntry,
35 async_add_entities: AddEntitiesCallback,
37 """Set up entry for a Rain Bird irrigation switches."""
38 coordinator = config_entry.runtime_data.coordinator
43 config_entry.options[ATTR_DURATION],
44 config_entry.data.get(CONF_IMPORTED_NAMES, {}).
get(
str(zone)),
46 for zone
in coordinator.data.zones
49 platform = entity_platform.async_get_current_platform()
50 platform.async_register_entity_service(
51 SERVICE_START_IRRIGATION,
52 SERVICE_SCHEMA_IRRIGATION,
58 """Representation of a Rain Bird switch."""
62 coordinator: RainbirdUpdateCoordinator,
64 duration_minutes: int,
65 imported_name: str |
None,
67 """Initialize a Rain Bird Switch Device."""
70 _LOGGER.debug(
"coordinator.unique_id=%s", coordinator.unique_id)
71 if coordinator.unique_id
is not None:
73 device_name = f
"{MANUFACTURER} Sprinkler {zone}"
78 self.
_attr_name_attr_name =
None if coordinator.unique_id
is not None else device_name
81 if coordinator.unique_id
is not None and self.
_attr_unique_id_attr_unique_id
is not None:
85 manufacturer=MANUFACTURER,
86 via_device=(DOMAIN, coordinator.unique_id),
91 """Return state attributes."""
92 return {
"zone": self.
_zone_zone}
95 """Turn the switch on."""
97 await self.coordinator.controller.irrigate_zone(
101 except RainbirdDeviceBusyException
as err:
103 "Rain Bird device is busy; Wait and try again"
105 except RainbirdApiException
as err:
110 self.coordinator.data.active_zones.add(self.
_zone_zone)
115 """Turn the switch off."""
117 await self.coordinator.controller.stop_irrigation()
118 except RainbirdDeviceBusyException
as err:
120 "Rain Bird device is busy; Wait and try again"
122 except RainbirdApiException
as err:
128 self.coordinator.data.active_zones.remove(self.
_zone_zone)
134 """Return true if switch is on."""
135 return self.
_zone_zone
in self.coordinator.data.active_zones
def async_turn_off(self, **kwargs)
def extra_state_attributes(self)
def async_turn_on(self, **kwargs)
None __init__(self, RainbirdUpdateCoordinator coordinator, int zone, int duration_minutes, str|None imported_name)
None async_write_ha_state(self)
None async_request_refresh(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, RainbirdConfigEntry config_entry, AddEntitiesCallback async_add_entities)