Skip to content

Add entity glob matching support to history#40387

Merged
balloob merged 3 commits intohome-assistant:devfrom
bdraco:add_glob_support_to_history
Sep 28, 2020
Merged

Add entity glob matching support to history#40387
balloob merged 3 commits intohome-assistant:devfrom
bdraco:add_glob_support_to_history

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Sep 21, 2020

I'm adding this because this is the implementation used in logbook as well, and it
doesn't actual work as documented (details below). history happens to get this
for free when we fix logbook.

Proposed change

Add entity glob matching support to history

The logbook and history docs are currently wrong about the include/exclude matching as its done in sql and uses a different algorithm. The tests were not end-to-end tests and only testing _keep_event which didn't include the sql part.

It actually works like this:

No includes or excludes - pass all entities
Includes, no excludes - only include specified entities
Excludes, no includes - only exclude specified entities
Both includes and excludes - include specified entities and exclude specified entities from the remaining.

Logbook is actually using both algorithms so the behavior is undefined when mixing excludes and includes so it has a broken entity globs implementation where only excludes work (in some cases) even though its documented as supporting both. #40075 fixes that, and after this PR history and logbook will both use the same method.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration (history) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@bdraco
Copy link
Member Author

bdraco commented Sep 21, 2020

We can remove the extra check in logbook


    if event.event_type == EVENT_STATE_CHANGED:
        return entities_filter is None or entities_filter(event.entity_id)

after this

@bdraco bdraco force-pushed the add_glob_support_to_history branch from f467ce6 to f640e17 Compare September 22, 2020 16:26
@balloob balloob merged commit a19e10c into home-assistant:dev Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants