From cf3bb300e69b53ba7fddd9409a8811d28b10cc44 Mon Sep 17 00:00:00 2001
From: SukramJ <sukramj@icloud.com>
Date: Wed, 28 Aug 2019 22:38:20 +0200
Subject: [PATCH] Fix for 0.98: Don't update disabled entities (Homematic IP
 Cloud) (#26236)

* Homematic IP Cloud Fix: Don't update disabled entities

* Added enabled to entity.py

* Update test for enabled

* Update entity.py
---
 homeassistant/components/homematicip_cloud/device.py | 12 ++++++++++--
 homeassistant/helpers/entity.py                      |  5 +++++
 tests/helpers/test_entity.py                         |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/homeassistant/components/homematicip_cloud/device.py b/homeassistant/components/homematicip_cloud/device.py
index b086eaa29c7..71855d7c3f5 100644
--- a/homeassistant/components/homematicip_cloud/device.py
+++ b/homeassistant/components/homematicip_cloud/device.py
@@ -76,8 +76,16 @@ class HomematicipGenericDevice(Entity):
 
     def _async_device_changed(self, *args, **kwargs):
         """Handle device state changes."""
-        _LOGGER.debug("Event %s (%s)", self.name, self._device.modelType)
-        self.async_schedule_update_ha_state()
+        # Don't update disabled entities
+        if self.enabled:
+            _LOGGER.debug("Event %s (%s)", self.name, self._device.modelType)
+            self.async_schedule_update_ha_state()
+        else:
+            _LOGGER.debug(
+                "Device Changed Event for %s (%s) not fired. Entity is disabled.",
+                self.name,
+                self._device.modelType,
+            )
 
     @property
     def name(self) -> str:
diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py
index dc2e46cc6b2..1aa405326e5 100644
--- a/homeassistant/helpers/entity.py
+++ b/homeassistant/helpers/entity.py
@@ -229,6 +229,11 @@ class Entity:
     # are used to perform a very specific function. Overwriting these may
     # produce undesirable effects in the entity's operation.
 
+    @property
+    def enabled(self):
+        """Return if the entity is enabled in the entity registry."""
+        return self.registry_entry is None or not self.registry_entry.disabled
+
     @callback
     def async_set_context(self, context):
         """Set the context the entity currently operates under."""
diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py
index 3c89a5c6537..18cedf1c46a 100644
--- a/tests/helpers/test_entity.py
+++ b/tests/helpers/test_entity.py
@@ -552,8 +552,10 @@ async def test_disabled_in_entity_registry(hass):
     await hass.async_block_till_done()
     assert entry2 != entry
     assert ent.registry_entry == entry2
+    assert ent.enabled is True
 
     entry3 = registry.async_update_entity("hello.world", disabled_by="user")
     await hass.async_block_till_done()
     assert entry3 != entry2
     assert ent.registry_entry == entry3
+    assert ent.enabled is False
-- 
GitLab