Skip to content

Commit 6f2e14e

Browse files
authored
feat: Fix time according to TZ (+1 on DST) (#69)
1 parent 58f0af6 commit 6f2e14e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ims_envista/meteo_data.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def __repr__(self) -> str:
153153

154154
def meteo_data_from_json(station_id: int, data: dict) -> MeteorologicalData:
155155
"""Create a MeteorologicalData object from a JSON object."""
156-
# is_dst = bool(time.localtime(time.time()).tm_isdst) # noqa: ERA001
156+
is_dst = bool(time.localtime(time.time()).tm_isdst)
157157

158158
dt = datetime.datetime.fromisoformat(data[API_DATETIME])
159159
dt.replace(tzinfo=tz)
@@ -189,7 +189,10 @@ def meteo_data_from_json(station_id: int, data: dict) -> MeteorologicalData:
189189
nip = channel_value_dict.get(API_NIP)
190190
rain_1_min = channel_value_dict.get(API_RAIN_1_MIN)
191191

192-
192+
if is_dst and time_val:
193+
# Strange IMS logic :o
194+
dt = dt + datetime.timedelta(hours=1)
195+
time_val = time_val.replace(hour=(time_val.hour+1)%24)
193196

194197
return MeteorologicalData(
195198
station_id=station_id,

0 commit comments

Comments
 (0)