mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 13:23:41 +00:00
Added new service for fetching historical/future price data:
- fetch_price_info_range: Query prices for arbitrary date ranges
- Supports start_time and end_time parameters
- Returns structured price data via service response
- Uses interval pool for efficient data retrieval
Service definition:
- services.yaml: Added fetch_price_info_range with date selectors
- services/__init__.py: Implemented handler with validation
- Response format: {"priceInfo": [...], "currency": "..."}
Schema updates:
- config_flow_handlers/schemas.py: Convert days slider to IntSelector
(was NumberSelector with float, caused "2.0 Tage" display issue)
Impact: Users can fetch price data for custom date ranges programmatically.
Config flow displays clean integer values for day offsets.
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""
|
|
Service handlers for Tibber Prices integration.
|
|
|
|
This package provides service endpoints for external integrations and data export:
|
|
- Chart data export (get_chartdata)
|
|
- ApexCharts YAML generation (get_apexcharts_yaml)
|
|
- User data refresh (refresh_user_data)
|
|
|
|
Architecture:
|
|
- helpers.py: Common utilities (get_entry_and_data)
|
|
- formatters.py: Data transformation and formatting functions
|
|
- chartdata.py: Main data export service handler
|
|
- apexcharts.py: ApexCharts card YAML generator
|
|
- refresh_user_data.py: User data refresh handler
|
|
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from custom_components.tibber_prices.const import DOMAIN
|
|
from homeassistant.core import SupportsResponse, callback
|
|
|
|
from .get_apexcharts_yaml import (
|
|
APEXCHARTS_SERVICE_SCHEMA,
|
|
APEXCHARTS_YAML_SERVICE_NAME,
|
|
handle_apexcharts_yaml,
|
|
)
|
|
from .get_chartdata import CHARTDATA_SERVICE_NAME, CHARTDATA_SERVICE_SCHEMA, handle_chartdata
|
|
from .get_price import GET_PRICE_SERVICE_NAME, GET_PRICE_SERVICE_SCHEMA, handle_get_price
|
|
from .refresh_user_data import (
|
|
REFRESH_USER_DATA_SERVICE_NAME,
|
|
REFRESH_USER_DATA_SERVICE_SCHEMA,
|
|
handle_refresh_user_data,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
__all__ = [
|
|
"async_setup_services",
|
|
]
|
|
|
|
|
|
@callback
|
|
def async_setup_services(hass: HomeAssistant) -> None:
|
|
"""Set up services for Tibber Prices integration."""
|
|
hass.services.async_register(
|
|
DOMAIN,
|
|
APEXCHARTS_YAML_SERVICE_NAME,
|
|
handle_apexcharts_yaml,
|
|
schema=APEXCHARTS_SERVICE_SCHEMA,
|
|
supports_response=SupportsResponse.ONLY,
|
|
)
|
|
hass.services.async_register(
|
|
DOMAIN,
|
|
CHARTDATA_SERVICE_NAME,
|
|
handle_chartdata,
|
|
schema=CHARTDATA_SERVICE_SCHEMA,
|
|
supports_response=SupportsResponse.ONLY,
|
|
)
|
|
hass.services.async_register(
|
|
DOMAIN,
|
|
GET_PRICE_SERVICE_NAME,
|
|
handle_get_price,
|
|
schema=GET_PRICE_SERVICE_SCHEMA,
|
|
supports_response=SupportsResponse.ONLY,
|
|
)
|
|
hass.services.async_register(
|
|
DOMAIN,
|
|
REFRESH_USER_DATA_SERVICE_NAME,
|
|
handle_refresh_user_data,
|
|
schema=REFRESH_USER_DATA_SERVICE_SCHEMA,
|
|
supports_response=SupportsResponse.ONLY,
|
|
)
|