Skip to content

Commit

Permalink
fix: Fix Time (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh authored Sep 24, 2024
1 parent 5a2ab83 commit fa16c84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ims_envista/meteo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from __future__ import annotations

import datetime
import textwrap
import time
from dataclasses import dataclass, field
from datetime import datetime
from datetime import time as dttime

import pytz

from .const import (
API_BP,
Expand All @@ -18,6 +19,7 @@
API_NAME,
API_NIP,
API_RAIN,
API_RAIN_1_MIN,
API_RH,
API_STATION_ID,
API_STATUS,
Expand All @@ -36,7 +38,7 @@
API_WS_1MM,
API_WS_10MM,
API_WS_MAX,
VARIABLES, API_RAIN_1_MIN,
VARIABLES,
)


Expand All @@ -46,7 +48,7 @@ class MeteorologicalData:

station_id: int
"""Station ID"""
datetime: datetime
datetime: datetime.datetime
"""Date and time of the data"""
rain: float
"""Rainfall in mm"""
Expand Down Expand Up @@ -76,7 +78,7 @@ class MeteorologicalData:
"""Maximum 1 minute wind speed in m/s"""
ws_10mm: float
"""Maximum 10 minute wind speed in m/s"""
time: dttime
time: datetime.time
"""Time"""
bp: float
"""Maximum barometric pressure in mb"""
Expand Down Expand Up @@ -150,7 +152,12 @@ def __repr__(self) -> str:

def meteo_data_from_json(station_id: int, data: dict) -> MeteorologicalData:
"""Create a MeteorologicalData object from a JSON object."""
dt = datetime.fromisoformat(data[API_DATETIME])
tz = pytz.timezone("Asia/Jerusalem")
# is_dst = bool(time.localtime(time.time()).tm_isdst) # noqa: ERA001

dt = datetime.datetime.fromisoformat(data[API_DATETIME])
dt.replace(tzinfo=tz)

channel_value_dict = {}
for channel_value in data[API_CHANNELS]:
if channel_value[API_VALID] is True and channel_value[API_STATUS] == 1:
Expand All @@ -174,13 +181,16 @@ 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:
time_val = time.strptime(str(int(time_val)), "%H%M")
t = time.strptime(str(int(time_val)), "%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)
grad = channel_value_dict.get(API_GRAD)
nip = channel_value_dict.get(API_NIP)
rain_1_min = channel_value_dict.get(API_RAIN_1_MIN)



return MeteorologicalData(
station_id=station_id,
datetime=dt,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest-cov
pytest-asyncio
loguru
async_timeout
pytz
aiohttp>=3.10.5
setuptools>=70.0.0
urllib3>=2.2.2 # not directly required, pinned by Snyk to avoid a vulnerability
Expand Down

0 comments on commit fa16c84

Please sign in to comment.