Преглед изворни кода

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 пре 4 година
родитељ
комит
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):
     def match_quality(self, dps):
         """Determine the match quality for the provided dps map."""
         """Determine the match quality for the provided dps map."""
         keys = list(dps.keys())
         keys = list(dps.keys())
+        matched = []
         if "updated_at" in keys:
         if "updated_at" in keys:
             keys.remove("updated_at")
             keys.remove("updated_at")
         total = len(keys)
         total = len(keys)
         for d in self.primary_entity.dps():
         for d in self.primary_entity.dps():
             if d.id not in keys or not _typematch(d.type, dps[d.id]):
             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 dev in self.secondary_entities():
             for d in dev.dps():
             for d in dev.dps():
                 if d.id not in keys or not _typematch(d.type, dps[d.id]):
                 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)
         return round((total - len(keys)) * 100 / total)