Skip to content
  • Sponsor GuyKh/py-ims-envista

  • Notifications You must be signed in to change notification settings
  • Fork 0

Commit 7948eae

Browse files
authoredOct 29, 2024··
Fix: Bad Time Parsing (single digit) (#80)
1 parent 63789e6 commit 7948eae

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed
 

‎.ruff.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ ignore = [
1919
"COM812", # incompatible with formatter
2020
"ISC001", # incompatible with formatter
2121
"S101", # Assert,
22-
"E501" # Line too long
22+
"E501", # Line too long
23+
"DTZ005" # datetime.now() without timezone
2324
]
2425

2526
[lint.flake8-pytest-style]

‎ims_envista/commons.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ async def get(
9090
msg = f"Received Error from IMS Envista API from {url}: {response.status, response.reason}"
9191
raise ImsEnvistaApiClientError(msg)
9292

93+
_LOGGER.debug("Response from %s: %s", url, json_resp)
9394
return json_resp

‎ims_envista/ims_envista.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, token: UUID | str, session: ClientSession | None = None) -> N
4848
raise ValueError(err_msg)
4949

5050
if not session:
51-
session = ClientSession(trace_configs=[trace_config])
51+
session = ClientSession()
5252
atexit.register(self._shutdown)
5353

5454
self._session = session

‎ims_envista/meteo_data.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
VARIABLES,
4242
)
4343

44+
MAX_HOUR_INT = 24
4445

4546
@dataclass
4647
class MeteorologicalData:
@@ -152,7 +153,7 @@ def __repr__(self) -> str:
152153
tz = pytz.timezone("Asia/Jerusalem")
153154

154155

155-
def _fix_datetime_offset(dt):
156+
def _fix_datetime_offset(dt: datetime.datetime) -> tuple[datetime.datetime, bool]:
156157
dt = dt.replace(tzinfo=None)
157158
dt = tz.localize(dt)
158159

@@ -200,7 +201,11 @@ def meteo_data_from_json(station_id: int, data: dict) -> MeteorologicalData:
200201
tw = channel_value_dict.get(API_TW)
201202
time_val = channel_value_dict.get(API_TIME)
202203
if time_val:
203-
t = time.strptime(str(int(time_val)), "%H%M")
204+
time_int = int(time_val)
205+
if time_int <= MAX_HOUR_INT:
206+
t = time.strptime(str(time_int), "%H")
207+
else :
208+
t = time.strptime(str(time_int), "%H%M")
204209
time_val = datetime.time(t.tm_hour, t.tm_min, tzinfo=tz)
205210
bp = channel_value_dict.get(API_BP)
206211
diff_r = channel_value_dict.get(API_DIFF)

‎tests/unit/test_ims_envista.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import os
44
import unittest
55
from datetime import date, datetime, timedelta
6-
from zoneinfo import ZoneInfo
76

7+
import pytest
88
import pytz
99
from aiohttp import ClientSession
1010

@@ -23,8 +23,8 @@ async def asyncSetUp(self) -> None:
2323
"""Do Setup."""
2424
self.token = os.environ.get("IMS_TOKEN")
2525
if not self.token:
26-
pytest.fail(f"Failed to load IMS Token")
27-
26+
pytest.fail("Failed to load IMS Token")
27+
2828
self.station_id = 178 # TEL AVIV COAST station
2929
self.region_id = 13
3030
self.channel_id = 7 # TD = Temperature Channel

0 commit comments

Comments
 (0)
Please sign in to comment.