Преглед на файлове

Deprecation: log the warning when the entity is added to hass

Logging the warning in async_setup_platform results in it being
always logged, as we have not been through the entity registry at
that point.

Only log when the entity is actually added to hass, to avoid logging
a warning for disabled entities.

Discussion #1961
Jason Rumney преди 1 година
родител
ревизия
dc63c80645
променени са 2 файла, в които са добавени 2 реда и са изтрити 2 реда
  1. 0 2
      custom_components/tuya_local/helpers/config.py
  2. 2 0
      custom_components/tuya_local/helpers/mixin.py

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

@@ -27,8 +27,6 @@ async def async_tuya_setup_platform(
         try:
             data[ecfg.config_id] = entity_class(device, ecfg)
             entities.append(data[ecfg.config_id])
-            if ecfg.deprecated:
-                _LOGGER.warning(ecfg.deprecation_message)
             _LOGGER.debug("Adding %s for %s", platform, ecfg.config_id)
         except Exception as e:
             _LOGGER.error(

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

@@ -106,6 +106,8 @@ class TuyaLocalEntity:
 
     async def async_added_to_hass(self):
         self._device.register_entity(self)
+        if self._config.deprecated:
+            _LOGGER.warning(self._config.deprecation_message)
 
     async def async_will_remove_from_hass(self):
         await self._device.async_unregister_entity(self)