async def async_step_user(self, user_input=None): """Handle the initial step.""" self._errors = {} if user_input is not None: await self.async_set_unique_id(user_input[CONF_EMAIL]) self._abort_if_unique_id_configured() self._email = user_input[CONF_EMAIL] self._password = user_input[CONF_PASSWORD] _LOGGER.debug("Configuring user: %s - Password hidden.", self._email) poolsense = PoolSense() api_key_valid = await poolsense.test_poolsense_credentials( aiohttp_client.async_get_clientsession(self.hass), self._email, self._password, ) if not api_key_valid: self._errors["base"] = "invalid_auth" if not self._errors: return self.async_create_entry( title=self._email, data={ CONF_EMAIL: self._email, CONF_PASSWORD: self._password }, ) return await self._show_setup_form(user_input, self._errors)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up PoolSense from a config entry.""" poolsense = PoolSense( aiohttp_client.async_get_clientsession(hass), entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD], ) auth_valid = await poolsense.test_poolsense_credentials() if not auth_valid: _LOGGER.error("Invalid authentication") return False coordinator = PoolSenseDataUpdateCoordinator(hass, entry) await coordinator.async_refresh() if not coordinator.last_update_success: raise ConfigEntryNotReady hass.data[DOMAIN][entry.entry_id] = coordinator for component in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component)) return True
def __init__(self, hass, entry): """Initialize.""" self.poolsense = PoolSense( aiohttp_client.async_get_clientsession(hass), entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD], ) self.hass = hass self.entry = entry super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(hours=1))
async def async_get_data(): _LOGGER.info("Run query to server") poolsense = PoolSense() return_data = {} with async_timeout.timeout(10): try: return_data = await poolsense.get_poolsense_data( aiohttp_client.async_get_clientsession(hass), entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD], ) except (PoolSenseError) as error: raise UpdateFailed(error) return return_data
async def async_step_user(self, user_input=None): """Handle the initial step.""" errors = {} if user_input is not None: await self.async_set_unique_id(user_input[CONF_EMAIL]) self._abort_if_unique_id_configured() _LOGGER.debug("Configuring user: %s - Password hidden", user_input[CONF_EMAIL]) poolsense = PoolSense( aiohttp_client.async_get_clientsession(self.hass), user_input[CONF_EMAIL], user_input[CONF_PASSWORD], ) api_key_valid = await poolsense.test_poolsense_credentials() if not api_key_valid: errors["base"] = "invalid_auth" if not errors: return self.async_create_entry( title=user_input[CONF_EMAIL], data={ CONF_EMAIL: user_input[CONF_EMAIL], CONF_PASSWORD: user_input[CONF_PASSWORD], }, ) return self.async_show_form( step_id="user", data_schema=vol.Schema({ vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str }), errors=errors, )
async def async_setup_entry(opp: OpenPeerPower, entry: ConfigEntry): """Set up PoolSense from a config entry.""" poolsense = PoolSense( aiohttp_client.async_get_clientsession(opp), entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD], ) auth_valid = await poolsense.test_poolsense_credentials() if not auth_valid: _LOGGER.error("Invalid authentication") return False coordinator = PoolSenseDataUpdateCoordinator(opp, entry) await coordinator.async_config_entry_first_refresh() opp.data.setdefault(DOMAIN, {}) opp.data[DOMAIN][entry.entry_id] = coordinator opp.config_entries.async_setup_platforms(entry, PLATFORMS) return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up PoolSense from a config entry.""" poolsense = PoolSense( aiohttp_client.async_get_clientsession(hass), entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD], ) auth_valid = await poolsense.test_poolsense_credentials() if not auth_valid: _LOGGER.error("Invalid authentication") return False coordinator = PoolSenseDataUpdateCoordinator(hass, entry) await coordinator.async_config_entry_first_refresh() hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True