Skip to content

Conversation

@bj00rn
Copy link

@bj00rn bj00rn commented Jun 25, 2025

  • Add formatter
    • fix formatting
    • add default value
    • deduce type from action
    • deduce environment variable from action
  • Add sections
$ python main.py --help
usage: MQTT Gateway [-h] [-m MQTT_URI] [--mqtt-server-cert TLS_SERVER_CERT_PATH] [--mqtt-user MQTT_USER]
                    [--mqtt-password MQTT_PASSWORD] [--mqtt-client-id MQTT_CLIENT_ID]
                    [--mqtt-topic-prefix MQTT_TOPIC] [--mqtt-allow-dots-in-topic MQTT_ALLOW_DOTS_IN_TOPIC]
                    [--mqtt-server-cert-check-hostname TLS_SERVER_CERT_CHECK_HOSTNAME] [-s SAIC_REST_URI]
                    [-u SAIC_USER] [-p SAIC_PASSWORD] [--saic-phone-country-code SAIC_PHONE_COUNTRY_CODE]
                    [--saic-region SAIC_REGION] [--saic-tenant-id SAIC_TENANT_ID]
                    [--battery-capacity-mapping BATTERY_CAPACITY_MAPPING]
                    [--saic-relogin-delay SAIC_RELOGIN_DELAY] [--saic-read-timeout SAIC_READ_TIMEOUT]
                    [--messages-request-interval MESSAGES_REQUEST_INTERVAL]
                    [--charge-min-percentage CHARGE_DYNAMIC_POLLING_MIN_PERCENTAGE]
                    [--publish-raw-api-data PUBLISH_RAW_API_DATA]
                    [--charging-stations-json CHARGING_STATIONS_FILE]
                    [--ha-discovery HA_DISCOVERY_ENABLED] [--ha-discovery-prefix HA_DISCOVERY_PREFIX]
                    [--ha-show-unavailable HA_SHOW_UNAVAILABLE] [--abrp-api-key ABRP_API_KEY]
                    [--abrp-user-token ABRP_USER_TOKEN] [--publish-raw-abrp-data PUBLISH_RAW_ABRP_DATA]
                    [--osmand-server-uri OSMAND_SERVER_URI] [--osmand-device-id OSMAND_DEVICE_ID]
                    [--osmand-use-knots OSMAND_USE_KNOTS]
                    [--publish-raw-osmand-data PUBLISH_RAW_OSMAND_DATA]

options:
  -h, --help            show this help message and exit

