Skip to content

Commit

Permalink
Merge pull request #3 from joshbenner/status-clear-dnd
Browse files Browse the repository at this point in the history
Optionally clear dnd with status control
  • Loading branch information
jamesridgway authored Aug 8, 2021
2 parents 4060b3d + 43ab911 commit 1853bdc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Example configuration:
key: 0
- action: away
key: 1
- action: status
key: 2
text: At my desk
emoji: ':desktop_computer:'
clear_dnd: true
- action: status
key: 5
text: In a meeting
Expand Down
8 changes: 7 additions & 1 deletion devdeck_slack/slack_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ def settings_schema(self):
},
'dnd': {
'type': 'boolean',
'required': False
'required': False,
'excludes': 'clear_dnd'
},
'clear_dnd': {
'type': 'boolean',
'required': False,
'excludes': 'dnd'
},
'duration': {
'type': 'integer',
Expand Down
11 changes: 10 additions & 1 deletion devdeck_slack/slack_status_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def pressed(self):
else:
expires = int(dt.timestamp())
dnd = self.settings.get('dnd', False)
clear_dnd = self.settings.get('clear_dnd', False)
self.api_client.users_profile_set(profile={
"status_text": self.settings['text'],
"status_emoji": self.settings.get('emoji_slack',
Expand All @@ -47,6 +48,8 @@ def pressed(self):
self.api_client.dnd_setSnooze(num_minutes=minutes)
else:
self.api_client.dnd_setSnooze()
elif clear_dnd:
self.api_client.dnd_endDnd()

def settings_schema(self):
return {
Expand All @@ -64,7 +67,13 @@ def settings_schema(self):
},
'dnd': {
'type': 'boolean',
'required': False
'required': False,
'excludes': 'clear_dnd'
},
'clear_dnd': {
'type': 'boolean',
'required': False,
'excludes': 'dnd'
},
'duration': {
'type': 'integer',
Expand Down
9 changes: 9 additions & 0 deletions tests/devdeck_slack/test_slack_status_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ def test_dnd_set_with_until(self, api_client):
'status_expiration': int(ts.timestamp())
})
api_client.dnd_setSnooze.assert_called_with(num_minutes=minutes)

@mock.patch('slack_sdk.WebClient')
def test_dnd_cleared(self, api_client):
control = SlackStatusControl(0, api_client, **{
'text': '', 'emoji': ':desktop_computer:', 'clear_dnd': True
})
with mock_context(control) as ctx:
control.pressed()
api_client.dnd_endDnd.assert_called()

0 comments on commit 1853bdc

Please sign in to comment.