Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,8 @@ async def async_trigger(self, variables, skip_condition=False, context=None):

try:
await self.action_script.async_run(variables, trigger_context)
except Exception as err: # pylint: disable=broad-except
self.action_script.async_log_exception(
_LOGGER, f"Error while executing automation {self.entity_id}", err
)
except Exception: # pylint: disable=broad-except
pass
Comment thread
pnbruckner marked this conversation as resolved.

self._last_triggered = utcnow()
await self.async_update_ha_state()
Expand Down Expand Up @@ -508,7 +506,9 @@ async def _async_process_config(hass, config, component):
hidden = config_block[CONF_HIDE_ENTITY]
initial_state = config_block.get(CONF_INITIAL_STATE)

action_script = script.Script(hass, config_block.get(CONF_ACTION, {}), name)
action_script = script.Script(
hass, config_block.get(CONF_ACTION, {}), name, logger=_LOGGER
)

if CONF_CONDITION in config_block:
cond_func = await _async_process_if(hass, config, config_block)
Expand Down
17 changes: 6 additions & 11 deletions homeassistant/components/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def __init__(self, hass, object_id, name, sequence):
"""Initialize the script."""
self.object_id = object_id
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
self.script = Script(hass, sequence, name, self.async_update_ha_state)
self.script = Script(
hass, sequence, name, self.async_update_ha_state, logger=_LOGGER
)

@property
def should_poll(self):
Expand Down Expand Up @@ -268,22 +270,15 @@ async def async_turn_on(self, **kwargs):
{ATTR_NAME: self.script.name, ATTR_ENTITY_ID: self.entity_id},
context=context,
)
try:
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
except Exception as err:
self.script.async_log_exception(
_LOGGER, f"Error executing script {self.entity_id}", err
)
raise err
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)

async def async_turn_off(self, **kwargs):
"""Turn script off."""
self.script.async_stop()
await self.script.async_stop()

async def async_will_remove_from_hass(self):
"""Stop script and remove service when it will be removed from Home Assistant."""
if self.script.is_running:
self.script.async_stop()
await self.script.async_stop()

# remove service
self.hass.services.async_remove(DOMAIN, self.object_id)
Loading