From a409072428041d73a160f24478ec2e223edc7c48 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 15 Dec 2025 13:01:11 +0100 Subject: [PATCH] Initial commit --- .gitignore | 5 ++ README.md | 0 pyproject.toml | 26 +++++++++ src/.gitignore | 3 + src/arielle_collect/__init__.py | 0 src/arielle_collect/all_cars.py | 91 +++++++++++++++++++++++++++++ src/arielle_collect/config.json | 28 +++++++++ src/arielle_collect/main.py | 0 src/arielle_collect/post_install.py | 7 +++ src/arielle_collect/webui.py | 90 ++++++++++++++++++++++++++++ 10 files changed, 250 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/.gitignore create mode 100644 src/arielle_collect/__init__.py create mode 100644 src/arielle_collect/all_cars.py create mode 100644 src/arielle_collect/config.json create mode 100644 src/arielle_collect/main.py create mode 100644 src/arielle_collect/post_install.py create mode 100644 src/arielle_collect/webui.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bc95d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +.venv +build +ArielleCollect.egg-info + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..744cd7d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = [ + "setuptools>=61.0", +] +build-backend = "setuptools.build_meta" + +[project] +name = "ArielleCollect" +description = "Application for collect data from Arielle (id.3)" +dynamic = ["version"] +requires-python = ">=3.9" +authors = [ + { name = "Jens Ahrensfeld" } +] +dependencies = [ + "CarConnectivity[all] @ git+https://github.com/tillsteinbach/CarConnectivity.git@main" + +] +readme = "README.md" + +[project.scripts] +post_install = "arielle_collect.post_install:main" + +[tool.setuptools] +package-dir = {"" = "src"} +packages = ["arielle_collect"] diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..298579d --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +build +ArielleCollect.egg-info + diff --git a/src/arielle_collect/__init__.py b/src/arielle_collect/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/arielle_collect/all_cars.py b/src/arielle_collect/all_cars.py new file mode 100644 index 0000000..002c180 --- /dev/null +++ b/src/arielle_collect/all_cars.py @@ -0,0 +1,91 @@ +""" +This script is an example showing how to retrieve all vehicles from the account using the CarConnectivity library. + +Functions: + main: The main function that sets up argument parsing, logging, and retrieves vehicle data. + +Usage: + python all_cars.py [--tokenstorefile TOKENSTOREFILE] [-v] [--logging-format LOGGING_FORMAT] [--logging-date-format LOGGING_DATE_FORMAT] + +Arguments: + config: Path to the configuration file. + --tokenstorefile: File to store tokenstore (default: /tmp/tokenstore). + -v, --verbose: Logging level (verbosity). + --logging-format: Logging format configured for python logging (default: %(asctime)s:%(levelname)s:%(message)s). + --logging-date-format: Logging date format configured for python logging (default: %Y-%m-%dT%H:%M:%S%z). + +Logging Levels: + DEBUG, INFO, WARNING, ERROR, CRITICAL + +Example: + python all_cars.py config.json --tokenstorefile /path/to/tokenstore -v +""" +from __future__ import annotations +from typing import TYPE_CHECKING + +import argparse +import json +import os +import tempfile +import logging + +from carconnectivity import carconnectivity + +if TYPE_CHECKING: + from typing import List, Optional + + from carconnectivity.garage import Garage + + +LOG_LEVELS: List[str] = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] +DEFAULT_LOG_LEVEL = "ERROR" +LOG: logging.Logger = logging.getLogger("carconnectivity-example") + + +# pylint: disable=duplicate-code +def main() -> None: + """ Simple example showing how to retrieve all vehicles from the account """ + parser = argparse.ArgumentParser( + prog='allCars', + description='Example retrieving all cars in all configured connectors' + ) + parser.add_argument('config', help='Path to the configuration file') + default_temp: str = os.path.join(tempfile.gettempdir(), 'tokenstore') + parser.add_argument('--tokenstorefile', help=f'file to store tokenstore (default: {default_temp})', default=default_temp) + + logging_group = parser.add_argument_group('Logging') + logging_group.add_argument('-v', '--verbose', action="append_const", help='Logging level (verbosity)', const=-1,) + logging_group.add_argument('--logging-format', dest='logging_format', help='Logging format configured for python logging ' + '(default: %%(asctime)s:%%(module)s:%%(message)s)', default='%(asctime)s:%(levelname)s:%(message)s') + logging_group.add_argument('--logging-date-format', dest='logging_date_format', help='Logging format configured for python logging ' + '(default: %%Y-%%m-%%dT%%H:%%M:%%S%%z)', default='%Y-%m-%dT%H:%M:%S%z') + + args = parser.parse_args() + + log_level: int = LOG_LEVELS.index(DEFAULT_LOG_LEVEL) + for adjustment in args.verbose or (): + log_level = min(len(LOG_LEVELS) - 1, max(log_level + adjustment, 0)) + + logging.basicConfig(level=LOG_LEVELS[log_level], format=args.logging_format, datefmt=args.logging_date_format) + + print('# read CarConnectivity configuration') + with open(args.config, 'r', encoding='utf-8') as config_file: + config_dict = json.load(config_file) + print('# Login') + car_connectivity = carconnectivity.CarConnectivity(config=config_dict, tokenstore_file=args.tokenstorefile) + print('# fetch data') + car_connectivity.fetch_all() + print('# getData') + garage: Optional[Garage] = car_connectivity.get_garage() + if garage is not None: + print('# list all vehicles') + for vehicle in garage.list_vehicles(): + print(f'# {vehicle}') + print('# Shutdown') + car_connectivity.shutdown() + + print('# done') + + +if __name__ == '__main__': + main() diff --git a/src/arielle_collect/config.json b/src/arielle_collect/config.json new file mode 100644 index 0000000..6cc2ec3 --- /dev/null +++ b/src/arielle_collect/config.json @@ -0,0 +1,28 @@ +{ + "carConnectivity": { + "connectors": [ + { + "type": "volkswagen", + "config": { + "interval": 180, + "force_enable_access": true, + "username": "alex.thoni@gmx.de", + "password": "Arielle2024!" + } + } + ], + "plugins": [ + { + "type": "webui", + "disabled": false, + "config": { + "interval": 30, + "username": "jens", + "password": "jens", + "log_level": "debug", + "port": 8087 + } + } + ] + } +} \ No newline at end of file diff --git a/src/arielle_collect/main.py b/src/arielle_collect/main.py new file mode 100644 index 0000000..e69de29 diff --git a/src/arielle_collect/post_install.py b/src/arielle_collect/post_install.py new file mode 100644 index 0000000..f13f774 --- /dev/null +++ b/src/arielle_collect/post_install.py @@ -0,0 +1,7 @@ +#import patch +#pset = patch.fromfile(unified_diff_filename) +#pset.apply() + + +print("Post install executed") + diff --git a/src/arielle_collect/webui.py b/src/arielle_collect/webui.py new file mode 100644 index 0000000..4192e93 --- /dev/null +++ b/src/arielle_collect/webui.py @@ -0,0 +1,90 @@ +""" +This script is an example showing how to retrieve all vehicles from the account using the CarConnectivity library. + +Functions: + main: The main function that sets up argument parsing, logging, and retrieves vehicle data. + +Usage: + python all_cars.py [--tokenstorefile TOKENSTOREFILE] [-v] [--logging-format LOGGING_FORMAT] [--logging-date-format LOGGING_DATE_FORMAT] + +Arguments: + config: Path to the configuration file. + --tokenstorefile: File to store tokenstore (default: /tmp/tokenstore). + -v, --verbose: Logging level (verbosity). + --logging-format: Logging format configured for python logging (default: %(asctime)s:%(levelname)s:%(message)s). + --logging-date-format: Logging date format configured for python logging (default: %Y-%m-%dT%H:%M:%S%z). + +Logging Levels: + DEBUG, INFO, WARNING, ERROR, CRITICAL + +Example: + python all_cars.py config.json --tokenstorefile /path/to/tokenstore -v +""" +from __future__ import annotations + +import time +from typing import TYPE_CHECKING + +import argparse +import json +import os +import tempfile +import logging + +from carconnectivity import carconnectivity + +if TYPE_CHECKING: + from typing import List, Optional + + from carconnectivity.garage import Garage + + +LOG_LEVELS: List[str] = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] +DEFAULT_LOG_LEVEL = "ERROR" +LOG: logging.Logger = logging.getLogger("carconnectivity-example") + + +# pylint: disable=duplicate-code +def main() -> None: + """ Simple example showing how to retrieve all vehicles from the account """ + parser = argparse.ArgumentParser( + prog='allCars', + description='Example retrieving all cars in all configured connectors' + ) + parser.add_argument('config', help='Path to the configuration file') + default_temp: str = os.path.join(tempfile.gettempdir(), 'tokenstore') + parser.add_argument('--tokenstorefile', help=f'file to store tokenstore (default: {default_temp})', default=default_temp) + + logging_group = parser.add_argument_group('Logging') + logging_group.add_argument('-v', '--verbose', action="append_const", help='Logging level (verbosity)', const=-1,) + logging_group.add_argument('--logging-format', dest='logging_format', help='Logging format configured for python logging ' + '(default: %%(asctime)s:%%(module)s:%%(message)s)', default='%(asctime)s:%(levelname)s:%(message)s') + logging_group.add_argument('--logging-date-format', dest='logging_date_format', help='Logging format configured for python logging ' + '(default: %%Y-%%m-%%dT%%H:%%M:%%S%%z)', default='%Y-%m-%dT%H:%M:%S%z') + + args = parser.parse_args() + + log_level: int = LOG_LEVELS.index(DEFAULT_LOG_LEVEL) + for adjustment in args.verbose or (): + log_level = min(len(LOG_LEVELS) - 1, max(log_level + adjustment, 0)) + + logging.basicConfig(level=LOG_LEVELS[log_level], format=args.logging_format, datefmt=args.logging_date_format) + + print('# read CarConnectivity configuration') + with open(args.config, 'r', encoding='utf-8') as config_file: + config_dict = json.load(config_file) + print('# Login') + car_connectivity = carconnectivity.CarConnectivity(config=config_dict, tokenstore_file=args.tokenstorefile) + print('# startup') + car_connectivity.startup() + + while True: + time.sleep(1) + + car_connectivity.shutdown() + + print('# done') + + +if __name__ == '__main__': + main()