Skip to content

Commit b519b1c

Browse files
committed
Poetry: Enable dynamic versioning based on git tags
1 parent a5c4404 commit b519b1c

File tree

3 files changed

+67
-42
lines changed

3 files changed

+67
-42
lines changed

pyproject.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[project]
22
name = "saic-python-mqtt-gateway"
3-
version = "0.9.4"
43
description = "A service that queries the data from an MG iSMART account and publishes the data over MQTT and to other sources"
54
authors = [
65
{ name = "Giovanni Condello", email = "saic-python-client@nanomad.net" }
@@ -22,14 +21,20 @@ dependencies = [
2221
'inflection (>=0.5.1,<0.6.0)',
2322
'apscheduler (>=3.11.0,<4.0.0)',
2423
]
24+
dynamic = ["version"]
2525

2626
[project.urls]
2727
Homepage = "https://github.com/SAIC-iSmart-API/saic-python-mqtt-gateway"
2828
Issues = "https://github.com/SAIC-iSmart-API/saic-python-mqtt-gateway/issues"
2929

30+
[build-system]
31+
requires = ["poetry-core>=2.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
32+
build-backend = "poetry_dynamic_versioning.backend"
33+
3034
[tool.poetry]
3135
package-mode = false
3236
requires-poetry = '>=2.0,<3.0'
37+
version = "0.0.0"
3338

3439
[tool.poetry.group.dev.dependencies]
3540
pytest = "^8.2.2"
@@ -45,9 +50,14 @@ pylint = "^3.3.6"
4550
[tool.poetry.dependencies]
4651
saic-ismart-client-ng = { develop = true }
4752

48-
[build-system]
49-
requires = ["poetry-core>=2.0.0"]
50-
build-backend = "poetry.core.masonry.api"
53+
[tool.poetry.requires-plugins]
54+
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
55+
56+
[tool.poetry-dynamic-versioning]
57+
enable = true
58+
vcs = "git"
59+
style = "semver"
60+
pattern = "default-unprefixed"
5161

5262
[tool.pytest.ini_options]
5363
norecursedirs = ".git build dist"
@@ -250,4 +260,4 @@ score = false
250260
expected-line-ending-format = "LF"
251261

252262
[tool.pylint.EXCEPTIONS]
253-
overgeneral-exceptions = ["builtins.BaseException", "builtins.Exception"]
263+
overgeneral-exceptions = ["builtins.BaseException", "builtins.Exception"]

src/configuration/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from enum import Enum
44
from typing import TYPE_CHECKING
55

6+
from saic_ismart_client_ng.model import DEFAULT_BASE_URI, DEFAULT_REGION, DEFAULT_TENANT_ID, DEFAULT_USER_AGENT
7+
68
if TYPE_CHECKING:
79
from integrations.openwb.charging_station import ChargingStation
810

@@ -22,9 +24,10 @@ def __init__(self) -> None:
2224
self.saic_user: str | None = None
2325
self.saic_password: str | None = None
2426
self.__saic_phone_country_code: str | None = None
25-
self.saic_rest_uri: str = "https://gateway-mg-eu.soimt.com/api.app/v1/"
26-
self.saic_region: str = "eu"
27-
self.saic_tenant_id: str = "459771"
27+
self.saic_rest_uri: str = DEFAULT_BASE_URI
28+
self.saic_region: str = DEFAULT_REGION
29+
self.saic_tenant_id: str = DEFAULT_TENANT_ID
30+
self.saic_user_agent: str = DEFAULT_USER_AGENT
2831
self.saic_relogin_delay: int = 15 * 60 # in seconds
2932
self.saic_read_timeout: float = 10.0 # in seconds
3033
self.battery_capacity_map: dict[str, float] = {}

src/configuration/parser.py

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pathlib import Path
77
import urllib.parse
88

9+
from saic_ismart_client_ng.model import DEFAULT_TENANT_ID, DEFAULT_REGION, DEFAULT_USER_AGENT, DEFAULT_BASE_URI
10+
911
from configuration import Configuration, TransportProtocol
1012
from configuration.argparse_extensions import (
1113
EnvDefault,
@@ -60,9 +62,9 @@ def process_arguments() -> Configuration:
6062
"-m",
6163
"--mqtt-uri",
6264
help="The URI to the MQTT Server. Environment Variable: MQTT_URI,"
63-
"TCP: tcp://mqtt.eclipseprojects.io:1883 "
64-
"WebSocket: ws://mqtt.eclipseprojects.io:9001"
65-
"TLS: tls://mqtt.eclipseprojects.io:8883",
65+
"TCP: tcp://mqtt.eclipseprojects.io:1883 "
66+
"WebSocket: ws://mqtt.eclipseprojects.io:9001"
67+
"TLS: tls://mqtt.eclipseprojects.io:8883",
6668
dest="mqtt_uri",
6769
required=False,
6870
action=EnvDefault,
@@ -95,8 +97,8 @@ def process_arguments() -> Configuration:
9597
parser.add_argument(
9698
"--mqtt-client-id",
9799
help="The MQTT Client Identifier. Environment Variable: "
98-
"MQTT_CLIENT_ID "
99-
"Default is saic-python-mqtt-gateway",
100+
"MQTT_CLIENT_ID "
101+
"Default is saic-python-mqtt-gateway",
100102
default="saic-python-mqtt-gateway",
101103
dest="mqtt_client_id",
102104
required=False,
@@ -126,8 +128,8 @@ def process_arguments() -> Configuration:
126128
"-s",
127129
"--saic-rest-uri",
128130
help="The SAIC uri. Environment Variable: SAIC_REST_URI Default is the European "
129-
"Production Endpoint: https://tap-eu.soimt.com",
130-
default="https://gateway-mg-eu.soimt.com/api.app/v1/",
131+
f"Production Endpoint: {DEFAULT_BASE_URI}",
132+
default=DEFAULT_BASE_URI,
131133
dest="saic_rest_uri",
132134
required=False,
133135
action=EnvDefault,
@@ -162,28 +164,37 @@ def process_arguments() -> Configuration:
162164
parser.add_argument(
163165
"--saic-region",
164166
"--saic-region",
165-
help="The SAIC API region. Environment Variable: SAIC_REGION",
166-
default="eu",
167+
help=f"The SAIC API region. Default is {DEFAULT_REGION}. Environment Variable: SAIC_REGION",
168+
default=DEFAULT_REGION,
167169
dest="saic_region",
168170
required=False,
169171
action=EnvDefault,
170172
envvar="SAIC_REGION",
171173
)
172174
parser.add_argument(
173175
"--saic-tenant-id",
174-
help="The SAIC API tenant id. Environment Variable: SAIC_TENANT_ID",
175-
default="459771",
176+
help=f"The SAIC API tenant id. Default is {DEFAULT_TENANT_ID}. Environment Variable: SAIC_TENANT_ID",
177+
default=DEFAULT_TENANT_ID,
176178
dest="saic_tenant_id",
177179
required=False,
178180
action=EnvDefault,
179181
envvar="SAIC_TENANT_ID",
180182
)
183+
parser.add_argument(
184+
"--saic-user-agent",
185+
help="The SAIC API User Agent. Defaults to the latest iOS app. Environment Variable: SAIC_USER_AGENT",
186+
default=DEFAULT_USER_AGENT,
187+
dest="saic_user_agent",
188+
required=False,
189+
action=EnvDefault,
190+
envvar="SAIC_USER_AGENT",
191+
)
181192
parser.add_argument(
182193
"--battery-capacity-mapping",
183194
help="The mapping of VIN to full batteryc"
184-
" apacity. Multiple mappings can be provided separated"
185-
" by , Example: LSJXXXX=54.0,LSJYYYY=64.0,"
186-
" Environment Variable: BATTERY_CAPACITY_MAPPING",
195+
" apacity. Multiple mappings can be provided separated"
196+
" by , Example: LSJXXXX=54.0,LSJYYYY=64.0,"
197+
" Environment Variable: BATTERY_CAPACITY_MAPPING",
187198
dest="battery_capacity_mapping",
188199
required=False,
189200
action=EnvDefault,
@@ -200,7 +211,7 @@ def process_arguments() -> Configuration:
200211
parser.add_argument(
201212
"--saic-relogin-delay",
202213
help="How long to wait before attempting another login to the SAIC API. Environment "
203-
"Variable: SAIC_RELOGIN_DELAY",
214+
"Variable: SAIC_RELOGIN_DELAY",
204215
dest="saic_relogin_delay",
205216
required=False,
206217
action=EnvDefault,
@@ -210,7 +221,7 @@ def process_arguments() -> Configuration:
210221
parser.add_argument(
211222
"--saic-read-timeout",
212223
help="HTTP Read timeout for the SAIC API. Environment "
213-
"Variable: SAIC_READ_TIMEOUT",
224+
"Variable: SAIC_READ_TIMEOUT",
214225
dest="saic_read_timeout",
215226
required=False,
216227
action=EnvDefault,
@@ -239,7 +250,7 @@ def process_arguments() -> Configuration:
239250
parser.add_argument(
240251
"--ha-show-unavailable",
241252
help="Show entities as Unavailable in Home Assistant when car polling fails. "
242-
"Environment Variable: HA_SHOW_UNAVAILABLE",
253+
"Environment Variable: HA_SHOW_UNAVAILABLE",
243254
dest="ha_show_unavailable",
244255
required=False,
245256
action=EnvDefault,
@@ -250,7 +261,7 @@ def process_arguments() -> Configuration:
250261
parser.add_argument(
251262
"--messages-request-interval",
252263
help="The interval for retrieving messages in seconds. Environment Variable: "
253-
"MESSAGES_REQUEST_INTERVAL",
264+
"MESSAGES_REQUEST_INTERVAL",
254265
dest="messages_request_interval",
255266
required=False,
256267
action=EnvDefault,
@@ -260,7 +271,7 @@ def process_arguments() -> Configuration:
260271
parser.add_argument(
261272
"--charge-min-percentage",
262273
help="How many % points we should try to refresh the charge state. Environment Variable: "
263-
"CHARGE_MIN_PERCENTAGE",
274+
"CHARGE_MIN_PERCENTAGE",
264275
dest="charge_dynamic_polling_min_percentage",
265276
required=False,
266277
action=EnvDefault,
@@ -271,7 +282,7 @@ def process_arguments() -> Configuration:
271282
parser.add_argument(
272283
"--publish-raw-api-data",
273284
help="Publish raw SAIC API request/response to MQTT. Environment Variable: "
274-
"PUBLISH_RAW_API_DATA_ENABLED",
285+
"PUBLISH_RAW_API_DATA_ENABLED",
275286
dest="publish_raw_api_data",
276287
required=False,
277288
action=EnvDefault,
@@ -284,9 +295,9 @@ def process_arguments() -> Configuration:
284295
parser.add_argument(
285296
"--abrp-api-key",
286297
help="The API key for the A Better Route Planer telemetry API."
287-
" Default is the open source telemetry"
288-
" API key 8cfc314b-03cd-4efe-ab7d-4431cd8f2e2d."
289-
" Environment Variable: ABRP_API_KEY",
298+
" Default is the open source telemetry"
299+
" API key 8cfc314b-03cd-4efe-ab7d-4431cd8f2e2d."
300+
" Environment Variable: ABRP_API_KEY",
290301
default="8cfc314b-03cd-4efe-ab7d-4431cd8f2e2d",
291302
dest="abrp_api_key",
292303
required=False,
@@ -296,9 +307,9 @@ def process_arguments() -> Configuration:
296307
parser.add_argument(
297308
"--abrp-user-token",
298309
help="The mapping of VIN to ABRP User Token."
299-
" Multiple mappings can be provided seperated by ,"
300-
" Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,"
301-
" Environment Variable: ABRP_USER_TOKEN",
310+
" Multiple mappings can be provided seperated by ,"
311+
" Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,"
312+
" Environment Variable: ABRP_USER_TOKEN",
302313
dest="abrp_user_token",
303314
required=False,
304315
action=EnvDefault,
@@ -307,7 +318,7 @@ def process_arguments() -> Configuration:
307318
parser.add_argument(
308319
"--publish-raw-abrp-data",
309320
help="Publish raw ABRP API request/response to MQTT. Environment Variable: "
310-
"PUBLISH_RAW_ABRP_DATA_ENABLED",
321+
"PUBLISH_RAW_ABRP_DATA_ENABLED",
311322
dest="publish_raw_abrp_data",
312323
required=False,
313324
action=EnvDefault,
@@ -319,8 +330,8 @@ def process_arguments() -> Configuration:
319330
parser.add_argument(
320331
"--osmand-server-uri",
321332
help="The URL of your OsmAnd Server."
322-
" Default unset"
323-
" Environment Variable: OSMAND_SERVER_URI",
333+
" Default unset"
334+
" Environment Variable: OSMAND_SERVER_URI",
324335
default=None,
325336
dest="osmand_server_uri",
326337
required=False,
@@ -330,10 +341,10 @@ def process_arguments() -> Configuration:
330341
parser.add_argument(
331342
"--osmand-device-id",
332343
help="The mapping of VIN to OsmAnd Device ID."
333-
" Multiple mappings can be provided seperated by ,"
334-
" Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,"
335-
" Default is to use the car VIN as Device ID, "
336-
" Environment Variable: OSMAND_DEVICE_ID",
344+
" Multiple mappings can be provided seperated by ,"
345+
" Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl,"
346+
" Default is to use the car VIN as Device ID, "
347+
" Environment Variable: OSMAND_DEVICE_ID",
337348
dest="osmand_device_id",
338349
required=False,
339350
action=EnvDefault,
@@ -342,7 +353,7 @@ def process_arguments() -> Configuration:
342353
parser.add_argument(
343354
"--publish-raw-osmand-data",
344355
help="Publish raw ABRP OsmAnd request/response to MQTT. Environment Variable: "
345-
"PUBLISH_RAW_OSMAND_DATA_ENABLED",
356+
"PUBLISH_RAW_OSMAND_DATA_ENABLED",
346357
dest="publish_raw_osmand_data",
347358
required=False,
348359
action=EnvDefault,
@@ -370,6 +381,7 @@ def process_arguments() -> Configuration:
370381
config.saic_rest_uri = args.saic_rest_uri
371382
config.saic_region = args.saic_region
372383
config.saic_tenant_id = str(args.saic_tenant_id)
384+
config.saic_user_agent = args.saic_user_agent
373385
config.saic_user = args.saic_user
374386
config.saic_password = args.saic_password
375387
config.saic_phone_country_code = args.saic_phone_country_code

0 commit comments

Comments
 (0)