From c5efb797419e0e33d39b7916256862394f9e6933 Mon Sep 17 00:00:00 2001 From: Martijn van der Meij Date: Wed, 10 Feb 2021 21:48:12 +0100 Subject: [PATCH 1/2] add teams presence --- Pipfile | 2 +- README.md | 1 + custom_components/o365/manifest.json | 2 +- custom_components/o365/sensor.py | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index be644ce..09db8f6 100644 --- a/Pipfile +++ b/Pipfile @@ -6,7 +6,7 @@ verify_ssl = true [dev-packages] [packages] -o365 = "==2.0.9" +o365 = "==2.0.14" beautifulsoup4 = "==4.9.0" [requires] diff --git a/README.md b/README.md index 7d08b68..e5cc4e2 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Under "Api Permissions" add the following delegated permission from the Microsof * Mail.ReadWrite.Shared - *Read and write user and shared mail* * Mail.Send - *Send mail as a user* * Mail.Send.Shared - *Send mail on behalf of others* +* Presence.Read - *Allow access to teams status* ## Adding to Home Assistant diff --git a/custom_components/o365/manifest.json b/custom_components/o365/manifest.json index d5f6553..6082ac7 100644 --- a/custom_components/o365/manifest.json +++ b/custom_components/o365/manifest.json @@ -4,5 +4,5 @@ "documentation": "https://github.com/PTST/O365Calendar-HomeAssistant", "dependencies": ["configurator", "http"], "codeowners": ["@PTST"], - "requirements": ["O365==2.0.9", "BeautifulSoup4==4.8.2"] + "requirements": ["O365==2.0.14", "BeautifulSoup4==4.8.2"] } diff --git a/custom_components/o365/sensor.py b/custom_components/o365/sensor.py index d2ff659..66bb7f4 100644 --- a/custom_components/o365/sensor.py +++ b/custom_components/o365/sensor.py @@ -39,6 +39,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): sensor = O365QuerySensor(account, conf) add_devices([sensor], True) + teamsStatusSensor = O365TeamsStatusSensor(account, conf) + add_devices([teamsStatusSensor], True) class O365QuerySensor(Entity): def __init__(self, account, conf): @@ -183,3 +185,28 @@ def update(self): self._state = len(mails) # self._attributes = {"data": attrs, "data_str_repr": json.dumps(attrs)} self._attributes = {"data": attrs} + +class O365TeamsStatusSensor(Entity): + def __init__(self, account, conf): + self.account = account + self.teams = account.teams() + self._name = conf.get( + CONF_NAME, f"{self.account.get_current_user().mail}-teams status" + ) + self._state = 0 + self._attributes = {} + + @property + def name(self): + return self._name + + @property + def state(self): + return self._state + + @property + def device_state_attributes(self): + return self._attributes + + def update(self): + self._state = self.teams.get_my_presence().activity From 3b170358c5341c6aba56a41e29bf20e1ac633d10 Mon Sep 17 00:00:00 2001 From: Martijn van der Meij Date: Wed, 10 Feb 2021 21:55:28 +0100 Subject: [PATCH 2/2] fix: teams sensor name --- custom_components/o365/sensor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/custom_components/o365/sensor.py b/custom_components/o365/sensor.py index 66bb7f4..5429edd 100644 --- a/custom_components/o365/sensor.py +++ b/custom_components/o365/sensor.py @@ -190,9 +190,7 @@ class O365TeamsStatusSensor(Entity): def __init__(self, account, conf): self.account = account self.teams = account.teams() - self._name = conf.get( - CONF_NAME, f"{self.account.get_current_user().mail}-teams status" - ) + self._name = f"{self.account.get_current_user().mail}-teams status" self._state = 0 self._attributes = {}