RogerSelwyn / O365-HomeAssistant

Office 365 integration for Home Assistant
MIT License
178 stars 14 forks source link

Teams presence sensor enhancement #197

Closed NightMean closed 4 months ago

NightMean commented 6 months ago

Hi, First of all, thanks for working on this integration!

With the reference to #19 I've noticed that Microsoft allows to write a presence status via Presence.ReadWrite as per their documentation

Having this, I could sync my Teams status with Webex and other stuff that I'm currently doing when I don't want to be bothered :) There is also Presence.Read.All which could be used to let me know once colleague is back at office for example. Would it be possible to add this feature ?

image

RogerSelwyn commented 6 months ago

I'll take a look ReadWrite. I don't see me doing anything with Read.All, because you will need to input who's presence you want to read somehow, but I'll take a look.

NightMean commented 6 months ago

Thank you! I assume that Read.All it would require to input user email address at best or at the worst, their User ID. I know it would be pretty specific but I could also see a use case for other colleagues who might not be able to get their admin approval. It's way easier to send the status from my HomeAssistant to theirs rather than fighting with a security admin haha :)

Of course, the ReadWrite would be the most useful.

RogerSelwyn commented 6 months ago

Currently there is no support in the library I use to access O365. Previous experience is that it can take a long time to get features added to the library. This is the python code set that supports Teams elements - https://github.com/O365/python-o365/blob/master/O365/teams.py.

NightMean commented 6 months ago

Ah, that's a pity.. Is there no other way to add it? I found this https://alexholmeset.blog/2022/01/09/set-presence-for-an-end-user-in-microsoft-teams/ which doesn't look that bad, only if it was a python code :)

I fully understand if you don't want to add something outside the library that you are using.

RogerSelwyn commented 6 months ago

I'm not going to start using random other bits of code I'm afraid (certainly not PowerShell). I didn't say it wouldn't get done, I said it will likely take time (months). I have contributed to that library before, so I will consider if I do the same again.

NightMean commented 6 months ago

Understood. Thanks for your effort.

RogerSelwyn commented 6 months ago

I think it needs this:-

https://learn.microsoft.com/en-us/graph/api/presence-setuserpreferredpresence?view=graph-rest-1.0&tabs=http

Not:-

https://learn.microsoft.com/en-us/graph/api/presence-setpresence?view=graph-rest-1.0&tabs=http

Set Presence requires a sessionId, which I guess is created by Teams or the like. No idea, and can't easily see. Anyway Set Preferred Presence seems to do the job when I tried it in Graph Explorer.

NightMean commented 6 months ago

Hm interesting. The preferredpresence does have the same options for status as Teams does in UI while the setpresence shows activities that are set only by another apps. I think it would require combination from both of those 2. When I'm in Webex call, I'd like to set the presence as InACall instead of just Busy. However I'm not sure if it would be possible to get the SessionID of currently running Teams easily.

RogerSelwyn commented 6 months ago

Done some more reading, looks like I should use client_id (application_id) in the session_id field. I'll take a look at it some time next week.

RogerSelwyn commented 5 months ago

I have submitted a PR for the library updates here - https://github.com/O365/python-o365/pull/1038 - I'll look to work on the integration when that has been merged and released (last release was in September).

NightMean commented 5 months ago

Wow, cool! Thanks for the update.

RogerSelwyn commented 5 months ago

Whilst the change has been released in the library, there are other changes in the library which have broken the integration. I have had some interaction with the library owner, but I'm awaiting resolution before I can progress.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

RogerSelwyn commented 4 months ago

I've added the ability to update user status, it will be in the next release. I need to think about the other part of this request, to monitor another users presence.

NightMean commented 4 months ago

Perfect! Thanks a lot! I will test it once it's released :)

RogerSelwyn commented 4 months ago

Beta just released - https://github.com/RogerSelwyn/O365-HomeAssistant/releases/tag/v4.7.0b1

RogerSelwyn commented 1 month ago

I'll probably tag a few posts, but I'm trying to get some views. I'm considering breaking up the monolithic O365 integration into smaller, more manageable items. If you have a view, please comment here:

O365 --> MS365 - A potential big change - your views needed