From 18cdf3f5651e18e008cb05c1108213e07d8f97f5 Mon Sep 17 00:00:00 2001 From: Malte Date: Sun, 19 Nov 2023 22:10:44 +0100 Subject: [PATCH] add 'people_now_present' sensor to fmt dict --- me.s3lph.spaceapi/base-config.yaml | 2 ++ me.s3lph.spaceapi/maubot.yaml | 2 +- me.s3lph.spaceapi/spaceapi.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/me.s3lph.spaceapi/base-config.yaml b/me.s3lph.spaceapi/base-config.yaml index c60bade..99c81d4 100644 --- a/me.s3lph.spaceapi/base-config.yaml +++ b/me.s3lph.spaceapi/base-config.yaml @@ -7,6 +7,8 @@ spaceapi: https://example.org/spaceapi messages: # You can use the following fields: # {lastchange}: Time the space state was last changed + # {known_users}: List of names that are currently in the space + # {user_cnt}: The number of people that are currently in the space open: | The hackerspace is now OPEN. closed: | diff --git a/me.s3lph.spaceapi/maubot.yaml b/me.s3lph.spaceapi/maubot.yaml index 6f628d8..caffd13 100644 --- a/me.s3lph.spaceapi/maubot.yaml +++ b/me.s3lph.spaceapi/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.2.1 id: me.s3lph.spaceapi -version: 0.1.2 +version: 0.1.3 license: MIT modules: - spaceapi diff --git a/me.s3lph.spaceapi/spaceapi.py b/me.s3lph.spaceapi/spaceapi.py index b88c3f6..d46327d 100644 --- a/me.s3lph.spaceapi/spaceapi.py +++ b/me.s3lph.spaceapi/spaceapi.py @@ -96,7 +96,9 @@ class SpaceapiBot(Plugin): room = await self._get_room() try: fmt = { - 'lastchange': datetime.fromtimestamp(state['state']['lastchange']).strftime('%H:%M') + 'lastchange': datetime.fromtimestamp(state['state']['lastchange']).strftime('%H:%M'), + 'known_users': state.get('state', {}).get('sensors', {}).get('people_now_present', [{}])[0].get('names', ""), + 'user_cnt': state.get('state', {}).get('sensors', {}).get('people_now_present', [{}])[0].get('value', 0) } if state['state']['open']: body = self.config['messages']['open'].format(**fmt)