Fix issue caused by restoring datetime value from mobile app (#77462)

* Only pass strings to dt_util.parse_datetime()

* Update homeassistant/components/mobile_app/sensor.py

* Update sensor.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Doug Hoffman 2022-08-29 06:19:44 -04:00 committed by GitHub
parent 8c41d0d3d7
commit 01c200e11d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,6 +110,9 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor):
SensorDeviceClass.DATE, SensorDeviceClass.DATE,
SensorDeviceClass.TIMESTAMP, SensorDeviceClass.TIMESTAMP,
) )
# Only parse strings: if the sensor's state is restored, the state is a
# native date or datetime, not str
and isinstance(state, str)
and (timestamp := dt_util.parse_datetime(state)) is not None and (timestamp := dt_util.parse_datetime(state)) is not None
): ):
if self.device_class == SensorDeviceClass.DATE: if self.device_class == SensorDeviceClass.DATE: