From 317d08b6c1af82250207f82f93e311cb9a98db97 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 16 Apr 2020 16:44:14 -0700 Subject: [PATCH] Update Coordinator: Only schedule a refresh if listenerrs (#34317) --- homeassistant/helpers/update_coordinator.py | 3 ++- tests/helpers/test_update_coordinator.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index b2b04816616..1f7e5326d6c 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -163,7 +163,8 @@ class DataUpdateCoordinator: self.name, monotonic() - start, ) - self._schedule_refresh() + if self._listeners: + self._schedule_refresh() for update_callback in self._listeners: update_callback() diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index c17c79ccbc8..cb53bc5e04e 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -40,6 +40,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 = []