<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import voluptuous as vol <EOL> from homeassistant . components import verisure <EOL> from homeassistant . const import ( <EOL> ATTR_CODE , ATTR_CODE_FORMAT , ATTR_ENTITY_ID , SERVICE_ALARM_TRIGGER , <EOL> SERVICE_ALARM_DISARM , SERVICE_ALARM_ARM_HOME , SERVICE_ALARM_ARM_AWAY ) <EOL> from homeassistant . config import load_yaml_config_file <EOL> from homeassistant . helpers . config_validation import PLATFORM_SCHEMA <EOL> import homeassistant . helpers . config_validation as cv <EOL> from homeassistant . helpers . entity import Entity <EOL> from homeassistant . helpers . entity_component import EntityComponent <EOL> DOMAIN = '<STR_LIT>' <EOL> SCAN_INTERVAL = <NUM_LIT:30> <EOL> ENTITY_ID_FORMAT = DOMAIN + '<STR_LIT>' <EOL> DISCOVERY_PLATFORMS = { <EOL> verisure . DISCOVER_ALARMS : '<STR_LIT>' <EOL> } <EOL> SERVICE_TO_METHOD = { <EOL> SERVICE_ALARM_DISARM : '<STR_LIT>' , <EOL> SERVICE_ALARM_ARM_HOME : '<STR_LIT>' , <EOL> SERVICE_ALARM_ARM_AWAY : '<STR_LIT>' , <EOL> SERVICE_ALARM_TRIGGER : '<STR_LIT>' <EOL> } <EOL> ATTR_TO_PROPERTY = [ <EOL> ATTR_CODE , <EOL> ATTR_CODE_FORMAT <EOL> ] <EOL> ALARM_SERVICE_SCHEMA = vol . Schema ( { <EOL> vol . Optional ( ATTR_ENTITY_ID ) : cv . entity_ids , <EOL> vol . Optional ( ATTR_CODE ) : cv . string , <EOL> } ) <EOL> def setup ( hass , config ) : <EOL> """<STR_LIT>""" <EOL> component = EntityComponent ( <EOL> logging . getLogger ( __name__ ) , DOMAIN , hass , SCAN_INTERVAL , <EOL> DISCOVERY_PLATFORMS ) <EOL> component . setup ( config ) <EOL> def alarm_service_handler ( service ) : <EOL> """<STR_LIT>""" <EOL> target_alarms = component . extract_from_service ( service ) <EOL> code = service . data . get ( ATTR_CODE ) <EOL> method = SERVICE_TO_METHOD [ service . service ] <EOL> for alarm in target_alarms : <EOL> getattr ( alarm , method ) ( code ) <EOL> if alarm . should_poll : <EOL> alarm . update_ha_state ( True ) <EOL> descriptions = load_yaml_config_file ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> for service in SERVICE_TO_METHOD : <EOL> hass . services . register ( DOMAIN , service , alarm_service_handler , <EOL> descriptions . get ( service ) , <EOL> schema = ALARM_SERVICE_SCHEMA ) <EOL> return True <EOL> def alarm_disarm ( hass , code = None , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { } <EOL> if code : <EOL> data [ ATTR_CODE ] = code <EOL> if entity_id : <EOL> data [ ATTR_ENTITY_ID ] = entity_id <EOL> hass . services . call ( DOMAIN , SERVICE_ALARM_DISARM , data ) <EOL> def alarm_arm_home ( hass , code = None , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { } <EOL> if code : <EOL> data [ ATTR_CODE ] = code <EOL> if entity_id : <EOL> data [ ATTR_ENTITY_ID ] = entity_id <EOL> hass . services . call ( DOMAIN , SERVICE_ALARM_ARM_HOME , data ) <EOL> def alarm_arm_away ( hass , code = None , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { } <EOL> if code : <EOL> data [ ATTR_CODE ] = code <EOL> if entity_id : <EOL> data [ ATTR_ENTITY_ID ] = entity_id <EOL> hass . services . call ( DOMAIN , SERVICE_ALARM_ARM_AWAY , data ) <EOL> def alarm_trigger ( hass , code = None , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { } <EOL> if code : <EOL> data [ ATTR_CODE ] = code <EOL> if entity_id : <EOL> data [ ATTR_ENTITY_ID ] = entity_id <EOL> hass . services . call ( DOMAIN , SERVICE_ALARM_TRIGGER , data ) <EOL> class AlarmControlPanel ( Entity ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def code_format ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def alarm_disarm ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def alarm_arm_home ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def alarm_arm_away ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def alarm_trigger ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def state_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> state_attr = { <EOL> ATTR_CODE_FORMAT : self . code_format , <EOL> } <EOL> return state_attr </s>
