Files
ha-core/tests/components/environment_canada/conftest.py
Glenn Waters 406f894dc1 Environment Canada: Add a detailed forecast action (#138806)
* Add forecast service.

* Add detailed Environment Canada forecast data.

* Add icon and translations.

* Fix missing commas

* Add const.

* Add test.
2025-02-19 15:07:53 -06:00

31 lines
788 B
Python

"""Common fixture for Environment Canada tests."""
import contextlib
from datetime import datetime
import json
import pytest
from tests.common import load_fixture
@pytest.fixture
def ec_data():
"""Load Environment Canada data."""
def date_hook(weather):
"""Convert timestamp string to datetime."""
if t := weather.get("timestamp"):
with contextlib.suppress(ValueError):
weather["timestamp"] = datetime.fromisoformat(t)
elif t := weather.get("period"):
with contextlib.suppress(ValueError):
weather["period"] = datetime.fromisoformat(t)
return weather
return json.loads(
load_fixture("environment_canada/current_conditions_data.json"),
object_hook=date_hook,
)