소스 검색

Config match script: Show matched entities' state.

This can help to judge whether a config is really a match.
Jason Rumney 3 년 전
부모
커밋
3b87187d90
1개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 17 0
      util/config_match.py

+ 17 - 0
util/config_match.py

@@ -5,10 +5,27 @@ import json
 from custom_components.tuya_local.helpers.device_config import possible_matches
 
 
+class FakeDevice:
+    def __init__(self, dps):
+        self._dps = dps
+
+    def get_property(self, id):
+        return self._dps.get(id)
+
+
 def main() -> int:
     dps = json.loads(" ".join(sys.argv[1:]))
+    device = FakeDevice(dps)
+
     for match in possible_matches(dps):
         print(f"{match.config_type} matched {match.match_quality(dps)}%")
+        print(f"  {match.primary_entity.config_id}:")
+        for dp in match.primary_entity.dps():
+            print(f"   {dp.name}: {dp.get_value(device)}")
+        for entity in match.secondary_entities():
+            print(f"  {entity.config_id}:")
+            for dp in entity.dps():
+                print(f"    {dp.name}: {dp.get_value(device)}")
 
 
 if __name__ == "__main__":