Skip to content

Commit ed73445

Browse files
authored
Update console on command to also support OnWithTimedOff (#1424)
Signed-off-by: Chris Jackson <[email protected]>
1 parent be97aef commit ed73445

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleSwitchOnCommand.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.zsmartsystems.zigbee.groups.ZigBeeGroup;
1919
import com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster;
2020
import com.zsmartsystems.zigbee.zcl.clusters.onoff.OnCommand;
21+
import com.zsmartsystems.zigbee.zcl.clusters.onoff.OnWithTimedOffCommand;
22+
import com.zsmartsystems.zigbee.zcl.clusters.onoff.ZclOnOffCommand;
2123

2224
/**
2325
* Uses the OnOff cluster to switch a device on
@@ -33,12 +35,12 @@ public String getCommand() {
3335

3436
@Override
3537
public String getDescription() {
36-
return "Switches a device ON";
38+
return "Switches a device ON. Second parameter sets off time and uses OnWithTimedOff command.";
3739
}
3840

3941
@Override
4042
public String getSyntax() {
41-
return "ENDPOINT";
43+
return "ENDPOINT [OFF TIME]";
4244
}
4345

4446
@Override
@@ -53,6 +55,11 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
5355
throw new IllegalArgumentException("Invalid number of arguments");
5456
}
5557

58+
Integer offTime = null;
59+
if (args.length == 3) {
60+
offTime = parseInteger(args[2]);
61+
}
62+
5663
List<ZclOnOffCluster> clusters = new ArrayList<>();
5764
if (WILDCARD.equals(args[1])) {
5865
for (ZigBeeNode node : networkManager.getNodes()) {
@@ -66,7 +73,12 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
6673
} else {
6774
ZigBeeGroup group = getGroup(networkManager, args[1]);
6875
if (group != null) {
69-
OnCommand command = new OnCommand();
76+
ZclOnOffCommand command;
77+
if (offTime != null) {
78+
command = new OnWithTimedOffCommand(0, offTime, 0);
79+
} else {
80+
command = new OnCommand();
81+
}
7082
group.sendCommand(command);
7183
return;
7284
}
@@ -80,12 +92,18 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
8092

8193
CommandResult result;
8294
for (ZclOnOffCluster cluster : clusters) {
83-
OnCommand command = new OnCommand();
95+
ZclOnOffCommand command;
96+
if (offTime != null) {
97+
command = new OnWithTimedOffCommand(0, offTime, 0);
98+
} else {
99+
command = new OnCommand();
100+
}
84101
try {
85102
result = cluster.sendCommand(command).get();
86103
} catch (Exception e) {
87104
out.println(
88-
"[Endpoint: " + cluster.getZigBeeAddress() + "] Fail to send command [" + e.getMessage() + "]");
105+
"[Endpoint: " + cluster.getZigBeeAddress() + "] Failed to send command [" + e.getMessage()
106+
+ "]");
89107
return;
90108
}
91109
if (result.isError() || result.isTimeout()) {

0 commit comments

Comments
 (0)