瀏覽代碼

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)