add 'people_now_present' sensor to fmt dict

This commit is contained in:
Malte 2023-11-19 22:10:44 +01:00
parent 504dd68c69
commit 18cdf3f565
3 changed files with 6 additions and 2 deletions

View file

@ -7,6 +7,8 @@ spaceapi: https://example.org/spaceapi
messages: messages:
# You can use the following fields: # You can use the following fields:
# {lastchange}: Time the space state was last changed # {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: | open: |
The hackerspace is now OPEN. The hackerspace is now OPEN.
closed: | closed: |

View file

@ -1,6 +1,6 @@
maubot: 0.2.1 maubot: 0.2.1
id: me.s3lph.spaceapi id: me.s3lph.spaceapi
version: 0.1.2 version: 0.1.3
license: MIT license: MIT
modules: modules:
- spaceapi - spaceapi

View file

@ -96,7 +96,9 @@ class SpaceapiBot(Plugin):
room = await self._get_room() room = await self._get_room()
try: try:
fmt = { 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']: if state['state']['open']:
body = self.config['messages']['open'].format(**fmt) body = self.config['messages']['open'].format(**fmt)