Skip to content

Commit

Permalink
Fix KeyError error when fetching sensors (Airthings) (#115844)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaStrada authored and frenck committed Apr 23, 2024
1 parent 32f82d4 commit 13ed2d2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions homeassistant/components/airthings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ def __init__(
def native_value(self) -> StateType:
"""Return the value reported by the sensor."""
return self.coordinator.data[self._id].sensors[self.entity_description.key] # type: ignore[no-any-return]

@property
def available(self) -> bool:
"""Check if device and sensor is available in data."""
return (
super().available
and self.entity_description.key in self.coordinator.data[self._id].sensors
)

0 comments on commit 13ed2d2

Please sign in to comment.