Skip to content

Commit

Permalink
(Sonar) Fixed finding: "Using timezone-aware "datetime" objects shoul…
Browse files Browse the repository at this point in the history
…d be preferred over using "datetime.datetime.utcnow" and "datetime.datetime.utcfromtimestamp""
  • Loading branch information
pixeebot[bot] authored Jan 6, 2025
1 parent 7e032f3 commit b02cf08
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/xplora_watch/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b02cf08

Please sign in to comment.