Add support for Join:// DeviceNames (#207)

This commit is contained in:
Chris Caron 2020-02-20 18:48:10 -05:00 committed by GitHub
parent a8ec23a9e8
commit 1ce7cbb679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -130,6 +130,11 @@ class NotifyJoin(NotifyBase):
'regex': (r'^[a-z0-9]{32}$', 'i'),
'map_to': 'targets',
},
'device_name': {
'name': _('Device Name'),
'type': 'string',
'map_to': 'targets',
},
'group': {
'name': _('Group'),
'type': 'choice:string',
@ -210,18 +215,7 @@ class NotifyJoin(NotifyBase):
'group.{}'.format(group_re.group('name').lower()))
continue
elif IS_DEVICE_RE.match(target):
self.targets.append(target)
continue
self.logger.warning(
'Ignoring invalid Join device/group "{}"'.format(target)
)
if not self.targets:
msg = 'No Join targets to notify.'
self.logger.warning(msg)
raise TypeError(msg)
self.targets.append(target)
return
@ -247,12 +241,18 @@ class NotifyJoin(NotifyBase):
url_args = {
'apikey': self.apikey,
'deviceId': target,
'priority': str(self.priority),
'title': title,
'text': body,
}
if IS_GROUP_RE.match(target) or IS_DEVICE_RE.match(target):
url_args['deviceId'] = target
else:
# Support Device Names
url_args['deviceNames'] = target
# prepare our image for display if configured to do so
image_url = None if not self.include_image \
else self.image_url(notify_type)

View File

@ -921,9 +921,9 @@ TEST_URLS = (
('join://%s@%s?image=False' % ('a' * 32, 'd' * 32), {
'instance': plugins.NotifyJoin,
}),
# API Key + invalid device
('join://%s/%s' % ('a' * 32, 'k' * 12), {
'instance': TypeError,
# API Key + Device Name
('join://%s/%s' % ('a' * 32, 'My Device'), {
'instance': plugins.NotifyJoin,
}),
# API Key + device
('join://%s/%s' % ('a' * 32, 'd' * 32), {