1 """The Balboa Spa Client integration."""
3 from __future__
import annotations
5 from datetime
import datetime, timedelta
8 from pybalboa
import SpaClient
17 from .const
import CONF_SYNC_TIME, DEFAULT_SYNC_TIME
19 _LOGGER = logging.getLogger(__name__)
22 Platform.BINARY_SENSOR,
33 type BalboaConfigEntry = ConfigEntry[SpaClient]
37 """Set up Balboa Spa from a config entry."""
38 host = entry.data[CONF_HOST]
40 _LOGGER.debug(
"Attempting to connect to %s", host)
42 if not await spa.connect():
43 _LOGGER.error(
"Failed to connect to spa at %s", host)
45 if not await spa.async_configuration_loaded():
46 _LOGGER.error(
"Failed to get spa info at %s", host)
49 entry.runtime_data = spa
51 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
54 entry.async_on_unload(entry.add_update_listener(update_listener))
55 entry.async_on_unload(spa.disconnect)
61 """Unload a config entry."""
62 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
66 """Handle options update."""
67 await hass.config_entries.async_reload(entry.entry_id)
71 """Set up the time sync."""
72 if not entry.options.get(CONF_SYNC_TIME, DEFAULT_SYNC_TIME):
75 _LOGGER.debug(
"Setting up daily time sync")
76 spa = entry.runtime_data
78 async
def sync_time(now: datetime) ->
None:
79 now = dt_util.as_local(now)
80 if (now.hour, now.minute) != (spa.time_hour, spa.time_minute):
81 _LOGGER.debug(
"Syncing time with Home Assistant")
82 await spa.set_time(now.hour, now.minute)
84 await sync_time(dt_util.utcnow())
85 entry.async_on_unload(
None async_setup_time_sync(HomeAssistant hass, BalboaConfigEntry entry)
None update_listener(HomeAssistant hass, BalboaConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, BalboaConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, BalboaConfigEntry entry)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)