@@ -103,6 +103,8 @@ void fillExecutable(Executable executable, Credentials credentials, String uid,
103
103
executable .ui_type = ExecutableType .TypeToggle ;
104
104
executable .deviceUID = credentials .getUid ();
105
105
executable .setUid (uid );
106
+ executable .min_value = 0 ;
107
+ executable .max_value = 1 ;
106
108
executable .current_value = value ;
107
109
executable .setCredentials (credentials , dataService .connections );
108
110
}
@@ -181,21 +183,21 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
181
183
containsOutlets = true ;
182
184
}
183
185
switch (c .command ) {
184
- case Executable .OFF :
186
+ case ExecutableAndCommand .OFF :
185
187
if (id >= 10 && id < 20 ) {
186
188
data_io = switchOff (data_io , id - 10 );
187
189
} else if (id >= 0 ) {
188
190
data_outlet = switchOff (data_outlet , id );
189
191
}
190
192
break ;
191
- case Executable .ON :
193
+ case ExecutableAndCommand .ON :
192
194
if (id >= 10 && id < 20 ) {
193
195
data_io = switchOn (data_io , id - 10 );
194
196
} else if (id >= 0 ) {
195
197
data_outlet = switchOn (data_outlet , id );
196
198
}
197
199
break ;
198
- case Executable .TOGGLE :
200
+ case ExecutableAndCommand .TOGGLE :
199
201
if (id >= 10 && id < 20 ) {
200
202
data_io = toggle (data_io , id - 10 );
201
203
} else if (id >= 0 ) {
@@ -251,7 +253,7 @@ public boolean executeViaHTTP(IOConnectionHTTP ioConnection, Executable port, in
251
253
}
252
254
// The http interface can only toggle. If the current state is the same as the command state
253
255
// then we request values instead of sending a command.
254
- if (command == Executable .TOGGLE && port .current_value == command )
256
+ if (command == ExecutableAndCommand .TOGGLE && port .current_value == command )
255
257
HttpThreadPool .execute (new HttpThreadPool .HTTPRunner <>(ioConnection , "strg.cfg" ,
256
258
"" , ioConnection , false , AnelReceiveSendHTTP .receiveCtrlHtml ));
257
259
else {
@@ -274,13 +276,7 @@ public boolean executeViaHTTP(IOConnectionHTTP ioConnection, Executable port, in
274
276
public boolean execute (@ NonNull Executable executable , int command , onExecutionFinished callback ) {
275
277
executable .setExecutionInProgress (true );
276
278
277
- boolean bValue = false ;
278
- if (command == Executable .ON )
279
- bValue = true ;
280
- else if (command == Executable .OFF )
281
- bValue = false ;
282
- else if (command == Executable .TOGGLE )
283
- bValue = executable .current_value <= 0 ;
279
+ int value = (command == ExecutableAndCommand .TOGGLE ) ? executable .getCurrentValueToggled () : command ;
284
280
285
281
DeviceIOConnections deviceIOConnections = dataService .connections .openDevice (executable .deviceUID );
286
282
final IOConnection ioConnection = deviceIOConnections != null ? deviceIOConnections .findReachable () : null ;
@@ -305,15 +301,15 @@ else if (command == Executable.TOGGLE)
305
301
byte [] data ;
306
302
if (id >= 10 && id < 20 ) {
307
303
// IOS
308
- data = String .format (Locale .US , "%s%d%s%s" , bValue ? "IO_on" : "IO_off" ,
304
+ data = String .format (Locale .US , "%s%d%s%s" , value > 0 ? "IO_on" : "IO_off" ,
309
305
id - 10 , credentials .userName , credentials .password ).getBytes ();
310
306
UDPSend .sendMessage (connectionUDP , data );
311
307
UDPSend .sendMessage (connectionUDP , requestMessage );
312
308
if (callback != null ) callback .addSuccess ();
313
309
return true ;
314
310
} else if (id >= 0 ) {
315
311
// Outlets
316
- data = String .format (Locale .US , "%s%d%s%s" , bValue ? "Sw_on" : "Sw_off" ,
312
+ data = String .format (Locale .US , "%s%d%s%s" , value > 0 ? "Sw_on" : "Sw_off" ,
317
313
id , credentials .userName , credentials .password ).getBytes ();
318
314
UDPSend .sendMessage (connectionUDP , data );
319
315
UDPSend .sendMessage (connectionUDP , requestMessage );
0 commit comments