Merge pull request #14 from SupaFlav/dev

Remove redundant connection attempt & don't process callback data on dead connection with persistent_conn active
This commit is contained in:
Patrick762 authored and GitHub committed 2023-08-30 20:58:58 +02:00
commit 3dc1cff551
4 files changed
+12 -16

No files matched your search

@@ -104,6 +104,10 @@ class BluettiBinarySensor(CoordinatorEntity, BinarySensorEntity):
@callback @callback
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator.""" """Handle updated data from the coordinator."""
if self.coordinator.persistent_conn and not self.coordinator.client.is_connected:
return
_LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id)) _LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id))
if not isinstance(self.coordinator.data, dict): if not isinstance(self.coordinator.data, dict):
_LOGGER.debug( _LOGGER.debug(
@@ -179,22 +179,6 @@ class PollingCoordinator(DataUpdateCoordinator):
parsed_data: dict = {} parsed_data: dict = {}
# Connect to device
try:
async with async_timeout.timeout(20):
await self.client.connect()
await self.client.start_notify(
BluetoothClient.NOTIFY_UUID, self._notification_handler
)
self.has_notifier = True
except TimeoutError:
self.logger.debug("Connection timed out for device %s", mac_loggable(self._address))
return None
except BleakError as err:
self.logger.debug("Bleak error: %s", err)
return None
try: try:
async with async_timeout.timeout(15): async with async_timeout.timeout(15):
+4
View File
@@ -130,6 +130,10 @@ class BluettiSensor(CoordinatorEntity, SensorEntity):
@callback @callback
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator.""" """Handle updated data from the coordinator."""
if self.coordinator.persistent_conn and not self.coordinator.client.is_connected:
return
_LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id)) _LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id))
if not isinstance(self.coordinator.data, dict): if not isinstance(self.coordinator.data, dict):
_LOGGER.debug( _LOGGER.debug(
+4
View File
@@ -114,6 +114,10 @@ class BluettiSwitch(CoordinatorEntity, SwitchEntity):
@callback @callback
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator.""" """Handle updated data from the coordinator."""
if self.coordinator.persistent_conn and not self.coordinator.client.is_connected:
return
_LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id)) _LOGGER.debug("Updating state of %s", unique_id_loggable(self._attr_unique_id))
if not isinstance(self.coordinator.data, dict): if not isinstance(self.coordinator.data, dict):
_LOGGER.error( _LOGGER.error(