mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Processed feedback from PR comments
This commit is contained in:
parent
aee4411cfb
commit
cc5dec3c59
@ -56,11 +56,11 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||||||
'''
|
'''
|
||||||
self.pushbullet.refresh()
|
self.pushbullet.refresh()
|
||||||
self.pbtargets = {
|
self.pbtargets = {
|
||||||
'devices':
|
'device':
|
||||||
{tgt.nickname: tgt for tgt in self.pushbullet.devices},
|
{tgt.nickname: tgt for tgt in self.pushbullet.devices},
|
||||||
'contacts':
|
'contact':
|
||||||
{tgt.email: tgt for tgt in self.pushbullet.contacts},
|
{tgt.email: tgt for tgt in self.pushbullet.contacts},
|
||||||
'channels':
|
'channel':
|
||||||
{tgt.channel_tag: tgt for tgt in self.pushbullet.channels},
|
{tgt.channel_tag: tgt for tgt in self.pushbullet.channels},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,37 +71,43 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||||||
linked to the PB account.
|
linked to the PB account.
|
||||||
"""
|
"""
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
targets = kwargs.get(ATTR_TARGET)
|
||||||
# Disabeling title
|
|
||||||
title = kwargs.get(ATTR_TITLE)
|
title = kwargs.get(ATTR_TITLE)
|
||||||
title = None
|
refreshed = False
|
||||||
|
|
||||||
|
if not targets:
|
||||||
|
# Backward compatebility, notify all devices in own account
|
||||||
|
self.pushbullet.push_note(title, message)
|
||||||
|
_LOGGER.info('Sent notification to self')
|
||||||
|
return
|
||||||
|
|
||||||
if targets:
|
|
||||||
# Make list if not so
|
# Make list if not so
|
||||||
if not isinstance(targets, list):
|
if not isinstance(targets, list):
|
||||||
targets = [targets]
|
targets = [targets]
|
||||||
|
|
||||||
# Main loop, Process all targets specified
|
# Main loop, Process all targets specified
|
||||||
for ttype, tname in [target.split('.', 1) for target in targets]:
|
for target in targets:
|
||||||
if ttype == 'device' and not tname:
|
|
||||||
# Allow for 'normal' push, combined with other targets
|
# Allow for untargeted push, combined with other types
|
||||||
|
if target in ['device', 'device/']:
|
||||||
self.pushbullet.push_note(title, message)
|
self.pushbullet.push_note(title, message)
|
||||||
_LOGGER.info('Sent notification to self')
|
_LOGGER.info('Sent notification to self')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
ttype, tname = target.split('/', 1)
|
||||||
|
|
||||||
|
# Refresh if name not found. Poor mans refresh ;)
|
||||||
|
if tname not in self.pbtargets[ttype] and not refreshed:
|
||||||
|
self.refresh()
|
||||||
|
refreshed = True
|
||||||
|
|
||||||
# Attempt push_note on a dict value. Keys are types & target
|
# Attempt push_note on a dict value. Keys are types & target
|
||||||
# name. The pbtargets have all *actual* targets.
|
# name. Dict pbtargets has all *actual* targets.
|
||||||
try:
|
try:
|
||||||
self.pbtargets[ttype+'s'][tname].push_note(title, message)
|
self.pbtargets[ttype][tname].push_note(title, message)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.error('No such target: %s.%s', ttype, tname)
|
_LOGGER.error('No such target: %s.%s', ttype, tname)
|
||||||
continue
|
continue
|
||||||
except self.pushbullet.errors.PushError:
|
except self.pushbullet.errors.PushError:
|
||||||
_LOGGER.error('Notify failed to: %s.%s', ttype, tname)
|
_LOGGER.error('Notify failed to: %s.%s', ttype, tname)
|
||||||
self.refresh()
|
|
||||||
continue
|
continue
|
||||||
_LOGGER.info('Sent notification to %s.%s', ttype, tname)
|
_LOGGER.info('Sent notification to %s.%s', ttype, tname)
|
||||||
|
|
||||||
else:
|
|
||||||
# Backward compatebility, notify all devices in own account
|
|
||||||
self.pushbullet.push_note(title, message)
|
|
||||||
_LOGGER.info('Sent notification to self')
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user