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 @@ -17,8 +17,15 @@ public class MspConfig {
@XStreamImplicit(itemFieldName = "System")
private final List<SystemConfig> systems = new ArrayList<>();

@XStreamImplicit(itemFieldName = "Backyard")
private final List<BackyardConfig> backyards = new ArrayList<>();

public List<SystemConfig> getSystems() {
return systems;
}

public List<BackyardConfig> getBackyards() {
return backyards;
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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.XStreamImplicit;

/**
* Representation of the System element within the MSP configuration.
Expand All @@ -20,15 +16,8 @@ public class SystemConfig {
@XStreamAlias("systemId")
private @Nullable String systemId;

@XStreamImplicit(itemFieldName = "Backyard")
private final List<BackyardConfig> backyards = new ArrayList<>();

public @Nullable String getSystemId() {
return systemId;
}

public List<BackyardConfig> getBackyards() {
return backyards;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.openhab.binding.haywardomnilogiclocal.internal.config.MspConfig;
import org.openhab.binding.haywardomnilogiclocal.internal.config.PumpConfig;
import org.openhab.binding.haywardomnilogiclocal.internal.config.RelayConfig;
import org.openhab.binding.haywardomnilogiclocal.internal.config.SystemConfig;
import org.openhab.binding.haywardomnilogiclocal.internal.config.VirtualHeaterConfig;
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardBridgeHandler;
import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService;
Expand Down Expand Up @@ -73,136 +72,133 @@ protected void startScan() {
public synchronized void mspConfigDiscovery(String xmlResponse) {
MspConfig config = ConfigParser.parse(xmlResponse);

for (SystemConfig system : config.getSystems()) {
String systemId = system.getSystemId();
for (BackyardConfig backyard : config.getBackyards()) {
Map<String, Object> backyardProps = new HashMap<>();
backyardProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BACKYARD);
String systemId = backyard.getSystemId();
if (systemId != null) {
backyardProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, systemId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, "Backyard", backyardProps);

for (BodyOfWaterConfig bow : backyard.getBodiesOfWater()) {
Map<String, Object> bowProps = new HashMap<>();
bowProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BOW);
String bowId = bow.getSystemId();
if (bowId != null) {
bowProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, bowId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BOW, bowId != null ? bowId : "BodyOfWater",
bowProps);
}

for (BackyardConfig backyard : system.getBackyards()) {
Map<String, Object> backyardProps = new HashMap<>();
backyardProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BACKYARD);
if (systemId != null) {
backyardProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, systemId);
for (PumpConfig pump : backyard.getPumps()) {
Map<String, Object> pumpProps = new HashMap<>();
pumpProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.PUMP);
String pumpId = pump.getSystemId();
if (pumpId != null) {
pumpProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, pumpId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BACKYARD, "Backyard", backyardProps);

for (BodyOfWaterConfig bow : backyard.getBodiesOfWater()) {
Map<String, Object> bowProps = new HashMap<>();
bowProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.BOW);
String bowId = bow.getSystemId();
if (bowId != null) {
bowProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, bowId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_BOW, bowId != null ? bowId : "BodyOfWater",
bowProps);
String name = pump.getName() != null ? pump.getName() : pumpId;
if (name == null) {
name = "Pump";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_PUMP, name, pumpProps);
}

for (PumpConfig pump : backyard.getPumps()) {
Map<String, Object> pumpProps = new HashMap<>();
pumpProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.PUMP);
String pumpId = pump.getSystemId();
if (pumpId != null) {
pumpProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, pumpId);
}
String name = pump.getName() != null ? pump.getName() : pumpId;
if (name == null) {
name = "Pump";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_PUMP, name, pumpProps);
for (FilterConfig filter : backyard.getFilters()) {
Map<String, Object> filterProps = new HashMap<>();
filterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.FILTER);
String filterId = filter.getSystemId();
if (filterId != null) {
filterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, filterId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_FILTER,
filterId != null ? filterId : "Filter", filterProps);
}

for (FilterConfig filter : backyard.getFilters()) {
Map<String, Object> filterProps = new HashMap<>();
filterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.FILTER);
String filterId = filter.getSystemId();
if (filterId != null) {
filterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, filterId);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_FILTER,
filterId != null ? filterId : "Filter", filterProps);
for (HeaterConfig heater : backyard.getHeaters()) {
Map<String, Object> heaterProps = new HashMap<>();
heaterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.HEATER);
String heaterId = heater.getSystemId();
if (heaterId != null) {
heaterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, heaterId);
}
String type = heater.getType();
if (type != null) {
heaterProps.put(HaywardBindingConstants.PROPERTY_HEATER_TYPE, type);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_HEATER,
heaterId != null ? heaterId : "Heater", heaterProps);
}

for (HeaterConfig heater : backyard.getHeaters()) {
Map<String, Object> heaterProps = new HashMap<>();
heaterProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.HEATER);
String heaterId = heater.getSystemId();
if (heaterId != null) {
heaterProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, heaterId);
}
String type = heater.getType();
if (type != null) {
heaterProps.put(HaywardBindingConstants.PROPERTY_HEATER_TYPE, type);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_HEATER,
heaterId != null ? heaterId : "Heater", heaterProps);
for (ChlorinatorConfig chlorinator : backyard.getChlorinators()) {
Map<String, Object> chlorProps = new HashMap<>();
chlorProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.CHLORINATOR);
String id = chlorinator.getSystemId();
if (id != null) {
chlorProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_CHLORINATOR, id != null ? id : "Chlorinator",
chlorProps);
}

for (ChlorinatorConfig chlorinator : backyard.getChlorinators()) {
Map<String, Object> chlorProps = new HashMap<>();
chlorProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.CHLORINATOR);
String id = chlorinator.getSystemId();
if (id != null) {
chlorProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_CHLORINATOR, id != null ? id : "Chlorinator",
chlorProps);
for (ColorLogicLightConfig light : backyard.getColorLogicLights()) {
Map<String, Object> lightProps = new HashMap<>();
lightProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.COLORLOGIC);
String id = light.getSystemId();
if (id != null) {
lightProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_COLORLOGIC, id != null ? id : "ColorLogic",
lightProps);
}

for (ColorLogicLightConfig light : backyard.getColorLogicLights()) {
Map<String, Object> lightProps = new HashMap<>();
lightProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.COLORLOGIC);
String id = light.getSystemId();
for (RelayConfig relay : backyard.getRelays()) {
String id = relay.getSystemId();
String relayType = relay.getType();
if ("RLY_VALVE_ACTUATOR".equals(relayType)) {
Map<String, Object> valveProps = new HashMap<>();
valveProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VALVEACTUATOR);
if (id != null) {
lightProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
valveProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_COLORLOGIC, id != null ? id : "ColorLogic",
lightProps);
}

for (RelayConfig relay : backyard.getRelays()) {
String id = relay.getSystemId();
String relayType = relay.getType();
if ("RLY_VALVE_ACTUATOR".equals(relayType)) {
Map<String, Object> valveProps = new HashMap<>();
valveProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VALVEACTUATOR);
if (id != null) {
valveProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
if (relayType != null) {
valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_TYPE, relayType);
}
String function = relay.getFunction();
if (function != null) {
valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_FUNCTION, function);
}
String name = relay.getName();
if (name == null) {
name = id != null ? id : "ValveActuator";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR, name, valveProps);
continue;
if (relayType != null) {
valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_TYPE, relayType);
}

Map<String, Object> relayProps = new HashMap<>();
relayProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.RELAY);
if (id != null) {
relayProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
String function = relay.getFunction();
if (function != null) {
valveProps.put(HaywardBindingConstants.PROPERTY_RELAY_FUNCTION, function);
}
String name = relay.getName();
if (name == null) {
name = id != null ? id : "Relay";
name = id != null ? id : "ValveActuator";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_RELAY, name, relayProps);
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR, name, valveProps);
continue;
}

for (VirtualHeaterConfig vh : backyard.getVirtualHeaters()) {
Map<String, Object> vhProps = new HashMap<>();
vhProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VIRTUALHEATER);
String id = vh.getSystemId();
if (id != null) {
vhProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER,
id != null ? id : "VirtualHeater", vhProps);
Map<String, Object> relayProps = new HashMap<>();
relayProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.RELAY);
if (id != null) {
relayProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
String name = relay.getName();
if (name == null) {
name = id != null ? id : "Relay";
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_RELAY, name, relayProps);
}

for (VirtualHeaterConfig vh : backyard.getVirtualHeaters()) {
Map<String, Object> vhProps = new HashMap<>();
vhProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.VIRTUALHEATER);
String id = vh.getSystemId();
if (id != null) {
vhProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
onDeviceDiscovered(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER,
id != null ? id : "VirtualHeater", vhProps);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ public class ConfigParserTest {
public void testParsePopulatesAllListsAndAttributes() {
String xml = "" +
"<MSPConfig>" +
" <System systemId='SYS'>" +
" <Backyard systemId='BY'>" +
" <BodyOfWater systemId='BOW'/>" +
" <Pump systemId='P1' name='Main'/>" +
" <Filter systemId='F1' pumpId='P1'/>" +
" <Heater systemId='H1' type='gas'/>" +
" <VirtualHeater systemId='VH1'/>" +
" <Chlorinator systemId='C1'/>" +
" <ColorLogic-Light systemId='L1'/>" +
" <Relay systemId='R1' name='Aux1'/>" +
" </Backyard>" +
" </System>" +
" <System systemId='SYS'/>" +
" <Backyard systemId='BY'>" +
" <BodyOfWater systemId='BOW'/>" +
" <Pump systemId='P1' name='Main'/>" +
" <Filter systemId='F1' pumpId='P1'/>" +
" <Heater systemId='H1' type='gas'/>" +
" <VirtualHeater systemId='VH1'/>" +
" <Chlorinator systemId='C1'/>" +
" <ColorLogic-Light systemId='L1'/>" +
" <Relay systemId='R1' name='Aux1'/>" +
" </Backyard>" +
"</MSPConfig>";

MspConfig config = ConfigParser.parse(xml);
assertEquals(1, config.getSystems().size());

SystemConfig system = config.getSystems().get(0);
assertEquals("SYS", system.getSystemId());
assertEquals(1, system.getBackyards().size());

BackyardConfig backyard = system.getBackyards().get(0);
assertEquals(1, config.getBackyards().size());

BackyardConfig backyard = config.getBackyards().get(0);
assertEquals("BY", backyard.getSystemId());
assertEquals(1, backyard.getBodiesOfWater().size());
assertEquals("BOW", backyard.getBodiesOfWater().get(0).getSystemId());
Expand Down
Loading