-
Notifications
You must be signed in to change notification settings - Fork 41
Clean up number
platform
#442
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
For Core, this should get rid of the diff --git a/homeassistant/components/zha/number.py b/homeassistant/components/zha/number.py
index 567e2a5b37a..401ffc39651 100644
--- a/homeassistant/components/zha/number.py
+++ b/homeassistant/components/zha/number.py
@@ -46,17 +46,6 @@ async def async_setup_entry(
class ZhaNumber(ZHAEntity, RestoreNumber):
"""Representation of a ZHA Number entity."""
- @property
- def name(self) -> str | UndefinedType | None:
- """Return the name of the number entity."""
- if (description := self.entity_data.entity.description) is None:
- return super().name
-
- # The name of this entity is reported by the device itself.
- # For backwards compatibility, we keep the same format as before. This
- # should probably be changed in the future to omit the prefix.
- return f"{super().name} {description}"
-
@property
def native_value(self) -> float | None:
"""Return the current value.""" |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #442 +/- ##
==========================================
+ Coverage 96.88% 96.92% +0.03%
==========================================
Files 63 63
Lines 10404 10362 -42
==========================================
- Hits 10080 10043 -37
+ Misses 324 319 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@property | ||
def state(self) -> dict[str, Any]: | ||
"""Return the state of the entity.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can now be removed from NumberConfigurationEntity
, as it's already implemented in BaseNumber
.
@@ -119,59 +96,92 @@ def state(self) -> dict[str, Any]: | |||
response["state"] = self.native_value | |||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda related: Should we include the min/max value attributes (and possibly others) in state
?
state
is only really important for maybe_emit_state_changed_event
. If only the min/max values were to change, the method would prevent an update from going through, unless native_value
is also changed at the same time.
This would matter if we were to "dynamically" call recompute_capabilities
(i.e. after sw updates) in the future.
For the analog input entity, if min_present_value
/max_present_value
ZCL attributes were updated at runtime before these changes (whilst native_value
is also changed due to what I mentioned above), the update of the min/max values would populate to HA as well.
Looking at this now, it would only happen after recompute_capabilities
is called, but that's not done for a simple attribute change, so we always prevent min/max changes for analog input entities going to HA now, I think.
In reality, I doubt any devices/quirks exposing an AnalogInput
cluster did this before, so it might not be an issue.
The same would also apply for the entities that useZCLHeatSetpointLimitEntity
(i.e. MaxHeatSetpointLimit
and MinHeatSetpointLimit
), as they overrode the methods HA called for min/max values, when HA state is written. Now it's also only done in recompute_capabilities
, so not possible "at runtime" (after the device is initialized).
Doubt that matters as well though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's true. I think we maybe could emit a new event when capabilities change. I'd like to eventually figure out
info_object
in preparation for the client/server split to allow devices to emit both types of updates in a more type-checked manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good, but note the comment below about changing the discovery for v2 quirks to NumberConfigurationEntity
.
To But we should update the discovery for quirks v2 to always initialize zha/zha/application/discovery.py Lines 192 to 205 in 4afffe1
Maybe we should also rename Actually, we should be able to completely remove the |
bd10579
to
947fdca
Compare
Good point. I've implemented the above change and will make a follow-up to remove the unnecessary entity type handling in the mapping. |
Should resolve zigpy/zha-device-handlers#3821 (comment).
BaseNumber
entity, with subclasses implementingnative_value
andasync_set_native_value
.recompute_capabilities()
._init_from_quirks_metadata
is implemented onNumberConfigurationEntity
. Should we move it up in the hierarchy?fallback_name
instead ofdescription
for standardization.