소스 검색

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:
         try:
             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:
-                _LOGGER.warning(ecfg.deprecation_message)
             _LOGGER.debug("Adding %s for %s", platform, ecfg.config_id)
             _LOGGER.debug("Adding %s for %s", platform, ecfg.config_id)
         except Exception as e:
         except Exception as e:
             _LOGGER.error(
             _LOGGER.error(

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

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