33import android .content .Context ;
44import android .content .Intent ;
55import android .net .Uri ;
6- import android .os .AsyncTask ;
76import android .support .annotation .NonNull ;
87import android .support .annotation .Nullable ;
98import android .util .Log ;
2524import oly .netpowerctrl .data .AbstractBasePlugin ;
2625import oly .netpowerctrl .data .DataService ;
2726import oly .netpowerctrl .devices .Credentials ;
28- import oly .netpowerctrl .devices .DevicesObserver ;
2927import oly .netpowerctrl .executables .Executable ;
3028import oly .netpowerctrl .executables .ExecutableAndCommand ;
3129import oly .netpowerctrl .executables .ExecutableType ;
@@ -105,10 +103,10 @@ public static String extractIDFromExecutableUID_s(String uid) {
105103
106104 void fillExecutable (Executable executable , Credentials credentials , String uid , int value ) {
107105 executable .ui_type = ExecutableType .TypeToggle ;
108- executable .credentials = credentials ;
109106 executable .deviceUID = credentials .getUid ();
110107 executable .setUid (uid );
111108 executable .current_value = value ;
109+ executable .setCredentials (credentials );
112110 }
113111
114112 Credentials createDefaultCredentials (String MacAddress ) {
@@ -140,7 +138,7 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
140138 int success = 0 ;
141139 // Use Http instead of UDP for sending. For each batch command we will send a single http request
142140 for (ExecutableAndCommand c : command_list ) {
143- boolean ok = executeViaHTTP (ioConnection , c .port , c .command );
141+ boolean ok = executeViaHTTP (ioConnection , c .executable , c .command );
144142 if (ok ) ++success ;
145143 }
146144 return success ;
@@ -175,9 +173,9 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
175173
176174 // Second step: Apply commands
177175 for (ExecutableAndCommand c : command_list ) {
178- c .port . last_command_timecode = System . currentTimeMillis ( );
176+ c .executable . setExecutionInProgress ( true );
179177
180- int id = extractIDFromExecutableUID (c .port .getUid ());
178+ int id = extractIDFromExecutableUID (c .executable .getUid ());
181179 if (id >= 10 && id < 20 ) {
182180 containsIO = true ;
183181 } else if (id >= 0 ) {
@@ -217,13 +215,13 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
217215 data [0 ] = 'S' ;
218216 data [1 ] = 'w' ;
219217 data [2 ] = data_outlet ;
220- new UDPSend (dataService , ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
218+ new UDPSend (ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
221219 }
222220 if (containsIO ) {
223221 data [0 ] = 'I' ;
224222 data [1 ] = 'O' ;
225223 data [2 ] = data_io ;
226- new UDPSend (dataService , ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
224+ new UDPSend (ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
227225 }
228226
229227 return command_list .size ();
@@ -325,7 +323,7 @@ public boolean executeViaHTTP(IOConnection ioConnection, Executable port, int co
325323 */
326324 @ Override
327325 public boolean execute (@ NonNull Executable executable , int command , onExecutionFinished callback ) {
328- executable .last_command_timecode = System . currentTimeMillis ( );
326+ executable .setExecutionInProgress ( true );
329327
330328 boolean bValue = false ;
331329 if (command == Executable .ON )
@@ -359,14 +357,14 @@ else if (command == Executable.TOGGLE)
359357 // IOS
360358 data = String .format (Locale .US , "%s%d%s%s" , bValue ? "IO_on" : "IO_off" ,
361359 id - 10 , credentials .userName , credentials .password ).getBytes ();
362- new UDPSend (dataService , ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
360+ new UDPSend (ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
363361 if (callback != null ) callback .addSuccess ();
364362 return true ;
365363 } else if (id >= 0 ) {
366364 // Outlets
367365 data = String .format (Locale .US , "%s%d%s%s" , bValue ? "Sw_on" : "Sw_off" ,
368366 id , credentials .userName , credentials .password ).getBytes ();
369- new UDPSend (dataService , ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
367+ new UDPSend (ioConnection , data , requestMessage , UDPErrors .INQUERY_REQUEST );
370368 if (callback != null ) callback .addSuccess ();
371369 return true ;
372370 } else {
@@ -408,7 +406,7 @@ public void requestData(@NonNull IOConnection ioConnection) {
408406 HttpThreadPool .execute (new HttpThreadPool .HTTPRunner <>((IOConnectionHTTP ) ioConnection ,
409407 "strg.cfg" , "" , ioConnection , false , AnelReceiveSendHTTP .receiveCtrlHtml ));
410408 } else {
411- new UDPSend (dataService , ioConnection , requestMessage , UDPErrors .INQUERY_REQUEST );
409+ new UDPSend (ioConnection , requestMessage , UDPErrors .INQUERY_REQUEST );
412410 }
413411 }
414412
@@ -417,22 +415,6 @@ public Credentials createNewDefaultCredentials() {
417415 return createDefaultCredentials (UUID .randomUUID ().toString ());
418416 }
419417
420- @ Override
421- public long getUpdatedTime (Executable executable ) {
422- DeviceIOConnections deviceIOConnections = dataService .connections .openDevice (executable .deviceUID );
423- if (deviceIOConnections == null ) return 0 ;
424- IOConnection ioConnection = deviceIOConnections .findReachable ();
425- if (ioConnection == null ) return 0 ;
426- return ioConnection .getLastUsed ();
427- }
428-
429- @ Override
430- public String getDeviceName (Executable executable ) {
431- Credentials credentials = dataService .credentials .findByUID (executable .deviceUID );
432- if (credentials == null ) throw new RuntimeException ();
433- return credentials .deviceName ;
434- }
435-
436418 @ Override
437419 public ReachabilityStates getReachableState (Executable executable ) {
438420 DeviceIOConnections deviceIOConnections = dataService .connections .openDevice (executable .deviceUID );
@@ -531,7 +513,7 @@ public void executeTransaction(onExecutionFinished callback) {
531513
532514 // add to tree
533515 for (ExecutableAndCommand executableAndCommand : command_list ) {
534- DeviceIOConnections deviceIOConnections = dataService .connections .openDevice (executableAndCommand .port .deviceUID );
516+ DeviceIOConnections deviceIOConnections = dataService .connections .openDevice (executableAndCommand .executable .deviceUID );
535517 if (deviceIOConnections == null ) continue ;
536518 IOConnection connection = deviceIOConnections .findReachable ();
537519 if (connection == null ) continue ;
@@ -567,22 +549,22 @@ public String getLocalizedName() {
567549 public void checkDevicesReachabilityAfterNetworkChange () {
568550 Logging .getInstance ().logEnergy ("Anel: check availability" );
569551
570- startNetworkReceivers (false );
571-
572- dataService .addDeviceObserver (new DevicesObserver (dataService .credentials .findByPlugin (this ), new DevicesObserver .onDevicesObserverFinished () {
573- @ Override
574- public void onObserverJobFinished (DevicesObserver devicesObserver ) {
575- if (!devicesObserver .isAllTimedOut ()) return ;
576- //TODO
577- new AsyncTask <AnelPlugin , Void , Void >() {
578- @ Override
579- protected Void doInBackground (AnelPlugin ... plugin ) {
580- plugin [0 ].stopNetwork ();
581- return null ;
582- }
583- }.execute (AnelPlugin .this );
584- }
585- }));
552+ // startNetworkReceivers(false);
553+ //
554+ // dataService.addDeviceObserver(new DevicesObserver(dataService.credentials.findByPlugin(this), new DevicesObserver.onDevicesObserverFinished() {
555+ // @Override
556+ // public void onObserverJobFinished(DevicesObserver devicesObserver) {
557+ // if (!devicesObserver.isAllTimedOut()) return;
558+ // //TODO
559+ // new AsyncTask<AnelPlugin, Void, Void>() {
560+ // @Override
561+ // protected Void doInBackground(AnelPlugin... plugin) {
562+ // plugin[0].stopNetwork();
563+ // return null;
564+ // }
565+ // }.execute(AnelPlugin.this);
566+ // }
567+ // }));
586568 }
587569
588570 @ Override
0 commit comments