<s> """<STR_LIT>""" <EOL> import logging <EOL> from homeassistant . components . switch import SwitchDevice <EOL> DEFAULT_NAME = "<STR_LIT>" <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> def setup_platform ( hass , config , add_devices_callback , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> from orvibo . s20 import S20 , S20Exception <EOL> switches = [ ] <EOL> switch_conf = config . get ( '<STR_LIT>' , [ config ] ) <EOL> for switch in switch_conf : <EOL> if switch . get ( '<STR_LIT:host>' ) is None : <EOL> _LOGGER . error ( "<STR_LIT>" ) <EOL> continue <EOL> host = switch . get ( '<STR_LIT:host>' ) <EOL> mac = switch . get ( '<STR_LIT>' ) <EOL> try : <EOL> switches . append ( S20Switch ( switch . get ( '<STR_LIT:name>' , DEFAULT_NAME ) , <EOL> S20 ( host , mac = mac ) ) ) <EOL> _LOGGER . info ( "<STR_LIT>" , host ) <EOL> except S20Exception : <EOL> _LOGGER . exception ( "<STR_LIT>" , <EOL> host ) <EOL> add_devices_callback ( switches ) <EOL> class S20Switch ( SwitchDevice ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , s20 ) : <EOL> """<STR_LIT>""" <EOL> from orvibo . s20 import S20Exception <EOL> self . _name = name <EOL> self . _s20 = s20 <EOL> self . _state = False <EOL> self . _exc = S20Exception <EOL> @ property <EOL> def should_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ property <EOL> def is_on ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _state <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _state = self . _s20 . on <EOL> except self . _exc : <EOL> _LOGGER . exception ( "<STR_LIT>" ) <EOL> def turn_on ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _s20 . on = True <EOL> except self . _exc : <EOL> _LOGGER . exception ( "<STR_LIT>" ) <EOL> def turn_off ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _s20 . on = False <EOL> except self . _exc : <EOL> _LOGGER . exception ( "<STR_LIT>" ) </s>
