Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -3,7 +3,7 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (CONF_API_KEY, CONF_MONITORED_CONDITIONS)
|
||||
from homeassistant.const import CONF_API_KEY, CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
@@ -11,29 +11,33 @@ from homeassistant.helpers.entity import Entity
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
'application_name': ['Application name'],
|
||||
'body': ['Body'],
|
||||
'notification_id': ['Notification ID'],
|
||||
'notification_tag': ['Notification tag'],
|
||||
'package_name': ['Package name'],
|
||||
'receiver_email': ['Receiver email'],
|
||||
'sender_email': ['Sender email'],
|
||||
'source_device_iden': ['Sender device ID'],
|
||||
'title': ['Title'],
|
||||
'type': ['Type'],
|
||||
"application_name": ["Application name"],
|
||||
"body": ["Body"],
|
||||
"notification_id": ["Notification ID"],
|
||||
"notification_tag": ["Notification tag"],
|
||||
"package_name": ["Package name"],
|
||||
"receiver_email": ["Receiver email"],
|
||||
"sender_email": ["Sender email"],
|
||||
"source_device_iden": ["Sender device ID"],
|
||||
"title": ["Title"],
|
||||
"type": ["Type"],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=['title', 'body']):
|
||||
vol.All(cv.ensure_list, vol.Length(min=1), [vol.In(SENSOR_TYPES)]),
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=["title", "body"]): vol.All(
|
||||
cv.ensure_list, vol.Length(min=1), [vol.In(SENSOR_TYPES)]
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Pushbullet Sensor platform."""
|
||||
from pushbullet import PushBullet
|
||||
from pushbullet import InvalidKeyError
|
||||
|
||||
try:
|
||||
pushbullet = PushBullet(config.get(CONF_API_KEY))
|
||||
except InvalidKeyError:
|
||||
@@ -73,7 +77,7 @@ class PushBulletNotificationSensor(Entity):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return '{} {}'.format('Pushbullet', self._element)
|
||||
return "{} {}".format("Pushbullet", self._element)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@@ -86,12 +90,13 @@ class PushBulletNotificationSensor(Entity):
|
||||
return self._state_attributes
|
||||
|
||||
|
||||
class PushBulletNotificationProvider():
|
||||
class PushBulletNotificationProvider:
|
||||
"""Provider for an account, leading to one or more sensors."""
|
||||
|
||||
def __init__(self, pb):
|
||||
"""Start to retrieve pushes from the given Pushbullet instance."""
|
||||
import threading
|
||||
|
||||
self.pushbullet = pb
|
||||
self._data = None
|
||||
self.listener = None
|
||||
@@ -105,8 +110,8 @@ class PushBulletNotificationProvider():
|
||||
Currently only monitors pushes but might be extended to monitor
|
||||
different kinds of Pushbullet events.
|
||||
"""
|
||||
if data['type'] == 'push':
|
||||
self._data = data['push']
|
||||
if data["type"] == "push":
|
||||
self._data = data["push"]
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
@@ -119,6 +124,7 @@ class PushBulletNotificationProvider():
|
||||
Spawn a new Listener and links it to self.on_push.
|
||||
"""
|
||||
from pushbullet import Listener
|
||||
|
||||
self.listener = Listener(account=self.pushbullet, on_push=self.on_push)
|
||||
_LOGGER.debug("Getting pushes")
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user