RogerSelwyn / O365-HomeAssistant

Office 365 integration for Home Assistant
MIT License
195 stars 15 forks source link

Cannot enable the chat related services to send Teams messages #222

Closed pantherale0 closed 4 months ago

pantherale0 commented 5 months ago

Hi,

I'm trying to link my personal Office 365 account (M365 Business Premium so technically a "work" account) with Home Assistant to be able to send notifications to my actual work account.

This integration creates the chat sensor, but when setting enable_updates to true under the chat_sensors section, the integration no longer loads with the following error logged:

Logger: homeassistant.setup
Source: setup.py:398
First occurred: 13:17:19 (1 occurrences)
Last logged: 13:17:19

Error during setup of component o365
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/o365/coordinator.py", line 230, in _async_update_data
    await self._async_teams_chat_update(key)
  File "/config/custom_components/o365/coordinator.py", line 280, in _async_teams_chat_update
    ATTR_MEMBERS: ",".join(memberlist),
                  ^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, NoneType found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 398, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/o365/__init__.py", line 50, in async_setup
    await _async_setup_account(hass, account, conf_type)
  File "/config/custom_components/o365/__init__.py", line 98, in _async_setup_account
    await do_setup(hass, account_conf, account, account_name, conf_type, perms)
  File "/config/custom_components/o365/setup.py", line 60, in do_setup
    await sensor_coordinator.async_config_entry_first_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 287, in async_config_entry_first_refresh
    raise ex
homeassistant.exceptions.ConfigEntryNotReady: sequence item 0: expected str instance, NoneType found

What is needed to enable the o365.send_chat_message service (https://rogerselwyn.github.io/O365-HomeAssistant/services.html#o365send_chat_message)?

Thanks

RogerSelwyn commented 5 months ago

I would delete your token (which you will need to do anyway) and re-authenticate, since you will need to give HA the authority to send messages as well.

pantherale0 commented 5 months ago

Thanks, just tried that, no luck:

This error originated from a custom integration.

Logger: custom_components.o365.coordinator
Source: helpers/update_coordinator.py:315
integration: Office 365 (documentation, issues)
First occurred: 13:52:12 (1 occurrences)
Last logged: 13:52:12

Unexpected error fetching O365 Sensors data: sequence item 0: expected str instance, NoneType found
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/o365/coordinator.py", line 230, in _async_update_data
    await self._async_teams_chat_update(key)
  File "/config/custom_components/o365/coordinator.py", line 280, in _async_teams_chat_update
    ATTR_MEMBERS: ",".join(memberlist),
                  ^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, NoneType found
RogerSelwyn commented 5 months ago

Ok. I’ll look into it. Unfortunately I won’t be able to look at it until next week. Just disable the update until then.

pantherale0 commented 5 months ago

Thanks, I've just spotted something that I think a few users on the forum might be interested in (https://community.home-assistant.io/t/microsoft-teams-status/202388/1). There's an endpoint to get external user presences (I think as long as they are a member of some description in a different tenant) - /communications/getPresencesByUserId which accepts a post request like so:

{
"ids": [...str array of guids...]
}

I'll see if I can find some time to add the functionality to python-o365 so it could then be used as part of this integration which if I can figure out, I'd be happy to open up a PR 👍

RogerSelwyn commented 5 months ago

Sounds good

RogerSelwyn commented 5 months ago

Thanks, I've just spotted something that I think a few users on the forum might be interested in (https://community.home-assistant.io/t/microsoft-teams-status/202388/1). There's an endpoint to get external user presences (I think as long as they are a member of some description in a different tenant) - /communications/getPresencesByUserId which accepts a post request like so:

{
"ids": [...str array of guids...]
}

I'll see if I can find some time to add the functionality to python-o365 so it could then be used as part of this integration which if I can figure out, I'd be happy to open up a PR 👍

Just a thought, the integration already gets current user teams status. Are you trying to add the ability to get another users status?

pantherale0 commented 5 months ago

Yes, in this case from an external directory (work disabled the ability to create app registrations and won't approve this without good business justification).

RogerSelwyn commented 5 months ago

Something to think about for python-o365, how do people supply a guid when probably what they know is an email address.

RogerSelwyn commented 4 months ago
Logger: homeassistant.setup
Source: setup.py:398
First occurred: 13:17:19 (1 occurrences)
Last logged: 13:17:19

Error during setup of component o365
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/o365/coordinator.py", line 230, in _async_update_data
    await self._async_teams_chat_update(key)
  File "/config/custom_components/o365/coordinator.py", line 280, in _async_teams_chat_update
    ATTR_MEMBERS: ",".join(memberlist),
                  ^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, NoneType found
homeassistant.exceptions.ConfigEntryNotReady: sequence item 0: expected str instance, NoneType found

This error seems to be because one of the members of the chat group has no DisplayName. I'm adding a fallback to email address

RogerSelwyn commented 4 months ago

Issue should be fixed with v4.7.2

pantherale0 commented 4 months ago

Thanks, all is working now :1st_place_medal: