Inside an integration I use homeassistant.components.recorder.statistics.get_last_statistics
like this:
last_inserted_stat = await get_instance(
self.hass
).async_add_executor_job(
get_last_statistics,
self.hass,
1,
'sensor.xxx',
True,
{"sum", "state"},
)
This returns something like this:
defaultdict(<class 'list'>, {'sensor.xxx': [{'start': 1677708000.0, 'end': 1677711600.0, 'state': 0.071, 'sum': 483.90700000000027}]})
Up to HA core 2022.12 you would get a str
as the start
and end
date. Then up to 2023.3 a datetime.datetime
object was returned. And now it is a float
- corresponding to the timestamp in UTC.
With all these changes, I fear the integration will break with every release. Do I have to call it in a different way to always get a datetime? Or is there a function that transforms it always into a datetime, no matter what is returned?