Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor group state logic #116318

Merged
merged 11 commits into from May 2, 2024
Merged

Refactor group state logic #116318

merged 11 commits into from May 2, 2024

Conversation

jbouwh
Copy link
Contributor

@jbouwh jbouwh commented Apr 27, 2024

Proposed change

This PR replaces #116116, which was based on #115866, but this change was reverted.

Needs #116317 to be merged first.
Needed by #111968 (Add lock open state).

Refactors the way group states are processed. There are no functional changes.

With #116317 on states were passed as a tuple, allowing to assign the first state as the default on state.

To allow additional on states that are also used for other platforms we need to group the on/off state state pairs to be able to check for a single use of a state pair.

To handle groups of groups some additional logic was added, as we need to know if a group uses single state group. E.g. groups of locks using lock and unlocked. The default state group is on / off

The logic as it is expected to work

Multipe domains with a single shared on / off state can be combined as they are have the same group state type, e.g.:

  • person and device_tracker: home and not_home
  • switch and light: ON and OFF

In case a domain has multiple on or off states we use the default on state, e.g.:

  • lock will have unlocked and open as ON state. The group on state will always be unlocked

So each group state type has its own consistent ON and OFF state.

If entities of different group state types are combined, the group state default to on/off

Example:

In case a lock entities are combined with other domain entities, e.g. cover, then the group status will be on or off.

Some group state types when entities of multiple domains are combined:

  • on/off: switch, light, vacuum, siren, climate etc.
  • zone: person, device_tracker etc.
  • open/closed: cover`
  • unlocked/locked: lock. Also open is an ON state, but in a group the default ON state (unlocked) will be used.

Groups will always be consistent on and off state, so:

  • when lock and cover are combined, and the group is ON, the status will be ON, and OFF if the group is OFF
  • when person and device_tracker are combined, and the group is ON, the status will be homeand not_home if the group is OFF

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@jbouwh jbouwh marked this pull request as ready for review April 28, 2024 14:35
@jbouwh jbouwh requested a review from a team as a code owner April 28, 2024 14:35
@jbouwh jbouwh marked this pull request as draft April 28, 2024 14:46
@jbouwh
Copy link
Contributor Author

jbouwh commented Apr 28, 2024

Drafted till some more test coverage is added.

@jbouwh jbouwh marked this pull request as ready for review April 28, 2024 19:18
@bdraco bdraco self-requested a review April 28, 2024 20:07
@jbouwh jbouwh marked this pull request as draft April 28, 2024 21:50
@jbouwh jbouwh marked this pull request as ready for review April 29, 2024 08:32
@bdraco
Copy link
Member

bdraco commented Apr 29, 2024

Pushing this to production now

@bdraco
Copy link
Member

bdraco commented Apr 29, 2024

Tested on production. Everything seems the same and working

Copy link
Member

@gjohansson-ST gjohansson-ST left a comment

Choose a reason for hiding this comment

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

Thanks @jbouwh 👍
As mentioned on discord I would still like to see a test for vacuum and also add on for lock later on it's PR

@jbouwh
Copy link
Contributor Author

jbouwh commented May 2, 2024

Thanks all for reviewing!

@jbouwh jbouwh merged commit 41b6886 into dev May 2, 2024
38 checks passed
@jbouwh jbouwh deleted the group-state-rework branch May 2, 2024 19:55
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2024
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.

None yet

4 participants