<s> """<STR_LIT>""" <EOL> import logging <EOL> import requests <EOL> import voluptuous as vol <EOL> from homeassistant . helpers import validate_config <EOL> import homeassistant . helpers . config_validation as cv <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> DOMAIN = "<STR_LIT>" <EOL> SERVICE_TRIGGER = '<STR_LIT>' <EOL> ATTR_EVENT = '<STR_LIT>' <EOL> ATTR_VALUE1 = '<STR_LIT>' <EOL> ATTR_VALUE2 = '<STR_LIT>' <EOL> ATTR_VALUE3 = '<STR_LIT>' <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> SERVICE_TRIGGER_SCHEMA = vol . Schema ( { <EOL> vol . Required ( ATTR_EVENT ) : cv . string , <EOL> vol . Optional ( ATTR_VALUE1 ) : cv . string , <EOL> vol . Optional ( ATTR_VALUE2 ) : cv . string , <EOL> vol . Optional ( ATTR_VALUE3 ) : cv . string , <EOL> } ) <EOL> def trigger ( hass , event , value1 = None , value2 = None , value3 = None ) : <EOL> """<STR_LIT>""" <EOL> data = { <EOL> ATTR_EVENT : event , <EOL> ATTR_VALUE1 : value1 , <EOL> ATTR_VALUE2 : value2 , <EOL> ATTR_VALUE3 : value3 , <EOL> } <EOL> hass . services . call ( DOMAIN , SERVICE_TRIGGER , data ) <EOL> def setup ( hass , config ) : <EOL> """<STR_LIT>""" <EOL> if not validate_config ( config , { DOMAIN : [ '<STR_LIT:key>' ] } , _LOGGER ) : <EOL> return False <EOL> key = config [ DOMAIN ] [ '<STR_LIT:key>' ] <EOL> def trigger_service ( call ) : <EOL> """<STR_LIT>""" <EOL> event = call . data [ ATTR_EVENT ] <EOL> value1 = call . data . get ( ATTR_VALUE1 ) <EOL> value2 = call . data . get ( ATTR_VALUE2 ) <EOL> value3 = call . data . get ( ATTR_VALUE3 ) <EOL> try : <EOL> import pyfttt as pyfttt <EOL> pyfttt . send_event ( key , event , value1 , value2 , value3 ) <EOL> except requests . exceptions . RequestException : <EOL> _LOGGER . exception ( "<STR_LIT>" ) <EOL> hass . services . register ( DOMAIN , SERVICE_TRIGGER , trigger_service , <EOL> schema = SERVICE_TRIGGER_SCHEMA ) <EOL> return True </s>
