From b02cf0869618ea4af13e0401303426a311969fad Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 03:23:37 +0000 Subject: [PATCH] (Sonar) Fixed finding: "Using timezone-aware "datetime" objects should be preferred over using "datetime.datetime.utcnow" and "datetime.datetime.utcfromtimestamp"" --- custom_components/xplora_watch/geocoder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/xplora_watch/geocoder.py b/custom_components/xplora_watch/geocoder.py index 8ae2a3c..a72d739 100644 --- a/custom_components/xplora_watch/geocoder.py +++ b/custom_components/xplora_watch/geocoder.py @@ -14,7 +14,7 @@ import collections import os import sys -from datetime import datetime +from datetime import timezone, datetime from decimal import Decimal import backoff @@ -303,7 +303,7 @@ def _opencage_request(self, params): if response.status_code in (402, 429): # Rate limit exceeded - reset_time = datetime.utcfromtimestamp(response.json()["rate"]["reset"]) + reset_time = datetime.fromtimestamp(response.json()["rate"]["reset"], tz=timezone.utc) raise RateLimitExceededError(reset_to=int(response.json()["rate"]["limit"]), reset_time=reset_time) @@ -346,7 +346,7 @@ async def _opencage_async_request(self, params): if response.status in (402, 429): # Rate limit exceeded - reset_time = datetime.utcfromtimestamp(response_json["rate"]["reset"]) + reset_time = datetime.fromtimestamp(response_json["rate"]["reset"], tz=timezone.utc) raise RateLimitExceededError(reset_to=int(response_json["rate"]["limit"]), reset_time=reset_time)