Add esphome sensor tests (#95077)

This commit is contained in:
J. Nick Koston 2023-06-22 21:02:47 +02:00 committed by GitHub
parent c7f2dab13c
commit 66b2214c55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 183 additions and 4 deletions

View file

@ -95,9 +95,7 @@ class EsphomeSensor(EsphomeEntity[SensorInfo, SensorState], SensorEntity):
def native_value(self) -> datetime | str | None:
"""Return the state of the entity."""
state = self._state
if math.isnan(state.state):
return None
if state.missing_state:
if math.isnan(state.state) or state.missing_state:
return None
if self._attr_device_class == SensorDeviceClass.TIMESTAMP:
return dt_util.utc_from_timestamp(state.state)