From 294d84128b88675b55a6882b3498a62b3fb63d43 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Sun, 23 Nov 2025 13:17:21 +0000 Subject: [PATCH] refactor(services): rename and reorganize custom services for clarity and functionality --- AGENTS.md | 10 ++++++++-- README.md | 3 +-- custom_components/tibber_prices/__init__.py | 3 +-- docs/development/architecture.md | 4 ++-- docs/user/period-calculation.md | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a32fcaa..98fbf80 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -379,7 +379,7 @@ After successful refactoring: 2. `TibberPricesDataUpdateCoordinator` (`coordinator.py`) orchestrates updates every 15 minutes, manages persistent storage via `Store`, and schedules quarter-hour entity refreshes 3. Price enrichment functions (`utils/price.py`, `utils/average.py`) calculate trailing/leading 24h averages, price differences, and rating levels for each 15-minute interval 4. Entity platforms (`sensor/` package, `binary_sensor/` package) expose enriched data as Home Assistant entities -5. Custom services (`services.py`) provide API endpoints for integrations like ApexCharts +5. Custom services (`services/` package) provide API endpoints for chart data export, ApexCharts YAML generation, and user data refresh **Key Patterns:** @@ -473,7 +473,13 @@ custom_components/tibber_prices/ │ ├── __init__.py # Package exports │ ├── average.py # Trailing/leading average utilities │ └── price.py # Price enrichment, level/rating calculations -├── services.py # Custom services (get_price, ApexCharts, etc.) +├── services/ # Custom services package +│ ├── __init__.py # Service registration +│ ├── chartdata.py # Chart data export service +│ ├── apexcharts.py # ApexCharts YAML generator +│ ├── refresh_user_data.py # User data refresh +│ ├── formatters.py # Data transformation utilities +│ └── helpers.py # Common service helpers ├── sensor/ # Sensor platform (package) │ ├── __init__.py # Platform setup (async_setup_entry) │ ├── core.py # TibberPricesSensor class (1,268 lines) diff --git a/README.md b/README.md index 6907ab6..ad35dd5 100644 --- a/README.md +++ b/README.md @@ -312,8 +312,7 @@ template: The integration provides custom services for advanced use cases: -- `tibber_prices.get_price` - Fetch price data for specific days/times -- `tibber_prices.get_apexcharts_data` - Get formatted data for ApexCharts cards +- `tibber_prices.get_chartdata` - Get price data in chart-friendly formats for any visualization card - `tibber_prices.get_apexcharts_yaml` - Generate complete ApexCharts configurations - `tibber_prices.refresh_user_data` - Manually refresh account information diff --git a/custom_components/tibber_prices/__init__.py b/custom_components/tibber_prices/__init__.py index 7a6413c..9f43185 100644 --- a/custom_components/tibber_prices/__init__.py +++ b/custom_components/tibber_prices/__init__.py @@ -163,8 +163,7 @@ async def async_unload_entry( # Unregister services if this was the last config entry if not hass.config_entries.async_entries(DOMAIN): for service in [ - "get_price", - "get_apexcharts_data", + "get_chartdata", "get_apexcharts_yaml", "refresh_user_data", ]: diff --git a/docs/development/architecture.md b/docs/development/architecture.md index 32bfd9c..f8d0a1b 100644 --- a/docs/development/architecture.md +++ b/docs/development/architecture.md @@ -36,7 +36,7 @@ flowchart TB %% Output Components SENSORS["sensor/
TibberPricesSensor

120+ price/level/rating sensors"] BINARY["binary_sensor/
TibberPricesBinarySensor

Period indicators"] - SERVICES["services.py

Custom service endpoints
(get_price, ApexCharts)"] + SERVICES["services/

Custom service endpoints
(get_chartdata, ApexCharts)"] %% Flow Connections TIBBER -->|"Query user data
Query prices
(yesterday/today/tomorrow)"| API @@ -199,7 +199,7 @@ For detailed cache behavior, see [Caching Strategy](./caching-strategy.md). | **Period Calculator** | `coordinator/periods.py` | Best/peak price period calculation with relaxation | | **Sensors** | `sensor/` | 80+ entities for prices, levels, ratings, statistics | | **Binary Sensors** | `binary_sensor/` | Period indicators (best/peak price active) | -| **Services** | `services.py` | Custom service endpoints (get_price, ApexCharts) | +| **Services** | `services/` | Custom service endpoints (get_chartdata, get_apexcharts_yaml, refresh_user_data) | ### Sensor Architecture (Calculator Pattern) diff --git a/docs/user/period-calculation.md b/docs/user/period-calculation.md index 56c1d24..0a847ad 100644 --- a/docs/user/period-calculation.md +++ b/docs/user/period-calculation.md @@ -665,7 +665,7 @@ These attributes allow automations to check: "Is the classification meaningful o For advanced configuration patterns and technical deep-dive, see: - [Automation Examples](./automation-examples.md) - Real-world automation patterns -- [Services](./services.md) - Using the `tibber_prices.get_price` service for custom logic +- [Services](./services.md) - Using the `tibber_prices.get_chartdata` service for custom visualizations ### Quick Reference