From 597f5e865c8b0b01b0250b375f113ed1ea3d090d Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 16 Sep 2025 11:42:26 -0400 Subject: [PATCH] Register new config DTOs for parsing --- .../internal/config/ConfigParser.java | 14 +- .../internal/config/ConfigParserTest.java | 203 ++++-------------- .../config/request-configuration-sample.xml | 164 ++++++++++++++ 3 files changed, 212 insertions(+), 169 deletions(-) create mode 100644 bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-configuration-sample.xml diff --git a/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParser.java b/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParser.java index 3857e2a544724..f8e94758947e7 100644 --- a/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParser.java +++ b/bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/config/ConfigParser.java @@ -13,16 +13,18 @@ public final class ConfigParser { private static final XStream XSTREAM = new XStream(new StaxDriver()); + private static final Class[] ANNOTATED_CONFIG_TYPES = new Class[] { ActionConfig.class, BackyardConfig.class, + BodyOfWaterConfig.class, ChlorinatorConfig.class, ColorLogicLightConfig.class, DeviceConfig.class, + DmtConfig.class, FilterConfig.class, HeaterConfig.class, HeaterConfig.HeaterEquipmentConfig.class, + MspConfig.class, OperationConfig.class, ParameterConfig.class, PumpConfig.class, RelayConfig.class, + ScheduleActionConfig.class, ScheduleConfig.class, SchedulesConfig.class, SensorConfig.class, + SystemConfig.class, VirtualHeaterConfig.class }; + static { XSTREAM.setClassLoader(ConfigParser.class.getClassLoader()); XSTREAM.ignoreUnknownElements(); XSTREAM.addPermission(AnyTypePermission.ANY); - XSTREAM.processAnnotations(new Class[] { MspConfig.class, SystemConfig.class, BackyardConfig.class, - BodyOfWaterConfig.class, PumpConfig.class, FilterConfig.class, HeaterConfig.class, - HeaterConfig.HeaterEquipmentConfig.class, SensorConfig.class, VirtualHeaterConfig.class, - ChlorinatorConfig.class, ColorLogicLightConfig.class, RelayConfig.class, OperationConfig.class, - ActionConfig.class, SchedulesConfig.class, ScheduleConfig.class, ScheduleActionConfig.class, - DeviceConfig.class, ParameterConfig.class, DmtConfig.class }); + XSTREAM.processAnnotations(ANNOTATED_CONFIG_TYPES); } private ConfigParser() { 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 bcbe8c8145ab3..0d534ec076e92 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 @@ -1,6 +1,11 @@ package org.openhab.binding.haywardomnilogiclocal.internal.config; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; @@ -9,169 +14,8 @@ */ public class ConfigParserTest { @Test - public void testParsePopulatesAllListsAndAttributes() { - String xml = "" + - "" + - " " + - " Percent" + - " 12 Hour Format" + - " America/New_York" + - " Enabled" + - " Disabled" + - " Metric" + - " Salt" + - " French" + - " true" + - " false" + - " true" + - " true" + - " false" + - " true" + - " false" + - " " + - " " + - " BY" + - " Main Backyard" + - " 15" + - " " + - " SENBY1" + - " Air Sensor" + - " SENSOR_AIR_TEMP" + - " UNITS_FAHRENHEIT" + - " " + - " " + - " Main Pool" + - " BOW_POOL" + - " BOW_SHARED_EQUIPMENT" + - " SHARED_EQUIPMENT_HIGH_PRIORITY" + - " BOW2" + - " yes" + - " 10" + - " 20" + - " no" + - " 15000" + - " " + - " Filter Pump" + - " BOW_SHARED_EQUIPMENT" + - " FMT_VARIABLE_SPEED_PUMP" + - " 100" + - " 18" + - " 3450" + - " 600" + - " 18" + - " 50" + - " 100" + - " 80" + - " PEO_FILTER_SAMPLE" + - " PEA_FILTER_SPEED" + - " 3200" + - " " + - " " + - " " + - " " + - " BOW_SHARED_EQUIPMENT" + - " yes" + - " 82" + - " 104" + - " 65" + - " 104" + - " no" + - " PEO_HEATER_EQUIPMENT" + - " " + - " HX1" + - " Gas Heater" + - " PET_HEATER" + - " HTR_GAS" + - " yes" + - " " + - " " + - " PEO_HEATER_FLOW" + - " PEA_FLOW" + - " 40" + - " " + - " " + - " " + - " " + - " Chlorinator" + - " CHLOR_OP_MODE_ORP_AUTO" + - " 50" + - " 24" + - " CELL_TYPE_T15" + - " 86400" + - " PEO_CHLOR_SAMPLE" + - " PEA_SET_PERCENT" + - " 60" + - " " + - " " + - " " + - " " + - " Pool Light" + - " COLOR_LOGIC_UCL" + - " " + - " " + - " RLY_HIGH_VOLTAGE_RELAY" + - " GENERIC" + - " " + - " " + - " SEN1" + - " Water Sensor" + - " SENSOR_WATER_TEMP" + - " UNITS_FAHRENHEIT" + - " PEO_SENSOR_SAMPLE" + - " 5" + - " PEA_SENSOR_REPORT" + - " 15" + - " " + - " " + - " " + - " " + - " " + - " PMP_VARIABLE_SPEED_PUMP" + - " PMP_FILTER" + - " 3450" + - " 600" + - " 20" + - " 100" + - " 60" + - " 70" + - " 100" + - " 30" + - " PEO_PUMP_SAMPLE" + - " PEA_SET_SPEED" + - " 3100" + - " " + - " PEO_PUMP_CHILD" + - " PEA_CHILD_SPEED" + - " 2800" + - " " + - " " + - " " + - " " + - " " + - " yes" + - " 92" + - " " + - " " + - " " + - " " + - " " + - " 6" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " 3450" + - " " + - " " + - " 12345" + - ""; - - MspConfig config = ConfigParser.parse(xml); + public void testParsePopulatesAllListsAndAttributes() throws IOException { + MspConfig config = parseSampleConfiguration(); assertEquals(1, config.getSystems().size()); SystemConfig system = config.getSystems().get(0); @@ -361,6 +205,12 @@ public void testParsePopulatesAllListsAndAttributes() { assertEquals(1, pumpAction.getParameters().size()); assertEquals("Speed", pumpAction.getParameters().get(0).getName()); assertEquals("3100", pumpAction.getParameters().get(0).getValue()); + assertEquals(1, pumpAction.getOperations().size()); + OperationConfig pumpActionNestedOperation = pumpAction.getOperations().get(0); + assertEquals("PEO_ACTION_CHILD", pumpActionNestedOperation.getType()); + assertEquals(1, pumpActionNestedOperation.getParameters().size()); + assertEquals("ChildParam", pumpActionNestedOperation.getParameters().get(0).getName()); + assertEquals("1", pumpActionNestedOperation.getParameters().get(0).getValue()); assertEquals(1, pumpOperation.getOperations().size()); OperationConfig nestedPumpOperation = pumpOperation.getOperations().get(0); assertEquals("PEO_PUMP_CHILD", nestedPumpOperation.getType()); @@ -395,6 +245,10 @@ public void testParsePopulatesAllListsAndAttributes() { assertEquals("on", action.getType()); assertEquals(1, action.getDevices().size()); assertEquals("R1", action.getDevices().get(0).getSystemId()); + assertEquals(1, action.getParameters().size()); + ParameterConfig scheduleActionParameter = action.getParameters().get(0); + assertEquals("Duration", scheduleActionParameter.getName()); + assertEquals("30", scheduleActionParameter.getValue()); assertEquals(1, config.getDmt().getDevices().size()); DeviceConfig device = config.getDmt().getDevices().get(0); @@ -407,5 +261,28 @@ public void testParsePopulatesAllListsAndAttributes() { assertEquals("12345", config.getChecksum()); } + + @Test + public void testParseSampleConfigurationNestedActionOperations() throws IOException { + MspConfig config = parseSampleConfiguration(); + + PumpConfig pump = config.getBackyards().get(0).getPumps().get(0); + OperationConfig pumpOperation = pump.getOperations().get(0); + ActionConfig pumpAction = pumpOperation.getActions().get(0); + + assertEquals(1, pumpAction.getOperations().size()); + OperationConfig nestedOperation = pumpAction.getOperations().get(0); + assertEquals("PEO_ACTION_CHILD", nestedOperation.getType()); + assertEquals("ChildParam", nestedOperation.getParameters().get(0).getName()); + assertEquals("1", nestedOperation.getParameters().get(0).getValue()); + } + + private static MspConfig parseSampleConfiguration() throws IOException { + try (InputStream stream = ConfigParserTest.class.getResourceAsStream("request-configuration-sample.xml")) { + assertNotNull(stream, "Sample RequestConfiguration XML is missing"); + String xml = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + return ConfigParser.parse(xml); + } + } } diff --git a/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-configuration-sample.xml b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-configuration-sample.xml new file mode 100644 index 0000000000000..b074f5756046d --- /dev/null +++ b/bundles/org.openhab.binding.haywardomnilogiclocal/src/test/resources/org/openhab/binding/haywardomnilogiclocal/internal/config/request-configuration-sample.xml @@ -0,0 +1,164 @@ + + + + Percent + 12 Hour Format + America/New_York + Enabled + Disabled + Metric + Salt + French + true + false + true + true + false + true + false + + + BY + Main Backyard + 15 + + SENBY1 + Air Sensor + SENSOR_AIR_TEMP + UNITS_FAHRENHEIT + + + Main Pool + BOW_POOL + BOW_SHARED_EQUIPMENT + SHARED_EQUIPMENT_HIGH_PRIORITY + BOW2 + yes + 10 + 20 + no + 15000 + + Filter Pump + BOW_SHARED_EQUIPMENT + FMT_VARIABLE_SPEED_PUMP + 100 + 18 + 3450 + 600 + 18 + 50 + 100 + 80 + PEO_FILTER_SAMPLE + PEA_FILTER_SPEED + 3200 + + + + + BOW_SHARED_EQUIPMENT + yes + 82 + 104 + 65 + 104 + no + PEO_HEATER_EQUIPMENT + + HX1 + Gas Heater + PET_HEATER + HTR_GAS + yes + + + PEO_HEATER_FLOW + PEA_FLOW + 40 + + + + + Chlorinator + CHLOR_OP_MODE_ORP_AUTO + 50 + 24 + CELL_TYPE_T15 + 86400 + PEO_CHLOR_SAMPLE + PEA_SET_PERCENT + 60 + + + + + Pool Light + COLOR_LOGIC_UCL + + + RLY_HIGH_VOLTAGE_RELAY + GENERIC + + + SEN1 + Water Sensor + SENSOR_WATER_TEMP + UNITS_FAHRENHEIT + PEO_SENSOR_SAMPLE + 5 + PEA_SENSOR_REPORT + 15 + + + + + + PMP_VARIABLE_SPEED_PUMP + PMP_FILTER + 3450 + 600 + 20 + 100 + 60 + 70 + 100 + 30 + PEO_PUMP_SAMPLE + PEA_SET_SPEED + 3100 + PEO_ACTION_CHILD + 1 + + + PEO_PUMP_CHILD + PEA_CHILD_SPEED + 2800 + + + + + + yes + 92 + + + + + + 6 + + + 30 + + + + + + 3450 + + + 12345 +