use cancel_on_disconnection helper

This commit is contained in:
Gilles Boccon-Gibod
2025-06-10 13:28:08 -04:00
parent 39518c89f5
commit 8137caf37b
9 changed files with 43 additions and 66 deletions

View File

@@ -335,7 +335,7 @@ class HearingAccessService(gatt.TemplateService):
# Update the active preset index if needed
await self.notify_active_preset_for_connection(connection)
utils.cancel_on_event(connection, 'disconnection', on_connection_async())
connection.cancel_on_disconnection(on_connection_async())
def _on_read_active_preset_index(self, connection: Connection) -> bytes:
del connection # Unused

View File

@@ -161,10 +161,8 @@ class VolumeControlService(gatt.TemplateService):
handler = getattr(self, '_on_' + opcode.name.lower())
if handler(*value[2:]):
self.change_counter = (self.change_counter + 1) % 256
utils.cancel_on_event(
connection,
'disconnection',
connection.device.notify_subscribers(attribute=self.volume_state),
connection.cancel_on_disconnection(
connection.device.notify_subscribers(attribute=self.volume_state)
)
self.emit(self.EVENT_VOLUME_STATE_CHANGE)