Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/helpers/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ async def async_refresh(self) -> None:
self.name,
monotonic() - start,
)
self._schedule_refresh()
if self._listeners:
self._schedule_refresh()

for update_callback in self._listeners:
update_callback()
3 changes: 3 additions & 0 deletions tests/helpers/test_update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ async def test_async_refresh(crd):
await crd.async_refresh()
assert crd.data == 1
assert crd.last_update_success is True
# Make sure we didn't schedule a refresh because we have 0 listeners
assert crd._unsub_refresh is None

updates = []

Expand All @@ -50,6 +52,7 @@ def update_callback():
unsub = crd.async_add_listener(update_callback)
await crd.async_refresh()
assert updates == [2]
assert crd._unsub_refresh is not None

# Test unsubscribing through function
unsub()
Expand Down