Permalink
Browse files

pushover_notifier - add support for sending through proxy (jantman/do…

…cker-twilio-ppp-proxy)
  • Loading branch information...
jantman committed Jan 1, 2019
1 parent 04d8f2b commit 2cf9eb933969f7527786393703e91f0a32538deb
Showing with 32 additions and 5 deletions.
  1. +32 −5 appdaemon/apps/pushover_notifier.py
@@ -62,10 +62,31 @@ def _do_notify_pushover(self, title, message, sound=None, image=None,
else:
self._log.info('Sending Pushover notification with image: %s', d)
d['files']['attachment'] = (image_name, image, 'image/jpeg')
try:
self._send_pushover(d)
except Exception:
self._log.critical('send_pushover raised exception', exc_info=True)
for i in range(0, 2):
try:
self._send_pushover(d)
return
except Exception:
self._log.critical(
'send_pushover raised exception', exc_info=True
)
if self._hass_secrets.get('proxies', {}) == {}:
self._log.critical(
'send_pushover failed on all attempts and proxies is empty!'
)
return
# try sending through proxy
if 'files' in d:
del d['files']
d['proxies'] = self._hass_secrets['proxies']
for i in range(0, 2):
try:
self._send_pushover(d)
return
except Exception:
self._log.critical(
'send_pushover via proxy raised exception', exc_info=True
)

def _send_pushover(self, params):
"""
@@ -75,7 +96,13 @@ def _send_pushover(self, params):
doesn't have support for images or some other API options.
"""
url = 'https://api.pushover.net/1/messages.json'
self._log.debug('Sending Pushover notification')
if 'proxies' in params:
self._log.debug(
'Sending Pushover notification with proxies=%s',
params['proxies']
)
else:
self._log.debug('Sending Pushover notification')
r = requests.post(url, **params)
self._log.debug(
'Pushover POST response HTTP %s: %s', r.status_code, r.text

0 comments on commit 2cf9eb9

Please sign in to comment.