Skip to content

Commit 685a664

Browse files
authored
Cleanup tasks on disconnect (#148)
* Clean up connections and tasks when disconnecting * Fix lint
1 parent d1f9efb commit 685a664

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

zigpy_xbee/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ async def _reconnect_till_done(self) -> None:
347347
)
348348

349349
def close(self):
350+
if self._conn_lost_task:
351+
self._conn_lost_task.cancel()
352+
self._conn_lost_task = None
353+
350354
if self._uart:
351355
self._uart.close()
352356
self._uart = None

zigpy_xbee/zigbee/application.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async def disconnect(self):
4949
"""Shutdown application."""
5050
if self._api:
5151
self._api.close()
52+
self._api = None
5253

5354
async def connect(self):
5455
self._api = await zigpy_xbee.api.XBee.new(self, self._config[CONF_DEVICE])
@@ -191,11 +192,11 @@ async def force_remove(self, dev):
191192
async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None:
192193
"""Register a new endpoint on the device."""
193194
self._device.replacement["endpoints"][descriptor.endpoint] = {
194-
"device_type": descriptor.device_type,
195-
"profile_id": descriptor.profile,
196-
"input_clusters": descriptor.input_clusters,
197-
"output_clusters": descriptor.output_clusters,
198-
}
195+
"device_type": descriptor.device_type,
196+
"profile_id": descriptor.profile,
197+
"input_clusters": descriptor.input_clusters,
198+
"output_clusters": descriptor.output_clusters,
199+
}
199200
self._device.add_endpoint(descriptor.endpoint)
200201

201202
async def _get_association_state(self):

0 commit comments

Comments
 (0)