Skip to content

Commit

Permalink
improved timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
timniklas authored Dec 29, 2024
1 parent bc47cbe commit ebe4ac5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions custom_components/govee_light_ble/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def _ensureConnected(self):
if self._client != None and self._client.is_connected:
return None
if self.receiving_in_progress:
self._stopReceiving()
await self._stopReceiving()
self._client = await bleak_retry_connector.establish_connection(BleakClient, self._ble_device, self.address)

async def _transmitPacket(self, packet: LedPacket):
Expand Down Expand Up @@ -116,6 +116,7 @@ async def _startReceiving(self):
async def _stopReceiving(self):
""" stop receiving packets """
self.receiving_in_progress = False
self.stop_event.set()
await self._client.stop_notify(READ_CHARACTERISTIC_UUID)

async def sendPacketBuffer(self):
Expand All @@ -126,15 +127,17 @@ async def sendPacketBuffer(self):
await self._ensureConnected()
if self._responseExpected:
await self._startReceiving()

for packet in self._packet_buffer:
await self._transmitPacket(packet)
await self._clearPacketBuffer()

if self._responseExpected:
#wait to receive all exptected packets
await self.stop_event.wait()
await self._stopReceiving()
try:
for packet in self._packet_buffer:
await self._transmitPacket(packet)
await self._clearPacketBuffer()
if self._responseExpected:
#wait to receive all exptected packets
await self.stop_event.wait()
#ensure receiving ist stopped
finally:
if self._responseExpected:
await self._stopReceiving()
#not disconnecting seems to improve connection speed

async def requestStateBuffered(self):
Expand Down

0 comments on commit ebe4ac5

Please sign in to comment.