From 3a85bebbf65bb7e16178b3dab86962f211acc6c0 Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Sun, 15 Nov 2015 18:57:16 +0000 Subject: [PATCH] pushbullet; styling and minor fixed before PR --- homeassistant/components/notify/pushbullet.py | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/notify/pushbullet.py b/homeassistant/components/notify/pushbullet.py index d8c07c066fd..a34d21408c3 100644 --- a/homeassistant/components/notify/pushbullet.py +++ b/homeassistant/components/notify/pushbullet.py @@ -13,9 +13,9 @@ from homeassistant.const import CONF_API_KEY _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['pushbullet.py==0.9.0'] -ATTR_TARGET='target' - +ATTR_TARGET = 'target' +# pylint: disable=unused-argument def get_service(hass, config): """ Get the PushBullet notification service. """ from pushbullet import PushBullet @@ -26,15 +26,14 @@ def get_service(hass, config): return None try: - pb = PushBullet(config[CONF_API_KEY]) - + pushbullet = PushBullet(config[CONF_API_KEY]) except InvalidKeyError: _LOGGER.error( "Wrong API key supplied. " "Get it at https://www.pushbullet.com/account") return None - return PushBulletNotificationService(pb) + return PushBulletNotificationService(pushbullet) # pylint: disable=too-few-public-methods @@ -43,6 +42,7 @@ class PushBulletNotificationService(BaseNotificationService): def __init__(self, pb): self.pushbullet = pb + self.pbtargets = {} self.refresh() def refresh(self): @@ -50,20 +50,20 @@ class PushBulletNotificationService(BaseNotificationService): self.pushbullet.refresh() self.pbtargets = { - 'devices' : - {target.nickname: target for target in self.pushbullet.devices}, - 'contacts' : - {target.email: target for target in self.pushbullet.contacts}, - 'channels' : - {target.channel_tag: target for target in self.pushbullet.channels}, + 'devices': + {tgt.nickname: tgt for tgt in self.pushbullet.devices}, + 'contacts': + {tgt.email: tgt for tgt in self.pushbullet.contacts}, + 'channels': + {tgt.channel_tag: tgt for tgt in self.pushbullet.channels}, } - import pprint - _LOGGER.error(pprint.pformat(self.pbtargets)) def send_message(self, message=None, **kwargs): """ Send a message to a user. """ targets = kwargs.get(ATTR_TARGET) title = kwargs.get(ATTR_TITLE) + # Disabeling title + title = None if targets: # Make list if not so @@ -71,25 +71,25 @@ class PushBulletNotificationService(BaseNotificationService): targets = [targets] # Main loop, Process all targets specified - for ttype,tname in [target.split('.') for target in targets]: - if ttype = 'device' and tname = '': + for ttype, tname in [target.split('.') for target in targets]: + if ttype == 'device' and not tname: # Allow for 'normal' push, combined with other targets - self.pushbullet.push_note(None, message) + self.pushbullet.push_note(title, message) + _LOGGER.info('Sent notification to self') continue try: - self.pbtargets[ttype+'s'][tname].push_note(None, message) + self.pbtargets[ttype+'s'][tname].push_note(title, message) except KeyError: - _LOGGER.error('No such target: %s.%s'%(ttype, tname)) + _LOGGER.error('No such target: %s.%s', ttype, tname) continue - except self.pushbullet.errors.PushError as e: - _LOGGER.error('Sending message failed to: %s.%s, %s'% - (ttype, tname, e)) + except self.pushbullet.errors.PushError: + _LOGGER.error('Notify failed to: %s.%s', ttype, tname) self.refresh() 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(None, message) - + self.pushbullet.push_note(title, message) + _LOGGER.info('Sent notification to self')