18
18
import com .zsmartsystems .zigbee .groups .ZigBeeGroup ;
19
19
import com .zsmartsystems .zigbee .zcl .clusters .ZclOnOffCluster ;
20
20
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 ;
21
23
22
24
/**
23
25
* Uses the OnOff cluster to switch a device on
@@ -33,12 +35,12 @@ public String getCommand() {
33
35
34
36
@ Override
35
37
public String getDescription () {
36
- return "Switches a device ON" ;
38
+ return "Switches a device ON. Second parameter sets off time and uses OnWithTimedOff command. " ;
37
39
}
38
40
39
41
@ Override
40
42
public String getSyntax () {
41
- return "ENDPOINT" ;
43
+ return "ENDPOINT [OFF TIME] " ;
42
44
}
43
45
44
46
@ Override
@@ -53,6 +55,11 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
53
55
throw new IllegalArgumentException ("Invalid number of arguments" );
54
56
}
55
57
58
+ Integer offTime = null ;
59
+ if (args .length == 3 ) {
60
+ offTime = parseInteger (args [2 ]);
61
+ }
62
+
56
63
List <ZclOnOffCluster > clusters = new ArrayList <>();
57
64
if (WILDCARD .equals (args [1 ])) {
58
65
for (ZigBeeNode node : networkManager .getNodes ()) {
@@ -66,7 +73,12 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
66
73
} else {
67
74
ZigBeeGroup group = getGroup (networkManager , args [1 ]);
68
75
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
+ }
70
82
group .sendCommand (command );
71
83
return ;
72
84
}
@@ -80,12 +92,18 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
80
92
81
93
CommandResult result ;
82
94
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
+ }
84
101
try {
85
102
result = cluster .sendCommand (command ).get ();
86
103
} catch (Exception e ) {
87
104
out .println (
88
- "[Endpoint: " + cluster .getZigBeeAddress () + "] Fail to send command [" + e .getMessage () + "]" );
105
+ "[Endpoint: " + cluster .getZigBeeAddress () + "] Failed to send command [" + e .getMessage ()
106
+ + "]" );
89
107
return ;
90
108
}
91
109
if (result .isError () || result .isTimeout ()) {
0 commit comments