From 8b893173fd8069f241babbbdc36ce7451853ca73 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 30 Aug 2020 12:10:22 -0500 Subject: [PATCH] Prevent CoordinatorEntity from requesting updates on disabled entities (#39452) --- homeassistant/helpers/update_coordinator.py | 5 +++++ tests/helpers/test_update_coordinator.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index b17ddcd3dd6..44e10243598 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -221,4 +221,9 @@ class CoordinatorEntity(entity.Entity): Only used by the generic entity update service. """ + + # Ignore manual update requests if the entity is disabled + if not self.enabled: + return + await self.coordinator.async_request_refresh() diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 73360a3053b..ee3c4af6daf 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -244,3 +244,9 @@ async def test_coordinator_entity(crd): await entity.async_added_to_hass() assert mock_async_on_remove.called + + # Verify we do not update if the entity is disabled + crd.last_update_success = False + with patch("homeassistant.helpers.entity.Entity.enabled", False): + await entity.async_update() + assert entity.available is False