Skip to content

Cleanup tasks on disconnect #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2023
Merged
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
4 changes: 4 additions & 0 deletions zigpy_xbee/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ async def _reconnect_till_done(self) -> None:
)

def close(self):
if self._conn_lost_task:
self._conn_lost_task.cancel()
self._conn_lost_task = None

if self._uart:
self._uart.close()
self._uart = None
Expand Down
11 changes: 6 additions & 5 deletions zigpy_xbee/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def disconnect(self):
"""Shutdown application."""
if self._api:
self._api.close()
self._api = None

async def connect(self):
self._api = await zigpy_xbee.api.XBee.new(self, self._config[CONF_DEVICE])
Expand Down Expand Up @@ -191,11 +192,11 @@ async def force_remove(self, dev):
async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None:
"""Register a new endpoint on the device."""
self._device.replacement["endpoints"][descriptor.endpoint] = {
"device_type": descriptor.device_type,
"profile_id": descriptor.profile,
"input_clusters": descriptor.input_clusters,
"output_clusters": descriptor.output_clusters,
}
"device_type": descriptor.device_type,
"profile_id": descriptor.profile,
"input_clusters": descriptor.input_clusters,
"output_clusters": descriptor.output_clusters,
}
self._device.add_endpoint(descriptor.endpoint)

async def _get_association_state(self):
Expand Down