MQTT Broker Configuration:
  -m MQTT_URI, --mqtt-uri MQTT_URI
                        The URI to the MQTT Server.
                        TCP: tcp://mqtt.eclipseprojects.io:1883
                        WebSocket: ws://mqtt.eclipseprojects.io:9001
                        TLS: tls://mqtt.eclipseprojects.io:8883
                        (type: str)
                        (default: tcp://localhost:1883)
                        (environment variable: MQTT_URI)
  --mqtt-server-cert TLS_SERVER_CERT_PATH
                        Path to the server certificate authority file in PEM format for TLS.
                        (type: str)
                        (default: None)
                        (environment variable: MQTT_SERVER_CERT)
  --mqtt-user MQTT_USER
                        The MQTT user name.
                        (type: str)
                        (default: mqtt_user)
                        (environment variable: MQTT_USER)
  --mqtt-password MQTT_PASSWORD
                        The MQTT password.
                        (type: str)
                        (default: secret)
                        (environment variable: MQTT_PASSWORD)
  --mqtt-client-id MQTT_CLIENT_ID
                        The MQTT Client Identifier.
                        (type: str)
                        (default: saic-python-mqtt-gateway)
                        (environment variable: MQTT_CLIENT_ID)
  --mqtt-topic-prefix MQTT_TOPIC
                        MQTT topic prefix.
                        (type: str)
                        (default: saic)
                        (environment variable: MQTT_TOPIC)
  --mqtt-allow-dots-in-topic MQTT_ALLOW_DOTS_IN_TOPIC
                        Allow dots in MQTT topics.
                        (type: bool)
                        (default: True)
                        (environment variable: MQTT_ALLOW_DOTS_IN_TOPIC)
  --mqtt-server-cert-check-hostname TLS_SERVER_CERT_CHECK_HOSTNAME
                        Check TLS certificate hostname when using custom certificate.
                        Set to (False) when using self-signed certificate without a matching hostname.
                        This option might be insecure.
                        (type: bool)
                        (default: True)
                        (environment variable: MQTT_SERVER_CERT_CHECK_HOSTNAME)

SAIC API Configuration:
  Configuration for the SAIC API connection.

  -s SAIC_REST_URI, --saic-rest-uri SAIC_REST_URI
                        The SAIC uri. Default is European Production Endpoint
                        (type: str)
                        (default: https://gateway-mg-eu.soimt.com/api.app/v1/)
                        (environment variable: SAIC_REST_URI)
  -u SAIC_USER, --saic-user SAIC_USER
                        The SAIC user name.
                        (type: str)
                        (default: [email protected])
                        (environment variable: SAIC_USER)
  -p SAIC_PASSWORD, --saic-password SAIC_PASSWORD
                        The SAIC password.
                        (type: str)
                        (default: 123456)
                        (environment variable: SAIC_PASSWORD)
  --saic-phone-country-code SAIC_PHONE_COUNTRY_CODE
                        The SAIC phone country code.
                        (type: str)
                        (default: None)
                        (environment variable: SAIC_PHONE_COUNTRY_CODE)
  --saic-region SAIC_REGION, --saic-region SAIC_REGION
                        The SAIC API region.
                        (type: str)
                        (default: eu)
                        (environment variable: SAIC_REGION)
  --saic-tenant-id SAIC_TENANT_ID
                        The SAIC API tenant id.
                        (type: str)
                        (default: 459771)
                        (environment variable: SAIC_TENANT_ID)
  --battery-capacity-mapping BATTERY_CAPACITY_MAPPING
                        The mapping of VIN to full battery capacity.
                        Multiple mappings can be provided separated by comma.
                        Example: LSJXXXX=54.0,LSJYYYY=64.0,
                        (type: str)
                        (default: None)
                        (environment variable: BATTERY_CAPACITY_MAPPING)
  --saic-relogin-delay SAIC_RELOGIN_DELAY
                        How long to wait before attempting another login to the SAIC API.
                        (type: int)
                        (default: None)
                        (environment variable: SAIC_RELOGIN_DELAY)
  --saic-read-timeout SAIC_READ_TIMEOUT
                        HTTP Read timeout for the SAIC API.
                        (type: float)
                        (default: None)
                        (environment variable: SAIC_READ_TIMEOUT)
  --messages-request-interval MESSAGES_REQUEST_INTERVAL
                        The interval for retrieving messages in seconds.
                        (type: int)
                        (default: 60)
                        (environment variable: MESSAGES_REQUEST_INTERVAL)
  --charge-min-percentage CHARGE_DYNAMIC_POLLING_MIN_PERCENTAGE
                        How many percentage points we should try to refresh the charge state.
                        (type: float)
                        (default: 1.0)
                        (environment variable: CHARGE_MIN_PERCENTAGE)
  --publish-raw-api-data PUBLISH_RAW_API_DATA
                        Publish raw SAIC API request/response to MQTT.
                        (type: bool)
                        (default: False)
                        (environment variable: PUBLISH_RAW_API_DATA_ENABLED)

OpenWB Integration:
  Configuration for the OpenWB integration.

  --charging-stations-json CHARGING_STATIONS_FILE
                        Custom charging stations configuration file name
                        (type: str)
                        (default: None)
                        (environment variable: CHARGING_STATIONS_JSON)

Home Assistant Integration:
  Configuration for the Home Assistant integration.

  --ha-discovery HA_DISCOVERY_ENABLED
                        Enable Home Assistant Discovery.
                        (type: bool)
                        (default: True)
                        (environment variable: HA_DISCOVERY_ENABLED)
  --ha-discovery-prefix HA_DISCOVERY_PREFIX
                        Home Assistant Discovery Prefix.
                        (default: homeassistant)
                        (environment variable: HA_DISCOVERY_PREFIX)
  --ha-show-unavailable HA_SHOW_UNAVAILABLE
                        Show entities as Unavailable in Home Assistant when car polling fails.
                        (type: bool)
                        (default: True)
                        (environment variable: HA_SHOW_UNAVAILABLE)

A Better Route Planner (ABRP) Integration:
  Configuration for the A Better Route Planner integration.

  --abrp-api-key ABRP_API_KEY
                        The API key for the A Better Route Planer telemetry API.
                        (type: str)
                        (default: 8cfc314b-03cd-4efe-ab7d-4431cd8f2e2d)
                        (environment variable: ABRP_API_KEY)
  --abrp-user-token ABRP_USER_TOKEN
                        The mapping of VIN to ABRP User Token.
                        Multiple mappings can be provided seperated by ,
                        Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,
                        (type: str)
                        (default: None)
                        (environment variable: ABRP_USER_TOKEN)
  --publish-raw-abrp-data PUBLISH_RAW_ABRP_DATA
                        Publish raw ABRP API request/response to MQTT.
                        (type: bool)
                        (default: False)
                        (environment variable: PUBLISH_RAW_ABRP_DATA_ENABLED)

OsmAnd Integration:
  Configuration for the OsmAnd integration.

  --osmand-server-uri OSMAND_SERVER_URI
                        The URL of your OsmAnd Server.
                        (type: str)
                        (default: None)
                        (environment variable: OSMAND_SERVER_URI)
  --osmand-device-id OSMAND_DEVICE_ID
                        The mapping of VIN to OsmAnd Device ID.
                        Multiple mappings can be provided seperated by ,
                        Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,
                        Uses the car VIN as Device ID if not set
                        (type: str)
                        (default: None)
                        (environment variable: OSMAND_DEVICE_ID)
  --osmand-use-knots OSMAND_USE_KNOTS
                        Whether to use knots of kph as a speed unit in OsmAnd messages to ensure compatibilty with Traccar.
                        (type: bool)
                        (default: True)
                        (environment variable: OSMAND_USE_KNOTS)
  --publish-raw-osmand-data PUBLISH_RAW_OSMAND_DATA
                        Publish raw ABRP OsmAnd request/response to MQTT.
                        (type: bool)
                        (default: False)
                        (environment variable: PUBLISH_RAW_OSMAND_DATA_ENABLED)

@bj00rn bj00rn force-pushed the chore/rework-help branch 6 times, most recently from 958b070 to 4c7da35 Compare June 25, 2025 20:54
@bj00rn bj00rn force-pushed the chore/rework-help branch from 4c7da35 to e379d51 Compare June 25, 2025 21:40
@bj00rn bj00rn changed the title rework argparse help Rework argparse help output Jun 25, 2025
@nanomad
Copy link
Contributor

nanomad commented Jun 26, 2025

@bj00rn very much appreciated 👍

Do you think we could split the parser creation into sub-functions? Let's say one for each argument group.

I'd like to eventually have each integration be responsible of its configuration

@bj00rn
Copy link
Author

bj00rn commented Jun 26, 2025

@bj00rn very much appreciated 👍

Do you think we could split the parser creation into sub-functions? Let's say one for each argument group.

I'd like to eventually have each integration be responsible of its configuration

Done.

Side note, i think it might be possible to generate documentation of the arguments to README using a formatter

@nanomad nanomad merged commit 8b513ca into SAIC-iSmart-API:develop Jun 27, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants