-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,11 +230,11 @@ def native_value(self) -> StateType: | |
@property | ||
def available(self) -> bool: | ||
"""Return if entity is available.""" | ||
available = super().available | ||
sensor_data = getattr(self.coordinator.data, self.entity_description.key) | ||
available = super().available and bool(sensor_data) | ||
|
||
# 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return available and bool(sensor_data) | ||
return available |
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 beFalse
if the value is 0. Should you check againstNone
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 aSensor
object orNone
, it couldn't be0
https://github.com/bieniu/gios/blob/d836f0c048bf2eb2847559467c5b05f264c42641/gios/model.py#L20