<s> """<STR_LIT>""" <EOL> import voluptuous as vol <EOL> from homeassistant . components import tellstick <EOL> from homeassistant . components . light import ATTR_BRIGHTNESS , Light <EOL> from homeassistant . components . tellstick import ( DEFAULT_SIGNAL_REPETITIONS , <EOL> ATTR_DISCOVER_DEVICES , <EOL> ATTR_DISCOVER_CONFIG ) <EOL> PLATFORM_SCHEMA = vol . Schema ( { vol . Required ( "<STR_LIT>" ) : tellstick . DOMAIN } ) <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> if ( discovery_info is None or <EOL> discovery_info [ ATTR_DISCOVER_DEVICES ] is None or <EOL> tellstick . TELLCORE_REGISTRY is None ) : <EOL> return <EOL> signal_repetitions = discovery_info . get ( ATTR_DISCOVER_CONFIG , <EOL> DEFAULT_SIGNAL_REPETITIONS ) <EOL> add_devices ( TellstickLight ( <EOL> tellstick . TELLCORE_REGISTRY . get_device ( switch_id ) , signal_repetitions ) <EOL> for switch_id in discovery_info [ ATTR_DISCOVER_DEVICES ] ) <EOL> class TellstickLight ( tellstick . TellstickDevice , Light ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tellstick_device , signal_repetitions ) : <EOL> """<STR_LIT>""" <EOL> self . _brightness = <NUM_LIT:255> <EOL> tellstick . TellstickDevice . __init__ ( self , <EOL> tellstick_device , <EOL> signal_repetitions ) <EOL> @ property <EOL> def is_on ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _state <EOL> @ property <EOL> def brightness ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _brightness <EOL> def set_tellstick_state ( self , last_command_sent , last_data_sent ) : <EOL> """<STR_LIT>""" <EOL> from tellcore . constants import TELLSTICK_TURNON , TELLSTICK_DIM <EOL> if last_command_sent == TELLSTICK_DIM : <EOL> if last_data_sent is not None : <EOL> self . _brightness = int ( last_data_sent ) <EOL> self . _state = self . _brightness > <NUM_LIT:0> <EOL> else : <EOL> self . _state = last_command_sent == TELLSTICK_TURNON <EOL> def _send_tellstick_command ( self , command , data ) : <EOL> """<STR_LIT>""" <EOL> from tellcore . constants import ( TELLSTICK_TURNOFF , TELLSTICK_DIM ) <EOL> if command == TELLSTICK_TURNOFF : <EOL> self . tellstick_device . turn_off ( ) <EOL> elif command == TELLSTICK_DIM : <EOL> self . tellstick_device . dim ( self . _brightness ) <EOL> else : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" . format ( command ) ) <EOL> def turn_on ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from tellcore . constants import TELLSTICK_DIM <EOL> brightness = kwargs . get ( ATTR_BRIGHTNESS ) <EOL> if brightness is not None : <EOL> self . _brightness = brightness <EOL> self . call_tellstick ( TELLSTICK_DIM , self . _brightness ) <EOL> def turn_off ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from tellcore . constants import TELLSTICK_TURNOFF <EOL> self . call_tellstick ( TELLSTICK_TURNOFF ) </s>
