Skip to content

Commit be34dcb

Browse files
authored
Merge pull request #74 from matchews/codex/create-valveactuator-and-update-status-class
Add valve actuator telemetry and handler
2 parents 3f9b2c7 + 99e7081 commit be34dcb

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.openhab.binding.haywardomnilogiclocal.internal.handler;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.jdt.annotation.Nullable;
6+
import org.openhab.binding.haywardomnilogiclocal.internal.HaywardException;
7+
import org.openhab.binding.haywardomnilogiclocal.internal.HaywardThingHandler;
8+
import org.openhab.binding.haywardomnilogiclocal.internal.protocol.ParameterValue;
9+
import org.openhab.binding.haywardomnilogiclocal.internal.telemetry.Status;
10+
import org.openhab.binding.haywardomnilogiclocal.internal.telemetry.TelemetryParser;
11+
import org.openhab.binding.haywardomnilogiclocal.internal.telemetry.ValveActuator;
12+
import org.openhab.core.thing.Thing;
13+
14+
public class HaywardValveActuatorHandler extends HaywardThingHandler {
15+
16+
public HaywardValveActuatorHandler(Thing thing) {
17+
super(thing);
18+
}
19+
20+
public void updateFromConfig(Map<String, ParameterValue> values) {
21+
String sysId = getThing().getProperties().get("systemID");
22+
if (sysId == null) {
23+
return;
24+
}
25+
26+
updateIfPresent(values, "valveActuatorState_" + sysId, "valveActuatorState");
27+
}
28+
29+
@Override
30+
public void getTelemetry(String xmlResponse) throws HaywardException {
31+
Status status = TelemetryParser.parse(xmlResponse);
32+
String sysId = getThing().getProperties().get("systemID");
33+
if (sysId == null) {
34+
return;
35+
}
36+
for (ValveActuator valveActuator : status.getValveActuators()) {
37+
if (sysId.equals(valveActuator.getSystemId())) {
38+
@Nullable String valveActuatorState = valveActuator.getValveActuatorState();
39+
if (valveActuatorState != null) {
40+
updateData("valveActuatorState", valveActuatorState);
41+
}
42+
}
43+
}
44+
}
45+
}

bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/telemetry/Status.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class Status {
3838
@XStreamImplicit(itemFieldName = "Relay")
3939
private final List<Relay> relays = new ArrayList<>();
4040

41+
@XStreamImplicit(itemFieldName = "ValveActuator")
42+
private final List<ValveActuator> valveActuators = new ArrayList<>();
43+
4144
@XStreamImplicit(itemFieldName = "Pump")
4245
private final List<Pump> pumps = new ArrayList<>();
4346

@@ -73,6 +76,10 @@ public List<Relay> getRelays() {
7376
return relays;
7477
}
7578

79+
public List<ValveActuator> getValveActuators() {
80+
return valveActuators;
81+
}
82+
7683
public List<Pump> getPumps() {
7784
return pumps;
7885
}

bundles/org.openhab.binding.haywardomnilogiclocal/src/main/java/org/openhab/binding/haywardomnilogiclocal/internal/telemetry/TelemetryParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class TelemetryParser {
1818
XSTREAM.addPermission(AnyTypePermission.ANY);
1919
XSTREAM.setClassLoader(TelemetryParser.class.getClassLoader());
2020
XSTREAM.processAnnotations(Status.class);
21+
XSTREAM.processAnnotations(ValveActuator.class);
2122
}
2223

2324
private TelemetryParser() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.openhab.binding.haywardomnilogiclocal.internal.telemetry;
2+
3+
import org.eclipse.jdt.annotation.NonNullByDefault;
4+
import org.eclipse.jdt.annotation.Nullable;
5+
6+
import com.thoughtworks.xstream.annotations.XStreamAlias;
7+
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
8+
9+
@NonNullByDefault
10+
@XStreamAlias("ValveActuator")
11+
public class ValveActuator {
12+
@XStreamAsAttribute
13+
@XStreamAlias("systemId")
14+
private @Nullable String systemId;
15+
16+
@XStreamAsAttribute
17+
@XStreamAlias("valveActuatorState")
18+
private @Nullable String valveActuatorState;
19+
20+
public @Nullable String getSystemId() {
21+
return systemId;
22+
}
23+
24+
public @Nullable String getValveActuatorState() {
25+
return valveActuatorState;
26+
}
27+
}

0 commit comments

Comments
 (0)