Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a0995ed
replace gmqtt with aiomqtt
bj00rn Jul 14, 2025
7ce9d6c
Set default port for TLS to 8883, fallback to 1883 if no port and TCP…
bj00rn Jul 14, 2025
131bb22
fix keepalive
bj00rn Oct 7, 2025
619c4d6
fix client not reconnecting
bj00rn Nov 18, 2025
b033b55
retain birth/keepalive message
bj00rn Nov 25, 2025
5243c6c
fix(tests): update publish mock signatures for aiomqtt migration
nanomad Jun 24, 2026
85e6091
fix: restore *, retain=True defaults on all publish_* methods
nanomad Jun 24, 2026
2a87077
style: apply ruff formatting
nanomad Jun 24, 2026
9ee28e6
fix(log_publisher): forward retain flag to internal_publish
nanomad Jun 24, 2026
9113cfd
fix(mqtt_publisher): read message.retain directly in _on_message
nanomad Jun 24, 2026
30f7bc2
fix(mqtt_publisher): call on_mqtt_reconnected after broker reconnect
nanomad Jun 24, 2026
6310e7f
fix(mqtt_publisher): restore imported_energy_topic subscription
nanomad Jun 24, 2026
ec833b3
fix(mqtt_publisher): add missing f-prefix to subscribe error log
nanomad Jun 24, 2026
3fd5a96
fix(mqtt_publisher): guard connect() against unconfigured host
nanomad Jun 24, 2026
3f62666
fix(tests): correct misleading test name for clear_topic
nanomad Jun 24, 2026
105627d
fix(mqtt_publisher): remove spurious "a" suffix from client identifier
nanomad Jun 24, 2026
5cc59b0
fix(mqtt_publisher): exit immediately on permanent MQTT connect failures
nanomad Jun 24, 2026
dcddcca
refactor(mqtt_publisher): use paho CONNACK constants instead of magic…
nanomad Jun 24, 2026
a8bc3c6
refactor(mqtt_publisher): replace paho constants with local MQTT 3.1.…
nanomad Jun 24, 2026
7e55aee
fix(mqtt_publisher): exponential backoff on reconnect with 5 min cap
nanomad Jun 24, 2026
27677a6
fix(mqtt_publisher): use create_task instead of run_coroutine_threadsafe
nanomad Jun 24, 2026
4fecfcd
fix(mqtt_publisher): fix fatal CONNACK detection and connect() hang
nanomad Jun 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ requires-python = '>=3.12,<4.0'
dependencies = [
"saic-ismart-client-ng (>=0.9.3,<0.10.0)",
'httpx (>=0.28.1,<0.29.0)',
'gmqtt (>=0.7.0,<0.8.0)',
'inflection (>=0.5.1,<0.6.0)',
'apscheduler (>=3.11.0,<4.0.0)',
'python-dotenv (>=1.1.1,<2.0.0)',
"aiomqtt (>=2.4.0,<3.0.0)",
]

[project.urls]
Expand Down
7 changes: 5 additions & 2 deletions src/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

if TYPE_CHECKING:
from zoneinfo import ZoneInfo

from integrations.openwb.charging_station import ChargingStation


Transport = Literal["tcp", "websockets"]


class TransportProtocol(Enum):
def __init__(self, transport_mechanism: str, with_tls: bool) -> None:
def __init__(self, transport_mechanism: Transport, with_tls: bool) -> None:
self.transport_mechanism = transport_mechanism
self.with_tls = with_tls

Expand Down
11 changes: 7 additions & 4 deletions src/configuration/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ def __parse_mqtt_transport(args: Namespace, config: Configuration) -> None:
args.tls_server_cert_check_hostname
)
else:
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tcp or ws"
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tls, tcp or ws"
raise SystemExit(msg)

if parse_result.port:
config.mqtt_port = parse_result.port
elif config.mqtt_transport_protocol == TransportProtocol.TCP:
config.mqtt_port = 1883
else:
elif config.mqtt_transport_protocol == TransportProtocol.TLS:
config.mqtt_port = 8883
elif config.mqtt_transport_protocol == TransportProtocol.WS:
config.mqtt_port = 9001
else:
# fallback to default mqtt port
config.mqtt_port = 1883
config.mqtt_host = str(parse_result.hostname)


Expand Down
2 changes: 1 addition & 1 deletion src/log_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

MODULES_DEFAULT_LOG_LEVEL = {
"asyncio": "WARNING",
"gmqtt": "WARNING",
"aiomqtt": "WARNING",
"httpcore": "WARNING",
"httpx": "WARNING",
"saic_ismart_client_ng": "WARNING",
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
configuration = process_command_line()

mqtt_gateway = MqttGateway(configuration)

asyncio.run(mqtt_gateway.run(), debug=debug_log_enabled())
39 changes: 33 additions & 6 deletions src/publisher/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,55 @@ def publish_json(
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
raise NotImplementedError

@abstractmethod
def publish_str(
self, key: str, value: str, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: str,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
raise NotImplementedError

@abstractmethod
def publish_int(
self, key: str, value: int, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: int,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
raise NotImplementedError

@abstractmethod
def publish_bool(
self, key: str, value: bool, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: bool,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
raise NotImplementedError

@abstractmethod
def publish_float(
self, key: str, value: float, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: float,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
raise NotImplementedError

Expand Down Expand Up @@ -173,7 +198,7 @@ def publish(
raise TypeError(msg)

@abstractmethod
def clear_topic(self, key: str, no_prefix: bool = False) -> None:
def clear_topic(self, key: str, no_prefix: bool = False, qos: int = 0) -> None:
raise NotImplementedError

def get_mqtt_account_prefix(self) -> str:
Expand Down Expand Up @@ -249,7 +274,9 @@ def __anonymize(self, data: T) -> T:
return data

def keepalive(self) -> None:
self.publish_str(mqtt_topics.INTERNAL_LWT, "online", False)
self.publish_str(
mqtt_topics.INTERNAL_LWT, "online", no_prefix=False, retain=True, qos=1
)

@staticmethod
def anonymize_str(value: str) -> str:
Expand Down
35 changes: 30 additions & 5 deletions src/publisher/log_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,61 @@ def publish_json(
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
anonymized_json = self.dict_to_anonymized_json(data)
self.internal_publish(key, anonymized_json, retain=retain)

@override
def publish_str(
self, key: str, value: str, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: str,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
self.internal_publish(key, value, retain=retain)

@override
def publish_int(
self, key: str, value: int, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: int,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
self.internal_publish(key, value, retain=retain)

@override
def publish_bool(
self, key: str, value: bool, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: bool,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
self.internal_publish(key, value, retain=retain)

@override
def publish_float(
self, key: str, value: float, no_prefix: bool = False, *, retain: bool = True
self,
key: str,
value: float,
no_prefix: bool = False,
*,
retain: bool = True,
qos: int = 0,
) -> None:
self.internal_publish(key, value, retain=retain)

@override
def clear_topic(self, key: str, no_prefix: bool = False) -> None:
def clear_topic(self, key: str, no_prefix: bool = False, qos: int = 0) -> None:
self.internal_publish(key, None)

def internal_publish(
Expand Down
Loading