Skip to content

Commit

Permalink
Consider the water temperature to be out of date 6 hours after measur…
Browse files Browse the repository at this point in the history
…ement (#40)

Co-authored-by: Maciej Bieniek <[email protected]>
  • Loading branch information
bieniu and bieniu authored Jun 6, 2024
1 parent afea399 commit 284c079
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions imgw_pib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Python wrapper for IMGW-PIB API."""

import logging
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
from typing import Any, Self

Expand Down Expand Up @@ -254,10 +254,9 @@ def _parse_hydrological_data(self: Self, data: dict[str, Any]) -> HydrologicalDa
data[ApiNames.WATER_TEMPERATURE_MEASUREMENT_DATE],
"%Y-%m-%d %H:%M:%S",
)
if (
water_temperature_measurement_date is not None
and water_temperature_measurement_date.date() == datetime.now(tz=UTC).date()
):
if water_temperature_measurement_date is not None and datetime.now(
tz=UTC
) - water_temperature_measurement_date < timedelta(hours=6):
water_temperature = data[ApiNames.WATER_TEMPERATURE]
else:
water_temperature_measurement_date = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "1.0.3"
VERSION = "1.0.4"

setup(
name="imgw_pib",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ async def test_water_temperature_not_current(
"""Test water_temperature is not current."""
session = aiohttp.ClientSession()

hydrological_station["temperatura_wody_data_pomiaru"] = "2002-01-01 12:00:01"
# The measurement was performed more than 6 hours before the test time
hydrological_station["temperatura_wody_data_pomiaru"] = "2024-04-22 05:00:00"

with aioresponses() as session_mock, freeze_time(TEST_TIME):
session_mock.get(API_HYDROLOGICAL_ENDPOINT, payload=hydrological_stations)
Expand Down

0 comments on commit 284c079

Please sign in to comment.