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 @@ -38,6 +38,7 @@ public class HaywardBindingConstants {
public static final ThingTypeUID THING_TYPE_HEATER = new ThingTypeUID(BINDING_ID, "heater");
public static final ThingTypeUID THING_TYPE_PUMP = new ThingTypeUID(BINDING_ID, "pump");
public static final ThingTypeUID THING_TYPE_RELAY = new ThingTypeUID(BINDING_ID, "relay");
public static final ThingTypeUID THING_TYPE_VALVEACTUATOR = new ThingTypeUID(BINDING_ID, "valveActuator");
public static final ThingTypeUID THING_TYPE_SENSOR = new ThingTypeUID(BINDING_ID, "sensor");
public static final ThingTypeUID THING_TYPE_VIRTUALHEATER = new ThingTypeUID(BINDING_ID, "virtualHeater");

Expand All @@ -48,7 +49,8 @@ public class HaywardBindingConstants {
HaywardBindingConstants.THING_TYPE_CHLORINATOR, HaywardBindingConstants.THING_TYPE_COLORLOGIC,
HaywardBindingConstants.THING_TYPE_FILTER, HaywardBindingConstants.THING_TYPE_HEATER,
HaywardBindingConstants.THING_TYPE_PUMP, HaywardBindingConstants.THING_TYPE_RELAY,
HaywardBindingConstants.THING_TYPE_SENSOR, HaywardBindingConstants.THING_TYPE_VIRTUALHEATER);
HaywardBindingConstants.THING_TYPE_SENSOR, HaywardBindingConstants.THING_TYPE_VALVEACTUATOR,
HaywardBindingConstants.THING_TYPE_VIRTUALHEATER);

// List of all Channel ids (bridge)
// No Channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardHeaterHandler;
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardPumpHandler;
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardRelayHandler;
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardValveActuatorHandler;
import org.openhab.binding.haywardomnilogiclocal.internal.handler.HaywardVirtualHeaterHandler;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -100,6 +101,9 @@ public HaywardHandlerFactory(final @Reference HaywardDynamicStateDescriptionProv
if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_RELAY)) {
return new HaywardRelayHandler(thing);
}
if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR)) {
return new HaywardValveActuatorHandler(thing);
}
if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER)) {
return new HaywardVirtualHeaterHandler(thing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum HaywardTypeToRequest {
HEATER,
PUMP,
RELAY,
VALVEACTUATOR,
SENSOR,
VIRTUALHEATER
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ public class RelayConfig {
@XStreamAsAttribute
private @Nullable String name;

@XStreamAlias("Type")
private @Nullable String type;

@XStreamAlias("Function")
private @Nullable String function;

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

public @Nullable String getName() {
return name;
}

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

public @Nullable String getFunction() {
return function;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,29 @@ public synchronized void mspConfigDiscovery(String xmlResponse) {
}

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);
}
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;
}

Map<String, Object> relayProps = new HashMap<>();
relayProps.put(HaywardBindingConstants.PROPERTY_TYPE, HaywardTypeToRequest.RELAY);
String id = relay.getSystemId();
if (id != null) {
relayProps.put(HaywardBindingConstants.PROPERTY_SYSTEM_ID, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ thing-type.haywardomnilogic.filter.label = Filter
thing-type.haywardomnilogic.heater.label = Heater
thing-type.haywardomnilogic.pump.label = Pump
thing-type.haywardomnilogic.relay.label = Relay
thing-type.haywardomnilogic.valveActuator.label = Valve Actuator
thing-type.haywardomnilogic.virtualHeater.label = Virtual Heater

# thing types config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="haywardomnilogiclocal"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<thing-type id="valveActuator" listed="false">
<supported-bridge-type-refs>
<bridge-type-ref id="bridge"/>
</supported-bridge-type-refs>

<label>Valve Actuator</label>
<channels>
<channel id="valveActuatorState" typeId="system.power"/>
</channels>

<properties>
<property name="vendor">Hayward</property>
<property name="thingTypeVersion">1</property>
</properties>
<representation-property>systemID</representation-property>
</thing-type>

</thing:thing-descriptions>
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.openhab.binding.haywardomnilogiclocal.internal.discovery;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.binding.haywardomnilogiclocal.internal.HaywardBindingConstants;
import org.openhab.binding.haywardomnilogiclocal.internal.HaywardTypeToRequest;
import org.openhab.core.thing.ThingTypeUID;

/**
Expand All @@ -19,10 +22,12 @@ public class HaywardDiscoveryServiceTest {

private static class TestDiscoveryService extends HaywardDiscoveryService {
final List<ThingTypeUID> types = new ArrayList<>();
final List<Map<String, Object>> propertyMaps = new ArrayList<>();

@Override
public void onDeviceDiscovered(ThingTypeUID thingType, String label, Map<String, Object> properties) {
types.add(thingType);
propertyMaps.add(new HashMap<>(properties));
}
}

Expand Down Expand Up @@ -55,4 +60,39 @@ public void mspConfigDiscoveryCreatesResultsForAllDevices() {
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());
}

@Test
public void mspConfigDiscoveryIdentifiesValveActuatorRelays() {
String xml = "" +
"<MspConfig>" +
" <System systemId='SYS'>" +
" <Backyard systemId='BY'>" +
" <Relay systemId='VA1' name='Valve'>" +
" <Type>RLY_VALVE_ACTUATOR</Type>" +
" <Function>POOL_RETURN</Function>" +
" </Relay>" +
" </Backyard>" +
" </System>" +
"</MspConfig>";

TestDiscoveryService service = new TestDiscoveryService();
service.mspConfigDiscovery(xml);

Map<String, Object> valveProps = null;
for (int i = 0; i < service.types.size(); i++) {
if (service.types.get(i).equals(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR)) {
valveProps = service.propertyMaps.get(i);
break;
}
}

assertNotNull(valveProps);
assertEquals(1, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_VALVEACTUATOR)).count());
assertEquals(0, service.types.stream().filter(t -> t.equals(HaywardBindingConstants.THING_TYPE_RELAY)).count());
assertEquals(HaywardTypeToRequest.VALVEACTUATOR,
valveProps.get(HaywardBindingConstants.PROPERTY_TYPE));
assertEquals("RLY_VALVE_ACTUATOR", valveProps.get(HaywardBindingConstants.PROPERTY_RELAY_TYPE));
assertEquals("POOL_RETURN", valveProps.get(HaywardBindingConstants.PROPERTY_RELAY_FUNCTION));
assertEquals("VA1", valveProps.get(HaywardBindingConstants.PROPERTY_SYSTEM_ID));
}
}