Skip to content

Commit

Permalink
Fix: Bad Time Parsing (single digit) (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh authored Oct 29, 2024
1 parent 63789e6 commit 7948eae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ ignore = [
"COM812", # incompatible with formatter
"ISC001", # incompatible with formatter
"S101", # Assert,
"E501" # Line too long
"E501", # Line too long
"DTZ005" # datetime.now() without timezone
]

[lint.flake8-pytest-style]
Expand Down
1 change: 1 addition & 0 deletions ims_envista/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ async def get(
msg = f"Received Error from IMS Envista API from {url}: {response.status, response.reason}"
raise ImsEnvistaApiClientError(msg)

_LOGGER.debug("Response from %s: %s", url, json_resp)
return json_resp
2 changes: 1 addition & 1 deletion ims_envista/ims_envista.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, token: UUID | str, session: ClientSession | None = None) -> N
raise ValueError(err_msg)

if not session:
session = ClientSession(trace_configs=[trace_config])
session = ClientSession()
atexit.register(self._shutdown)

self._session = session
Expand Down
9 changes: 7 additions & 2 deletions ims_envista/meteo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
VARIABLES,
)

MAX_HOUR_INT = 24

@dataclass
class MeteorologicalData:
Expand Down Expand Up @@ -152,7 +153,7 @@ def __repr__(self) -> str:
tz = pytz.timezone("Asia/Jerusalem")


def _fix_datetime_offset(dt):
def _fix_datetime_offset(dt: datetime.datetime) -> tuple[datetime.datetime, bool]:
dt = dt.replace(tzinfo=None)
dt = tz.localize(dt)

Expand Down Expand Up @@ -200,7 +201,11 @@ def meteo_data_from_json(station_id: int, data: dict) -> MeteorologicalData:
tw = channel_value_dict.get(API_TW)
time_val = channel_value_dict.get(API_TIME)
if time_val:
t = time.strptime(str(int(time_val)), "%H%M")
time_int = int(time_val)
if time_int <= MAX_HOUR_INT:
t = time.strptime(str(time_int), "%H")
else :
t = time.strptime(str(time_int), "%H%M")
time_val = datetime.time(t.tm_hour, t.tm_min, tzinfo=tz)
bp = channel_value_dict.get(API_BP)
diff_r = channel_value_dict.get(API_DIFF)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_ims_envista.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import unittest
from datetime import date, datetime, timedelta
from zoneinfo import ZoneInfo

import pytest
import pytz
from aiohttp import ClientSession

Expand All @@ -23,8 +23,8 @@ async def asyncSetUp(self) -> None:
"""Do Setup."""
self.token = os.environ.get("IMS_TOKEN")
if not self.token:
pytest.fail(f"Failed to load IMS Token")
pytest.fail("Failed to load IMS Token")

self.station_id = 178 # TEL AVIV COAST station
self.region_id = 13
self.channel_id = 7 # TD = Temperature Channel
Expand Down

0 comments on commit 7948eae

Please sign in to comment.