Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nikohomecontrol] Added ability to directly use virtual flags as switches #11751

Merged
merged 1 commit into from
Dec 11, 2021
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 @@ -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