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

Add a Warning when configuring devices without a perfect matching config.

Jason Rumney 4 лет назад
Родитель
Сommit
f2dee92d9f
1 измененных файлов с 20 добавлено и 1 удалено
  1. 20 1
      custom_components/tuya_local/config_flow.py

+ 20 - 1
custom_components/tuya_local/config_flow.py

@@ -57,12 +57,31 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
             return await self.async_step_choose_entities()
 
         types = []
+        best_match = 0
+        best_matching_type = None
+
         async for type in self.device.async_possible_types():
             types.append(type.legacy_type)
+            q = type.match_quality(self.device._get_cached_state())
+            if q > best_match:
+                best_match = q
+                best_matching_type = type.legacy_type
+
+        if best_match < 100:
+            best_match = int(best_match)
+            dps = self.device._get_cached_state()
+            _LOGGER.warning(
+                f"Device matches {best_matching_type} with quality of {best_match}%. DPS: {dps}"
+            )
+            _LOGGER.warning(
+                f"Report this to https://github.com/make-all/tuya-local/issues/"
+            )
         if types:
             return self.async_show_form(
                 step_id="select_type",
-                data_schema=vol.Schema({vol.Required(CONF_TYPE): vol.In(types)}),
+                data_schema=vol.Schema(
+                    {vol.Required(CONF_TYPE, default=best_matching_type): vol.In(types)}
+                ),
             )
         else:
             return self.async_abort(reason="not_supported")