<s> """<STR_LIT>""" <EOL> import logging <EOL> from homeassistant . components . isy994 import ( <EOL> HIDDEN_STRING , ISY , SENSOR_STRING , ISYDeviceABC ) <EOL> from homeassistant . const import STATE_OFF , STATE_ON <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( __name__ ) <EOL> devs = [ ] <EOL> if ISY is None or not ISY . connected : <EOL> logger . error ( '<STR_LIT>' ) <EOL> return False <EOL> for ( path , node ) in ISY . nodes : <EOL> if not node . dimmable and SENSOR_STRING not in node . name : <EOL> if HIDDEN_STRING in path : <EOL> node . name += HIDDEN_STRING <EOL> devs . append ( ISYSwitchDevice ( node ) ) <EOL> for folder_name , states in ( ( '<STR_LIT>' , [ STATE_ON , STATE_OFF ] ) , <EOL> ( '<STR_LIT>' , [ STATE_ON , STATE_OFF ] ) ) : <EOL> try : <EOL> folder = ISY . programs [ '<STR_LIT>' ] [ folder_name ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> for dtype , name , node_id in folder . children : <EOL> if dtype is '<STR_LIT>' : <EOL> custom_switch = folder [ node_id ] <EOL> try : <EOL> actions = custom_switch [ '<STR_LIT>' ] . leaf <EOL> assert actions . dtype == '<STR_LIT>' , '<STR_LIT>' <EOL> node = custom_switch [ '<STR_LIT:status>' ] . leaf <EOL> except ( KeyError , AssertionError ) : <EOL> pass <EOL> else : <EOL> devs . append ( ISYProgramDevice ( name , node , actions , <EOL> states ) ) <EOL> add_devices ( devs ) <EOL> class ISYSwitchDevice ( ISYDeviceABC ) : <EOL> """<STR_LIT>""" <EOL> _domain = '<STR_LIT>' <EOL> _dtype = '<STR_LIT>' <EOL> _states = [ STATE_ON , STATE_OFF ] <EOL> class ISYProgramDevice ( ISYSwitchDevice ) : <EOL> """<STR_LIT>""" <EOL> _domain = '<STR_LIT>' <EOL> _dtype = '<STR_LIT>' <EOL> def __init__ ( self , name , node , actions , states ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( node ) <EOL> self . _states = states <EOL> self . _name = name <EOL> self . action_node = actions <EOL> def turn_on ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . action_node . runThen ( ) <EOL> def turn_off ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . action_node . runElse ( ) </s>
