Switched to generic notify function
This commit is contained in:
parent
b102e4eaad
commit
6eafd9af8b
1 changed files with 12 additions and 10 deletions
|
@ -4537,9 +4537,10 @@ class SimpleServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
def __init__(self, server_address, RequestHandlerClass):
|
def __init__(self, server_address, RequestHandlerClass):
|
||||||
socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
|
socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
|
||||||
|
|
||||||
def persistent_notification(title="HASS Configurator",
|
def notify(service="persistent_notification.create",
|
||||||
message="Notification by HASS Configurator",
|
title="HASS Configurator",
|
||||||
notification_id="HC_PERSISTENT_NOTIFICATION"):
|
message="Notification by HASS Configurator",
|
||||||
|
notification_id=None):
|
||||||
if not HASS_API:
|
if not HASS_API:
|
||||||
return
|
return
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -4547,13 +4548,14 @@ def persistent_notification(title="HASS Configurator",
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
"title": title,
|
"title": title,
|
||||||
"message": message,
|
"message": message
|
||||||
"notification_id": notification_id
|
|
||||||
}
|
}
|
||||||
|
if notification_id:
|
||||||
|
data["notification_id"] = notification_id
|
||||||
if HASS_API_PASSWORD:
|
if HASS_API_PASSWORD:
|
||||||
headers["x-ha-access"] = HASS_API_PASSWORD
|
headers["x-ha-access"] = HASS_API_PASSWORD
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
"%sservices/persistent_notification/create" % HASS_API,
|
"%sservices/%s" % (HASS_API, service.replace('.', '/')),
|
||||||
data=bytes(json.dumps(data).encode('utf-8')),
|
data=bytes(json.dumps(data).encode('utf-8')),
|
||||||
headers=headers, method='POST')
|
headers=headers, method='POST')
|
||||||
try:
|
try:
|
||||||
|
@ -4561,7 +4563,7 @@ def persistent_notification(title="HASS Configurator",
|
||||||
message = response.read().decode('utf-8')
|
message = response.read().decode('utf-8')
|
||||||
LOG.debug(message)
|
LOG.debug(message)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
LOG.warning("Exception while creating persistent notification: %s" % err)
|
LOG.warning("Exception while creating notification: %s" % err)
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
global HTTPD, CREDENTIALS
|
global HTTPD, CREDENTIALS
|
||||||
|
@ -4582,7 +4584,7 @@ def main(args):
|
||||||
"Refer to the HASS configurator logs for further information." % problems,
|
"Refer to the HASS configurator logs for further information." % problems,
|
||||||
"notification_id": "HC_HASS_API_PASSWORD"
|
"notification_id": "HC_HASS_API_PASSWORD"
|
||||||
}
|
}
|
||||||
persistent_notification(**data)
|
notify(**data)
|
||||||
|
|
||||||
problems = None
|
problems = None
|
||||||
if SESAME:
|
if SESAME:
|
||||||
|
@ -4594,7 +4596,7 @@ def main(args):
|
||||||
"Refer to the HASS configurator logs for further information." % problems,
|
"Refer to the HASS configurator logs for further information." % problems,
|
||||||
"notification_id": "HC_SESAME"
|
"notification_id": "HC_SESAME"
|
||||||
}
|
}
|
||||||
persistent_notification(**data)
|
notify(**data)
|
||||||
|
|
||||||
problems = None
|
problems = None
|
||||||
if CREDENTIALS:
|
if CREDENTIALS:
|
||||||
|
@ -4606,7 +4608,7 @@ def main(args):
|
||||||
"Refer to the HASS configurator logs for further information." % problems,
|
"Refer to the HASS configurator logs for further information." % problems,
|
||||||
"notification_id": "HC_CREDENTIALS"
|
"notification_id": "HC_CREDENTIALS"
|
||||||
}
|
}
|
||||||
persistent_notification(**data)
|
notify(**data)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
LOG.warning("Exception while checking passwords: %s" % err)
|
LOG.warning("Exception while checking passwords: %s" % err)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue