Skip to content

Commit 77bcc4d

Browse files
committed
chore: address co-pilot readability comments
1 parent dda0a3c commit 77bcc4d

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

roborock/diagnostics.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ def redact_device_data(data: T) -> T | dict[str, Any]:
132132
def redact_topic_name(topic: str) -> str:
133133
"""Redact potentially identifying information from a topic name."""
134134
parts = topic.split("/")
135-
if len(parts) < 5:
136-
return topic
137-
138135
redacted_parts = parts[:4]
139136
for part in parts[4:]:
140137
if len(part) <= 5:
@@ -146,6 +143,4 @@ def redact_topic_name(topic: str) -> str:
146143

147144
def redact_device_uid(duid: str) -> str:
148145
"""Redact a device UID to hide identifying information."""
149-
if len(duid) <= 5:
150-
return "*****"
151146
return "******" + duid[-5:]

roborock/mqtt/roborock_session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from aiomqtt import MqttCodeError, MqttError, TLSParameters
1919

2020
from roborock.callbacks import CallbackMap
21-
from roborock.diagnostics import Diagnostics
21+
from roborock.diagnostics import Diagnostics, redact_topic_name
2222

2323
from .health_manager import HealthManager
2424
from .session import MqttParams, MqttSession, MqttSessionException, MqttSessionUnauthorized
@@ -241,7 +241,7 @@ async def _mqtt_client(self, params: MqttParams) -> aiomqtt.Client:
241241
self._client = client
242242
for topic in self._client_subscribed_topics:
243243
self._diagnostics.increment("resubscribe")
244-
_LOGGER.debug("Re-establishing subscription to topic %s", topic)
244+
_LOGGER.debug("Re-establishing subscription to topic %s", redact_topic_name(topic))
245245
# TODO: If this fails it will break the whole connection. Make
246246
# this retry again in the background with backoff.
247247
await client.subscribe(topic)
@@ -261,13 +261,13 @@ async def subscribe(self, topic: str, callback: Callable[[bytes], None]) -> Call
261261
unsubscription for the idle timeout period. If a new subscription comes in during the
262262
timeout, the timer is cancelled and the subscription is reused.
263263
"""
264-
_LOGGER.debug("Subscribing to topic %s", topic)
264+
_LOGGER.debug("Subscribing to topic %s", redact_topic_name(topic))
265265

266266
# If there is an idle timer for this topic, cancel it (reuse subscription)
267267
if idle_timer := self._idle_timers.pop(topic, None):
268268
self._diagnostics.increment("unsubscribe_idle_cancel")
269269
idle_timer.cancel()
270-
_LOGGER.debug("Cancelled idle timer for topic %s (reused subscription)", topic)
270+
_LOGGER.debug("Cancelled idle timer for topic %s (reused subscription)", redact_topic_name(topic))
271271

272272
unsub = self._listeners.add_callback(topic, callback)
273273

tests/test_diagnostics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test_redact_topic_name(topic: str, expected: str) -> None:
9090
"duid,expected",
9191
[
9292
("3zQRtuIfY14BrRTivxxcMd", "******xxcMd"),
93-
("3zQ", "*****"),
94-
("", "*****"),
93+
("3zQ", "******3zQ"),
94+
("", "******"),
9595
],
9696
)
9797
def test_redact_device(duid: str, expected: str) -> None:

0 commit comments

Comments
 (0)