mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
fix issue (#6470)
* fix issue fix issue: https://community.home-assistant.io/t/error-in-new-notification-pushsafer/13308 * Update pushsafer.py * Update requirements_all.txt * Update pushsafer.py * Update pushsafer.py * Update pushsafer.py
This commit is contained in:
parent
44d4987536
commit
d16bc632da
@ -6,65 +6,42 @@ https://home-assistant.io/components/notify.pushsafer/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_TARGET, ATTR_DATA,
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
BaseNotificationService)
|
|
||||||
from homeassistant.const import CONF_API_KEY
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['python-pushsafer==0.2']
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
_RESOURCE = 'https://www.pushsafer.com/api'
|
||||||
|
|
||||||
|
CONF_DEVICE_KEY = 'private_key'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
DEFAULT_TIMEOUT = 10
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_DEVICE_KEY): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Pushsafer notification service."""
|
"""Get the Pushsafer.com notification service."""
|
||||||
from pushsafer import InitError
|
return PushsaferNotificationService(config.get(CONF_DEVICE_KEY))
|
||||||
|
|
||||||
try:
|
|
||||||
return PushsaferNotificationService(config[CONF_API_KEY])
|
|
||||||
except InitError:
|
|
||||||
_LOGGER.error(
|
|
||||||
'Wrong private key supplied. Get it at https://www.pushsafer.com')
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class PushsaferNotificationService(BaseNotificationService):
|
class PushsaferNotificationService(BaseNotificationService):
|
||||||
"""Implement the notification service for Pushsafer."""
|
"""Implementation of the notification service for Pushsafer.com."""
|
||||||
|
|
||||||
def __init__(self, privatekey):
|
def __init__(self, private_key):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
from pushsafer import Client
|
self._private_key = private_key
|
||||||
self._privatekey = privatekey
|
|
||||||
self.pushsafer = Client(
|
|
||||||
"", privatekey=self._privatekey)
|
|
||||||
|
|
||||||
def send_message(self, message='', **kwargs):
|
def send_message(self, message='', **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a user."""
|
||||||
# Make a copy and use empty dict if necessary
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
data = dict(kwargs.get(ATTR_DATA) or {})
|
payload = {'k': self._private_key, 't': title, 'm': message}
|
||||||
|
response = requests.get(_RESOURCE, params=payload,
|
||||||
data['title'] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
timeout=DEFAULT_TIMEOUT)
|
||||||
|
if response.status_code != 200:
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
_LOGGER.error("Not possible to send notification")
|
||||||
|
|
||||||
if not isinstance(targets, list):
|
|
||||||
targets = [targets]
|
|
||||||
|
|
||||||
for target in targets:
|
|
||||||
if target is not None:
|
|
||||||
data['device'] = target
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.pushsafer.send_message(message, data['title'], "", "",
|
|
||||||
"", "", "", "",
|
|
||||||
"0", "", "", "")
|
|
||||||
except ValueError as val_err:
|
|
||||||
_LOGGER.error(str(val_err))
|
|
||||||
|
@ -598,9 +598,6 @@ python-nmap==0.6.1
|
|||||||
# homeassistant.components.notify.pushover
|
# homeassistant.components.notify.pushover
|
||||||
python-pushover==0.2
|
python-pushover==0.2
|
||||||
|
|
||||||
# homeassistant.components.notify.pushsafer
|
|
||||||
python-pushsafer==0.2
|
|
||||||
|
|
||||||
# homeassistant.components.sensor.synologydsm
|
# homeassistant.components.sensor.synologydsm
|
||||||
python-synology==0.1.0
|
python-synology==0.1.0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user