Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class BackyardConfig {
@XStreamAlias("Service-Mode-Timeout")
private @Nullable String serviceModeTimeoutElement;

@XStreamImplicit(itemFieldName = "Sensor")
private final List<SensorConfig> sensors = new ArrayList<>();

@XStreamImplicit(itemFieldName = "BodyOfWater")
private final List<BodyOfWaterConfig> bodiesOfWater = new ArrayList<>();

Expand All @@ -57,6 +60,10 @@ public class BackyardConfig {
return serviceModeTimeout != null ? serviceModeTimeout : serviceModeTimeoutElement;
}

public List<SensorConfig> getSensors() {
return sensors;
}

public List<BodyOfWaterConfig> getBodiesOfWater() {
return bodiesOfWater;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.openhab.binding.haywardomnilogiclocal.internal.config;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;

/**
* Representation of a Sensor element.
Expand Down Expand Up @@ -37,6 +43,9 @@ public class SensorConfig {
@XStreamAlias("Units")
private @Nullable String unitsElement;

@XStreamImplicit(itemFieldName = "Operation")
private final List<OperationConfig> operations = new ArrayList<>();

public @Nullable String getSystemId() {
return systemId != null ? systemId : systemIdElement;
}
Expand All @@ -52,5 +61,59 @@ public class SensorConfig {
public @Nullable String getUnits() {
return units != null ? units : unitsElement;
}

public List<OperationConfig> getOperations() {
return operations;
}

@NonNullByDefault
@XStreamAlias("Operation")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = "type")
public static class OperationConfig {
private @Nullable String type;

@XStreamImplicit(itemFieldName = "Action")
private final List<ActionConfig> actions = new ArrayList<>();

@XStreamImplicit(itemFieldName = "Parameter")
private final List<ParameterConfig> parameters = new ArrayList<>();

public @Nullable String getType() {
return type;
}

public List<ActionConfig> getActions() {
return actions;
}

public List<ParameterConfig> getParameters() {
return parameters;
}
}

@NonNullByDefault
@XStreamAlias("Action")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = "type")
public static class ActionConfig {
private @Nullable String type;

@XStreamImplicit(itemFieldName = "Device")
private final List<DeviceConfig> devices = new ArrayList<>();

@XStreamImplicit(itemFieldName = "Parameter")
private final List<ParameterConfig> parameters = new ArrayList<>();

public @Nullable String getType() {
return type;
}

public List<DeviceConfig> getDevices() {
return devices;
}

public List<ParameterConfig> getParameters() {
return parameters;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ public synchronized void mspConfigDiscovery(String xmlResponse) {
putIfNotNull(backyardProps, HaywardBindingConstants.PROPERTY_SYSTEM_ID, systemId);
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, "Backyard", backyardProps);

for (SensorConfig sensor : backyard.getSensors()) {
Map<String, Object> sensorProps = new HashMap<>();
sensorProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.SENSOR);
String sensorId = sensor.getSystemId();
putIfNotNull(sensorProps, HaywardBindingConstants.PROPERTY_SYSTEM_ID, sensorId);
putIfNotNull(sensorProps, HaywardBindingConstants.PROPERTY_SENSOR_TYPE, sensor.getType());
putIfNotNull(sensorProps, HaywardBindingConstants.PROPERTY_SENSOR_UNITS, sensor.getUnits());
String name = sensor.getName();
if (name == null) {
name = sensorId != null ? sensorId : "Sensor";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_SENSOR, name, sensorProps);
}

for (BodyOfWaterConfig bow : backyard.getBodiesOfWater()) {
Map<String, Object> bowProps = new HashMap<>();
bowProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BOW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public void testParsePopulatesAllListsAndAttributes() {
" <System-Id>BY</System-Id>" +
" <Name>Main Backyard</Name>" +
" <Service-Mode-Timeout>15</Service-Mode-Timeout>" +
" <Sensor>" +
" <System-Id>SENBY1</System-Id>" +
" <Name>Air Sensor</Name>" +
" <Type>SENSOR_AIR_TEMP</Type>" +
" <Units>UNITS_FAHRENHEIT</Units>" +
" </Sensor>" +
" <BodyOfWater systemId='BOW' type='BOW_POOL' sharedType='BOW_SHARED_EQUIPMENT' supportsSpillover='yes'" +
" spilloverMode='manual' spilloverTimedPercent='50' freezeProtectEnabled='yes'" +
" freezeProtectSetPoint='38' sizeInLiters='56781'>" +
Expand Down Expand Up @@ -113,6 +119,11 @@ public void testParsePopulatesAllListsAndAttributes() {
" <Name>Water Sensor</Name>" +
" <Type>SENSOR_WATER_TEMP</Type>" +
" <Units>UNITS_FAHRENHEIT</Units>" +
" <Operation>PEO_SENSOR_SAMPLE" +
" <Action>PEA_SENSOR_REPORT" +
" <Parameter name='Interval' dataType='int'>15</Parameter>" +
" </Action>" +
" </Operation>" +
" </Sensor>" +
" </BodyOfWater>" +
" <Pump systemId='P1' name='Main'>" +
Expand Down Expand Up @@ -181,6 +192,13 @@ public void testParsePopulatesAllListsAndAttributes() {
assertEquals("BY", backyard.getSystemId());
assertEquals("Main Backyard", backyard.getName());
assertEquals("15", backyard.getServiceModeTimeout());
assertEquals(1, backyard.getSensors().size());
SensorConfig backyardSensor = backyard.getSensors().get(0);
assertEquals("SENBY1", backyardSensor.getSystemId());
assertEquals("Air Sensor", backyardSensor.getName());
assertEquals("SENSOR_AIR_TEMP", backyardSensor.getType());
assertEquals("UNITS_FAHRENHEIT", backyardSensor.getUnits());
assertEquals(0, backyardSensor.getOperations().size());
assertEquals(1, backyard.getBodiesOfWater().size());
BodyOfWaterConfig bow = backyard.getBodiesOfWater().get(0);
assertEquals("BOW", bow.getSystemId());
Expand Down Expand Up @@ -298,6 +316,16 @@ public void testParsePopulatesAllListsAndAttributes() {
assertEquals("Water Sensor", sensor.getName());
assertEquals("SENSOR_WATER_TEMP", sensor.getType());
assertEquals("UNITS_FAHRENHEIT", sensor.getUnits());
assertEquals(1, sensor.getOperations().size());
SensorConfig.OperationConfig sensorOperation = sensor.getOperations().get(0);
assertEquals("PEO_SENSOR_SAMPLE", sensorOperation.getType());
assertEquals(1, sensorOperation.getActions().size());
SensorConfig.ActionConfig sensorAction = sensorOperation.getActions().get(0);
assertEquals("PEA_SENSOR_REPORT", sensorAction.getType());
assertEquals(0, sensorAction.getDevices().size());
assertEquals(1, sensorAction.getParameters().size());
assertEquals("Interval", sensorAction.getParameters().get(0).getName());
assertEquals("15", sensorAction.getParameters().get(0).getValue());

assertEquals(1, backyard.getPumps().size());
PumpConfig pump = backyard.getPumps().get(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openhab.binding.haywardomnilogiclocal.internal.discovery;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -37,6 +38,7 @@ public void mspConfigDiscoveryCreatesResultsForAllDevices() {
"<MSPConfig>" +
" <System systemId='SYS'/>" +
" <Backyard systemId='BY'>" +
" <Sensor systemId='S2' name='Air' type='SENSOR_AIR_TEMP' units='UNITS_FAHRENHEIT'/>" +
" <BodyOfWater systemId='BOW1' name='Pool' type='BOW_POOL' sharedType='BOW_SHARED_EQUIPMENT'" +
" sharedPriority='SHARED_EQUIPMENT_HIGH_PRIORITY' sharedEquipmentSystemId='BOW2'" +
" supportsSpillover='yes' sizeInGallons='15000'>" +
Expand All @@ -61,19 +63,28 @@ public void mspConfigDiscoveryCreatesResultsForAllDevices() {
TestDiscoveryService service = new TestDiscoveryService();
service.mspConfigDiscovery(xml);

assertEquals(13, service.types.size());
assertEquals(14, service.types.size());
assertEquals(2, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_PUMP)).count());
assertEquals(2, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_FILTER)).count());
assertEquals(2, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_BOW)).count());
assertEquals(1, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_SENSOR)).count());
assertEquals(2, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_SENSOR)).count());

Map<String, Object> bowProps = null;
Map<String, Object> backyardSensorProps = null;
for (int i = 0; i < service.types.size(); i++) {
if (bowProps != null && backyardSensorProps != null) {
break;
}
if (service.types.get(i).equals(HaywardBindingConstants.THING_TYPE_BOW)) {
Map<String, Object> properties = service.propertyMaps.get(i);
if ("BOW1".equals(properties.get(HaywardBindingConstants.PROPERTY_SYSTEM_ID))) {
bowProps = properties;
break;
}
}
if (service.types.get(i).equals(HaywardBindingConstants.THING_TYPE_SENSOR)) {
Map<String, Object> properties = service.propertyMaps.get(i);
if ("S2".equals(properties.get(HaywardBindingConstants.PROPERTY_SYSTEM_ID))) {
backyardSensorProps = properties;
}
}
}
Expand All @@ -87,6 +98,12 @@ public void mspConfigDiscoveryCreatesResultsForAllDevices() {
assertEquals("BOW2", bowProps.get(HaywardBindingConstants.PROPERTY_BOW_SHAREDEQUIPID));
assertEquals("yes", bowProps.get(HaywardBindingConstants.PROPERTY_BOW_SUPPORTSSPILLOVER));
assertEquals("15000", bowProps.get(HaywardBindingConstants.PROPERTY_BOW_SIZEINGALLONS));

assertNotNull(backyardSensorProps);
assertEquals(HaywardTypeToRequest.SENSOR, backyardSensorProps.get(HaywardBindingConstants.PROPERTY_TYPE));
assertEquals("SENSOR_AIR_TEMP", backyardSensorProps.get(HaywardBindingConstants.PROPERTY_SENSOR_TYPE));
assertEquals("UNITS_FAHRENHEIT", backyardSensorProps.get(HaywardBindingConstants.PROPERTY_SENSOR_UNITS));
assertFalse(backyardSensorProps.containsKey(HaywardBindingConstants.PROPERTY_BOWID));
}

@Test
Expand Down