mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Add automation and script events to logbook filter events (#19253)
* Add automation and script events to logbook filter events * Update logbook.py * Update logbook.py * Update logbook tests * Update test_logbook.py * Update test_logbook.py * Update test_logbook.py * Update test_logbook.py
This commit is contained in:
parent
4f98818258
commit
fb680bc1e4
@ -469,6 +469,14 @@ def _exclude_events(events, entities_filter):
|
||||
domain = event.data.get(ATTR_DOMAIN)
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
elif event.event_type == EVENT_AUTOMATION_TRIGGERED:
|
||||
domain = 'automation'
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
elif event.event_type == EVENT_SCRIPT_STARTED:
|
||||
domain = 'script'
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
elif event.event_type == EVENT_ALEXA_SMART_HOME:
|
||||
domain = 'alexa'
|
||||
|
||||
|
@ -265,22 +265,50 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
def test_exclude_automation_events(self):
|
||||
"""Test if automation entries can be excluded by entity_id."""
|
||||
name = 'My Automation Rule'
|
||||
message = 'has been triggered'
|
||||
domain = 'automation'
|
||||
entity_id = 'automation.my_automation_rule'
|
||||
entity_id2 = 'automation.my_automation_rule_2'
|
||||
entity_id2 = 'sensor.blu'
|
||||
|
||||
eventA = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
|
||||
eventA = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
eventB = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
|
||||
eventB = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_ENTITY_ID: entity_id2,
|
||||
})
|
||||
|
||||
config = logbook.CONFIG_SCHEMA({
|
||||
ha.DOMAIN: {},
|
||||
logbook.DOMAIN: {logbook.CONF_EXCLUDE: {
|
||||
logbook.CONF_ENTITIES: [entity_id, ]}}})
|
||||
events = logbook._exclude_events(
|
||||
(ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB),
|
||||
logbook._generate_filter_from_config(config[logbook.DOMAIN]))
|
||||
entries = list(logbook.humanify(self.hass, events))
|
||||
|
||||
assert 2 == len(entries)
|
||||
self.assert_entry(
|
||||
entries[0], name='Home Assistant', message='stopped',
|
||||
domain=ha.DOMAIN)
|
||||
self.assert_entry(
|
||||
entries[1], name=name, domain=domain, entity_id=entity_id2)
|
||||
|
||||
def test_exclude_script_events(self):
|
||||
"""Test if script start can be excluded by entity_id."""
|
||||
name = 'My Script Rule'
|
||||
domain = 'script'
|
||||
entity_id = 'script.my_script'
|
||||
entity_id2 = 'script.my_script_2'
|
||||
entity_id2 = 'sensor.blu'
|
||||
|
||||
eventA = ha.Event(logbook.EVENT_SCRIPT_STARTED, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
eventB = ha.Event(logbook.EVENT_SCRIPT_STARTED, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id2,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user