From 92802e8fbeb4c7d5f860916ae7ad5577127e74b4 Mon Sep 17 00:00:00 2001 From: Ernesto Ruge Date: Sun, 21 Jun 2026 12:21:58 +0200 Subject: [PATCH] more mobilithek improvements --- README.md | 20 ++++---- config_dist.yaml | 8 +-- webapp/cli/cli.py | 2 - webapp/cli/location_cli.py | 41 +++++++++------- webapp/cli/push_cli.py | 49 ------------------- .../import_services/generic_import_runner.py | 8 +-- 6 files changed, 42 insertions(+), 86 deletions(-) delete mode 100644 webapp/cli/push_cli.py diff --git a/README.md b/README.md index cc2b8beb..55a17e5f 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,9 @@ flask match run ### DATEX II push to Mobilithek ```bash -flask push datex-static # Full static DATEX II snapshot -flask push datex-realtime-full # Full realtime status snapshot -flask push datex-realtime-diff # Incremental realtime status diff +flask location push-mobilithek-static # Full static DATEX II snapshot +flask location push-mobilithek-realtime-full # Full realtime status snapshot +flask location push-mobilithek-realtime-diff # Incremental realtime status diff ``` See [DATEX II push to Mobilithek](#datex-ii-push-to-mobilithek-1) for details. @@ -137,9 +137,9 @@ Both DATEX II `3.5` and `3.7` are supported, selected via `MOBILITHEK_VERSION`. The pushes can be triggered manually through the CLI: ```bash -flask push datex-static # Full static DATEX II snapshot -flask push datex-realtime-full # Full realtime status snapshot (SNAPSHOT_PUSH) -flask push datex-realtime-diff # Incremental realtime status diff (DELTA_PUSH, skipped when empty) +flask location push-mobilithek-static # Full static DATEX II snapshot +flask location push-mobilithek-realtime-full # Full realtime status snapshot (SNAPSHOT_PUSH) +flask location push-mobilithek-realtime-diff # Incremental realtime status diff (DELTA_PUSH, skipped when empty) ``` ### Scheduled push @@ -157,10 +157,10 @@ MOBILITHEK_CERTIFICATE_FILENAME: 'mobilithek-binary-butterfly.crt.pem' # client MOBILITHEK_KEY_FILENAME: 'mobilithek-binary-butterfly.key.pem' # client key in KEY_DIR # Push schedule (only active when MOBILITHEK_ENABLED is true): -DATEX_STATIC_PUSH_HOUR: 3 # static snapshot once a day at this hour ... -DATEX_STATIC_PUSH_MINUTE: 0 # ... and minute -DATEX_REALTIME_FULL_PUSH_FREQUENCY: 21600 # full realtime snapshot, in seconds (default every 6 hours) -DATEX_REALTIME_DIFF_PUSH_FREQUENCY: 60 # incremental realtime diff, in seconds (default every minute) +MOBILITHEK_STATIC_PUSH_HOUR: 3 # static snapshot once a day at this hour ... +MOBILITHEK_STATIC_PUSH_MINUTE: 0 # ... and minute +MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY: 21600 # full realtime snapshot, in seconds (default every 6 hours) +MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY: 60 # incremental realtime diff, in seconds (default every minute) ``` Messages are sent via mutual-TLS `POST` to the Mobilithek publication endpoint, using the client certificate and key diff --git a/config_dist.yaml b/config_dist.yaml index ce866a61..b350bdff 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -23,12 +23,12 @@ MOBILITHEK_KEY_FILENAME: 'mobilithek-binary-butterfly.key.pem' # DATEX II push schedule (only active when MOBILITHEK_ENABLED is true). # Static data is pushed once a day at the configured time of day: -DATEX_STATIC_PUSH_HOUR: 3 -DATEX_STATIC_PUSH_MINUTE: 0 +MOBILITHEK_STATIC_PUSH_HOUR: 3 +MOBILITHEK_STATIC_PUSH_MINUTE: 0 # Full realtime status snapshot, in seconds (default every 6 hours): -DATEX_REALTIME_FULL_PUSH_FREQUENCY: 21600 +MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY: 21600 # Incremental realtime status diff, in seconds (default every minute): -DATEX_REALTIME_DIFF_PUSH_FREQUENCY: 60 +MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY: 60 SERVER_AUTH_USERS: # Test user for local development diff --git a/webapp/cli/cli.py b/webapp/cli/cli.py index 4ef345b4..c3239f8d 100644 --- a/webapp/cli/cli.py +++ b/webapp/cli/cli.py @@ -21,7 +21,6 @@ from .import_cli import import_cli from .location_cli import location_cli from .match_cli import match_cli -from .push_cli import push_cli from .source_cli import source_cli @@ -30,4 +29,3 @@ def register_cli_to_app(app: Flask): app.cli.add_command(import_cli) app.cli.add_command(source_cli) app.cli.add_command(location_cli) - app.cli.add_command(push_cli) diff --git a/webapp/cli/location_cli.py b/webapp/cli/location_cli.py index 404e783c..af08c173 100644 --- a/webapp/cli/location_cli.py +++ b/webapp/cli/location_cli.py @@ -16,12 +16,12 @@ along with this program. If not, see . """ -from datetime import datetime - import click from flask.cli import AppGroup +from webapp.common.error_handling import catch_exception from webapp.dependencies import dependencies +from webapp.services.push_services.datex_push_service import ChargeLocationService location_cli = AppGroup('location') @@ -33,21 +33,28 @@ def assign_regionalschluessel(source_id: str | None, re_assign: bool): dependencies.get_location_service().assign_official_region_codes(source_id=source_id, re_assign=re_assign) -@location_cli.command('push-datex-static', help='pushes datex2 static data') -def push_datex_static() -> None: - charge_location_service = dependencies.get_charge_location_service() +@location_cli.command('push-mobilithek-static', help='Push the full static DATEX II snapshot to Mobilithek.') +@catch_exception +def push_mobilithek_static() -> None: + charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() charge_location_service.push_datex_static() -@location_cli.command('push-datex-realtime', help='pushes datex2 realtime data') -@click.option('-s', '--since', 'updated_since', type=click.DateTime()) -@click.option('--incremental-update', 'incremental_update', default=False, is_flag=True) -def push_datex_realtime(updated_since: datetime | None = None, incremental_update: bool | None = None) -> None: - if incremental_update is not None and updated_since is not None: - raise click.BadParameter('Cannot specify incremental update and updated since') - - charge_location_service = dependencies.get_charge_location_service() - charge_location_service.push_datex_realtime( - updated_since=updated_since, - incremental_update=incremental_update or False, - ) +@location_cli.command( + 'push-mobilithek-realtime-full', + help='Push the full realtime DATEX II status snapshot to Mobilithek.', +) +@catch_exception +def push_mobilithek_realtime_full() -> None: + charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() + charge_location_service.push_datex_realtime(incremental_update=False) + + +@location_cli.command( + 'push-mobilithek-realtime-diff', + help='Push an incremental realtime DATEX II status diff to Mobilithek (nothing is sent if the diff is empty).', +) +@catch_exception +def push_mobilithek_realtime_diff() -> None: + charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() + charge_location_service.push_datex_realtime(incremental_update=True) diff --git a/webapp/cli/push_cli.py b/webapp/cli/push_cli.py deleted file mode 100644 index ddb9bc71..00000000 --- a/webapp/cli/push_cli.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -Open ChargePoint DataBase OCPDB -Copyright (C) 2026 binary butterfly GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -""" - -from flask.cli import AppGroup - -from webapp.common.error_handling import catch_exception -from webapp.dependencies import dependencies -from webapp.services.push_services.datex_push_service import ChargeLocationService - -push_cli = AppGroup('push') - - -@push_cli.command('datex-static', help='Push the full static DATEX II snapshot to Mobilithek.') -@catch_exception -def cli_push_datex_static() -> None: - charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() - charge_location_service.push_datex_static() - - -@push_cli.command('datex-realtime-full', help='Push the full realtime DATEX II status snapshot to Mobilithek.') -@catch_exception -def cli_push_datex_realtime_full() -> None: - charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() - charge_location_service.push_datex_realtime(incremental_update=False) - - -@push_cli.command( - 'datex-realtime-diff', - help='Push an incremental realtime DATEX II status diff to Mobilithek (nothing is sent if the diff is empty).', -) -@catch_exception -def cli_push_datex_realtime_diff() -> None: - charge_location_service: ChargeLocationService = dependencies.get_charge_location_service() - charge_location_service.push_datex_realtime(incremental_update=True) diff --git a/webapp/services/import_services/generic_import_runner.py b/webapp/services/import_services/generic_import_runner.py index 0087f3e4..f19af7fb 100644 --- a/webapp/services/import_services/generic_import_runner.py +++ b/webapp/services/import_services/generic_import_runner.py @@ -85,21 +85,21 @@ def _schedule_push(self): # Static data: push the full snapshot once a day. celery.add_periodic_task( crontab( - minute=str(self.config_helper.get('DATEX_STATIC_PUSH_MINUTE', 0)), - hour=str(self.config_helper.get('DATEX_STATIC_PUSH_HOUR', 3)), + minute=str(self.config_helper.get('MOBILITHEK_STATIC_PUSH_MINUTE', 0)), + hour=str(self.config_helper.get('MOBILITHEK_STATIC_PUSH_HOUR', 3)), ), push_datex_static_task, ) # Realtime data: push the full status snapshot every 6 hours ... celery.add_periodic_task( - self.config_helper.get('DATEX_REALTIME_FULL_PUSH_FREQUENCY', 6 * 60 * 60), + self.config_helper.get('MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY', 6 * 60 * 60), push_datex_realtime_full_task, ) # ... and an incremental diff every minute (skipped when nothing changed). celery.add_periodic_task( - self.config_helper.get('DATEX_REALTIME_DIFF_PUSH_FREQUENCY', 60), + self.config_helper.get('MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY', 60), push_datex_realtime_diff_task, )