<s> """<STR_LIT>""" <EOL> import logging <EOL> from homeassistant . components . thermostat import ThermostatDevice <EOL> from homeassistant . const import TEMP_CELSIUS <EOL> CONF_IPADDRESS = '<STR_LIT>' <EOL> CONF_PORT = '<STR_LIT:port>' <EOL> CONF_TSTATS = '<STR_LIT>' <EOL> REQUIREMENTS = [ "<STR_LIT>" ] <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> from heatmiserV3 import heatmiser , connection <EOL> ipaddress = str ( config [ CONF_IPADDRESS ] ) <EOL> port = str ( config [ CONF_PORT ] ) <EOL> if ipaddress is None or port is None : <EOL> _LOGGER . error ( "<STR_LIT>" , <EOL> CONF_IPADDRESS , CONF_PORT ) <EOL> return False <EOL> serport = connection . connection ( ipaddress , port ) <EOL> serport . open ( ) <EOL> tstats = [ ] <EOL> if CONF_TSTATS in config : <EOL> tstats = config [ CONF_TSTATS ] <EOL> if tstats is None : <EOL> _LOGGER . error ( "<STR_LIT>" ) <EOL> return False <EOL> for tstat in tstats : <EOL> add_devices ( [ <EOL> HeatmiserV3Thermostat ( <EOL> heatmiser , <EOL> tstat . get ( "<STR_LIT:id>" ) , <EOL> tstat . get ( "<STR_LIT:name>" ) , <EOL> serport ) <EOL> ] ) <EOL> return <EOL> class HeatmiserV3Thermostat ( ThermostatDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , heatmiser , device , name , serport ) : <EOL> """<STR_LIT>""" <EOL> self . heatmiser = heatmiser <EOL> self . device = device <EOL> self . serport = serport <EOL> self . _current_temperature = None <EOL> self . _name = name <EOL> self . _id = device <EOL> self . dcb = None <EOL> self . update ( ) <EOL> self . _target_temperature = int ( self . dcb . get ( "<STR_LIT>" ) ) <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> if self . dcb is not None : <EOL> low = self . dcb . get ( "<STR_LIT>" ) <EOL> high = self . dcb . get ( "<STR_LIT>" ) <EOL> temp = ( high * <NUM_LIT> + low ) / <NUM_LIT> <EOL> self . _current_temperature = temp <EOL> else : <EOL> self . _current_temperature = None <EOL> return self . _current_temperature <EOL> @ property <EOL> def target_temperature ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _target_temperature <EOL> def set_temperature ( self , temperature ) : <EOL> """<STR_LIT>""" <EOL> temperature = int ( temperature ) <EOL> self . heatmiser . hmSendAddress ( <EOL> self . _id , <EOL> <NUM_LIT> , <EOL> temperature , <EOL> <NUM_LIT:1> , <EOL> self . serport ) <EOL> self . _target_temperature = int ( temperature ) <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dcb = self . heatmiser . hmReadAddress ( self . _id , '<STR_LIT>' , self . serport ) </s>
