Skip to content

Commit 0003032

Browse files
author
LAB02 Research
committed
v2021.12.21
1 parent 0effd52 commit 0003032

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

custom_components/hass_agent_notifier/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"issue_tracker": "https://github.com/LAB02-Research/HASS.Agent-Notifier/issues",
66
"dependencies": [],
77
"codeowners": ["@LAB02-Admin"],
8-
"version": "2021.11.30",
8+
"version": "2021.12.21",
99
"requirements": [],
1010
"iot_class": "local_push"
1111
}

custom_components/hass_agent_notifier/notify.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
PLATFORM_SCHEMA,
2525
BaseNotificationService,
2626
)
27-
"""from homeassistant.const import (
28-
CONF_RESOURCE,
29-
HTTP_BAD_REQUEST,
30-
HTTP_INTERNAL_SERVER_ERROR,
31-
HTTP_OK,
32-
)"""
27+
28+
from http import HTTPStatus
29+
3330
from homeassistant.const import (
3431
CONF_RESOURCE,
3532
)
@@ -51,6 +48,8 @@ def get_service(hass, config, discovery_info=None):
5148
"""Get the HASS Agent notification service."""
5249
resource = config.get(CONF_RESOURCE)
5350

51+
_LOGGER.info("Service created")
52+
5453
return HassAgentNotificationService(
5554
hass,
5655
resource
@@ -71,6 +70,8 @@ def __init__(
7170

7271
def send_message(self, message="", title="", **kwargs):
7372
"""Send the message to the provided resource."""
73+
_LOGGER.debug("Preparing notification ..")
74+
7475
data = kwargs.get(ATTR_DATA, None)
7576
image = data.get(ATTR_IMAGE) if data is not None and ATTR_IMAGE in data else None
7677
duration = data.get(ATTR_DURATION) if data is not None and ATTR_DURATION in data else 0
@@ -82,17 +83,33 @@ def send_message(self, message="", title="", **kwargs):
8283
'duration': duration
8384
})
8485

86+
_LOGGER.debug("Sending notification ..")
87+
8588
response = requests.post(
8689
self._resource,
8790
json=payload,
8891
timeout=10
8992
)
9093

91-
""" if HTTP_INTERNAL_SERVER_ERROR <= response.status_code < 600:
92-
_LOGGER.exception("Server error. Response %d: %s:", response.status_code, response.reason)
93-
elif HTTP_BAD_REQUEST <= response.status_code < HTTP_INTERNAL_SERVER_ERROR:
94-
_LOGGER.exception("Client error. Response %d: %s:", response.status_code, response.reason)
95-
elif HTTP_OK <= response.status_code < 300:
96-
_LOGGER.debug("Success. Response %d: %s:", response.status_code, response.reason)
94+
_LOGGER.debug("Checking result ..")
95+
96+
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
97+
_LOGGER.exception("Server error. Response %d: %s", response.status_code, response.reason)
98+
elif response.status_code == HTTPStatus.BAD_REQUEST:
99+
_LOGGER.exception("Client error (bad request). Response %d: %s", response.status_code, response.reason)
100+
elif response.status_code == HTTPStatus.NOT_FOUND:
101+
_LOGGER.exception("Server error (not found). Response %d: %s", response.status_code, response.reason)
102+
elif response.status_code == HTTPStatus.METHOD_NOT_ALLOWED:
103+
_LOGGER.exception("Server error (method not allowed). Response %d", response.status_code)
104+
elif response.status_code == HTTPStatus.REQUEST_TIMEOUT:
105+
_LOGGER.exception("Server error (request timeout). Response %d: %s", response.status_code, response.reason)
106+
elif response.status_code == HTTPStatus.NOT_IMPLEMENTED:
107+
_LOGGER.exception("Server error (not implemented). Response %d: %s", response.status_code, response.reason)
108+
elif response.status_code == HTTPStatus.SERVICE_UNAVAILABLE:
109+
_LOGGER.exception("Server error (service unavailable). Response %d", response.status_code)
110+
elif response.status_code == HTTPStatus.GATEWAY_TIMEOUT:
111+
_LOGGER.exception("Network error (gateway timeout). Response %d: %s", response.status_code, response.reason)
112+
elif response.status_code == HTTPStatus.OK:
113+
_LOGGER.debug("Success. Response %d: %s", response.status_code, response.reason)
97114
else:
98-
_LOGGER.debug("Response %d: %s:", response.status_code, response.reason)"""
115+
_LOGGER.debug("Unknown response %d: %s", response.status_code, response.reason)

0 commit comments

Comments
 (0)