Fix KeyError error when fetching sensors (Airthings) (#115844)

This commit is contained in:
Ståle Storø Hauknes 2024-04-23 15:53:31 +02:00 committed by Franck Nijhof
parent 32f82d480f
commit 13ed2d2919
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3

View file

@ -157,3 +157,11 @@ class AirthingsHeaterEnergySensor(
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
)