pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Attributes with type datetime casts to str after reboot on persistent sensors

Open StarkJohan opened this issue 2 years ago • 2 comments

I have a sensor in the pyscript domain with a dict with a number of elements as attributes in the form: <class 'datetime.datetime'>: <class 'float'> <class 'datetime.datetime'>: <class 'float'> e.g.: 2023-04-05T00:00:00+02:00: 2.1957 2023-04-05T01:00:00+02:00: 2.2242 and so on...

After HA reboots, state.persist works fine for the float type but the datetime type is casted as str after reboot. "Looks" the same but is no longer a datetime object.

I expected the type for datetime to be preserved after reboot. I can of course handle this on startup but that's just a nasty workaround :-)

HA Supervised, Docker on Debian 11. Home Assistant 2023.3.6 Supervisor 2023.03.3 Frontend 20230309.1

StarkJohan avatar Apr 05 '23 09:04 StarkJohan

Issue remains (as expected) on pyscript 1.4.0 and Supervisor 2023.04.0

StarkJohan avatar Apr 05 '23 19:04 StarkJohan

Looking at the code I see that this might be because of how the HA class RestoreStateData works. I don't fully understand what is going on but maybe this isn't even a pyscript issue?

StarkJohan avatar Apr 05 '23 19:04 StarkJohan