From 63afcecaa53249ef4da1c192ced6d0489ef85f99 Mon Sep 17 00:00:00 2001 From: Anko Hanse Date: Mon, 4 Nov 2024 08:57:08 +1300 Subject: [PATCH] Prevent diagnostics from interfering with data update --- custom_components/dabpumps/api.py | 4 ++++ custom_components/dabpumps/binary_sensor.py | 6 ++---- custom_components/dabpumps/number.py | 6 ++---- custom_components/dabpumps/select.py | 5 ++--- custom_components/dabpumps/sensor.py | 8 +++----- custom_components/dabpumps/switch.py | 4 +--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/custom_components/dabpumps/api.py b/custom_components/dabpumps/api.py index 43eb640..726df6e 100644 --- a/custom_components/dabpumps/api.py +++ b/custom_components/dabpumps/api.py @@ -518,6 +518,10 @@ async def async_get_diagnostics(self) -> dict[str, Any]: async def _async_update_diagnostics(self, timestamp, context: str, request: dict|None, response: dict|None, token: dict|None = None): # worker function async def _async_worker(self, timestamp, context, request, response, token): + + # Wait one or two seconds to not interfere with the updating of the entities after retrieving the data + await asyncio.sleep(2) + item = DabPumpsApiHistoryItem(timestamp, context, request, response, token) detail = DabPumpsApiHistoryDetail(timestamp, context, request, response, token) diff --git a/custom_components/dabpumps/binary_sensor.py b/custom_components/dabpumps/binary_sensor.py index 635cf61..8f743ea 100644 --- a/custom_components/dabpumps/binary_sensor.py +++ b/custom_components/dabpumps/binary_sensor.py @@ -116,11 +116,9 @@ def name(self) -> str: @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - super()._handle_coordinator_update() - - (_, _, status_map) = self._coordinator.data - + # find the correct device and status corresponding to this sensor + (_, _, status_map) = self._coordinator.data status = status_map.get(self.object_id) # Update any attributes diff --git a/custom_components/dabpumps/number.py b/custom_components/dabpumps/number.py index 11564df..017340e 100644 --- a/custom_components/dabpumps/number.py +++ b/custom_components/dabpumps/number.py @@ -102,11 +102,9 @@ def name(self) -> str: @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - super()._handle_coordinator_update() - - (_, _, status_map) = self._coordinator.data - + # find the correct device and status corresponding to this sensor + (_, _, status_map) = self._coordinator.data status = status_map.get(self.object_id) # Update any attributes diff --git a/custom_components/dabpumps/select.py b/custom_components/dabpumps/select.py index 485562d..d76c508 100644 --- a/custom_components/dabpumps/select.py +++ b/custom_components/dabpumps/select.py @@ -103,11 +103,9 @@ def name(self) -> str: @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - super()._handle_coordinator_update() - - (_, _, status_map) = self._coordinator.data # find the correct device and status corresponding to this sensor + (_, _, status_map) = self._coordinator.data status = status_map.get(self.object_id) # Update any attributes @@ -136,6 +134,7 @@ def _update_attributes(self, status, is_create): self._name = status.key self._attr_options = list(self._dict.values()) + self._attr_current_option = None self._attr_entity_category = self.get_entity_category() diff --git a/custom_components/dabpumps/sensor.py b/custom_components/dabpumps/sensor.py index 25ceb9d..5aa2e10 100644 --- a/custom_components/dabpumps/sensor.py +++ b/custom_components/dabpumps/sensor.py @@ -104,11 +104,9 @@ def name(self) -> str: @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - super()._handle_coordinator_update() - - (_, _, status_map) = self._coordinator.data - + # find the correct device and status corresponding to this sensor + (_, _, status_map) = self._coordinator.data status = status_map.get(self.object_id) # Update any attributes @@ -147,7 +145,7 @@ def _update_attributes(self, status, is_create): attr_precision = None attr_val = self._get_string(str(status.val)) if status.val!=None else None attr_unit = None - + # Process any changes changed = False diff --git a/custom_components/dabpumps/switch.py b/custom_components/dabpumps/switch.py index 841efa0..13a93e7 100644 --- a/custom_components/dabpumps/switch.py +++ b/custom_components/dabpumps/switch.py @@ -111,11 +111,9 @@ def name(self) -> str: @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - super()._handle_coordinator_update() - - (_, _, status_map) = self._coordinator.data # find the correct device and status corresponding to this sensor + (_, _, status_map) = self._coordinator.data status = status_map.get(self.object_id) # Update any attributes