Skip to content

Commit 0aebe13

Browse files
committed
chore: Update comments
1 parent dbb6a54 commit 0aebe13

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

roborock/devices/v1_channel.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,24 @@ async def subscribe(self, callback: Callable[[RoborockMessage], None]) -> Callab
123123
if self._callback is not None:
124124
raise ValueError("Only one subscription allowed at a time")
125125

126-
# Make an initial, optimistic attempt to connect to local with the cache
126+
# Make an initial, optimistic attempt to connect to local with the
127+
# cache. The cache information will be refreshed by the background task.
127128
try:
128129
await self._local_connect(use_cache=True)
129130
except RoborockException as err:
130131
_LOGGER.warning("Could not establish local connection for device %s: %s", self._device_uid, err)
131132

132-
# Start a background task to manage the local connection health
133+
# Start a background task to manage the local connection health. This
134+
# happens independent of whether we were able to connect locally now.
133135
_LOGGER.info("self._reconnect_task=%s", self._reconnect_task)
134136
if self._reconnect_task is None:
135137
loop = asyncio.get_running_loop()
136138
self._reconnect_task = loop.create_task(self._background_reconnect())
137139

138-
# We were not able to connect locally, so fallback to MQTT. If this fails
139-
# then we'll fail to subscribe.
140140
if not self.is_local_connected:
141-
if self._mqtt_unsub is not None:
142-
self._mqtt_unsub()
143-
self._mqtt_unsub = None
141+
# We were not able to connect locally, so fallback to MQTT and at least
142+
# establish that connection explicitly. If this fails then raise an
143+
# error and let the caller know we failed to subscribe.
144144
self._mqtt_unsub = await self._mqtt_channel.subscribe(self._on_mqtt_message)
145145
_LOGGER.debug("V1Channel connected to device %s via MQTT", self._device_uid)
146146

@@ -183,8 +183,6 @@ async def _get_networking_info(self, *, use_cache: bool = True) -> NetworkInfo:
183183

184184
async def _local_connect(self, *, use_cache: bool = True) -> None:
185185
"""Set up local connection if possible."""
186-
if self.is_local_connected:
187-
return
188186
_LOGGER.debug(
189187
"Attempting to connect to local channel for device %s (use_cache=%s)", self._device_uid, use_cache
190188
)

0 commit comments

Comments
 (0)