-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RuntimeWarning: coroutine 'OctopusIntelligentSystem.start' was never awaited #38
Conversation
@@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): | |||
) | |||
|
|||
try: | |||
await hass.async_add_executor_job(octopus_system.start) | |||
await octopus_system.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for HASS log messages such as:
2024-02-25 15:05:06.334 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.12/asyncio/base_events.py:1959: RuntimeWarning: coroutine 'OctopusIntelligentSystem.start' was never awaited
handle = self._ready.popleft()
Or:
2024-02-15 19:03:02.926 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.12/asyncio/base_events.py:1975: RuntimeWarning: coroutine 'OctopusIntelligentSystem.start' was never awaited
handle = None # Needed to break cycles when an exception occurs.
The start()
method was simply not being called. async_add_executor_job()
creates a new thread to run the given function, but it does not expect the function to be asynchronous and does not await
it. When not awaited, asynchronous functions like start()
are not executed.
@@ -191,7 +191,7 @@ async def __async_cancel_boost_charge(self, session, account_id: str): | |||
result = await session.execute(query, variable_values=params, operation_name="deleteBoostCharge") | |||
return result['deleteBoostCharge'] | |||
|
|||
async def __async_get_accounts(session): | |||
async def __async_get_accounts(self, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start()
function was not being executed, as it wasn’t awaited. When start()
is executed, another issue is uncovered: __async_get_accounts() takes 1 positional argument but 2 were given
2024-02-25 23:25:02.662 ERROR (MainThread) [custom_components.octopus_intelligent.octopus_intelligent_system] Authentication failed : OctopusEnergyGraphQLClient.__async_get_accounts() takes 1 positional argument but 2 were given. You may need to check your token or create a new app in the gardena api and use the new token.
d36f405
to
7d6bebf
Compare
Issue #28 had already been closed as “hopefully fixed”, but it remained. This PR fixes that issue and another issue that got uncovered by the fix.