<s> """<STR_LIT>""" <EOL> import logging <EOL> from collections import namedtuple <EOL> import homeassistant . util as util <EOL> from homeassistant . const import TEMP_CELSIUS <EOL> from homeassistant . helpers . entity import Entity <EOL> DatatypeDescription = namedtuple ( "<STR_LIT>" , [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> import tellcore . telldus as telldus <EOL> import tellcore . constants as tellcore_constants <EOL> sensor_value_descriptions = { <EOL> tellcore_constants . TELLSTICK_TEMPERATURE : <EOL> DatatypeDescription ( <EOL> '<STR_LIT>' , config . get ( '<STR_LIT>' , TEMP_CELSIUS ) ) , <EOL> tellcore_constants . TELLSTICK_HUMIDITY : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT:%>' ) , <EOL> tellcore_constants . TELLSTICK_RAINRATE : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> tellcore_constants . TELLSTICK_RAINTOTAL : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> tellcore_constants . TELLSTICK_WINDDIRECTION : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> tellcore_constants . TELLSTICK_WINDAVERAGE : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> tellcore_constants . TELLSTICK_WINDGUST : <EOL> DatatypeDescription ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> } <EOL> try : <EOL> core = telldus . TelldusCore ( ) <EOL> except OSError : <EOL> logging . getLogger ( __name__ ) . exception ( <EOL> '<STR_LIT>' ) <EOL> return <EOL> sensors = [ ] <EOL> datatype_mask = util . convert ( config . get ( '<STR_LIT>' ) , int , <NUM_LIT> ) <EOL> for ts_sensor in core . sensors ( ) : <EOL> try : <EOL> sensor_name = config [ ts_sensor . id ] <EOL> except KeyError : <EOL> if util . convert ( config . get ( '<STR_LIT>' ) , bool , False ) : <EOL> continue <EOL> sensor_name = str ( ts_sensor . id ) <EOL> for datatype in sensor_value_descriptions . keys ( ) : <EOL> if datatype & datatype_mask and ts_sensor . has_value ( datatype ) : <EOL> sensor_info = sensor_value_descriptions [ datatype ] <EOL> sensors . append ( <EOL> TellstickSensor ( <EOL> sensor_name , ts_sensor , datatype , sensor_info ) ) <EOL> add_devices ( sensors ) <EOL> class TellstickSensor ( Entity ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , sensor , datatype , sensor_info ) : <EOL> """<STR_LIT>""" <EOL> self . datatype = datatype <EOL> self . sensor = sensor <EOL> self . _unit_of_measurement = sensor_info . unit or None <EOL> self . _name = "<STR_LIT>" . format ( name , sensor_info . name ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . sensor . value ( self . datatype ) . value <EOL> @ property <EOL> def unit_of_measurement ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _unit_of_measurement </s>
