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
Fix availability for GIOS index sensors #113021
Conversation
sensor_data = getattr(self.coordinator.data, self.entity_description.key) | ||
available = super().available and bool(sensor_data) |
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.
bool(sensor_data)
will be False
if the value is 0. Should you check against None
instead ?
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.
sensor_data
could be a Sensor
object or None
, it couldn't be 0
https://github.com/bieniu/gios/blob/d836f0c048bf2eb2847559467c5b05f264c42641/gios/model.py#L20
|
||
# Sometimes the API returns sensor data without indexes | ||
if self.entity_description.subkey: | ||
if self.entity_description.subkey and available: | ||
return available and bool(sensor_data.index) |
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.
An index can also be 0 ?
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.
index
is a non-empty string (good
, very_good
, moderate
, etc.) or None
https://github.com/bieniu/gios/blob/d836f0c048bf2eb2847559467c5b05f264c42641/gios/model.py#L12
Thanks! :) |
* Fix availability for index sensors * Improve test_availability() --------- Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
* Fix availability for index sensors * Improve test_availability() --------- Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
Breaking change
Improves availability to avoid
AttributeError
when measurement station suddenly does not return data for one sensor.Proposed change
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: