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
2 changes: 2 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ region = "us"
mode = "embedded"
host = "127.0.0.1"
port = 18830
username = "roborock"
password = "replace-with-a-secure-password"
mosquitto_binary = "mosquitto"
enable_topic_bridge = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def __init__(
*,
host: str,
port: int,
username: str = "",
password: str = "",
logger: logging.Logger,
fixed_device_did: str = "",
fixed_device_duid: str = "",
Expand All @@ -76,6 +78,8 @@ def __init__(
) -> None:
self._host = host
self._port = port
self._username = username
self._password = password
self._logger = logger
self._stop_event = asyncio.Event()
self._task: asyncio.Task[None] | None = None
Expand Down Expand Up @@ -440,10 +444,18 @@ async def _handle_device_message(
)

async def _run(self) -> None:
auth: dict[str, str] = {}
if self._username:
auth["username"] = self._username
auth["password"] = self._password
self._logger.info(
"MQTT topic bridge auth attempt with username:password (%s:REDACTED)",
self._username
)
retry_delay_seconds = 2.0
while not self._stop_event.is_set():
try:
async with aiomqtt.Client(hostname=self._host, port=self._port) as client:
async with aiomqtt.Client(hostname=self._host, port=self._port, **auth) as client:
await client.subscribe("rr/m/i/#")
await client.subscribe("rr/d/i/#")
self._logger.info(
Expand Down
6 changes: 6 additions & 0 deletions src/roborock_local_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class BrokerConfig:
mode: str
host: str
port: int
username: str
password: str
mosquitto_binary: str
enable_topic_bridge: bool

Expand Down Expand Up @@ -200,6 +202,8 @@ def load_config(path: str | Path) -> AppConfig:
if broker_mode == "embedded" and not broker_host:
broker_host = "127.0.0.1"
broker_port_default = 18830 if broker_mode == "embedded" else 1883
broker_username = str(broker.get("username")) or ""
broker_password = str(broker.get("password")) or ""

config = AppConfig(
network=NetworkConfig(
Expand All @@ -218,6 +222,8 @@ def load_config(path: str | Path) -> AppConfig:
mode=broker_mode,
host=broker_host,
port=_as_port(broker.get("port"), "broker.port", broker_port_default),
username=broker_username,
password=broker_password,
mosquitto_binary=str(broker.get("mosquitto_binary", "mosquitto")).strip() or "mosquitto",
enable_topic_bridge=_as_bool(broker.get("enable_topic_bridge"), True),
),
Expand Down
4 changes: 4 additions & 0 deletions src/roborock_local_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,8 @@ async def start(self) -> None:
self._topic_bridge = MqttTopicBridge(
host=self.config.broker.host,
port=self.config.broker.port,
username=self.config.broker.username,
password=self.config.broker.password,
logger=self.loggers["mqtt"],
runtime_state=self.runtime_state,
inventory_path=self.paths.inventory_path,
Expand Down Expand Up @@ -1677,6 +1679,8 @@ async def start(self) -> None:
self.config.broker.mode,
self.config.broker.host,
self.config.broker.port,
self.config.broker.username,
self.config.broker.password,
)

if self.config.tls.mode == "cloudflare_acme":
Expand Down