@@ -173,7 +173,7 @@ public void clearNewDevices() {
173
173
public void addToConfiguredDevices (DeviceInfo current_device , boolean write_to_disk ) {
174
174
// Already in configured devices?
175
175
for (int i = configuredDevices .size () - 1 ; i >= 0 ; --i ) {
176
- if (current_device .UniqueDeviceID . equals (configuredDevices .get (i ). UniqueDeviceID )) {
176
+ if (current_device .equalsByUniqueID (configuredDevices .get (i ))) {
177
177
configuredDevices .set (i , current_device );
178
178
if (write_to_disk ) {
179
179
saveConfiguredDevices (true );
@@ -189,7 +189,7 @@ public void addToConfiguredDevices(DeviceInfo current_device, boolean write_to_d
189
189
190
190
// Remove from new devices list
191
191
for (int i = 0 ; i < newDevices .size (); ++i ) {
192
- if (newDevices .get (i ).UniqueDeviceID . equals (current_device . UniqueDeviceID )) {
192
+ if (newDevices .get (i ).equalsByUniqueID (current_device )) {
193
193
newDevices .remove (i );
194
194
notifyNewDeviceObservers (current_device , true );
195
195
break ;
@@ -326,7 +326,7 @@ public void rename(DevicePort port, String new_name, DevicePortRenamed callback)
326
326
if (callback != null )
327
327
callback .devicePort_start_rename (port );
328
328
329
- PluginInterface remote = port .device .getPluginInterface ();
329
+ PluginInterface remote = port .device .getPluginInterface (NetpowerctrlApplication . getService () );
330
330
if (remote != null ) {
331
331
remote .rename (port , new_name , callback );
332
332
if (callback != null )
@@ -346,7 +346,7 @@ public void execute(Scene scene, ExecutionFinished callback) {
346
346
if (p == null )
347
347
continue ;
348
348
349
- PluginInterface remote = p .device .getPluginInterface ();
349
+ PluginInterface remote = p .device .getPluginInterface (NetpowerctrlApplication . getService () );
350
350
if (remote == null )
351
351
continue ;
352
352
@@ -361,9 +361,27 @@ public void execute(Scene scene, ExecutionFinished callback) {
361
361
}
362
362
363
363
public void execute (final DevicePort port , final int command , final ExecutionFinished callback ) {
364
- PluginInterface remote = port .device .getPluginInterface ();
364
+ PluginInterface remote = port .device .getPluginInterface (NetpowerctrlApplication . getService () );
365
365
if (remote != null ) {
366
366
remote .execute (port , command , callback );
367
+
368
+ // Support for slaves of an outlet.
369
+ List <UUID > slaves = port .getSlaves ();
370
+ if (slaves .size () > 0 ) {
371
+ boolean bValue = false ;
372
+ if (command == DevicePort .ON )
373
+ bValue = true ;
374
+ else if (command == DevicePort .OFF )
375
+ bValue = false ;
376
+ else if (command == DevicePort .TOGGLE )
377
+ bValue = port .current_value <= 0 ;
378
+
379
+ for (UUID slave_uuid : slaves ) {
380
+ DevicePort p = NetpowerctrlApplication .getDataController ().findDevicePort (slave_uuid );
381
+ if (p != null )
382
+ execute (p , bValue ? DevicePort .ON : DevicePort .OFF , null );
383
+ }
384
+ }
367
385
return ;
368
386
}
369
387
@@ -390,7 +408,7 @@ public void setDevicePortBitmap(Context context, DevicePort port, Bitmap bitmap)
390
408
public int countNetworkDevices () {
391
409
int i = 0 ;
392
410
for (DeviceInfo di : configuredDevices )
393
- if (di .isNetworkDevice ()) ++i ;
411
+ if (di .isNetworkDevice (NetpowerctrlApplication . getService () )) ++i ;
394
412
return i ;
395
413
}
396
414
}
0 commit comments