Skip to content

Commit 9aec720

Browse files
author
LAB02 Research
committed
v2022.3.15
1 parent ca178da commit 9aec720

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

custom_components/hass_agent_notifier/manifest.json

+1-1
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.12.21",
8+
"version": "2022.3.15",
99
"requirements": [],
1010
"iot_class": "local_push"
1111
}

custom_components/hass_agent_notifier/notify.py

+34-28
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,37 @@ def send_message(self, message="", title="", **kwargs):
8585

8686
_LOGGER.debug("Sending notification ..")
8787

88-
response = requests.post(
89-
self._resource,
90-
json=payload,
91-
timeout=10
92-
)
93-
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)
114-
else:
115-
_LOGGER.debug("Unknown response %d: %s", response.status_code, response.reason)
88+
try:
89+
90+
response = requests.post(
91+
self._resource,
92+
json=payload,
93+
timeout=10
94+
)
95+
96+
_LOGGER.debug("Checking result ..")
97+
98+
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
99+
_LOGGER.error("Server error. Response %d: %s", response.status_code, response.reason)
100+
elif response.status_code == HTTPStatus.BAD_REQUEST:
101+
_LOGGER.error("Client error (bad request). Response %d: %s", response.status_code, response.reason)
102+
elif response.status_code == HTTPStatus.NOT_FOUND:
103+
_LOGGER.debug("Server error (not found). Response %d: %s", response.status_code, response.reason)
104+
elif response.status_code == HTTPStatus.METHOD_NOT_ALLOWED:
105+
_LOGGER.error("Server error (method not allowed). Response %d", response.status_code)
106+
elif response.status_code == HTTPStatus.REQUEST_TIMEOUT:
107+
_LOGGER.debug("Server error (request timeout). Response %d: %s", response.status_code, response.reason)
108+
elif response.status_code == HTTPStatus.NOT_IMPLEMENTED:
109+
_LOGGER.error("Server error (not implemented). Response %d: %s", response.status_code, response.reason)
110+
elif response.status_code == HTTPStatus.SERVICE_UNAVAILABLE:
111+
_LOGGER.error("Server error (service unavailable). Response %d", response.status_code)
112+
elif response.status_code == HTTPStatus.GATEWAY_TIMEOUT:
113+
_LOGGER.error("Network error (gateway timeout). Response %d: %s", response.status_code, response.reason)
114+
elif response.status_code == HTTPStatus.OK:
115+
_LOGGER.debug("Success. Response %d: %s", response.status_code, response.reason)
116+
else:
117+
_LOGGER.debug("Unknown response %d: %s", response.status_code, response.reason)
118+
119+
except Exception as e:
120+
_LOGGER.debug("Error sending message: %s", e)
121+

0 commit comments

Comments
 (0)