-
Notifications
You must be signed in to change notification settings - Fork 40
[RFC] Explicit entity object discovery, lifetimes, and registration #365
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
Conversation
This PR is "done" architecturally, for the most part. Main changes:
That about covers everything. This is a very, very rough first pass PR and is in not in a state for review beyond architecture changes. |
0f4faef
to
fb3dfd6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #365 +/- ##
==========================================
- Coverage 96.58% 96.40% -0.19%
==========================================
Files 61 61
Lines 9526 9584 +58
==========================================
+ Hits 9201 9239 +38
- Misses 325 345 +20 ☔ View full report in Codecov by Sentry. |
* Improvements to Cover PlatformEntity status methods This aims to address issues in correctly representing the current cover status. - Fixes issue where the movement state instigated by 'go to' commands is not cleared upon completion - Implements movement timeout and previous sate comparison to determine device instigated changes - Removed target position entity attributes (we don't need to restore these) - Fix tests for tilt axis * Test coverage for timeout and device instigated movement * Use common functions for instigating target tracking * Calculate axis states only if their position/target has changed More efficient on devices that frequently report position updates. * Improve debug logging outputs * Use CoverState StrEnum in const for states rather than literals * Readability improvement for _determine_state method * Simplify stop_cover methods * Fix _attr_device_class for WindowCoveringType.Rollershade The previous logic was failing to populate the `_attr_device_class` because WindowCoveringType.Rollershade == 0x00. We should instead check for `is not None`. * Amend tests following shade device_class fix * Include missing ATTR_CURRENT_TILT_POSITION in state property * Docstring updates and use of converter functions for Shade PlatformEntity * Guard against state change when target is equal to current position This prevents ZHA from incorrectly marking the state as opening/closing if the cover is already at its target. This could occur if the cover immediately reported an attribute update after receiving the command. * Add test for dynamic movement timeout * Full test coverage for tilt axis * Remove unused seconds arg from start_movement_timer * Only debug log timer cancellation if timer existed * Refinements to cover property handling - Properties return None when the value not known (per https://developers.home-assistant.io/docs/core/entity/cover/) - Move shade _attr_supported_features out of init - Improvements to common zcl/ha value conversion functions * Remove position tolerance This scenario can be handled using the timeout * Apply pre-commit auto fixes * Handle concurrent movement of lift and tilt axis - Use separate timers for lift and tilt - Add test for concurrent movement state handling * Simplify async_update_state * Robustness and clarity improvements - Clear active transition when setting a new target position - Use properties to abstract from previous position deque mechanism - Consider whether a transition is active when determining state * Clean up determine_state method * Implement recompute_capabilities Per #365 * Apply pre-commit auto fixes * Ensure supported_features is not cached --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
PlatformEntity
objects, among others, rely on implicit "registration" inside of__init__
by mutating a global dictionary that ZHA flushes when creating new devices. This is a bit difficult to work with, in my opinion, and is somewhat preventing zigpy/zigpy#1535 from being implemented.This PR:
on_add
interface to mirroron_remove
and allow for entity object creation to not rely on any sort of global state.Entity.is_supported
(this is mostly a copy/paste of thecreate_platform_entity
logic).gateway.py
.