From d2d3150255da8eb67a3b8a0a8269fb4657beead5 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 16 Sep 2025 20:34:54 -0400 Subject: [PATCH] Fix DMT device parsing and add nested device test --- .../internal/config/DeviceConfig.java | 85 +++++++++++++++++-- .../internal/config/ConfigParserTest.java | 28 ++++++ .../config/request-dmt-nested-sample.xml | 23 +++++ 3 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-dmt-nested-sample.xml diff --git a/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/DeviceConfig.java b/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/DeviceConfig.java index 093c13d17ce17..8a2658fcf2092 100644 --- a/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/DeviceConfig.java +++ b/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/DeviceConfig.java @@ -1,6 +1,7 @@ package org.openhab.binding.haywardomnilogiclocal.internal.config; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -23,24 +24,36 @@ public class DeviceConfig { @XStreamAlias("System-Id") private @Nullable String systemIdElement; + @XStreamAlias("Device-System-Id") + private @Nullable String deviceSystemIdElement; + @XStreamAsAttribute private @Nullable String name; @XStreamAlias("Name") private @Nullable String nameElement; + @XStreamAlias("Device-Name") + private @Nullable String deviceNameElement; + @XStreamAsAttribute private @Nullable String type; @XStreamAlias("Type") private @Nullable String typeElement; + @XStreamAlias("Device-Type") + private @Nullable String deviceTypeElement; + @XStreamAsAttribute private @Nullable String subType; @XStreamAlias("Sub-Type") private @Nullable String subTypeElement; + @XStreamAlias("Device-Sub-Type") + private @Nullable String deviceSubTypeElement; + @XStreamAsAttribute @XStreamAlias("parentSystemId") private @Nullable String parentSystemId; @@ -48,30 +61,92 @@ public class DeviceConfig { @XStreamAlias("Parent-System-Id") private @Nullable String parentSystemIdElement; + @XStreamAlias("Device-Parent-System-Id") + private @Nullable String deviceParentSystemIdElement; + + @XStreamAlias("Node-ID") + private @Nullable String nodeIdElement; + + @XStreamAlias("Devices") + private @Nullable DeviceList devicesElement; + @XStreamImplicit(itemFieldName = "Parameter") private final List parameters = new ArrayList<>(); public @Nullable String getSystemId() { - return systemId != null ? systemId : systemIdElement; + if (deviceSystemIdElement != null) { + return deviceSystemIdElement; + } + if (systemIdElement != null) { + return systemIdElement; + } + return systemId; } public @Nullable String getName() { - return name != null ? name : nameElement; + if (deviceNameElement != null) { + return deviceNameElement; + } + if (nameElement != null) { + return nameElement; + } + return name; } public @Nullable String getType() { - return type != null ? type : typeElement; + if (deviceTypeElement != null) { + return deviceTypeElement; + } + if (typeElement != null) { + return typeElement; + } + return type; } public @Nullable String getSubType() { - return subType != null ? subType : subTypeElement; + if (deviceSubTypeElement != null) { + return deviceSubTypeElement; + } + if (subTypeElement != null) { + return subTypeElement; + } + return subType; } public @Nullable String getParentSystemId() { - return parentSystemId != null ? parentSystemId : parentSystemIdElement; + if (deviceParentSystemIdElement != null) { + return deviceParentSystemIdElement; + } + if (parentSystemIdElement != null) { + return parentSystemIdElement; + } + return parentSystemId; + } + + public @Nullable String getNodeId() { + return nodeIdElement; + } + + public List getChildDevices() { + DeviceList list = devicesElement; + if (list == null) { + return Collections.emptyList(); + } + return list.getDevices(); } public List getParameters() { return parameters; } + + @XStreamAlias("Devices") + @NonNullByDefault + private static class DeviceList { + @XStreamImplicit(itemFieldName = "Device") + private final List devices = new ArrayList<>(); + + public List getDevices() { + return devices; + } + } } diff --git a/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParserTest.java b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParserTest.java index 298beaf6d0fa2..81e4f313bf571 100644 --- a/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParserTest.java +++ b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParserTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.List; import org.junit.jupiter.api.Test; @@ -314,6 +315,33 @@ public void testParseSchedulesWithScheElements() throws IOException { assertEquals(0, secondSchedule.getActions().size()); } + @Test + public void testParseDmtNestedDevices() throws IOException { + MspConfig config = parseConfigurationResource("request-dmt-nested-sample.xml"); + + List devices = config.getDmt().getDevices(); + assertEquals(1, devices.size()); + + DeviceConfig parentDevice = devices.get(0); + assertEquals("DEV-PARENT", parentDevice.getSystemId()); + assertEquals("Water Feature Pump", parentDevice.getName()); + assertEquals("PMP_WATER_FEATURE", parentDevice.getType()); + assertEquals("PMP_FEATURE", parentDevice.getSubType()); + assertEquals("BY1", parentDevice.getParentSystemId()); + assertEquals("NODE-001", parentDevice.getNodeId()); + + List childDevices = parentDevice.getChildDevices(); + assertEquals(1, childDevices.size()); + + DeviceConfig childDevice = childDevices.get(0); + assertEquals("DEV-CHILD", childDevice.getSystemId()); + assertEquals("Waterfall Light", childDevice.getName()); + assertEquals("LIGHT_COLOR_LOGIC", childDevice.getType()); + assertEquals("LIGHT_FEATURE", childDevice.getSubType()); + assertEquals("DEV-PARENT", childDevice.getParentSystemId()); + assertEquals("NODE-002", childDevice.getNodeId()); + } + private static MspConfig parseSampleConfiguration() throws IOException { return parseConfigurationResource("request-configuration-sample.xml"); } diff --git a/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-dmt-nested-sample.xml b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-dmt-nested-sample.xml new file mode 100644 index 0000000000000..bfc38e36ae1d2 --- /dev/null +++ b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-dmt-nested-sample.xml @@ -0,0 +1,23 @@ + + + + + DEV-PARENT + Water Feature Pump + PMP_WATER_FEATURE + PMP_FEATURE + BY1 + NODE-001 + + + DEV-CHILD + Waterfall Light + LIGHT_COLOR_LOGIC + LIGHT_FEATURE + DEV-PARENT + NODE-002 + + + + +