def _setup_us(username, password, config, add_devices): """Set up the user.""" import somecomfort try: client = somecomfort.SomeComfort(username, password) except somecomfort.AuthError: _LOGGER.error("Failed to login to honeywell account %s", username) return False except somecomfort.SomeComfortError as ex: _LOGGER.error("Failed to initialize honeywell client: %s", str(ex)) return False dev_id = config.get('thermostat') loc_id = config.get('location') cool_away_temp = config.get(CONF_COOL_AWAY_TEMPERATURE) heat_away_temp = config.get(CONF_HEAT_AWAY_TEMPERATURE) add_devices([ HoneywellUSThermostat(client, device, cool_away_temp, heat_away_temp, username, password) for location in client.locations_by_id.values() for device in location.devices_by_id.values() if ((not loc_id or location.locationid == loc_id) and ( not dev_id or device.deviceid == dev_id)) ]) return True
def setup_platform(opp, config, add_entities, discovery_info=None): """Set up the Honeywell thermostat.""" username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) try: client = somecomfort.SomeComfort(username, password) except somecomfort.AuthError: _LOGGER.error("Failed to login to honeywell account %s", username) return except somecomfort.SomeComfortError: _LOGGER.error("Failed to initialize the Honeywell client: " "Check your configuration (username, password), " "or maybe you have exceeded the API rate limit?") return dev_id = config.get(CONF_DEV_ID) loc_id = config.get(CONF_LOC_ID) cool_away_temp = config.get(CONF_COOL_AWAY_TEMPERATURE) heat_away_temp = config.get(CONF_HEAT_AWAY_TEMPERATURE) add_entities([ HoneywellUSThermostat( client, device, cool_away_temp, heat_away_temp, username, password, ) for location in client.locations_by_id.values() for device in location.devices_by_id.values() if ((not loc_id or location.locationid == loc_id) and ( not dev_id or device.deviceid == dev_id)) ])
def _retry(self): """Recreate a new somecomfort client. When we got an error, the best way to be sure that the next query will succeed, is to recreate a new somecomfort client. """ import somecomfort try: self._client = somecomfort.SomeComfort(self._username, self._password) except somecomfort.AuthError: _LOGGER.error("Failed to login to honeywell account %s", self._username) return False except somecomfort.SomeComfortError as ex: _LOGGER.error("Failed to initialize honeywell client: %s", str(ex)) return False devices = [ device for location in self._client.locations_by_id.values() for device in location.devices_by_id.values() if device.name == self._device.name ] if len(devices) != 1: _LOGGER.error("Failed to find device %s", self._device.name) return False self._device = devices[0] return True
def get_somecomfort_client(username, password): """Initialize the somecomfort client.""" try: return somecomfort.SomeComfort(username, password) except somecomfort.AuthError: _LOGGER.error("Failed to login to honeywell account %s", username) return None except somecomfort.SomeComfortError as ex: raise ConfigEntryNotReady( "Failed to initialize the Honeywell client: " "Check your configuration (username, password), " "or maybe you have exceeded the API rate limit?") from ex
def _connect(self): logging.info('Somecomfort connecting to user account {}'.format(self.username)) try: self.client = somecomfort.SomeComfort(self.username,self.password) logging.info('Somecomfort connected to user account {}'.format(self.username)) self._add_devices() self.account_device.account_status.value="Connected" except Exception as exc: logging.warning('Somecomfort unable to connect to user account {}, error {}'.format(self.username,exc), exc_info=True) self.client = None self.account_device.account_status.value="Not Connected to {} Error {}".format(self.username,exc)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Honeywell thermostat.""" username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) if config.get(CONF_REGION) == "us": try: client = somecomfort.SomeComfort(username, password) except somecomfort.AuthError: _LOGGER.error("Failed to login to honeywell account %s", username) return except somecomfort.SomeComfortError: _LOGGER.error( "Failed to initialize the Honeywell client: " "Check your configuration (username, password), " "or maybe you have exceeded the API rate limit?" ) return dev_id = config.get("thermostat") loc_id = config.get("location") cool_away_temp = config.get(CONF_COOL_AWAY_TEMPERATURE) heat_away_temp = config.get(CONF_HEAT_AWAY_TEMPERATURE) add_entities( [ HoneywellUSThermostat( client, device, cool_away_temp, heat_away_temp, username, password ) for location in client.locations_by_id.values() for device in location.devices_by_id.values() if ( (not loc_id or location.locationid == loc_id) and (not dev_id or device.deviceid == dev_id) ) ] ) return _LOGGER.warning( "The honeywell component has been deprecated for EU (i.e. non-US) " "systems. For EU-based systems, use the evohome component, " "see: https://home-assistant.io/components/evohome" )
def _setup_us(username, password, config, add_devices): """Setup user.""" import somecomfort try: client = somecomfort.SomeComfort(username, password) except somecomfort.AuthError: _LOGGER.error('Failed to login to honeywell account %s', username) return False except somecomfort.SomeComfortError as ex: _LOGGER.error('Failed to initialize honeywell client: %s', str(ex)) return False dev_id = config.get('thermostat') loc_id = config.get('location') add_devices([HoneywellUSThermostat(client, device) for location in client.locations_by_id.values() for device in location.devices_by_id.values() if ((not loc_id or location.locationid == loc_id) and (not dev_id or device.deviceid == dev_id))]) return True
def _main(session): number_things = ['setpoint_cool', 'setpoint_heat'] string_things = ['fan_mode', 'system_mode'] bool_things = ['cancel_hold', 'permanent_hold'] settable_things = {float: number_things, str: string_things} readonly_things = [ 'current_temperature', 'current_humidity', 'outdoor_temperature', 'outdoor_humidity', 'equipment_output_status' ] parser = argparse.ArgumentParser() for thingtype, thinglist in settable_things.items(): for thing in thinglist: parser.add_argument('--get_%s' % thing, action='store_const', const=True, default=False, help='Get %s' % thing) parser.add_argument('--set_%s' % thing, type=thingtype, default=None, help='Set %s' % thing) for thing in readonly_things: parser.add_argument('--get_%s' % thing, action='store_const', const=True, default=False, help='Get %s' % thing) for thing in bool_things: parser.add_argument('--%s' % thing, action='store_const', const=True, default=False, help='Set %s' % thing) parser.add_argument('--hold_until', type=str, default=None, help='Hold until time (HH:MM)') parser.add_argument('--get_hold', action='store_const', const=True, default=False, help='Get the current hold mode') parser.add_argument('--username', help='username') parser.add_argument('--password', help='password') parser.add_argument('--device', help='device', default=None, type=int) parser.add_argument('--login', help='Just try to login', action='store_const', const=True, default=False) parser.add_argument('--devices', help='List available devices', action='store_const', const=True, default=False) args = parser.parse_args() try: client = somecomfort.SomeComfort(args.username, args.password, session=session) except somecomfort.AuthError as ex: if not args.username and args.password: print('Login required and no credentials provided') else: print(str(ex)) return 1 if args.login: print('Success') return 0 if args.devices: for l_name, location in client.locations_by_id.items(): print('Location %s:' % l_name) for key, device in location.devices_by_id.items(): print(' Device %s: %s' % (key, device.name)) return 0 if not args.device: device = client.default_device else: device = client.get_device(args.device) if not device: print('Device not found') return 1 if any([ args.hold_until, args.cancel_hold, args.permanent_hold, args.get_hold ]): cont = do_holds(client, args, device) if not cont: return try: return get_or_set_things( client, args, device, number_things + string_things, number_things + string_things + readonly_things) except somecomfort.SomeComfortError as ex: print('%s: %s' % (ex.__class__.__name__, str(ex)))