1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-14 18:14:35 +01:00
Files
core/tests/components/omie/__init__.py
T
Abílio Costa 9004f3a89a Add get_prices_for_date service action to OMIE (#175820)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-07 15:49:00 +02:00

51 lines
1.5 KiB
Python

"""Tests for the OMIE - Spain and Portugal electricity prices integration."""
from datetime import date
from pyomie.model import OMIEResults
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def setup_integration(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
"""Set up the OMIE integration."""
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
def price_enc(country: int, day: int, hour: int, minute: int) -> float:
"""Encode the given data into a price.
Format is CCDDhhmm000. Examples:
- 351 15 01 15 000 for CC=351 (Portugal), DD=15 (day),
hh=01 (1 am), mm=15.
- 34 16 23 00 000 for CC=34 (Spain), DD=16 (day of month), hh=23 (11 pm), mm=00.
This allows us to make assertions in tests without having
to look up the expected values in large datasets.
"""
return country * 10**9 + day * 10**7 + hour * 10**5 + minute * 10**3
def spot_price_fetcher(spot_price_data: dict):
"""Return spot price fetcher for any data dictionary.
Args:
spot_price_data: Dictionary mapping ISO date strings to mock results
"""
data_by_date = {
date.fromisoformat(iso_date): mock_result
for iso_date, mock_result in spot_price_data.items()
}
async def _spot_price_fetcher(session, requested_date) -> OMIEResults | None:
return data_by_date.get(requested_date)
return _spot_price_fetcher