Skip to content

Commit a7ce19f

Browse files
committed
fix: Improve device logging
The logging chnages include: (1) Log less of HomeData since it is large, and instead log a short TL;Dr for each device to make it easier to read. We will rely more on diagnostics for this (though this also needs some changes to get there) (2) Remove redudundant local connection logging (done both in v1 channel and local channel) (3) Fix some additional cases not using the device logger (4) Remove an unncessary line that says "Connecting to device" after it has already connected
1 parent 11f362e commit a7ce19f

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

roborock/data/containers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ class HomeDataProduct(RoborockBase):
228228
def product_nickname(self) -> RoborockProductNickname:
229229
return SHORT_MODEL_TO_ENUM.get(self.model.split(".")[-1], RoborockProductNickname.PEARLPLUS)
230230

231+
def summary_info(self) -> str:
232+
"""Return a string with key product information for logging purposes."""
233+
return f"HomeDataProduct(name={self.name}, model={self.model}, category={self.category})"
234+
231235

232236
@dataclass
233237
class HomeDataDevice(RoborockBase):
@@ -263,6 +267,13 @@ class HomeDataDevice(RoborockBase):
263267
share_type: Any | None = None
264268
share_expired_time: int | None = None
265269

270+
def summary_info(self) -> str:
271+
"""Return a string with key device information for logging purposes."""
272+
return (
273+
f"HomeDataDevice(name={self.name}, model={self.product_id}, "
274+
f"fv={self.fv}, pv={self.pv}, online={self.online})"
275+
)
276+
266277

267278
@dataclass
268279
class HomeDataRoom(RoborockBase):

roborock/devices/device.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ async def connect(self) -> None:
183183
if self._unsub:
184184
raise ValueError("Already connected to the device")
185185
unsub = await self._channel.subscribe(self._on_message)
186-
self._logger.info("Connecting to device")
187186
if self.v1_properties is not None:
188187
try:
189188
await self.v1_properties.discover_features()

roborock/devices/device_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ async def discover_devices(self) -> list[RoborockDevice]:
7878
home_data = cache_data.home_data
7979

8080
device_products = home_data.device_products
81-
_LOGGER.debug("Discovered %d devices %s", len(device_products), home_data)
81+
_LOGGER.debug("Discovered %d devices", len(device_products))
8282

8383
# These are connected serially to avoid overwhelming the MQTT broker
8484
new_devices = {}
8585
start_tasks = []
8686
for duid, (device, product) in device_products.items():
87+
_LOGGER.debug("[%s] Discovered device (%s, %s)", duid, product.summary_info(), device.summary_info())
8788
if duid in self._devices:
8889
continue
8990
new_device = self._device_creator(home_data, device, product)

roborock/devices/local_channel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ async def connect(self) -> None:
179179
if self._is_connected:
180180
self._logger.debug("Unexpected call to connect when already connected")
181181
return
182-
self._logger.debug("Connecting to %s:%s", self._host, _PORT)
183182
loop = asyncio.get_running_loop()
184183
protocol = _LocalProtocol(self._data_received, self._connection_lost)
185184
try:

roborock/devices/v1_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ async def _local_connect(self, *, prefer_cache: bool = True) -> None:
373373
# Wire up the new channel
374374
self._local_channel = local_channel
375375
self._local_unsub = await self._local_channel.subscribe(self._on_local_message)
376-
_LOGGER.info("Successfully connected to local device %s", self._device_uid)
376+
self._logger.info("Connected to local channel successfully")
377377

378378
async def _background_reconnect(self) -> None:
379379
"""Task to run in the background to manage the local connection."""

0 commit comments

Comments
 (0)