1 """Interface to the SmartTub API."""
4 from datetime
import timedelta
7 from aiohttp
import client_exceptions
8 from smarttub
import APIError, LoginFailed, SmartTub
9 from smarttub.api
import Account
28 from .helpers
import get_spa_name
30 _LOGGER = logging.getLogger(__name__)
34 """Interface between Home Assistant and the SmartTub API."""
37 """Initialize an interface to SmartTub."""
45 """Perform initial setup.
47 Authenticate, query static state, set up polling, and otherwise make
48 ready for normal operations .
53 entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD]
55 except LoginFailed
as ex:
57 raise ConfigEntryAuthFailed
from ex
60 client_exceptions.ClientOSError,
61 client_exceptions.ServerDisconnectedError,
62 client_exceptions.ContentTypeError,
64 raise ConfigEntryNotReady
from err
73 update_interval=
timedelta(seconds=SCAN_INTERVAL),
83 """Query the API and return the new state."""
87 async
with asyncio.timeout(POLLING_TIMEOUT):
88 for spa
in self.
spasspas:
90 except APIError
as err:
96 full_status, reminders, errors = await asyncio.gather(
97 spa.get_status_full(),
102 ATTR_STATUS: full_status,
103 ATTR_PUMPS: {pump.id: pump
for pump
in full_status.pumps},
104 ATTR_LIGHTS: {light.zone: light
for light
in full_status.lights},
105 ATTR_REMINDERS: {reminder.id: reminder
for reminder
in reminders},
111 """Register devices with the device registry for all spas."""
112 device_registry = dr.async_get(self.
_hass_hass)
113 for spa
in self.
spasspas:
114 device_registry.async_get_or_create(
115 config_entry_id=entry.entry_id,
116 identifiers={(DOMAIN, spa.id)},
117 manufacturer=spa.brand,
122 async
def login(self, email, password) -> Account:
123 """Retrieve the account corresponding to the specified email and password.
125 Returns None if the credentials are invalid.
130 await api.login(email, password)
131 return await api.get_account()
def _get_spa_data(self, spa)
def async_register_devices(self, entry)
Account login(self, email, password)
def async_setup_entry(self, entry)
def async_update_data(self)
str get_spa_name(smarttub.Spa spa)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)