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

Device config: log the right error when no entities are defined.

If a config was missing any entities list, the error message would
be for primary_entity, since this was a fallback for backward compatibility.
Catch this earlier and log an explicit error instead of allowing a
runtime exception to mislead the user into thinking primary_entity is the
answer.

Discussion #3248
Jason Rumney 9 месяцев назад
Родитель
Сommit
c346c835ef
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      custom_components/tuya_local/helpers/device_config.py

+ 6 - 0
custom_components/tuya_local/helpers/device_config.py

@@ -125,6 +125,12 @@ class TuyaDeviceConfig:
     @property
     def primary_entity(self):
         """Return the primary type of entity for this device."""
+        if not "primary_entity" in self._config:
+            # primary entity is a deprecated fallback, so if it is
+            # missing, we need to log a warning about the missing entities
+            # list.
+            _LOGGER.error(f"{self.config_type}.yaml does not define an entities list.")
+            return TuyaEntityConfig(self, self._config["entities"][0])
         if not self._reported_deprecated_primary:
             _LOGGER.warning(
                 f"{self.config_type}.yaml distinguishes between primary"