From db0baab692a2e4fbe7ba1f378cda3f6cd9fe42e2 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 10 Dec 2019 11:02:26 +0100 Subject: [PATCH] Only update disabled_by when enabled default and entity enabled states differ (#29643) --- homeassistant/components/unifi/device_tracker.py | 10 ++++++---- homeassistant/components/unifi/sensor.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index 0806a2c04e3..159949f2985 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -75,6 +75,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Update the values of the controller.""" for entity in tracked.values(): + if entity.entity_registry_enabled_default == entity.enabled: + continue + disabled_by = None if not entity.entity_registry_enabled_default and entity.enabled: disabled_by = DISABLED_CONFIG_ENTRY @@ -227,10 +230,9 @@ class UniFiDeviceTracker(ScannerEntity): @property def entity_registry_enabled_default(self): """Return if the entity should be enabled when first added to the entity registry.""" - if not self.controller.option_track_devices: - return False - - return True + if self.controller.option_track_devices: + return True + return False async def async_added_to_hass(self): """Subscribe to device events.""" diff --git a/homeassistant/components/unifi/sensor.py b/homeassistant/components/unifi/sensor.py index e4f9b0df6c9..9145fd8e00f 100644 --- a/homeassistant/components/unifi/sensor.py +++ b/homeassistant/components/unifi/sensor.py @@ -40,6 +40,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Update the values of the controller.""" for entity in sensors.values(): + if entity.entity_registry_enabled_default == entity.enabled: + continue + disabled_by = None if not entity.entity_registry_enabled_default and entity.enabled: disabled_by = DISABLED_CONFIG_ENTRY