1313from homeassistant .components .number import DOMAIN as NUMBER_DOMAIN
1414from homeassistant .components .switch import DOMAIN as SWITCH_DOMAIN
1515from homeassistant .const import CONF_NAME , STATE_UNAVAILABLE , STATE_UNKNOWN
16- from homeassistant .core import callback
16+ from homeassistant .core import callback , Context
1717from homeassistant .exceptions import TemplateError
1818from homeassistant .helpers import device_registry as dr , entity_registry
1919import homeassistant .helpers .config_validation as cv
2222from homeassistant .helpers .network import get_url
2323from homeassistant .helpers .reload import async_integration_yaml_config
2424from homeassistant .helpers .restore_state import RestoreEntity
25- from homeassistant .helpers .service import async_call_from_config
25+ from homeassistant .helpers .script import Script
2626from homeassistant .util import slugify
2727import jsonschema
2828import voluptuous as vol
@@ -103,7 +103,7 @@ def hasp_object(value):
103103
104104
105105# Configuration YAML schemas
106- EVENT_SCHEMA = cv .schema_with_slug_keys ([ cv .SERVICE_SCHEMA ] )
106+ EVENT_SCHEMA = cv .schema_with_slug_keys (cv .SCRIPT_SCHEMA )
107107
108108PROPERTY_SCHEMA = cv .schema_with_slug_keys (cv .template )
109109
@@ -700,7 +700,10 @@ def __init__(self, hass, plate_topic, config):
700700 self .cached_properties = {}
701701
702702 self .properties = config .get (CONF_PROPERTIES )
703- self .event_services = config .get (CONF_EVENT )
703+ self .event_services = {
704+ event : Script (hass , script , plate_topic , DOMAIN )
705+ for (event , script ) in config [CONF_EVENT ].items ()
706+ }
704707 self ._tracked_property_templates = []
705708 self ._freeze_properties = []
706709 self ._subscriptions = []
@@ -794,7 +797,7 @@ async def message_received(msg):
794797 elif message [HASP_EVENT ] in [HASP_EVENT_UP , HASP_EVENT_RELEASE ]:
795798 self ._freeze_properties = []
796799
797- for event in self .event_services :
800+ for event , script in self .event_services . items () :
798801 if event in message [HASP_EVENT ]:
799802 _LOGGER .debug (
800803 "Service call for '%s' triggered by '%s' on '%s' with variables %s" ,
@@ -803,13 +806,10 @@ async def message_received(msg):
803806 msg .topic ,
804807 message ,
805808 )
806- for service in self .event_services [event ]:
807- await async_call_from_config (
808- self .hass ,
809- service ,
810- validate_config = False ,
811- variables = message ,
812- )
809+ await script .async_run (
810+ run_variables = message ,
811+ context = Context (),
812+ )
813813 except vol .error .Invalid :
814814 _LOGGER .debug (
815815 "Could not handle openHASP event: '%s' on '%s'" ,
0 commit comments