2019-04-03 15:40:03 +00:00
|
|
|
"""Support for Rain Bird Irrigation system LNK WiFi Module."""
|
2021-07-22 13:29:50 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
from pyrainbird.async_client import AsyncRainbirdClient, AsyncRainbirdController
|
2023-07-09 23:49:44 +00:00
|
|
|
from pyrainbird.exceptions import RainbirdApiException
|
2023-05-05 14:53:40 +00:00
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, Platform
|
2023-05-05 14:22:07 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2023-07-09 23:49:44 +00:00
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
2022-12-22 21:00:17 +00:00
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
2019-09-26 09:24:03 +00:00
|
|
|
|
2023-09-26 00:27:38 +00:00
|
|
|
from .coordinator import RainbirdData
|
2019-09-26 09:24:03 +00:00
|
|
|
|
2023-09-26 00:27:38 +00:00
|
|
|
PLATFORMS = [
|
|
|
|
Platform.SWITCH,
|
|
|
|
Platform.SENSOR,
|
|
|
|
Platform.BINARY_SENSOR,
|
|
|
|
Platform.NUMBER,
|
|
|
|
Platform.CALENDAR,
|
|
|
|
]
|
2017-12-25 09:07:18 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN = "rainbird"
|
2017-12-25 09:07:18 +00:00
|
|
|
|
2022-12-22 21:00:17 +00:00
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up the config entry for Rain Bird."""
|
2022-12-22 21:00:17 +00:00
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
|
|
|
|
controller = AsyncRainbirdController(
|
|
|
|
AsyncRainbirdClient(
|
|
|
|
async_get_clientsession(hass),
|
|
|
|
entry.data[CONF_HOST],
|
|
|
|
entry.data[CONF_PASSWORD],
|
2019-09-26 09:24:03 +00:00
|
|
|
)
|
2023-01-07 17:34:01 +00:00
|
|
|
)
|
2023-07-09 23:49:44 +00:00
|
|
|
try:
|
|
|
|
model_info = await controller.get_model_and_version()
|
|
|
|
except RainbirdApiException as err:
|
|
|
|
raise ConfigEntryNotReady from err
|
2023-01-07 17:34:01 +00:00
|
|
|
|
2023-09-26 00:27:38 +00:00
|
|
|
data = RainbirdData(hass, entry, controller, model_info)
|
|
|
|
await data.coordinator.async_config_entry_first_refresh()
|
|
|
|
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = data
|
2023-01-07 17:34:01 +00:00
|
|
|
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
|
2017-12-25 09:07:18 +00:00
|
|
|
return True
|
2023-01-07 17:34:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload a config entry."""
|
|
|
|
|
|
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|