1 """Integration with the Rachio Iro sprinkler system controller."""
6 from rachiopy
import Rachio
7 from requests.exceptions
import ConnectTimeout
15 from .const
import CONF_CLOUDHOOK_URL, CONF_MANUAL_RUN_MINS, DOMAIN
16 from .device
import RachioPerson
17 from .webhooks
import (
18 async_get_or_create_registered_webhook_id_and_url,
19 async_register_webhook,
20 async_unregister_webhook,
23 _LOGGER = logging.getLogger(__name__)
25 PLATFORMS = [Platform.BINARY_SENSOR, Platform.CALENDAR, Platform.SWITCH]
29 """Unload a config entry."""
30 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
32 hass.data[DOMAIN].pop(entry.entry_id)
37 """Remove a rachio config entry."""
38 if CONF_CLOUDHOOK_URL
in entry.data:
39 await cloud.async_delete_cloudhook(hass, entry.data[CONF_WEBHOOK_ID])
43 """Set up the Rachio config entry."""
46 options = entry.options
49 if not options.get(CONF_MANUAL_RUN_MINS)
and config.get(CONF_MANUAL_RUN_MINS):
50 options_copy = options.copy()
51 options_copy[CONF_MANUAL_RUN_MINS] = config[CONF_MANUAL_RUN_MINS]
52 hass.config_entries.async_update_entry(entry, options=options_copy)
55 api_key = config[CONF_API_KEY]
56 rachio = Rachio(api_key)
59 rachio.webhook_auth = secrets.token_hex()
66 raise ConfigEntryNotReady
from exc
67 rachio.webhook_url = webhook_url
73 await person.async_setup(hass)
74 except ConfigEntryAuthFailed
as error:
76 _LOGGER.error(
"Authentication failed: %s", error)
78 except ConnectTimeout
as error:
79 _LOGGER.error(
"Could not reach the Rachio API: %s", error)
80 raise ConfigEntryNotReady
from error
83 if not person.controllers
and not person.base_stations:
84 _LOGGER.error(
"No Rachio devices found in account %s", person.username)
88 "%d Rachio device(s) found; The url %s must be accessible from the internet"
89 " in order to receive updates"
91 len(person.controllers) + len(person.base_stations),
95 for base
in person.base_stations:
96 await base.status_coordinator.async_config_entry_first_refresh()
97 await base.schedule_coordinator.async_config_entry_first_refresh()
100 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = person
103 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
None async_register_webhook(HomeAssistant hass, ConfigEntry entry)
None async_unregister_webhook(HomeAssistant hass, ConfigEntry entry)
str async_get_or_create_registered_webhook_id_and_url(HomeAssistant hass, ConfigEntry entry)
None async_remove_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)