You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue with 'await' after upgrade from 1.6.1 to 1.6.3 #712
I have the following code to get the history data from recorder statistics in Home Assistant. The code stopped working after upgrading to 1.6.3 from 1.6.1. I also tested with 1.6.2 and the issue also occurs.
fromdatetimeimportdatetime, timedeltafromhomeassistant.components.recorderimporthistoryfromhomeassistant.components.recorderimportget_instancefromhomeassistant.components.recorder.statisticsimport (
statistics_during_period,
)
fromcalendarimportmonthrangeyear=2025month=2defget_full_charge_days(year, month):
# First day of the given month at 00:00:00first_day_of_month=datetime(year, month, 1, 0, 0, 0)
# Get the last day of the monthlast_day=monthrange(year, month)[1]
# Last moment of the current monthlast_day_of_month=datetime(year, month, last_day, 23, 59, 59)
sensor_name="sensor.solax_battery_capacity"sensor_history=awaitget_instance(hass).async_add_executor_job(
lambdafd=first_day_of_month, ld=last_day_of_month, sensor=sensor_name: statistics_during_period(
hass=hass,
start_time=fd,
end_time=ld,
statistic_ids={sensor},
period="day",
units=None,
types={"max"}
)
)
return [datetime.fromtimestamp(entry["start"]).dayforentryinsensor_history[sensor_name] ifentry["max"] >=90]
data=get_full_charge_days(year, month)
log.debug(data)
log.debug(len(data))
The error is: Exception in <jupyter_0> line 47:
return [datetime.fromtimestamp(entry["start"]).day for entry in sensor_history[sensor_name] if entry["max"] >= 90] TypeError: '_asyncio.Future' object is not subscriptable
It seems like the Future returned from async_add_executor_job can't be awaited to a result. The sensor_history returned from the await is still a Future instance.
Activity
dmamelin commentedon Apr 3, 2025
@craigbarratt I think the change in ast_await should help, but I can’t verify it yet:
craigbarratt commentedon Apr 5, 2025
@stopcoder can you confirm whether @dmamelin's proposed fix solves your problem?
stopcoder commentedon Apr 6, 2025
My script works again after patching the line with the given code in
eval.py.fix await for futures; see #712
craigbarratt commentedon Apr 13, 2025
Released 1.6.4 with this fix.