<s> """<STR_LIT>""" <EOL> import logging <EOL> import requests <EOL> import homeassistant . components . alarm_control_panel as alarm <EOL> from homeassistant . const import ( <EOL> STATE_ALARM_ARMED_AWAY , STATE_ALARM_ARMED_HOME , STATE_ALARM_DISARMED , <EOL> STATE_UNKNOWN ) <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> host = config . get ( '<STR_LIT:host>' , '<STR_LIT>' ) <EOL> try : <EOL> add_devices ( [ NX584Alarm ( hass , host , config . get ( '<STR_LIT:name>' , '<STR_LIT>' ) ) ] ) <EOL> except requests . exceptions . ConnectionError as ex : <EOL> _LOGGER . error ( '<STR_LIT>' , str ( ex ) ) <EOL> return False <EOL> class NX584Alarm ( alarm . AlarmControlPanel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , hass , host , name ) : <EOL> """<STR_LIT>""" <EOL> from nx584 import client <EOL> self . _hass = hass <EOL> self . _host = host <EOL> self . _name = name <EOL> self . _alarm = client . Client ( '<STR_LIT>' % host ) <EOL> self . _alarm . list_zones ( ) <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 code_format ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> part = self . _alarm . list_partitions ( ) [ <NUM_LIT:0> ] <EOL> zones = self . _alarm . list_zones ( ) <EOL> except requests . exceptions . ConnectionError as ex : <EOL> _LOGGER . error ( '<STR_LIT>' , <EOL> dict ( host = self . _host , reason = ex ) ) <EOL> return STATE_UNKNOWN <EOL> except IndexError : <EOL> _LOGGER . error ( '<STR_LIT>' ) <EOL> return STATE_UNKNOWN <EOL> bypassed = False <EOL> for zone in zones : <EOL> if zone [ '<STR_LIT>' ] : <EOL> _LOGGER . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> dict ( zone = zone [ '<STR_LIT>' ] ) ) <EOL> bypassed = True <EOL> break <EOL> if not part [ '<STR_LIT>' ] : <EOL> return STATE_ALARM_DISARMED <EOL> elif bypassed : <EOL> return STATE_ALARM_ARMED_HOME <EOL> else : <EOL> return STATE_ALARM_ARMED_AWAY <EOL> def alarm_disarm ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> self . _alarm . disarm ( code ) <EOL> def alarm_arm_home ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> self . _alarm . arm ( '<STR_LIT>' ) <EOL> def alarm_arm_away ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> self . _alarm . arm ( '<STR_LIT>' ) <EOL> def alarm_trigger ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
