diff --git a/custom_components/bluetti_bt/binary_sensor.py b/custom_components/bluetti_bt/binary_sensor.py index b177e1c..a52a269 100644 --- a/custom_components/bluetti_bt/binary_sensor.py +++ b/custom_components/bluetti_bt/binary_sensor.py @@ -104,6 +104,10 @@ class BluettiBinarySensor(CoordinatorEntity, BinarySensorEntity): @callback def _handle_coordinator_update(self) -> None: """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)) if not isinstance(self.coordinator.data, dict): _LOGGER.debug( diff --git a/custom_components/bluetti_bt/coordinator.py b/custom_components/bluetti_bt/coordinator.py index f8ded43..66caf77 100644 --- a/custom_components/bluetti_bt/coordinator.py +++ b/custom_components/bluetti_bt/coordinator.py @@ -179,22 +179,6 @@ class PollingCoordinator(DataUpdateCoordinator): 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: async with async_timeout.timeout(15): diff --git a/custom_components/bluetti_bt/sensor.py b/custom_components/bluetti_bt/sensor.py index 9721f70..9dedc9b 100644 --- a/custom_components/bluetti_bt/sensor.py +++ b/custom_components/bluetti_bt/sensor.py @@ -130,6 +130,10 @@ class BluettiSensor(CoordinatorEntity, SensorEntity): @callback def _handle_coordinator_update(self) -> None: """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)) if not isinstance(self.coordinator.data, dict): _LOGGER.debug( diff --git a/custom_components/bluetti_bt/switch.py b/custom_components/bluetti_bt/switch.py index 6e4d5f0..1ca2c69 100644 --- a/custom_components/bluetti_bt/switch.py +++ b/custom_components/bluetti_bt/switch.py @@ -114,6 +114,10 @@ class BluettiSwitch(CoordinatorEntity, SwitchEntity): @callback def _handle_coordinator_update(self) -> None: """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)) if not isinstance(self.coordinator.data, dict): _LOGGER.error(