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 GitHub
parent fced9eb4b5
commit d367bc63f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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
)