def test_zone_cooling_air(self): """Tests for nexia thermostat zone cooling.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(2293892) zone = thermostat.get_zone_by_id(83394130) self.assertEqual(zone.get_name(), "Master") self.assertEqual(zone.get_cooling_setpoint(), 71) self.assertEqual(zone.get_heating_setpoint(), 63) self.assertEqual(zone.get_current_mode(), "AUTO") self.assertEqual( zone.get_requested_mode(), "AUTO", ) self.assertEqual( zone.get_presets(), ["None", "Home", "Away", "Sleep"], ) self.assertEqual( zone.get_preset(), "None", ) self.assertEqual( zone.get_status(), "Damper Open", ) self.assertEqual( zone.get_setpoint_status(), "Permanent Hold", ) self.assertEqual(zone.is_calling(), True) self.assertEqual(zone.is_in_permanent_hold(), True)
def test_zone_issue_33758(self): """Tests for nexia thermostat zone relieving air.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_issue_33758.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(12345678) zone = thermostat.get_zone_by_id(12345678) self.assertEqual(zone.thermostat, thermostat) self.assertEqual(zone.get_name(), "Thermostat NativeZone") self.assertEqual(zone.get_cooling_setpoint(), 73) self.assertEqual(zone.get_heating_setpoint(), 68) self.assertEqual(zone.get_current_mode(), "AUTO") self.assertEqual( zone.get_requested_mode(), "AUTO", ) self.assertEqual( zone.get_presets(), ["None", "Home", "Away", "Sleep"], ) self.assertEqual( zone.get_preset(), "None", ) self.assertEqual( zone.get_status(), "Idle", ) self.assertEqual( zone.get_setpoint_status(), "Run Schedule - None", ) self.assertEqual(zone.is_calling(), False) self.assertEqual(zone.is_in_permanent_hold(), False)
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
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
def test_zone_issue_33968_zone_83037343(self): """Tests for nexia thermostat zone that is cooling.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_issue_33968.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(1690380) zone = thermostat.get_zone_by_id(83037343) self.assertEqual(zone.thermostat, thermostat) self.assertEqual(zone.get_name(), "Master") self.assertEqual(zone.get_cooling_setpoint(), 77) self.assertEqual(zone.get_heating_setpoint(), 68) self.assertEqual(zone.get_current_mode(), "COOL") self.assertEqual( zone.get_requested_mode(), "COOL", ) self.assertEqual( zone.get_presets(), ["None", "Home", "Away", "Sleep"], ) self.assertEqual( zone.get_preset(), "None", ) self.assertEqual( zone.get_status(), "Damper Open", ) self.assertEqual( zone.get_setpoint_status(), "Permanent Hold", ) self.assertEqual(zone.is_calling(), True) self.assertEqual(zone.is_in_permanent_hold(), True)
def test_zone_idle(self): """Tests for nexia thermostat zone idle.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(2059661) zone = thermostat.get_zone_by_id(83261002) self.assertEqual(zone.get_name(), "Living East") self.assertEqual(zone.get_cooling_setpoint(), 79) self.assertEqual(zone.get_heating_setpoint(), 63) self.assertEqual(zone.get_current_mode(), "AUTO") self.assertEqual( zone.get_requested_mode(), "AUTO", ) self.assertEqual( zone.get_presets(), ["None", "Home", "Away", "Sleep"], ) self.assertEqual( zone.get_preset(), "None", ) self.assertEqual( zone.get_status(), "Idle", ) self.assertEqual( zone.get_setpoint_status(), "Permanent Hold", ) self.assertEqual(zone.is_calling(), False) self.assertEqual(zone.is_in_permanent_hold(), True)
def test_update(self): nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(2059661) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [83261002, 83261005, 83261008, 83261011]) nexia.update_from_json(devices_json) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [83261002, 83261005, 83261008, 83261011]) nexia.update_from_json(devices_json)
async def async_init_integration( hass: HomeAssistant, skip_setup: bool = False, ) -> MockConfigEntry: """Set up the nexia integration in Safegate Pro.""" house_fixture = "nexia/mobile_houses_123456.json" session_fixture = "nexia/session_123456.json" sign_in_fixture = "nexia/sign_in.json" nexia = NexiaHome(auto_login=False) with requests_mock.mock() as m, patch("nexia.home.load_or_create_uuid", return_value=uuid.uuid4()): m.post(nexia.API_MOBILE_SESSION_URL, text=load_fixture(session_fixture)) m.get( nexia.API_MOBILE_HOUSES_URL.format(house_id=123456), text=load_fixture(house_fixture), ) m.post( nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL, text=load_fixture(sign_in_fixture), ) entry = MockConfigEntry(domain=DOMAIN, data={ CONF_USERNAME: "******", CONF_PASSWORD: "******" }) entry.add_to_hass(hass) if not skip_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry
def test_idle_thermo_issue_33758(self): """Get methods for an idle thermostat.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads( load_fixture("mobile_house_issue_33758.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(12345678) self.assertEqual(thermostat.get_model(), "XL1050") self.assertEqual(thermostat.get_firmware(), "5.9.1") self.assertEqual(thermostat.get_dev_build_number(), "1581321824") self.assertEqual(thermostat.get_device_id(), "xxxxxx") self.assertEqual(thermostat.get_type(), "XL1050") self.assertEqual(thermostat.get_name(), "Thermostat") self.assertEqual(thermostat.get_deadband(), 3) self.assertEqual(thermostat.get_setpoint_limits(), (55, 99)) self.assertEqual(thermostat.get_variable_fan_speed_limits(), (0.35, 1.0)) self.assertEqual(thermostat.get_unit(), "F") self.assertEqual(thermostat.get_humidity_setpoint_limits(), (0.35, 0.65)) self.assertEqual(thermostat.get_fan_mode(), "Auto") self.assertEqual(thermostat.get_fan_modes(), ["Auto", "On", "Circulate"]) self.assertEqual(thermostat.get_outdoor_temperature(), 55.0) self.assertEqual(thermostat.get_relative_humidity(), 0.43) self.assertEqual(thermostat.get_current_compressor_speed(), 0.0) self.assertEqual(thermostat.get_requested_compressor_speed(), 0.0) self.assertEqual(thermostat.get_fan_speed_setpoint(), 1) self.assertEqual(thermostat.get_dehumidify_setpoint(), 0.55) self.assertEqual(thermostat.has_dehumidify_support(), True) self.assertEqual(thermostat.has_humidify_support(), True) self.assertEqual(thermostat.has_emergency_heat(), True) self.assertEqual(thermostat.is_emergency_heat_active(), False) self.assertEqual(thermostat.get_system_status(), "System Idle") self.assertEqual(thermostat.has_air_cleaner(), True) self.assertEqual(thermostat.get_air_cleaner_mode(), "auto") self.assertEqual(thermostat.is_blower_active(), False) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [12345678])
def test_active_thermo(self): """Get methods for an active thermostat.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) thermostat = nexia.get_thermostat_by_id(2293892) self.assertEqual(thermostat.get_model(), "XL1050") self.assertEqual(thermostat.get_firmware(), "5.9.1") self.assertEqual(thermostat.get_dev_build_number(), "1581321824") self.assertEqual(thermostat.get_device_id(), "0281B02C") self.assertEqual(thermostat.get_type(), "XL1050") self.assertEqual(thermostat.get_name(), "Master Suite") self.assertEqual(thermostat.get_deadband(), 3) self.assertEqual(thermostat.get_setpoint_limits(), (55, 99)) self.assertEqual(thermostat.get_variable_fan_speed_limits(), (0.35, 1.0)) self.assertEqual(thermostat.get_unit(), "F") self.assertEqual(thermostat.get_humidity_setpoint_limits(), (0.35, 0.65)) self.assertEqual(thermostat.get_fan_mode(), "Auto") self.assertEqual(thermostat.get_fan_modes(), ["Auto", "On", "Circulate"]) self.assertEqual(thermostat.get_outdoor_temperature(), 87.0) self.assertEqual(thermostat.get_relative_humidity(), 0.52) self.assertEqual(thermostat.get_current_compressor_speed(), 0.69) self.assertEqual(thermostat.get_requested_compressor_speed(), 0.69) self.assertEqual(thermostat.get_fan_speed_setpoint(), 0.35) self.assertEqual(thermostat.get_dehumidify_setpoint(), 0.45) self.assertEqual(thermostat.has_dehumidify_support(), True) self.assertEqual(thermostat.has_humidify_support(), False) self.assertEqual(thermostat.has_emergency_heat(), False) self.assertEqual(thermostat.get_system_status(), "Cooling") self.assertEqual(thermostat.has_air_cleaner(), True) self.assertEqual(thermostat.get_air_cleaner_mode(), "auto") self.assertEqual(thermostat.is_blower_active(), True) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [83394133, 83394130, 83394136, 83394127, 83394139])
def test_xl824_idle(self): """Tests for nexia xl824 zone idle.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_xl624.json")) nexia.update_from_json(devices_json) thermostat_ids = nexia.get_thermostat_ids() self.assertEqual(thermostat_ids, [2222222, 3333333]) thermostat = nexia.get_thermostat_by_id(3333333) zone = thermostat.get_zone_by_id(99999999) self.assertEqual(zone.get_name(), "Upstairs NativeZone") self.assertEqual(zone.get_cooling_setpoint(), 74) self.assertEqual(zone.get_heating_setpoint(), 62) self.assertEqual(zone.get_current_mode(), "COOL") self.assertEqual( zone.get_requested_mode(), "COOL", ) self.assertEqual( zone.get_presets(), ["None", "Home", "Away", "Sleep"], ) self.assertEqual( zone.get_preset(), "None", ) self.assertEqual( zone.get_status(), "Idle", ) self.assertEqual( zone.get_setpoint_status(), "Permanent Hold", ) self.assertEqual(zone.is_calling(), False) self.assertEqual(zone.is_in_permanent_hold(), True)
def test_automations(self): """Get methods for an active thermostat.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_houses_123456.json")) nexia.update_from_json(devices_json) automation_ids = nexia.get_automation_ids() self.assertEqual( automation_ids, [3467876, 3467870, 3452469, 3452472, 3454776, 3454774, 3486078, 3486091], ) automation_one = nexia.get_automation_by_id(3467876) self.assertEqual(automation_one.name, "Away for 12 Hours") self.assertEqual( automation_one.description, "When IFTTT activates the automation Upstairs West Wing will " "permanently hold the heat to 62.0 and cool to 83.0 AND " "Downstairs East Wing will permanently hold the heat to 62.0 " "and cool to 83.0 AND Downstairs West Wing will permanently " "hold the heat to 62.0 and cool to 83.0 AND Activate the mode " "named 'Away 12' AND Master Suite will permanently hold the " "heat to 62.0 and cool to 83.0", ) self.assertEqual(automation_one.enabled, True) self.assertEqual(automation_one.automation_id, 3467876)
def test_xl624(self): """Get methods for an xl624 thermostat.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_xl624.json")) nexia.update_from_json(devices_json) thermostat_ids = nexia.get_thermostat_ids() self.assertEqual(thermostat_ids, [2222222, 3333333]) thermostat = nexia.get_thermostat_by_id(1111111) self.assertEqual(thermostat.get_model(), None) self.assertEqual(thermostat.get_firmware(), "2.8") self.assertEqual(thermostat.get_dev_build_number(), "0603340208") self.assertEqual(thermostat.get_device_id(), None) self.assertEqual(thermostat.get_type(), None) self.assertEqual(thermostat.get_name(), "Downstairs Hall") self.assertEqual(thermostat.get_deadband(), 3) self.assertEqual(thermostat.get_setpoint_limits(), (55, 99)) self.assertEqual(thermostat.has_variable_fan_speed(), False) self.assertEqual(thermostat.get_unit(), "F") self.assertEqual(thermostat.get_humidity_setpoint_limits(), (0.35, 0.65)) self.assertEqual(thermostat.get_fan_mode(), "Auto") self.assertEqual(thermostat.get_fan_modes(), ["Auto", "On", "Cycler"]) self.assertEqual(thermostat.get_current_compressor_speed(), 0.0) self.assertEqual(thermostat.get_requested_compressor_speed(), 0.0) self.assertEqual(thermostat.has_dehumidify_support(), False) self.assertEqual(thermostat.has_humidify_support(), False) self.assertEqual(thermostat.has_emergency_heat(), False) self.assertEqual(thermostat.get_system_status(), "System Idle") self.assertEqual(thermostat.has_air_cleaner(), False) self.assertEqual(thermostat.is_blower_active(), False) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [12345678])
def test_xl824_2(self): """Get methods for an xl824 thermostat.""" nexia = NexiaHome(auto_login=False) devices_json = json.loads(load_fixture("mobile_house_xl624.json")) nexia.update_from_json(devices_json) thermostat_ids = nexia.get_thermostat_ids() self.assertEqual(thermostat_ids, [2222222, 3333333]) thermostat = nexia.get_thermostat_by_id(3333333) self.assertEqual(thermostat.get_model(), "XL824") self.assertEqual(thermostat.get_firmware(), "5.9.1") self.assertEqual(thermostat.get_dev_build_number(), "1581314625") self.assertEqual(thermostat.get_device_id(), "01573380") self.assertEqual(thermostat.get_type(), "XL824") self.assertEqual(thermostat.get_name(), "Upstairs") self.assertEqual(thermostat.get_deadband(), 3) self.assertEqual(thermostat.get_setpoint_limits(), (55, 99)) self.assertEqual(thermostat.has_variable_fan_speed(), True) self.assertEqual(thermostat.get_unit(), "F") self.assertEqual(thermostat.get_humidity_setpoint_limits(), (0.35, 0.65)) self.assertEqual(thermostat.get_fan_mode(), "Circulate") self.assertEqual(thermostat.get_fan_modes(), ["Auto", "On", "Circulate"]) self.assertEqual(thermostat.get_current_compressor_speed(), 0.0) self.assertEqual(thermostat.get_requested_compressor_speed(), 0.0) self.assertEqual(thermostat.has_dehumidify_support(), True) self.assertEqual(thermostat.has_humidify_support(), False) self.assertEqual(thermostat.has_emergency_heat(), False) self.assertEqual(thermostat.get_system_status(), "System Idle") self.assertEqual(thermostat.has_air_cleaner(), True) self.assertEqual(thermostat.is_blower_active(), False) zone_ids = thermostat.get_zone_ids() self.assertEqual(zone_ids, [99999999])
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])
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])
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Configure the base Nexia device for Home Assistant.""" conf = entry.data username = conf[CONF_USERNAME] password = conf[CONF_PASSWORD] brand = conf.get(CONF_BRAND, BRAND_NEXIA) state_file = hass.config.path(f"nexia_config_{username}.conf") session = async_get_clientsession(hass) nexia_home = NexiaHome( session, username=username, password=password, device_name=hass.config.location_name, state_file=state_file, brand=brand, ) try: await nexia_home.login() except asyncio.TimeoutError as ex: raise ConfigEntryNotReady( f"Timed out trying to connect to Nexia service: {ex}") from ex except aiohttp.ClientResponseError as http_ex: if is_invalid_auth_code(http_ex.status): _LOGGER.error( "Access error from Nexia service, please check credentials: %s", http_ex) return False raise ConfigEntryNotReady( f"Error from Nexia service: {http_ex}") from http_ex coordinator = NexiaDataUpdateCoordinator(hass, nexia_home) await coordinator.async_config_entry_first_refresh() hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True
"""Nexia Climate Device Access""" import argparse import pprint from nexia.home import NexiaHome parser = argparse.ArgumentParser() parser.add_argument("--username", type=str, help="Your Nexia username/email address.") parser.add_argument("--password", type=str, help="Your Nexia password.") args = parser.parse_args() if args.username and args.password: nexia_home = NexiaHome(username=args.username, password=args.password) else: parser.print_help() exit() count = 0 for phone_id in nexia_home.get_phone_ids(): count += 1 if count < 5: continue print("Delete phone id: ", phone_id) response = nexia_home.session.delete( "https://www.mynexia.com/mobile/phones/" + str(phone_id), headers=nexia_home._api_key_headers(), )
import code import readline import rlcompleter from nexia.home import NexiaHome parser = argparse.ArgumentParser() parser.add_argument("--username", type=str, help="Your Nexia username/email address.") parser.add_argument("--password", type=str, help="Your Nexia password.") args = parser.parse_args() if args.username and args.password: nexia_home = NexiaHome(username=args.username, password=args.password) else: parser.print_help() exit() print("NexiaThermostat instance can be referenced using nt.<command>.") print("List of available thermostats and zones:") for _thermostat_id in nexia_home.get_thermostat_ids(): thermostat = nexia_home.get_thermostat_by_id(_thermostat_id) _thermostat_name = thermostat.get_name() _thermostat_model = thermostat.get_model() _thermostat_compressor_speed = thermostat.get_current_compressor_speed() print( f'{_thermostat_id} - "{_thermostat_name}" ({_thermostat_model}) [{_thermostat_compressor_speed}]' )
#!/usr/bin/python3 """Nexia Climate Device Access""" import argparse from nexia.home import NexiaHome from nexia.const import BRAND_NEXIA parser = argparse.ArgumentParser() parser.add_argument("--brand", type=str, help="Brand (nexia or asair).") parser.add_argument("--username", type=str, help="Your username/email address.") parser.add_argument("--password", type=str, help="Your password.") args = parser.parse_args() brand = args.brand or BRAND_NEXIA if args.username and args.password: nexia_home = NexiaHome(username=args.username, password=args.password, brand=brand) else: parser.print_help() exit() print(nexia_home.devices_json) print(nexia_home.automations_json)