Skip to content

Commit

Permalink
Add service name and descriptions
Browse files Browse the repository at this point in the history
Recalculate bills in service reprocess_energy_data
  • Loading branch information
yinyang17 committed Mar 17, 2024
1 parent 1ec87d1 commit a24070b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions custom_components/pvpc_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def handle_import_energy_data(call):
hass.async_create_task(PvpcCoordinator.import_energy_data(hass))
def handle_force_import_energy_data(call):
hass.async_create_task(PvpcCoordinator.import_energy_data(hass, True))
def handle_reprocess_statistics(call):
hass.async_create_task(PvpcCoordinator.reprocess_statistics(hass))
def handle_reprocess_energy_data(call):
hass.async_create_task(PvpcCoordinator.reprocess_energy_data(hass))

hass.services.register(DOMAIN, "import_energy_data", handle_import_energy_data)
hass.services.register(DOMAIN, "force_import_energy_data", handle_force_import_energy_data)
hass.services.register(DOMAIN, "reprocess_statistics", handle_reprocess_statistics)
hass.services.register(DOMAIN, "reprocess_energy_data", handle_reprocess_energy_data)

async_track_time_change(hass, handle_import_energy_data, hour=7, minute=5, second=0)
handle_import_energy_data(None)
Expand Down
5 changes: 4 additions & 1 deletion custom_components/pvpc_energy/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def set_config(config):
UFD.cups = config['cups']
_LOGGER.debug(f"END - set_config")

async def reprocess_statistics(hass):
async def reprocess_energy_data(hass):
_LOGGER.debug(f"START - reprocess_statistics()")
consumptions, prices = PvpcCoordinator.load_energy_data(ENERGY_FILE)

Expand All @@ -64,6 +64,9 @@ async def reprocess_statistics(hass):
_LOGGER.info(f"len(consumption_statistics)={len(consumption_statistics)}, len(cost_statistics)={len(cost_statistics)}")
await get_instance(hass).async_add_executor_job(async_add_external_statistics, hass, consumption_metadata, consumption_statistics)
await get_instance(hass).async_add_executor_job(async_add_external_statistics, hass, cost_metadata, cost_statistics)

billing_periods = PvpcCoordinator.load_billing_periods(BILLING_PERIODS_FILE)
await PvpcCoordinator.calculate_bills(billing_periods, consumptions, hass, True)
_LOGGER.debug(f"END - reprocess_statistics()")

async def import_energy_data(hass, force_update=False):
Expand Down
8 changes: 7 additions & 1 deletion custom_components/pvpc_energy/services.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import_energy_data:
name: Obtener nuevos datos de energía
description: Obtiene nuevos datos de energía desde el último día hasta dos menos del actual. Se ejecuta automáticamnete todos los días a las 7:05.
force_import_energy_data:
reprocess_statistics:
name: Forzar obtención de datos de energía
description: Obtiene los datos de energía (consumo y coste) de los dos últimos años y actualiza los datos existentes, las estadísticas y las facturas.
reprocess_energy_data:
name: Reprocesar datos (panel de energía y facturas)
description: Reprocesa los datos existentes y regenera las estadísticas del panel de energía y las facturas.

0 comments on commit a24070b

Please sign in to comment.