Skip to content

Commit

Permalink
Fix issue with authentication I/O within the event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Sep 7, 2021
1 parent 7631c0a commit 2dfa785
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/o365/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Main initialisation code."""
import logging
from functools import partial

from homeassistant.components.http import HomeAssistantView
from homeassistant.core import callback
Expand Down Expand Up @@ -35,7 +36,7 @@
_LOGGER = logging.getLogger(__name__)


def setup(hass, config):
async def async_setup(hass, config):
"""Set up the O365 platform."""
validate_permissions()
conf = config.get(DOMAIN, {})
Expand Down Expand Up @@ -137,7 +138,7 @@ def __init__(self, config, add_devices, account, state, callback_url, hass):
self.configurator = self._hass.components.configurator

@callback
def get(self, request):
async def get(self, request):
"""Receive authorization token."""
from aiohttp import web_response

Expand All @@ -149,7 +150,9 @@ def get(self, request):
headers={"content-type": "text/html"},
text="<script>window.close()</script>Error, the originating url does not seem to be a valid microsoft redirect",
)
self.account.con.request_token(url, state=self.state, redirect_uri=self.callback)
await self._hass.async_add_executor_job(
partial(self.account.con.request_token, url, state=self.state, redirect_uri=self.callback)
)
domain_data = self._hass.data[DOMAIN]
do_setup(self._hass, self.config, self.account)
self.configurator.async_request_done(domain_data)
Expand Down

0 comments on commit 2dfa785

Please sign in to comment.