Browse Source

feat(util/match_against): report differences in both direction

When comparing two configs, or logs against a specific config, missing
dps and type mismatches were reported, but extra dps were not. To get
extra dps reported, you needed to run one of the other matching utilities.

Add reporting of extra dps so that one utility is enough to get a full picture
of compatibility.
Jason Rumney 1 tháng trước cách đây
mục cha
commit
96376aa5ca
1 tập tin đã thay đổi với 6 bổ sung và 1 xóa
  1. 6 1
      util/match_against.py

+ 6 - 1
util/match_against.py

@@ -15,14 +15,17 @@ def main() -> int:
         dps = json.loads(rest)
         dps = json.loads(rest)
     else:
     else:
         dps = make_sample_dps(config)
         dps = make_sample_dps(config)
-    device = FakeDevice(dps)
+
     config = load_config(sys.argv[1])
     config = load_config(sys.argv[1])
     if config is None:
     if config is None:
         print(f"No config could be loaded for {sys.argv[1]}")
         print(f"No config could be loaded for {sys.argv[1]}")
         return 1
         return 1
+    device = FakeDevice(dps)
+    unseen = set(dps.keys())
     for entity in config.all_entities():
     for entity in config.all_entities():
         print(f"{entity.config_id}:")
         print(f"{entity.config_id}:")
         for dp in entity.dps():
         for dp in entity.dps():
+            unseen.discard(dp.id)
             if dp.id not in dps.keys():
             if dp.id not in dps.keys():
                 print(f"   {dp.name} missing from data")
                 print(f"   {dp.name} missing from data")
                 if not dp.optional:
                 if not dp.optional:
@@ -38,6 +41,8 @@ def main() -> int:
                 else:
                 else:
                     values = ""
                     values = ""
                 print(f"   {dp.name}: {dp.get_value(device)}{values}")
                 print(f"   {dp.name}: {dp.get_value(device)}{values}")
+    for dp in unseen:
+        print(f"   Extra dp {dp} in data")
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":