New Events and Context Fixes (#18765)
* Add new events for automation trigger and script run, fix context for image processing, add tests to ensure same context * remove custom logbook entry for automation and add new automation event to logbook * code review updates
This commit is contained in:
1 parent
8e9c73eb18
commit
b900005d1e
8 files changed
+214
-19
No files matched your search
@@ -14,7 +14,8 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||
SERVICE_TOGGLE, SERVICE_RELOAD, STATE_ON, CONF_ALIAS)
|
||||
SERVICE_TOGGLE, SERVICE_RELOAD, STATE_ON, CONF_ALIAS,
|
||||
EVENT_SCRIPT_STARTED, ATTR_NAME)
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
@@ -170,8 +171,14 @@ class ScriptEntity(ToggleEntity):
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the script on."""
|
||||
context = kwargs.get('context')
|
||||
self.async_set_context(context)
|
||||
self.hass.bus.async_fire(EVENT_SCRIPT_STARTED, {
|
||||
ATTR_NAME: self.script.name,
|
||||
ATTR_ENTITY_ID: self.entity_id,
|
||||
}, context=context)
|
||||
await self.script.async_run(
|
||||
kwargs.get(ATTR_VARIABLES), kwargs.get('context'))
|
||||
kwargs.get(ATTR_VARIABLES), context)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn script off."""
|
||||
|
||||
Reference in new issue
Block a user