From cafed142e7dfac916eda8e6d893b5817a4a89e0b Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Sat, 11 Dec 2021 19:39:40 +0100 Subject: [PATCH] Add virtual flag handling. (#11751) Signed-off-by: Mark Herwege --- .../internal/protocol/NikoHomeControlConstants.java | 3 +++ .../internal/protocol/nhc2/NhcAction2.java | 11 ++++++++++- .../protocol/nhc2/NikoHomeControlCommunication2.java | 7 ++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlConstants.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlConstants.java index 55f2ca6699267..f748ce3229e95 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlConstants.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NikoHomeControlConstants.java @@ -35,6 +35,9 @@ public static enum ActionType { public static final String NHCON = "On"; public static final String NHCOFF = "Off"; + public static final String NHCTRUE = "True"; + public static final String NHCFALSE = "False"; + public static final String NHCTRIGGERED = "Triggered"; // rollershutter constants in the Nhc layer diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcAction2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcAction2.java index 1155ac5b6f843..cc65d27307815 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcAction2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NhcAction2.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.nikohomecontrol.internal.protocol.nhc2; +import static org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.*; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.nikohomecontrol.internal.protocol.NhcAction; @@ -117,7 +119,14 @@ public void setState(int state) { public void execute(String command) { logger.debug("execute action {} of type {} for {}", command, type, id); - nhcComm.executeAction(id, command); + String cmd; + if ("flag".equals(model)) { + cmd = NHCON.equals(command) ? NHCTRUE : NHCFALSE; + } else { + cmd = command; + } + + nhcComm.executeAction(id, cmd); } /** diff --git a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java index 61d407f29ba0e..8cd4e82e72ce1 100644 --- a/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java +++ b/bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/nhc2/NikoHomeControlCommunication2.java @@ -362,7 +362,7 @@ private void addDevice(NhcDevice2 device) { .orElse(null); } - if ("action".equals(device.type)) { + if ("action".equals(device.type) || "virtual".equals(device.type)) { if (!actions.containsKey(device.uuid)) { logger.debug("adding action device {}, {}", device.uuid, device.name); @@ -382,6 +382,7 @@ private void addDevice(NhcDevice2 device) { case "socket": case "switched-generic": case "switched-fan": + case "flag": actionType = ActionType.RELAY; break; case "dimmer": @@ -480,7 +481,7 @@ private void updateLightState(NhcAction2 action, List devicePropert booleanState = basicStateProperty.get().basicState; } - if (NHCOFF.equals(booleanState)) { + if (NHCOFF.equals(booleanState) || NHCFALSE.equals(booleanState)) { action.setBooleanState(false); logger.debug("setting action {} internally to OFF", action.getId()); } @@ -497,7 +498,7 @@ private void updateLightState(NhcAction2 action, List devicePropert } } - if (NHCON.equals(booleanState)) { + if (NHCON.equals(booleanState) || NHCTRUE.equals(booleanState)) { action.setBooleanState(true); logger.debug("setting action {} internally to ON", action.getId()); }