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

Allow dps to be duplicated in the config file.

This allows for additional sensor to be defined in addition to just
including them as attributes for convenience, or alternate types such
as a humidifier offering a humidifier and a climate option depending
on user preference. The latter has more functions and is better
supported in the front end, even though it does not really fit
humidifiers, but the former is the modern way of doing things even
though the front end is not really supporting it well yet.
Jason Rumney 5 лет назад
Родитель
Сommit
7ddec40a57
1 измененных файлов с 11 добавлено и 4 удалено
  1. 11 4
      custom_components/tuya_local/helpers/device_config.py

+ 11 - 4
custom_components/tuya_local/helpers/device_config.py

@@ -87,19 +87,26 @@ class TuyaDeviceConfig:
     def match_quality(self, dps):
         """Determine the match quality for the provided dps map."""
         keys = list(dps.keys())
+        matched = []
         if "updated_at" in keys:
             keys.remove("updated_at")
         total = len(keys)
         for d in self.primary_entity.dps():
             if d.id not in keys or not _typematch(d.type, dps[d.id]):
-                return 0
-            keys.remove(d.id)
+                if d.id not in matched:
+                    return 0
+            if d.id in keys:
+                matched.append(d.id)
+                keys.remove(d.id)
 
         for dev in self.secondary_entities():
             for d in dev.dps():
                 if d.id not in keys or not _typematch(d.type, dps[d.id]):
-                    return 0
-                keys.remove(d.id)
+                    if d.id not in matched:
+                        return 0
+                if d.id in keys:
+                    matched.append(d.id)
+                    keys.remove(d.id)
         return round((total - len(keys)) * 100 / total)