Skip to content

Commit

Permalink
Merge pull request #55 from timniklas/timniklas-patch-1
Browse files Browse the repository at this point in the history
increased update stability
  • Loading branch information
timniklas authored Dec 27, 2024
2 parents d935b09 + c84660f commit facd36f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions custom_components/govee_light_ble/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, ble_device: BLEDevice, segmented: bool = False):
self._packet_buffer = []
self._expected_responses = []
self._client = None
self.receiving_in_progress = False

@property
def address(self):
Expand All @@ -41,6 +42,7 @@ def _responseExpected(self):
async def _ensureConnected(self):
""" connects to a bluetooth device """
if self._client == None or not self._client.is_connected:
self.receiving_in_progress = False
self._client = await bleak_retry_connector.establish_connection(BleakClient, self._ble_device, self.address)

async def _transmitPacket(self, packet: LedPacket):
Expand Down Expand Up @@ -105,11 +107,13 @@ async def _clearPacketBuffer(self):

async def _startReceiving(self):
""" start receiving packets """
self.receiving_in_progress = True
self.stop_event = asyncio.Event()
await self._client.start_notify(READ_CHARACTERISTIC_UUID, self._handleReceive)

async def _stopReceiving(self):
""" stop receiving packets """
self.receiving_in_progress = False
await self._client.stop_notify(READ_CHARACTERISTIC_UUID)

async def sendPacketBuffer(self):
Expand Down
6 changes: 5 additions & 1 deletion custom_components/govee_light_ble/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
update_method=self._async_update_data,
# Do not set a polling interval as data will be pushed.
# You can remove this line but left here for explanatory purposes.
update_interval=timedelta(seconds=10)
update_interval=timedelta(seconds=15)
)

async def _async_update_data(self):
Expand All @@ -61,6 +61,10 @@ async def _async_update_data(self):
This is the place to pre-process the data to lookup tables
so entities can quickly look up their data.
"""
if self._api.receiving_in_progress:
#dont connect if update handler is still receiving
_LOGGER.warn("still connected, aborting data update")
return self.data
await self._api.requestStateBuffered()
await self._api.requestBrightnessBuffered()
await self._api.requestColorBuffered()
Expand Down

0 comments on commit facd36f

Please sign in to comment.