mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Use latest version of python-pushover (forked) to fix issue with diff… (#31647)
* Use latest version of python-pushover (forked) to fix issue with different API tokens. (https://community.home-assistant.io/t/different-applications-in-pushover/6985) * Rewrite pushover notify to use pushover_complete library * Remove possibility to attach urls to notifications * Fix comment
This commit is contained in:
parent
284fd46ea8
commit
d55846c33a
@ -2,7 +2,7 @@
|
|||||||
"domain": "pushover",
|
"domain": "pushover",
|
||||||
"name": "Pushover",
|
"name": "Pushover",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/pushover",
|
"documentation": "https://www.home-assistant.io/integrations/pushover",
|
||||||
"requirements": ["python-pushover==0.4"],
|
"requirements": ["pushover_complete==1.1.1"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
"""Pushover platform for notify component."""
|
"""Pushover platform for notify component."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pushover import Client, InitError, RequestError
|
from pushover_complete import PushoverAPI
|
||||||
import requests
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
@ -19,6 +18,15 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_ATTACHMENT = "attachment"
|
ATTR_ATTACHMENT = "attachment"
|
||||||
|
ATTR_URL = "url"
|
||||||
|
ATTR_URL_TITLE = "url_title"
|
||||||
|
ATTR_PRIORITY = "priority"
|
||||||
|
ATTR_RETRY = "retry"
|
||||||
|
ATTR_SOUND = "sound"
|
||||||
|
ATTR_HTML = "html"
|
||||||
|
ATTR_CALLBACK_URL = "callback_url"
|
||||||
|
ATTR_EXPIRE = "expire"
|
||||||
|
ATTR_TIMESTAMP = "timestamp"
|
||||||
|
|
||||||
CONF_USER_KEY = "user_key"
|
CONF_USER_KEY = "user_key"
|
||||||
|
|
||||||
@ -29,13 +37,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Pushover notification service."""
|
"""Get the Pushover notification service."""
|
||||||
try:
|
|
||||||
return PushoverNotificationService(
|
return PushoverNotificationService(
|
||||||
hass, config[CONF_USER_KEY], config[CONF_API_KEY]
|
hass, config[CONF_USER_KEY], config[CONF_API_KEY]
|
||||||
)
|
)
|
||||||
except InitError:
|
|
||||||
_LOGGER.error("Wrong API key supplied")
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class PushoverNotificationService(BaseNotificationService):
|
class PushoverNotificationService(BaseNotificationService):
|
||||||
@ -46,54 +50,42 @@ class PushoverNotificationService(BaseNotificationService):
|
|||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._user_key = user_key
|
self._user_key = user_key
|
||||||
self._api_token = api_token
|
self._api_token = api_token
|
||||||
self.pushover = Client(self._user_key, api_token=self._api_token)
|
self.pushover = PushoverAPI(self._api_token)
|
||||||
|
|
||||||
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
|
|
||||||
|
# Extract params from data dict
|
||||||
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
data = dict(kwargs.get(ATTR_DATA) or {})
|
data = dict(kwargs.get(ATTR_DATA) or {})
|
||||||
|
url = data.get(ATTR_URL, None)
|
||||||
|
url_title = data.get(ATTR_URL_TITLE, None)
|
||||||
|
priority = data.get(ATTR_PRIORITY, None)
|
||||||
|
retry = data.get(ATTR_PRIORITY, None)
|
||||||
|
expire = data.get(ATTR_EXPIRE, None)
|
||||||
|
callback_url = data.get(ATTR_CALLBACK_URL, None)
|
||||||
|
timestamp = data.get(ATTR_TIMESTAMP, None)
|
||||||
|
sound = data.get(ATTR_SOUND, None)
|
||||||
|
html = 1 if data.get(ATTR_HTML, False) else 0
|
||||||
|
|
||||||
data["title"] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
image = data.get(ATTR_ATTACHMENT, None)
|
||||||
|
# Check for attachment
|
||||||
# Check for attachment.
|
if image is not None:
|
||||||
if ATTR_ATTACHMENT in data:
|
# Only allow attachments from whitelisted paths, check valid path
|
||||||
# If attachment is a URL, use requests to open it as a stream.
|
|
||||||
if data[ATTR_ATTACHMENT].startswith("http"):
|
|
||||||
try:
|
|
||||||
response = requests.get(
|
|
||||||
data[ATTR_ATTACHMENT], stream=True, timeout=5
|
|
||||||
)
|
|
||||||
if response.status_code == 200:
|
|
||||||
# Replace the attachment identifier with file object.
|
|
||||||
data[ATTR_ATTACHMENT] = response.content
|
|
||||||
else:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Failed to download image %s, response code: %d",
|
|
||||||
data[ATTR_ATTACHMENT],
|
|
||||||
response.status_code,
|
|
||||||
)
|
|
||||||
# Remove attachment key to send without attachment.
|
|
||||||
del data[ATTR_ATTACHMENT]
|
|
||||||
except requests.exceptions.RequestException as ex_val:
|
|
||||||
_LOGGER.error(ex_val)
|
|
||||||
# Remove attachment key to try sending without attachment
|
|
||||||
del data[ATTR_ATTACHMENT]
|
|
||||||
else:
|
|
||||||
# Not a URL, check valid path first
|
|
||||||
if self._hass.config.is_allowed_path(data[ATTR_ATTACHMENT]):
|
if self._hass.config.is_allowed_path(data[ATTR_ATTACHMENT]):
|
||||||
# try to open it as a normal file.
|
# try to open it as a normal file.
|
||||||
try:
|
try:
|
||||||
file_handle = open(data[ATTR_ATTACHMENT], "rb")
|
file_handle = open(data[ATTR_ATTACHMENT], "rb")
|
||||||
# Replace the attachment identifier with file object.
|
# Replace the attachment identifier with file object.
|
||||||
data[ATTR_ATTACHMENT] = file_handle
|
image = file_handle
|
||||||
except OSError as ex_val:
|
except OSError as ex_val:
|
||||||
_LOGGER.error(ex_val)
|
_LOGGER.error(ex_val)
|
||||||
# Remove attachment key to send without attachment.
|
# Remove attachment key to send without attachment.
|
||||||
del data[ATTR_ATTACHMENT]
|
image = None
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Path is not whitelisted")
|
_LOGGER.error("Path is not whitelisted")
|
||||||
# Remove attachment key to send without attachment.
|
# Remove attachment key to send without attachment.
|
||||||
del data[ATTR_ATTACHMENT]
|
image = None
|
||||||
|
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
targets = kwargs.get(ATTR_TARGET)
|
||||||
|
|
||||||
@ -101,12 +93,22 @@ class PushoverNotificationService(BaseNotificationService):
|
|||||||
targets = [targets]
|
targets = [targets]
|
||||||
|
|
||||||
for target in targets:
|
for target in targets:
|
||||||
if target is not None:
|
|
||||||
data["device"] = target
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.pushover.send_message(message, **data)
|
self.pushover.send_message(
|
||||||
|
self._user_key,
|
||||||
|
message,
|
||||||
|
target,
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
url_title,
|
||||||
|
image,
|
||||||
|
priority,
|
||||||
|
retry,
|
||||||
|
expire,
|
||||||
|
callback_url,
|
||||||
|
timestamp,
|
||||||
|
sound,
|
||||||
|
html,
|
||||||
|
)
|
||||||
except ValueError as val_err:
|
except ValueError as val_err:
|
||||||
_LOGGER.error(val_err)
|
_LOGGER.error(val_err)
|
||||||
except RequestError:
|
|
||||||
_LOGGER.exception("Could not send pushover notification")
|
|
||||||
|
@ -1067,6 +1067,9 @@ pushbullet.py==0.11.0
|
|||||||
# homeassistant.components.pushetta
|
# homeassistant.components.pushetta
|
||||||
pushetta==1.0.15
|
pushetta==1.0.15
|
||||||
|
|
||||||
|
# homeassistant.components.pushover
|
||||||
|
pushover_complete==1.1.1
|
||||||
|
|
||||||
# homeassistant.components.rpi_gpio_pwm
|
# homeassistant.components.rpi_gpio_pwm
|
||||||
pwmled==1.4.1
|
pwmled==1.4.1
|
||||||
|
|
||||||
@ -1611,9 +1614,6 @@ python-nest==4.1.0
|
|||||||
# homeassistant.components.nmap_tracker
|
# homeassistant.components.nmap_tracker
|
||||||
python-nmap==0.6.1
|
python-nmap==0.6.1
|
||||||
|
|
||||||
# homeassistant.components.pushover
|
|
||||||
python-pushover==0.4
|
|
||||||
|
|
||||||
# homeassistant.components.qbittorrent
|
# homeassistant.components.qbittorrent
|
||||||
python-qbittorrent==0.4.1
|
python-qbittorrent==0.4.1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user