* Initial "group members assume state" implementation for ZHA
* Remove left-over debug flag (where polling was disabled)
* Implement _send_member_assume_state_event() method and also use after turn_off
* Only assume updated arguments from service call to group
* Make code more readable and change checks slightly
* Move "send member assume state" events to LightGroup on/off calls
* Include new config option in tests
* Check that member is available before updating to assumed state
* Lower "update group from child delay" for debouncer to basically 0 when using assumed member state
* Allow "child to group" updates regardless of config option
This is not needed, as group members will not update their state, as long as they're transitioning. (If a group transitions, it also sets its members to transitioning mode)
This fixes multiple issues. Previously, the state of a group was completely wrong when:
- turn on group with 10 second transition
- turn on members individually
- turn off members individually
- group state would not update correctly
* Move "default update group from child delay" constant
* Change to new constant name in test
* Also update fan test to new constant name
* Decrease "update group from child delay" to 10ms
In my testing, 0.0 also works without any issues and correctly de-bounces child updates when using the "assume state option".
This is just for avoiding multiple state changes when changing the group -> children issue individual updates.
With 2 children in a group and delay 0, both child updates only cause one group re-calculation and state change.
0.01 (10ms) should be plenty for very slow systems to de-bounce the update (and in the worst case, it'll cause just another state change but nothing breaks)
* Also implement "assuming state" for effect
Not sure if anybody even uses this, but this one is a bit special because the effect is always deactivated if it's not provided in the light.turn_on call.
* Move shortened delay for "assuming members" to a constant
* Add basic test to verify that group members assume on/off state
* Move _assume_group_state function declaration out of async_added_to_hass
* Fix rare edge-case when rapidly toggling lights and light groups at the same time
This prevents an issue where either the group transition would unset the transition flag or the single light would unset the group transition status midst-transition.
Note: When a new individual transition is started, we want to unset the group flag, as we actually cancel that transition.
* Check that effect list exists, add return type
* Re-trigger CI due to timeout
* Increase ASSUME_UPDATE_GROUP_FROM_CHILD_DELAY slightly
The debouncer is used when updating group member states either by assuming them (in which case we want to barely have any delay), or between the time we get the results back from polling (where we want a slightly longer time).
As it's not easily possible to distinguish if a group member was updated via assuming the state of the group or by the polling that follows, 50 ms seems to be a good middle point.
* Add debug print for when updating group state
* Fix issues with "off brightness" when switching between group/members
This fixes a bunch of issues with "off brightness" and passes it down to the members correctly.
For example, if a light group is turned off with a transition (so bulbs get their level set to 1), this will also set the "off brightness" of all individual bulbs to the last level that they were at.
(It really fixes a lot of issues when using the "member assume group state" option. It's not really possible to fix them without that.)
Furthermore, issues where polling was previously needed to get the correct state after "playing with transitions", should now get be resolved and get correct state when using the "members assume group state" option.
Note: The only case which still can't be fixed is the following:
If individual lights have off_with_transition set, but not the group, and the group is then turned on without a level, individual lights might fall back to brightness level 1 (<- at least now shows correctly in UI even before polling).
Since all lights might need different brightness levels to be turned on, we can't use one group call. But making individual calls when turning on a ZHA group would cause a lot of traffic and thereby be counter-productive.
In this case, light.turn_on should just be called with a level (or individual calls to the lights should be made).
Another thing that was changed is to reset off_with_transition/off_brightness for a LightGroup when a member is turned on (even if the LightGroup wasn't turned on using its turn_on method).
off_with_transition/off_brightness for individual bulbs is now also turned off when a light is detected to be on during polling.
Lastly, the waiting for polled attributes could previously cause "invalid state" to be set (so mid-transition levels).
This could happen when group and members are repeatedly toggled at similar times. These "invalid states" could cause wrong "off brightness" levels if transitions are also used.
To fix this, we check after waiting for the polled attributes in async_get_state to see if a transition has started in the meanwhile. If so, the values can be discarded. A new poll will happen later and if using the "members assume group state" config option, the values should already be correct before the polling.
* Enable "group members assume state" config option by default
The config tests are also updated to expect the config option be enabled by default.
For all tests, the config option is generally disabled though:
There are only two group related tests. The one that tests this new feature overrides the config option to be enabled anyway.
The other tests works in a similar way but also "sends" attribute reports, so we want to disable the feature for that test.
(It would also run with it enabled (if the correct CHILD_UPDATE value is patched), but then it would test the same stuff as the other test, hence we're disabling the config option for that test.)
* Make unit tests pass
* Flip response type check to not rely on it being a list
https://github.com/zigpy/zigpy/pull/716#issuecomment-1025236190
* Bump zigpy and quirks versions to ZCLR8 releases
* Fix renamed zigpy cluster attributes
* Handle the default response for ZLL `get_group_identifiers`
* Add more error context to `stage failed` errors
* Fix unit test returning lists as ZCL request responses
* Always load quirks when testing ZHA
* Bump zha-quirks to 0.0.69
* Replace ZHA tests FakeDevice
* Refactor ZHA tests to use zigpy devices and endpoints
* Use common consts for zigpy device mocks
Use the same dict key names for device signature mocks as zha quirks.
* Use const for test device list
* Update tests/components/zha/common.py
* Delay ZHA group updates to ensure all members are updated first
After turning off a group, when the first device reports "off", the
other devices may still be "on". If HA processes the group state update
quickly enough, the group will see that some devices are on, so the
state of the group will revert back to "on", and then "off" when the
remaining devices all report "off". That would cause the UI toggle to go
back and forward quickly, and automations that trigger with "state: on"
to fire when the user turns the group off.
This PR fixes that by delaying the group state update, giving time for
all the devices to report their states first.
* Fix zha group tests
* Reorder sleeping.
* Update tests/components/zha/common.py
Co-authored-by: Alexei Chetroi <lexoid@gmail.com>
* start implementation
* handle members correctly
* fix group member info
* align groupable devices with group members
* handle group endpoint adding and removing
* update add group
* update group and group member
* update create group
* remove domain check
* update test
* remove temporary 2nd groupable device api
* update test
* rename validator - review comment
* fix test that was never running
* additional testing
* fix coordinator descriptors
* remove check that was done twice
* update test
* Use AsyncMock()
Co-authored-by: Alexei Chetroi <lexoid@gmail.com>
* start of fan groups
* update fan classes
* update group entity domains
* add set speed
* update discovery for multiple entities for groups
* add fan group entity tests
* cleanup const
* cleanup entity_domain usage
* remove bad super call
* remove bad update line
* fix set speed on fan group
* change comparison
* pythonic list
* discovery guards
* Update homeassistant/components/zha/core/discovery.py
Co-Authored-By: Alexei Chetroi <lexoid@gmail.com>
Co-authored-by: Alexei Chetroi <lexoid@gmail.com>
* Add support for DoorLock cluster
* Add test for zha lock
* Change lock_state report to REPORT_CONFIG_IMMEDIATE
* Update channel command wrapper to return the entire result
This allows for return values other than result[1]
* Fix tests
* Fix lint
* Update DoorLock test to work with updated zigpy schema
* Fix lint
* Fix unlock test
* start test setup
test cleanup
test deps
update switch test
actually update test deps
cleanup and remove switch from coveragerc
comment
refactor to use fixtures and shared components
lint
* remove availability part that isn't in zha yet
* review comments and cleanup
* review comments
* add switch back unil post reorg merge