Fix CO2Signal having unknown data (#67453)

This commit is contained in:
Franck Nijhof
2022-03-02 01:06:36 +01:00
committed by GitHub
parent dc10a4f0bb
commit 133add6100

View File

@@ -92,14 +92,15 @@ class CO2Sensor(update_coordinator.CoordinatorEntity[CO2SignalResponse], SensorE
def available(self) -> bool:
"""Return True if entity is available."""
return (
super().available
and self.coordinator.data["data"].get(self._description.key) is not None
super().available and self._description.key in self.coordinator.data["data"]
)
@property
def native_value(self) -> StateType:
"""Return sensor state."""
return round(self.coordinator.data["data"][self._description.key], 2) # type: ignore[misc]
if (value := self.coordinator.data["data"][self._description.key]) is None: # type: ignore[misc]
return None
return round(value, 2)
@property
def native_unit_of_measurement(self) -> str | None: