Skip to content
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

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

pdcastro
Copy link
Collaborator

@pdcastro pdcastro commented Mar 3, 2024

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.

@@ -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()
Copy link
Collaborator Author

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):
Copy link
Collaborator Author

@pdcastro pdcastro Mar 3, 2024

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.

@pdcastro pdcastro marked this pull request as ready for review March 3, 2024 18:22
@pdcastro pdcastro merged commit 9dc2970 into megakid:main Mar 15, 2024
2 checks passed
@pdcastro pdcastro deleted the issue_28_start_never_awaited branch March 15, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants