Skip to content

Commit

Permalink
Prevent diagnostics from interfering with data update
Browse files Browse the repository at this point in the history
  • Loading branch information
ankohanse committed Nov 3, 2024
1 parent dec6a6f commit 63afcec
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
4 changes: 4 additions & 0 deletions custom_components/dabpumps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions custom_components/dabpumps/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions custom_components/dabpumps/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions custom_components/dabpumps/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 3 additions & 5 deletions custom_components/dabpumps/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions custom_components/dabpumps/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63afcec

Please sign in to comment.