async def validate_input(opp: core.OpenPeerPower, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ state_file = opp.config.path(f"nexia_config_{data[CONF_USERNAME]}.conf") try: nexia_home = NexiaHome( username=data[CONF_USERNAME], password=data[CONF_PASSWORD], brand=data[CONF_BRAND], auto_login=False, auto_update=False, device_name=opp.config.location_name, state_file=state_file, ) await opp.async_add_executor_job(nexia_home.login) except ConnectTimeout as ex: _LOGGER.error("Unable to connect to Nexia service: %s", ex) raise CannotConnect from ex except HTTPError as http_ex: _LOGGER.error("HTTP error from Nexia service: %s", http_ex) if is_invalid_auth_code(http_ex.response.status_code): raise InvalidAuth from http_ex raise CannotConnect from http_ex if not nexia_home.get_name(): raise InvalidAuth info = {"title": nexia_home.get_name(), "house_id": nexia_home.house_id} _LOGGER.debug("Setup ok with info: %s", info) return info
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ try: nexia_home = NexiaHome( username=data[CONF_USERNAME], password=data[CONF_PASSWORD], auto_login=False, auto_update=False, device_name=hass.config.location_name, ) await hass.async_add_executor_job(nexia_home.login) except ConnectTimeout as ex: _LOGGER.error("Unable to connect to Nexia service: %s", ex) raise CannotConnect except HTTPError as http_ex: _LOGGER.error("HTTP error from Nexia service: %s", http_ex) if (http_ex.response.status_code >= HTTP_BAD_REQUEST and http_ex.response.status_code < HTTP_INTERNAL_SERVER_ERROR): raise InvalidAuth raise CannotConnect if not nexia_home.get_name(): raise InvalidAuth info = {"title": nexia_home.get_name(), "house_id": nexia_home.house_id} _LOGGER.debug("Setup ok with info: %s", info) return info
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ state_file = hass.config.path( f"{data[CONF_BRAND]}_config_{data[CONF_USERNAME]}.conf") session = async_get_clientsession(hass) nexia_home = NexiaHome( session, username=data[CONF_USERNAME], password=data[CONF_PASSWORD], brand=data[CONF_BRAND], device_name=hass.config.location_name, state_file=state_file, ) try: await nexia_home.login() except asyncio.TimeoutError as ex: _LOGGER.error("Unable to connect to Nexia service: %s", ex) raise CannotConnect from ex except aiohttp.ClientResponseError as http_ex: _LOGGER.error("HTTP error from Nexia service: %s", http_ex) if is_invalid_auth_code(http_ex.status): raise InvalidAuth from http_ex raise CannotConnect from http_ex if not nexia_home.get_name(): raise InvalidAuth info = {"title": nexia_home.get_name(), "house_id": nexia_home.house_id} _LOGGER.debug("Setup ok with info: %s", info) return info
def test_basic_issue_33758(self): """Basic tests for NexiaHome.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_issue_33758.json")) nexia.update_from_json(devices_json) self.assertEqual(nexia.get_name(), "Hidden") thermostat_ids = nexia.get_thermostat_ids() self.assertEqual(thermostat_ids, [12345678])
def test_basic(self): """Basic tests for NexiaHome.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) self.assertEqual(nexia.get_name(), "Hidden") thermostat_ids = nexia.get_thermostat_ids() self.assertEqual(thermostat_ids, [2059661, 2059676, 2293892, 2059652])