Logbook filtering of automations by entity_id (#3927)
* Logbook filtering of automations by entity_id * Trigger action function parameters required
This commit is contained in:
1 parent
57f32fa629
commit
7d32e5eeeb
3 files changed
+50
-4
No files matched your search
@@ -282,7 +282,7 @@ class AutomationEntity(ToggleEntity):
|
||||
This method is a coroutine.
|
||||
"""
|
||||
if skip_condition or self._cond_func(variables):
|
||||
yield from self._async_action(variables)
|
||||
yield from self._async_action(self.entity_id, variables)
|
||||
self._last_triggered = utcnow()
|
||||
self.hass.loop.create_task(self.async_update_ha_state())
|
||||
|
||||
@@ -357,10 +357,11 @@ def _async_get_action(hass, config, name):
|
||||
script_obj = script.Script(hass, config, name)
|
||||
|
||||
@asyncio.coroutine
|
||||
def action(variables=None):
|
||||
def action(entity_id, variables):
|
||||
"""Action to be executed."""
|
||||
_LOGGER.info('Executing %s', name)
|
||||
logbook.async_log_entry(hass, name, 'has been triggered', DOMAIN)
|
||||
logbook.async_log_entry(
|
||||
hass, name, 'has been triggered', DOMAIN, entity_id)
|
||||
hass.loop.create_task(script_obj.async_run(variables))
|
||||
|
||||
return action
|
||||
|
||||
@@ -257,7 +257,7 @@ def humanify(events):
|
||||
event.time_fired, "Home Assistant", action,
|
||||
domain=HA_DOMAIN)
|
||||
|
||||
elif event.event_type.lower() == EVENT_LOGBOOK_ENTRY:
|
||||
elif event.event_type == EVENT_LOGBOOK_ENTRY:
|
||||
domain = event.data.get(ATTR_DOMAIN)
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
if domain is None and entity_id is not None:
|
||||
@@ -290,6 +290,8 @@ def _exclude_events(events, config):
|
||||
|
||||
filtered_events = []
|
||||
for event in events:
|
||||
domain, entity_id = None, None
|
||||
|
||||
if event.event_type == EVENT_STATE_CHANGED:
|
||||
to_state = State.from_dict(event.data.get('new_state'))
|
||||
# Do not report on new entities
|
||||
@@ -303,6 +305,12 @@ def _exclude_events(events, config):
|
||||
|
||||
domain = to_state.domain
|
||||
entity_id = to_state.entity_id
|
||||
|
||||
elif event.event_type == EVENT_LOGBOOK_ENTRY:
|
||||
domain = event.data.get(ATTR_DOMAIN)
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
if domain or entity_id:
|
||||
# filter if only excluded is configured for this domain
|
||||
if excluded_domains and domain in excluded_domains and \
|
||||
not included_domains:
|
||||
|
||||
Reference in new issue
Block a user