Skip to content

Commit

Permalink
Add virtual flag handling. (#11751)
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
  • Loading branch information
mherwege authored Dec 11, 2021
1 parent adecb53 commit cafed14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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":
Expand Down Expand Up @@ -480,7 +481,7 @@ private void updateLightState(NhcAction2 action, List<NhcProperty> 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());
}
Expand All @@ -497,7 +498,7 @@ private void updateLightState(NhcAction2 action, List<NhcProperty> devicePropert
}
}

if (NHCON.equals(booleanState)) {
if (NHCON.equals(booleanState) || NHCTRUE.equals(booleanState)) {
action.setBooleanState(true);
logger.debug("setting action {} internally to ON", action.getId());
}
Expand Down

0 comments on commit cafed14

Please sign in to comment.