Просмотр исходного кода

Use HA entity registry to disable deprecated entities by default.

Previously our device config had a list of checkboxes for each entity
to allow enabling and disabling in the integration config.
But these were removed when HA made it easy to enable and disable
entities from the main Settings / Devices UI.  Some code related to
these was still present, causing deprecated entities to be disabled by
default, but needing the old config UI to enable them.

Instead, use the entity_registry_enabled_default property to indicate
that it should be disabled in the registry by default, but otherwise
set it up as usual.

Issue #1143
Jason Rumney 2 лет назад
Родитель
Сommit
e456048b2d

+ 2 - 6
custom_components/tuya_local/helpers/config.py

@@ -22,9 +22,7 @@ async def async_tuya_setup_platform(
     if cfg is None:
     if cfg is None:
         raise ValueError(f"No device config found for {discovery_info}")
         raise ValueError(f"No device config found for {discovery_info}")
     ecfg = cfg.primary_entity
     ecfg = cfg.primary_entity
-    if ecfg.entity == platform and (
-        discovery_info.get(ecfg.config_id, False) or not ecfg.deprecated
-    ):
+    if ecfg.entity == platform:
         data[ecfg.config_id] = entity_class(device, ecfg)
         data[ecfg.config_id] = entity_class(device, ecfg)
         entities.append(data[ecfg.config_id])
         entities.append(data[ecfg.config_id])
         if ecfg.deprecated:
         if ecfg.deprecated:
@@ -32,9 +30,7 @@ async def async_tuya_setup_platform(
         _LOGGER.debug(f"Adding {platform} for {ecfg.config_id}")
         _LOGGER.debug(f"Adding {platform} for {ecfg.config_id}")
 
 
     for ecfg in cfg.secondary_entities():
     for ecfg in cfg.secondary_entities():
-        if ecfg.entity == platform and (
-            discovery_info.get(ecfg.config_id, False) or not ecfg.deprecated
-        ):
+        if ecfg.entity == platform:
             data[ecfg.config_id] = entity_class(device, ecfg)
             data[ecfg.config_id] = entity_class(device, ecfg)
             entities.append(data[ecfg.config_id])
             entities.append(data[ecfg.config_id])
             if ecfg.deprecated:
             if ecfg.deprecated:

+ 1 - 1
custom_components/tuya_local/helpers/device_config.py

@@ -244,7 +244,7 @@ class TuyaEntityConfig:
 
 
     @property
     @property
     def deprecated(self):
     def deprecated(self):
-        """Return whether this entitiy is deprecated."""
+        """Return whether this entity is deprecated."""
         return "deprecated" in self._config.keys()
         return "deprecated" in self._config.keys()
 
 
     @property
     @property

+ 5 - 0
custom_components/tuya_local/helpers/mixin.py

@@ -91,6 +91,11 @@ class TuyaLocalEntity:
                 attr[a.name] = value
                 attr[a.name] = value
         return attr
         return attr
 
 
+    @property
+    def entity_registry_enabled_default(self):
+        """Disable deprecated entities on new installations"""
+        return not self._config.deprecated
+
     async def async_update(self):
     async def async_update(self):
         await self._device.async_refresh()
         await self._device.async_refresh()