<s> """<STR_LIT>""" <EOL> import logging <EOL> import socket <EOL> from homeassistant . components . thermostat import ThermostatDevice <EOL> from homeassistant . const import ( <EOL> CONF_PASSWORD , CONF_USERNAME , TEMP_CELSIUS , TEMP_FAHRENHEIT ) <EOL> REQUIREMENTS = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> CONF_AWAY_TEMP = "<STR_LIT>" <EOL> DEFAULT_AWAY_TEMP = <NUM_LIT:16> <EOL> def _setup_round ( username , password , config , add_devices ) : <EOL> """<STR_LIT>""" <EOL> from evohomeclient import EvohomeClient <EOL> try : <EOL> away_temp = float ( config . get ( CONF_AWAY_TEMP , DEFAULT_AWAY_TEMP ) ) <EOL> except ValueError : <EOL> _LOGGER . error ( "<STR_LIT>" , <EOL> CONF_AWAY_TEMP ) <EOL> return False <EOL> evo_api = EvohomeClient ( username , password ) <EOL> try : <EOL> zones = evo_api . temperatures ( force_refresh = True ) <EOL> for i , zone in enumerate ( zones ) : <EOL> add_devices ( [ RoundThermostat ( evo_api , <EOL> zone [ '<STR_LIT:id>' ] , <EOL> i == <NUM_LIT:0> , <EOL> away_temp ) ] ) <EOL> except socket . error : <EOL> _LOGGER . error ( <EOL> "<STR_LIT>" <EOL> ) <EOL> return False <EOL> return True <EOL> def _setup_us ( username , password , config , add_devices ) : <EOL> """<STR_LIT>""" <EOL> import somecomfort <EOL> try : <EOL> client = somecomfort . SomeComfort ( username , password ) <EOL> except somecomfort . AuthError : <EOL> _LOGGER . error ( '<STR_LIT>' , username ) <EOL> return False <EOL> except somecomfort . SomeComfortError as ex : <EOL> _LOGGER . error ( '<STR_LIT>' , str ( ex ) ) <EOL> return False <EOL> dev_id = config . get ( '<STR_LIT>' ) <EOL> loc_id = config . get ( '<STR_LIT:location>' ) <EOL> add_devices ( [ HoneywellUSThermostat ( client , device ) <EOL> for location in client . locations_by_id . values ( ) <EOL> for device in location . devices_by_id . values ( ) <EOL> if ( ( not loc_id or location . locationid == loc_id ) and <EOL> ( not dev_id or device . deviceid == dev_id ) ) ] ) <EOL> return True <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> username = config . get ( CONF_USERNAME ) <EOL> password = config . get ( CONF_PASSWORD ) <EOL> region = config . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) <EOL> if username is None or password is None : <EOL> _LOGGER . error ( "<STR_LIT>" , <EOL> CONF_USERNAME , CONF_PASSWORD ) <EOL> return False <EOL> if region not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> _LOGGER . error ( '<STR_LIT>' , region ) <EOL> return False <EOL> if region == '<STR_LIT>' : <EOL> return _setup_us ( username , password , config , add_devices ) <EOL> else : <EOL> return _setup_round ( username , password , config , add_devices ) <EOL> class RoundThermostat ( ThermostatDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , device , zone_id , master , away_temp ) : <EOL> """<STR_LIT>""" <EOL> self . device = device <EOL> self . _current_temperature = None <EOL> self . _target_temperature = None <EOL> self . _name = "<STR_LIT>" <EOL> self . _id = zone_id <EOL> self . _master = master <EOL> self . _is_dhw = False <EOL> self . _away_temp = away_temp <EOL> self . _away = False <EOL> self . update ( ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ property <EOL> def unit_of_measurement ( self ) : <EOL> """<STR_LIT>""" <EOL> return TEMP_CELSIUS <EOL> @ property <EOL> def current_temperature ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _current_temperature <EOL> @ property <EOL> def target_temperature ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _is_dhw : <EOL> return None <EOL> return self . _target_temperature <EOL> def set_temperature ( self , temperature ) : <EOL> """<STR_LIT>""" <EOL> self . device . set_temperature ( self . _name , temperature ) <EOL> @ property <EOL> def is_away_mode_on ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _away <EOL> def turn_away_mode_on ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _away = True <EOL> self . device . set_temperature ( self . _name , self . _away_temp ) <EOL> def turn_away_mode_off ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _away = False <EOL> self . device . cancel_temp_override ( self . _name ) <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> for val in self . device . temperatures ( force_refresh = self . _master ) : <EOL> if val [ '<STR_LIT:id>' ] == self . _id : <EOL> data = val <EOL> except StopIteration : <EOL> _LOGGER . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return <EOL> self . _current_temperature = data [ '<STR_LIT>' ] <EOL> self . _target_temperature = data [ '<STR_LIT>' ] <EOL> if data [ '<STR_LIT>' ] == "<STR_LIT>" : <EOL> self . _name = "<STR_LIT>" <EOL> self . _is_dhw = True <EOL> else : <EOL> self . _name = data [ '<STR_LIT:name>' ] <EOL> self . _is_dhw = False <EOL> class HoneywellUSThermostat ( ThermostatDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , device ) : <EOL> """<STR_LIT>""" <EOL> self . _client = client <EOL> self . _device = device <EOL> @ property <EOL> def is_fan_on ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _device . fan_running <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _device . name <EOL> @ property <EOL> def unit_of_measurement ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( TEMP_CELSIUS if self . _device . temperature_unit == '<STR_LIT:C>' <EOL> else TEMP_FAHRENHEIT ) <EOL> @ property <EOL> def current_temperature ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _device . refresh ( ) <EOL> return self . _device . current_temperature <EOL> @ property <EOL> def target_temperature ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _device . system_mode == '<STR_LIT>' : <EOL> return self . _device . setpoint_cool <EOL> else : <EOL> return self . _device . setpoint_heat <EOL> def set_temperature ( self , temperature ) : <EOL> """<STR_LIT>""" <EOL> import somecomfort <EOL> try : <EOL> if self . _device . system_mode == '<STR_LIT>' : <EOL> self . _device . setpoint_cool = temperature <EOL> else : <EOL> self . _device . setpoint_heat = temperature <EOL> except somecomfort . SomeComfortError : <EOL> _LOGGER . error ( '<STR_LIT>' , temperature ) <EOL> @ property <EOL> def device_state_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : ( self . is_fan_on and '<STR_LIT>' or '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _device . fan_mode , <EOL> '<STR_LIT>' : self . _device . system_mode } <EOL> def turn_away_mode_on ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def turn_away_mode_off ( self ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
