Skip to content

Exclude filter for event types#7627

Merged
balloob merged 8 commits into
home-assistant:devfrom
amigian74:event_type_filter
May 24, 2017
Merged

Exclude filter for event types#7627
balloob merged 8 commits into
home-assistant:devfrom
amigian74:event_type_filter

Conversation

@amigian74
Copy link
Copy Markdown
Contributor

@amigian74 amigian74 commented May 17, 2017

Description:

We are using an SD Card as persitent memory on our system. Extensive write operations killing these cards in a few months. Therefore it should be possible to exclude events just like states from being persisted into the database.

With this change events can be excluded from being persisted. If 'state_change' is excluded states won't be persisted too.

Example entry for configuration.yaml:

recorder:
  exclude:
    event_types:
      - call_service
      - service_executed

@mention-bot
Copy link
Copy Markdown

@amigian74, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @rhooper and @kellerza to be potential reviewers.

session.add(dbevent)

if event.event_type == EVENT_STATE_CHANGED:
if event.event_type == EVENT_STATE_CHANGED and EVENT_STATE_CHANGED not in self.exclude_t:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (105 > 79 characters)

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also require tests to be written.

with session_scope(session=self.get_session()) as session:
dbevent = Events.from_event(event)
session.add(dbevent)
dbevent = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct way to filter out the event. Have a look at the above examples on how things get filtered.

add test for exclude event types
Comment thread tests/components/recorder/test_init.py Outdated
hass = hass_recorder({'exclude': {'event_types': 'test'}})
events = _add_events(hass, {'test': 'nothing', 'test2': 'something'})
assert len(events) == 1
#assert hass.e.get('test2.recorder') == states[0]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

continue

with session_scope(session=self.get_session()) as session:
dbevent = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still way too difficult. Just add this elif event.event_type == EVENT_TIME_CHANGED::

if event.event_type in self.exclude_t:
    self.queue.task_done()
    continue

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐬 when tests pass.

@balloob balloob merged commit 775d45a into home-assistant:dev May 24, 2017
@amigian74 amigian74 deleted the event_type_filter branch May 29, 2017 11:02
@balloob balloob mentioned this pull request Jun 2, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants