Assign _attr_* fields rather than overriding properties to return custom field values#62
Draft
MarijnS95 wants to merge 5 commits intoniltrip:mainfrom
Draft
Assign _attr_* fields rather than overriding properties to return custom field values#62MarijnS95 wants to merge 5 commits intoniltrip:mainfrom
_attr_* fields rather than overriding properties to return custom field values#62MarijnS95 wants to merge 5 commits intoniltrip:mainfrom
Conversation
…ate-class-from-entity-key
_attr_* fields rather than overriding properties to return custom field values
MarijnS95
commented
Feb 1, 2026
| self._unit = getattr(endpoint, "unit", None) | ||
| ( | ||
| self._attr_device_class, | ||
| self._attr_native_unit_of_measurement, |
Author
There was a problem hiding this comment.
Drive-by fix: afaik SensorEntity shouldn't set unit_of_measurement but native_unit_of_measurement. That way HASS can automatically convert to the unit of preference by the user (i.e. Celsius to Fahrenheit).
Of course, we should check in the JSON (or otherwise) if the native unit that the EcoFlow device returns is always Celsius, but that's strictly for another issue.
Collaborator
|
@MarijnS95 some minor changes are needed to make Lint / Ruff happy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #60, #61 (but I can rebase this off, depending on the order you want to accept/merge things)
The default property implementations for
EntityandSensorEntityreturn the_attr_*fields. Hence it is unnecessary to craft our own fields only to return them out of overridden property getters; we should instead directly assign them toself._attr_*in__init__().https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/entity.py
https://github.com/home-assistant/core/blob/dev/homeassistant/components/sensor/__init__.py