diff --git a/custom_components/pvpc_energy/__init__.py b/custom_components/pvpc_energy/__init__.py index 5a2ef44..31a8e75 100755 --- a/custom_components/pvpc_energy/__init__.py +++ b/custom_components/pvpc_energy/__init__.py @@ -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) diff --git a/custom_components/pvpc_energy/coordinator.py b/custom_components/pvpc_energy/coordinator.py index 71898d4..f6f23cf 100644 --- a/custom_components/pvpc_energy/coordinator.py +++ b/custom_components/pvpc_energy/coordinator.py @@ -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) @@ -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): diff --git a/custom_components/pvpc_energy/services.yaml b/custom_components/pvpc_energy/services.yaml index 75a4098..ca9fe86 100644 --- a/custom_components/pvpc_energy/services.yaml +++ b/custom_components/pvpc_energy/services.yaml @@ -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: \ No newline at end of file + 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.