added logging

This commit is contained in:
2026-08-30 12:01:46 +02:00
parent ea591fc8fb
commit c1d731f85d
6 changed files with 92 additions and 4 deletions
+16 -1
View File
@@ -76,10 +76,25 @@ class NetatmoClient:
return bool(self.access_token or (self.client_id and self.client_secret and self.refresh_token))
def _request(self, request: urllib.request.Request) -> dict:
endpoint = urllib.parse.urlsplit(request.full_url).path
method = request.get_method()
started = time.monotonic()
LOG.info("Netatmo request attempt method=%s endpoint=%s", method, endpoint)
try:
with urllib.request.urlopen(request, timeout=30) as response:
return json.load(response)
result = json.load(response)
LOG.info(
"Netatmo request success method=%s endpoint=%s status=%s duration_ms=%d",
method, endpoint, response.status,
round((time.monotonic() - started) * 1000),
)
return result
except (urllib.error.URLError, urllib.error.HTTPError, ValueError) as exc:
LOG.exception(
"Netatmo request failure method=%s endpoint=%s status=%s duration_ms=%d",
method, endpoint, getattr(exc, "code", "unavailable"),
round((time.monotonic() - started) * 1000),
)
detail = getattr(exc, "read", lambda: b"")().decode(errors="replace")
raise NetatmoError(f"Netatmo request failed: {exc}; {detail}") from exc