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:
# 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: |

View file

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

View file

@ -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)