Skip to content

Commit

Permalink
Re-organise code
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed May 1, 2023
1 parent 64a29a5 commit a6e3e82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 10 additions & 1 deletion custom_components/o365/repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.repairs import RepairsFlow # ConfirmRepairFlow,
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.network import get_url

from .const import (
AUTH_CALLBACK_NAME,
AUTH_CALLBACK_PATH_ALT,
AUTH_CALLBACK_PATH_DEFAULT,
CONF_ACCOUNT,
CONF_ACCOUNT_CONF,
CONF_ACCOUNT_NAME,
Expand All @@ -28,7 +30,6 @@
build_minimum_permissions,
build_requested_permissions,
build_token_filename,
get_callback_url,
validate_permissions,
)

Expand Down Expand Up @@ -185,3 +186,11 @@ async def get(self, request):
headers={"content-type": "text/html"},
text="<script>window.close()</script>This window can be closed",
)


def get_callback_url(hass, alt_config):
"""Get the callback URL."""
if alt_config:
return f"{get_url(hass, prefer_external=True)}{AUTH_CALLBACK_PATH_ALT}"

return AUTH_CALLBACK_PATH_DEFAULT
11 changes: 0 additions & 11 deletions custom_components/o365/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
from bs4 import BeautifulSoup
from homeassistant.const import CONF_ENABLED, CONF_NAME
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.network import get_url
from homeassistant.util import dt
from voluptuous.error import Error as VoluptuousError

from O365.calendar import Attendee # pylint: disable=no-name-in-module)

from .const import (
AUTH_CALLBACK_PATH_ALT,
AUTH_CALLBACK_PATH_DEFAULT,
CONF_ACCOUNT_NAME,
CONF_AUTO_REPLY_SENSORS,
CONF_CAL_ID,
Expand Down Expand Up @@ -541,14 +538,6 @@ def check_file_location(hass, filepath, newpath):
shutil.move(oldpath, newpath)


def get_callback_url(hass, alt_config):
"""Get the callback URL."""
if alt_config:
return f"{get_url(hass, prefer_external=True)}{AUTH_CALLBACK_PATH_ALT}"

return AUTH_CALLBACK_PATH_DEFAULT


def build_entity_id(hass, name):
"""Build and entity ID."""
return async_generate_entity_id(
Expand Down

0 comments on commit a6e3e82

Please sign in to comment.