refactor(services): rename and reorganize custom services for clarity and functionality

This commit is contained in:
Julian Pawlowski 2025-11-23 13:17:21 +00:00
parent 9ee7f81164
commit 294d84128b
5 changed files with 13 additions and 9 deletions

View file

@ -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 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 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 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:** **Key Patterns:**
@ -473,7 +473,13 @@ custom_components/tibber_prices/
│ ├── __init__.py # Package exports │ ├── __init__.py # Package exports
│ ├── average.py # Trailing/leading average utilities │ ├── average.py # Trailing/leading average utilities
│ └── price.py # Price enrichment, level/rating calculations │ └── 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) ├── sensor/ # Sensor platform (package)
│ ├── __init__.py # Platform setup (async_setup_entry) │ ├── __init__.py # Platform setup (async_setup_entry)
│ ├── core.py # TibberPricesSensor class (1,268 lines) │ ├── core.py # TibberPricesSensor class (1,268 lines)

View file

@ -312,8 +312,7 @@ template:
The integration provides custom services for advanced use cases: The integration provides custom services for advanced use cases:
- `tibber_prices.get_price` - Fetch price data for specific days/times - `tibber_prices.get_chartdata` - Get price data in chart-friendly formats for any visualization card
- `tibber_prices.get_apexcharts_data` - Get formatted data for ApexCharts cards
- `tibber_prices.get_apexcharts_yaml` - Generate complete ApexCharts configurations - `tibber_prices.get_apexcharts_yaml` - Generate complete ApexCharts configurations
- `tibber_prices.refresh_user_data` - Manually refresh account information - `tibber_prices.refresh_user_data` - Manually refresh account information

View file

@ -163,8 +163,7 @@ async def async_unload_entry(
# Unregister services if this was the last config entry # Unregister services if this was the last config entry
if not hass.config_entries.async_entries(DOMAIN): if not hass.config_entries.async_entries(DOMAIN):
for service in [ for service in [
"get_price", "get_chartdata",
"get_apexcharts_data",
"get_apexcharts_yaml", "get_apexcharts_yaml",
"refresh_user_data", "refresh_user_data",
]: ]:

View file

@ -36,7 +36,7 @@ flowchart TB
%% Output Components %% Output Components
SENSORS["sensor/<br/>TibberPricesSensor<br/><br/>120+ price/level/rating sensors"] SENSORS["sensor/<br/>TibberPricesSensor<br/><br/>120+ price/level/rating sensors"]
BINARY["binary_sensor/<br/>TibberPricesBinarySensor<br/><br/>Period indicators"] BINARY["binary_sensor/<br/>TibberPricesBinarySensor<br/><br/>Period indicators"]
SERVICES["services.py<br/><br/>Custom service endpoints<br/>(get_price, ApexCharts)"] SERVICES["services/<br/><br/>Custom service endpoints<br/>(get_chartdata, ApexCharts)"]
%% Flow Connections %% Flow Connections
TIBBER -->|"Query user data<br/>Query prices<br/>(yesterday/today/tomorrow)"| API TIBBER -->|"Query user data<br/>Query prices<br/>(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 | | **Period Calculator** | `coordinator/periods.py` | Best/peak price period calculation with relaxation |
| **Sensors** | `sensor/` | 80+ entities for prices, levels, ratings, statistics | | **Sensors** | `sensor/` | 80+ entities for prices, levels, ratings, statistics |
| **Binary Sensors** | `binary_sensor/` | Period indicators (best/peak price active) | | **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) ### Sensor Architecture (Calculator Pattern)

View file

@ -665,7 +665,7 @@ These attributes allow automations to check: "Is the classification meaningful o
For advanced configuration patterns and technical deep-dive, see: For advanced configuration patterns and technical deep-dive, see:
- [Automation Examples](./automation-examples.md) - Real-world automation patterns - [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 ### Quick Reference