Skip to content

Commit d43bb0c

Browse files
committed
replace gmqtt with aiomqtt
1 parent 401cd93 commit d43bb0c

File tree

8 files changed

+196
-119
lines changed

8 files changed

+196
-119
lines changed

poetry.lock

Lines changed: 31 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ requires-python = '>=3.12,<4.0'
1818
dependencies = [
1919
"saic-ismart-client-ng (>=0.9.2,<0.10.0)",
2020
'httpx (>=0.28.1,<0.29.0)',
21-
'gmqtt (>=0.7.0,<0.8.0)',
2221
'inflection (>=0.5.1,<0.6.0)',
2322
'apscheduler (>=3.11.0,<4.0.0)',
2423
'python-dotenv (>=1.1.1,<2.0.0)',
24+
"aiomqtt (>=2.4.0,<3.0.0)",
2525
]
2626

2727
[project.urls]

src/configuration/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from __future__ import annotations
22

33
from enum import Enum
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Literal
55

66
if TYPE_CHECKING:
77
from integrations.openwb.charging_station import ChargingStation
88

99

10+
Transport = Literal["tcp", "websockets"]
11+
12+
1013
class TransportProtocol(Enum):
11-
def __init__(self, transport_mechanism: str, with_tls: bool) -> None:
14+
def __init__(self, transport_mechanism: Transport, with_tls: bool) -> None:
1215
self.transport_mechanism = transport_mechanism
1316
self.with_tls = with_tls
1417

src/configuration/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __parse_mqtt_transport(args: Namespace, config: Configuration) -> None:
102102
args.tls_server_cert_check_hostname
103103
)
104104
else:
105-
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tcp or ws"
105+
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tls, tcp or ws"
106106
raise SystemExit(msg)
107107

108108
if parse_result.port:

src/log_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
MODULES_DEFAULT_LOG_LEVEL = {
99
"asyncio": "WARNING",
10-
"gmqtt": "WARNING",
10+
"aiomqtt": "WARNING",
1111
"httpcore": "WARNING",
1212
"httpx": "WARNING",
1313
"saic_ismart_client_ng": "WARNING",

src/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
import signal
66
import sys
77

8-
from configuration.parser import process_command_line
8+
from configuration import Configuration, parser
99
from mqtt_gateway import MqttGateway
1010

11+
12+
async def run(config: Configuration) -> None:
13+
mqtt_gateway = MqttGateway(config)
14+
await mqtt_gateway.run()
15+
16+
1117
if __name__ == "__main__":
1218
# Keep this at the top!
1319
from log_config import debug_log_enabled, setup_logging
@@ -18,7 +24,6 @@
1824
faulthandler.enable(file=sys.stderr, all_threads=True)
1925
if hasattr(faulthandler, "register") and hasattr(signal, "SIGQUIT"):
2026
faulthandler.register(signal.SIGQUIT, chain=False)
21-
configuration = process_command_line()
27+
configuration = parser.process_command_line()
2228

23-
mqtt_gateway = MqttGateway(configuration)
24-
asyncio.run(mqtt_gateway.run(), debug=debug_log_enabled())
29+
asyncio.run(run(configuration), debug=debug_log_enabled())

0 commit comments

Comments
 (0)