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

Multiple accounts #26

Merged
merged 46 commits into from
Apr 11, 2022
Merged

Multiple accounts #26

merged 46 commits into from
Apr 11, 2022

Conversation

RogerSelwyn
Copy link
Owner

Enable the usage of multiple O365 accounts

@aaronpowell
Copy link

Giving this branch a whirl and I've hit an error with it starting up, here's the error:

Logger: homeassistant.setup
Source: helpers/network.py:172
First occurred: 21:58:30 (1 occurrences)
Last logged: 21:58:30

Error during setup of component o365
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
    result = await task
  File "/config/custom_components/o365/__init__.py", line 65, in async_setup
    _setup_account(hass, account, conf_type)
  File "/config/custom_components/o365/__init__.py", line 90, in _setup_account
    _request_authorization(hass, account_conf, account, account_name, conf_type)
  File "/config/custom_components/o365/__init__.py", line 189, in _request_authorization
    callback_url = _get_callback_url(hass, alt_config)
  File "/config/custom_components/o365/__init__.py", line 211, in _get_callback_url
    return f"{get_url(hass, prefer_external=True)}{AUTH_CALLBACK_PATH}"
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 133, in get_url
    request_host = _get_request_host()
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 172, in _get_request_host
    raise NoURLAvailableError
homeassistant.helpers.network.NoURLAvailableError

Config:

accounts:
    - account_name: Aaron
      client_id: !secret o365_aaron_client_id
      client_secret: !secret o365_aaron_client_secret
      enable_update: True
      email_sensor:
        - name: Aaron's inbox
          folder: Inbox
          max_items: 10
          is_unread: True
          download_attachments: False
      status_sensors:
        - name: "Aaron's Teams status"

I know the client_id/client_secret are valid (I was using them before the upgrade to 3.0.0a8).

Thoughts on what that might be, or how to debug further?

@RogerSelwyn
Copy link
Owner Author

Giving this branch a whirl and I've hit an error with it starting up, here's the error:

Logger: homeassistant.setup
Source: helpers/network.py:172
First occurred: 21:58:30 (1 occurrences)
Last logged: 21:58:30

Error during setup of component o365
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
    result = await task
  File "/config/custom_components/o365/__init__.py", line 65, in async_setup
    _setup_account(hass, account, conf_type)
  File "/config/custom_components/o365/__init__.py", line 90, in _setup_account
    _request_authorization(hass, account_conf, account, account_name, conf_type)
  File "/config/custom_components/o365/__init__.py", line 189, in _request_authorization
    callback_url = _get_callback_url(hass, alt_config)
  File "/config/custom_components/o365/__init__.py", line 211, in _get_callback_url
    return f"{get_url(hass, prefer_external=True)}{AUTH_CALLBACK_PATH}"
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 133, in get_url
    request_host = _get_request_host()
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 172, in _get_request_host
    raise NoURLAvailableError
homeassistant.helpers.network.NoURLAvailableError

Config:

accounts:
    - account_name: Aaron
      client_id: !secret o365_aaron_client_id
      client_secret: !secret o365_aaron_client_secret
      enable_update: True
      email_sensor:
        - name: Aaron's inbox
          folder: Inbox
          max_items: 10
          is_unread: True
          download_attachments: False
      status_sensors:
        - name: "Aaron's Teams status"

I know the client_id/client_secret are valid (I was using them before the upgrade to 3.0.0a8).

Thoughts on what that might be, or how to debug further?

Do you use alt_auth_flow as False (or not present) previously? This is it failing to get an external url from HA as configured in the settings of your HA instance.

@RogerSelwyn
Copy link
Owner Author

Do you use alt_auth_flow as False (or not present) previously? This is it failing to get an external url from HA as configured in the settings of your HA instance.

I can't even force my dev instance to generate that error, so there is something weird with your HTTP setup on your HA instance.

@RogerSelwyn
Copy link
Owner Author

Looks like you are using an older version of HA than I am which could be why I can't get the error (I can see they have made changes recently), but could be worth just using alternate path of authentication if you can't figure out what is wrong with your http config.

@aaronpowell
Copy link

Do you use alt_auth_flow as False (or not present) previously? This is it failing to get an external url from HA as configured in the settings of your HA instance.

That's it - I forgot that I'd used that previously (must have removed it from the config before my last git push).

Added in and it works now, thanks - I'll see about testing multiple accounts now

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 11, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.02%.

Quality metrics Before After Change
Complexity 3.22 ⭐ 3.07 ⭐ -0.15 👍
Method Length 62.94 🙂 61.27 🙂 -1.67 👍
Working memory 16.40 ⛔ 16.30 ⛔ -0.10 👍
Quality 70.21% 🙂 71.23% 🙂 1.02% 👍
Other metrics Before After Change
Lines 1458 1723 265
Changed files Quality Before Quality After Quality Change
custom_components/o365/init.py 72.37% 🙂 75.13% ⭐ 2.76% 👍
custom_components/o365/calendar.py 77.10% ⭐ 77.85% ⭐ 0.75% 👍
custom_components/o365/const.py 33.34% 😞 33.34% 😞 0.00%
custom_components/o365/notify.py 77.38% ⭐ 76.74% ⭐ -0.64% 👎
custom_components/o365/sensor.py 79.18% ⭐ 81.36% ⭐ 2.18% 👍
custom_components/o365/utils.py 75.72% ⭐ 76.31% ⭐ 0.59% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
custom_components/o365/utils.py add_call_data_to_event 12 🙂 189 😞 8 🙂 52.03% 🙂 Try splitting into smaller methods
custom_components/o365/calendar.py O365CalendarData._get_root_event 19 😞 86 🙂 7 🙂 60.41% 🙂 Refactor to reduce nesting
custom_components/o365/sensor.py O365QuerySensor.__init__ 2 ⭐ 160 😞 9 🙂 61.96% 🙂 Try splitting into smaller methods
custom_components/o365/calendar.py O365CalendarEventDevice.async_update 6 ⭐ 134 😞 7 🙂 65.38% 🙂 Try splitting into smaller methods
custom_components/o365/init.py do_setup 1 ⭐ 90 🙂 12 😞 65.77% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@RogerSelwyn RogerSelwyn merged commit c91dda1 into master Apr 11, 2022
@RogerSelwyn RogerSelwyn linked an issue Apr 11, 2022 that may be closed by this pull request
@RogerSelwyn RogerSelwyn deleted the multiple-accounts branch April 17, 2022 15:01
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.

Multiple account support
3 participants