Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 32 additions & 17 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 @@ -18,10 +18,10 @@ requires-python = '>=3.12,<4.0'
dependencies = [
"saic-ismart-client-ng (>=0.9.2,<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,14 +1,17 @@
from __future__ import annotations

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

if TYPE_CHECKING:
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 @@ -102,15 +102,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())
49 changes: 42 additions & 7 deletions src/publisher/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,61 @@ def is_connected(self) -> bool:

@abstractmethod
def publish_json(
self, key: str, data: dict[str, Any], no_prefix: bool = False
self,
key: str,
data: dict[str, Any],
no_prefix: bool = False,
retain: bool = False,
qos: int = 0,
) -> None:
raise NotImplementedError

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

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

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

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

@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 @@ -154,7 +187,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
45 changes: 39 additions & 6 deletions src/publisher/log_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,62 @@ def enable_commands(self) -> None:

@override
def publish_json(
self, key: str, data: dict[str, Any], no_prefix: bool = False
self,
key: str,
data: dict[str, Any],
no_prefix: bool = False,
retain: bool = False,
qos: int = 0,
) -> None:
anonymized_json = self.dict_to_anonymized_json(data)
self.internal_publish(key, anonymized_json)

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

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

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

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

@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(self, key: str, value: Any) -> None:
Expand Down
Loading