From 98d1777d0450c59efdb29e5296af9fcf26e4bca1 Mon Sep 17 00:00:00 2001
From: David Hammer <david.hammer@xfel.eu>
Date: Thu, 29 Aug 2024 15:14:18 +0200
Subject: [PATCH] Fix addon filter from entry_points

---
 src/calng/base_correction.py                 |  2 +-
 src/calng/corrections/Gotthard2Correction.py |  1 +
 src/calng/corrections/JungfrauCorrection.py  |  1 +
 tests/test_addon_system.py                   | 44 ++++++++++++++++++++
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_addon_system.py

diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py
index b461c88c..de7e9910 100644
--- a/src/calng/base_correction.py
+++ b/src/calng/base_correction.py
@@ -1043,7 +1043,7 @@ def add_addon_nodes(schema, device_class, prefix="addons"):
         addon.load()
         for addon in entry_points().select().get("calng.correction_addon", [])
         if not addon.extras
-        or det_name in (extra[0] for extra in addon.extras)
+        or det_name in addon.extras
     ]
 
     for addon_class in device_class._available_addons:
diff --git a/src/calng/corrections/Gotthard2Correction.py b/src/calng/corrections/Gotthard2Correction.py
index 386aafc7..84dc79e6 100644
--- a/src/calng/corrections/Gotthard2Correction.py
+++ b/src/calng/corrections/Gotthard2Correction.py
@@ -319,6 +319,7 @@ class Gotthard2Correction(base_correction.BaseCorrection):
     def expectedParameters(cls, expected):
         cls._calcat_friend_class.add_schema(expected)
         cls._kernel_runner_class.add_schema(expected)
+        base_correction.add_addon_nodes(expected, cls)
         PreviewFriend.add_schema(expected, cls._preview_outputs)
         (
             OUTPUT_CHANNEL(expected)
diff --git a/src/calng/corrections/JungfrauCorrection.py b/src/calng/corrections/JungfrauCorrection.py
index c51cbe08..1d9cb0c4 100644
--- a/src/calng/corrections/JungfrauCorrection.py
+++ b/src/calng/corrections/JungfrauCorrection.py
@@ -461,6 +461,7 @@ class JungfrauCorrection(base_correction.BaseCorrection):
     def expectedParameters(cls, expected):
         cls._calcat_friend_class.add_schema(expected)
         JungfrauBaseRunner.add_schema(expected)
+        base_correction.add_addon_nodes(expected, cls)
         PreviewFriend.add_schema(expected, cls._preview_outputs)
         (
             OUTPUT_CHANNEL(expected)
diff --git a/tests/test_addon_system.py b/tests/test_addon_system.py
new file mode 100644
index 00000000..0a2ece76
--- /dev/null
+++ b/tests/test_addon_system.py
@@ -0,0 +1,44 @@
+from karabo.bound import Configurator, Schema
+
+from calng.correction_addons import litpixel_counter, random_frames
+from calng.corrections import (
+    AgipdCorrection,
+    DsscCorrection,
+    Epix100Correction,
+    Gotthard2Correction,
+    JungfrauCorrection,
+    LpdCorrection,
+    LpdminiCorrection,
+    PnccdCorrection,
+)
+
+
+def test_available_addons():
+    all_device_classes = [
+        AgipdCorrection,
+        DsscCorrection,
+        Epix100Correction,
+        Gotthard2Correction,
+        JungfrauCorrection,
+        LpdCorrection,
+        LpdminiCorrection,
+        PnccdCorrection,
+    ]
+    actual_classes = [
+        getattr(cls, cls.__name__.rpartition(".")[-1]) for cls in all_device_classes
+    ]
+
+    configurator = Configurator("PythonDevice")
+    for cls in actual_classes:
+        schema_hash = configurator.getSchema(cls).getParameterHash()
+
+        # everyone should have RandomFrames
+        assert random_frames.RandomFrames in cls._available_addons  # available
+        assert schema_hash.has("addons.RandomFrames")  # and in schema
+        # only AGIPD has the litpixelcounter (for now)
+        if cls == AgipdCorrection.AgipdCorrection:
+            assert litpixel_counter.LitPixelCounter in cls._available_addons
+            assert schema_hash.has("addons.LitPixelCounter")
+        else:
+            assert litpixel_counter.LitPixelCounter not in cls._available_addons
+            assert not schema_hash.has("addons.LitPixelCounter")
-- 
GitLab