1 /*
  2  * This is system cordova_plugin (TV specific API).
  3  * Apache License (2004). See http://www.apache.org/licenses/LICENSE-2.0
  4  *
  5  * Copyright (c) 2014, LG Electronics, Inc.
  6  */
  7 
  8 
  9 /**
 10  * This represents the power API itself, and provides a global namespace for operating power service.
 11  * @class
 12  */
 13 cordova.define('cordova/plugin/power', function (require, exports, module) { // jshint ignore:line
 14     
 15     function log(msg) {
 16     //    //console.log//will be removed // jshint ignore:line
 17     }
 18     
 19     var service;
 20     if(window.PalmSystem) { // jshint ignore:line
 21         log("Window.PalmSystem Available");
 22         service = require('cordova/plugin/webos/service');
 23     } else {
 24         service = {
 25             Request : function(uri, params) {
 26                log(uri + " invoked. But I am a dummy because PalmSystem is not available");
 27                         
 28                if (typeof params.onFailure === 'function') {
 29                   params.onFailure({ returnValue:false,
 30                      errorText:"PalmSystem Not Available. Cordova is not installed?"});
 31                }
 32         }};
 33     }
 34 
 35     /**
 36      * power interface
 37      */
 38     var Power = function () {
 39     };
 40     
 41     function checkErrorCodeNText(result, errorCode, errorText) {
 42         
 43         if (result.errorCode === undefined || result.errorCode === null ) {
 44             result.errorCode = errorCode;
 45         }
 46         if (result.errorText ===undefined || result.errorText === null) {
 47             result.errorText = errorText;
 48         }
 49     }
 50     
 51     var version = null;
 52     var platformInfoObj = {}; 
 53     function checkPlatformVersion(cb) {
 54         
 55         if (version === null) {
 56             
 57             service.Request('luna://com.webos.service.tv.systemproperty', {
 58                 method: 'getSystemInfo',
 59                 parameters: {
 60                     keys: ["sdkVersion", "boardType"]
 61                 },
 62                 onSuccess: function(result) {
 63                     log("getPlatformInfo: onSuccess");
 64                     log("version : " + result.sdkVersion);
 65                     
 66                     var temp = result.sdkVersion.split('.');
 67                     if (temp.length >= 1 && temp[0] === '1') {
 68                         platformInfoObj = {
 69                             webOSVer : 1,
 70                             chipset : result.boardType.split("_")[0]
 71                         };
 72                     } else if (temp.length >= 1 && temp[0] === '2') {
 73                         platformInfoObj = {
 74                             webOSVer : 2,
 75                             chipset : result.boardType.split("_")[0]
 76                         };
 77                     } else if (temp.length >= 1 && temp[0] === '3') {
 78                         platformInfoObj = {
 79                             webOSVer : 3,
 80                             chipset : result.boardType.split("_")[0]
 81                         };
 82                     } else {
 83                         platformInfoObj = {
 84                             webOSVer : 0,
 85                             chipset : ""
 86                         };
 87                     }
 88                     version = platformInfoObj.webOSVer;
 89                     
 90                     delete result.returnValue;
 91                     
 92                     cb(platformInfoObj);
 93                     
 94                 },
 95                 onFailure: function(error) {
 96                     log("getPlatformInfo: onFailure");
 97                     delete error.returnValue;
 98                     platformInfoObj = {
 99                         webOSVer : 0,
100                         chipset : ""
101                     }
102                     
103                     cb(platformInfoObj);
104                 }
105             });
106             
107         } else {
108             cb(platformInfoObj);
109         }
110     }
111     
112     function convertExternal(extStr) {
113         if (platformInfoObj.chipset == 'H15') {
114             switch (extStr) { // H15 only
115                 case "ext://hdmi:1":
116                     return "HDMI1";
117                 case "ext://hdmi:2":
118                     return "HDMI2";
119                 case "ext://hdmi:3":
120                     return "OPS/HDMI3/DVI";
121                 case "ext://dvi:1":
122                     return "OPS/HDMI3/DVI";
123                 case "ext://dp:1":
124                     return "DISPLAYPORT";
125                 case "ext://rgb:1":
126                     return "RGB";
127                 case "ext://ops:1":
128                     return "OPS/HDMI3/DVI";
129                     
130                 case "HDMI1":
131                     return "ext://hdmi:1";
132                 /*
133                 case "HDMI": // Not used
134                     return "ext://hdmi:1";
135                 */
136                 case "HDMI2":
137                     return "ext://hdmi:2";
138                 case "HDMI3":
139                     return "ext://hdmi:3";
140                 case "DVI":
141                     return "ext://dvi:1";
142                 case "DISPLAYPORT":
143                     return "ext://dp:1";
144                 case "RGB":
145                     return "ext://rgb:1";
146                 case "OPS":
147                     return "ext://ops:1";
148                 case "OPS/HDMI3/DVI":
149                     return "ext://hdmi:3"
150             }
151         }
152         else { // M14 and LM15U
153             switch (extStr) {
154                 case "ext://hdmi:1":
155                     if (platformInfoObj.webOSVer === 1)
156                         return "HDMI1";
157                     else 
158                         return "HDMI";
159                 case "ext://hdmi:2":
160                     return "HDMI2";
161                 case "ext://hdmi:3":
162                     return "HDMI3";
163                 case "ext://dvi:1":
164                     return "DVI";
165                 case "ext://dp:1":
166                     return "DISPLAYPORT";
167                 case "ext://rgb:1":
168                     return "RGB";
169                 case "ext://ops:1":
170                     return "OPS";
171                     
172                 case "HDMI1":
173                     return "ext://hdmi:1";
174                 case "HDMI":
175                     return "ext://hdmi:1";
176                 case "HDMI2":
177                     return "ext://hdmi:2";
178                 case "HDMI3":
179                     return "ext://hdmi:3";
180                 case "DVI":
181                     return "ext://dvi:1";
182                 case "DISPLAYPORT":
183                     return "ext://dp:1";
184                 case "RGB":
185                     return "ext://rgb:1";
186                 case "OPS":
187                     return "ext://ops:1";
188                 case "OPS/HDMI3/DVI":
189                     return "ext://hdmi:3"
190             }
191         }
192         return null;
193     }
194     
195     /*
196     function convertWeekToStr(week) {
197         
198         var str = "";
199         week *= 1;
200         
201         if ( (week & Power.TimerWeek.EVERYDAY) === Power.TimerWeek.EVERYDAY ) { // jshint ignore:line
202             return "Everyday";
203         }
204         if ( (week & Power.TimerWeek.MONDAY) === Power.TimerWeek.MONDAY ) { // jshint ignore:line
205             str += "Mon ";
206             week -= Power.TimerWeek.MONDAY;
207         }
208         if ( (week & Power.TimerWeek.TUESDAY) === Power.TimerWeek.TUESDAY ) { // jshint ignore:line
209             str += "Tue ";
210             week -= Power.TimerWeek.TUESDAY;
211         }
212         if ( (week & Power.TimerWeek.WEDNESDAY) === Power.TimerWeek.WEDNESDAY ) { // jshint ignore:line
213             str += "Wed ";
214             week -= Power.TimerWeek.WEDNESDAY;
215         }
216         if ( (week & Power.TimerWeek.THURSDAY) === Power.TimerWeek.THURSDAY ) { // jshint ignore:line
217             str += "Thu ";
218             week -= Power.TimerWeek.THURSDAY;
219         }
220         if ( (week & Power.TimerWeek.FRIDAY) === Power.TimerWeek.FRIDAY ) { // jshint ignore:line
221             str += "Fri ";
222             week -= Power.TimerWeek.FRIDAY;
223         }
224         if ( (week & Power.TimerWeek.SATURDAY) === Power.TimerWeek.SATURDAY ) { // jshint ignore:line
225             str += "Sat ";
226             week -= Power.TimerWeek.SATURDAY;
227         }
228         if ( (week & Power.TimerWeek.SUNDAY) === Power.TimerWeek.SUNDAY ) { // jshint ignore:line
229             str += "Sun ";
230             week -= Power.TimerWeek.SUNDAY;
231         }
232         
233         if (str === "")  {
234             str = "None";
235         }
236 
237 
238         return str;
239     }
240     */
241     
242     
243     /*
244     function padZero(num, size) {
245         var s = num+"";
246         while (s.length < size) s = "0" + s;
247         return s;
248     }
249     */
250     
251     /**
252      * @namespace Power.PowerMode
253      */
254     Power.PowerCommand = {
255     /**
256      * shutdown
257      * @since 1.0
258      * @constant
259      */
260     SHUTDOWN : "powerOff",
261     /**
262      * reboot
263      * @since 1.0
264      * @constant
265      */
266     REBOOT : "reboot"
267     };
268     
269     /**
270      * @namespace Power.DisplayMode
271      */
272     Power.DisplayMode = {
273     /**
274      * display off
275      * @since 1.0
276      * @constant
277      */
278     DISPLAY_OFF : "Screen Off",
279     /**
280      * display on
281      * @since 1.0
282      * @constant
283      */
284     DISPLAY_ON : "Active"
285     };
286     
287     /**
288      * @namespace Power.TimerWeek
289      */
290     Power.TimerWeek = {
291     /**
292      * Monday
293      * @since 1.0
294      * @constant
295      */
296     MONDAY : 1,
297     /**
298      * Tuesday
299      * @since 1.0
300      * @constant
301      */
302     TUESDAY : 2,
303     /**
304      * Wednesday
305      * @since 1.0
306      * @constant
307      */
308     WEDNESDAY : 4,
309     /**
310      * Thursday
311      * @since 1.0
312      * @constant
313      */
314     THURSDAY : 8,
315     /**
316      * Friday
317      * @since 1.0
318      * @constant
319      */
320     FRIDAY : 16,
321     /**
322      * Saturday
323      * @since 1.0
324      * @constant
325      */
326     SATURDAY : 32,
327     /**
328      * Sunday
329      * @since 1.0
330      * @constant
331      */
332     SUNDAY : 64,
333     /**
334      * Everyday
335      * @since 1.0
336      * @constant
337      */
338     EVERYDAY : 127
339     };
340 
341     /**
342      * @namespace Power.DPMSignalType
343      */
344     Power.DPMSignalType = {
345     /**
346      * CLOCK
347      * @since 1.0
348      * @constant
349      */
350     CLOCK : "clock",
351     /**
352      * CLOCK_WITH_DATA
353      * @since 1.0
354      * @constant
355      */
356     CLOCK_WITH_DATA : "clockAndData"
357     };
358 
359 	 /**
360      * @namespace Power.PMMode
361      */
362     Power.PMMode = {
363     /**
364      * PowerOff
365      * @since 1.4
366      * @constant
367      */
368     PowerOff : "powerOff",
369     /**
370      * SustainAspectRatio
371      * @since 1.4
372      * @constant
373      */
374     SustainAspectRatio : "sustainAspectRatio",
375     /**
376      * ScreenOff
377      * @since 1.4
378      * @constant
379      */
380     ScreenOff : "screenOff",
381     /**
382      * ScreenOffAlways
383      * @since 1.4
384      * @constant
385      */
386     ScreenOffAlways : "screenOffAlways",
387     /**
388      * ScreenOffBacklight (Only for outdoor model)
389      * @since 1.4.1
390      * @constant
391      */
392     ScreenOffBacklight : "screenOffBacklight"
393     };
394     
395     /**
396      * Gets power status 
397      * @class Power
398      * @param {Function} successCallback success callback function.
399      * @param {Function} errorCallback failure callback function.
400      * @return <p>{Object} </p>
401      * <div align=left>
402      * <table class="hcap_spec" width=400>
403      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
404      *   <tbody>
405      *       <tr><th>wakeOnLan</th><th>Boolean</th><th>true : enabled / false : disabled </th></tr>
406      *       <tr class="odd"><th>displayMode</th><th>String</th><th><a href="Power.DisplayMode.html#.DISPLAY_ON">Power.DisplayMode.DISPLAY_ON</a> | <a href="Power.DisplayMode.html#.DISPLAY_OFF">Power.DisplayMode.DISPLAY_OFF</a> </th></tr>
407      *       <tr><th>allOnTimer</th><th>Boolean</th><th>true : enabled / false : disabled </th></tr>
408      *       <tr class="odd"><th>allOffTimer</th><th>Boolean</th><th>true : enabled / false : disabled </th></tr>
409      *   </tbody>
410      * </table>
411      * </div>
412      *
413      * @example
414      * // Javascript code
415      * function getPowerStatus () {
416      *   function successCb(cbObject) {
417      *      console.log("cbObject : " + JSON.stringify(cbObject));
418      *      console.log("wakeOnLan : " + cbObject.wakeOnLan);
419      *      console.log("displayMode : " + cbObject.displayMode);
420      *      console.log("allOnTimer : " + cbObject.allOnTimer);
421      *      console.log("allOffTimer : " + cbObject.allOffTimer);         
422      *
423      *      // Do something
424      *         ...
425      *   }
426      *
427      *   function failureCb(cbObject) {
428      *      var errorCode = cbObject.errorCode;
429      *      var errorText = cbObject.errorText;
430      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
431      *   }
432      *
433      *   var power = new Power();
434      *   power.getPowerStatus(successCb, failureCb);
435      * }
436      * @since 1.0
437      * @see
438      * <a href="Power%23setWakeOnLan.html">Power.setWakeOnLan()</a>, 
439      * <a href="Power%23setDisplayMode.html">Power.setDisplayMode()</a><br>
440      */
441     Power.prototype.getPowerStatus = function (successCallback, errorCallback) {
442          
443         log("getPowerStatus: ");
444         
445         /*
446         service.Request("luna://com.webos.service.tvpower/power/", {
447         */
448         service.Request("luna://com.webos.service.tv.signage/", {
449             method : "getPowerState",
450                 onSuccess : function(result) {
451                     log("getPowerStatus: On Success");
452                     var cbObj = {};
453                     
454                     if(result.returnValue === true) {
455                         cbObj.displayMode = result.state;
456                     }
457                     
458                     service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
459                         method : "get",
460                         parameters : {
461                             category : "commercial",
462                             keys : ["wolEnable"]
463                         },
464                         onSuccess : function(result) {
465                             log("getPowerStatus: On Success 2");
466                             
467                             if(result.returnValue === true) {
468                                 cbObj.wakeOnLan = (result.settings.wolEnable === "1" ? true : false );
469                             }
470                             
471                             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
472                                 method : "get",
473                                 parameters : {
474                                     category : "time",
475                                     keys : ["onTimerEnable", "offTimerEnable"]
476                                 },
477                                 onSuccess : function(result) {
478                                     log("getPowerStatus: On Success 3");
479                                     
480                                     if(result.returnValue === true) {
481                                         cbObj.allOnTimer = (result.settings.onTimerEnable === "on" ? true : false );
482                                         cbObj.allOffTimer = (result.settings.offTimerEnable === "on" ? true : false );
483                                     
484                                         if(typeof successCallback === 'function') {
485                                             successCallback(cbObj);
486                                         }
487                                     }
488                                 },
489                                 onFailure : function(result) {
490                                     log("getPowerStatus: On Failure 3");
491                                     delete result.returnValue;
492                                     if(typeof errorCallback === 'function') {
493                                         checkErrorCodeNText(result, "PGPS", "Power.getPowerStatus returns failure.");
494                                         errorCallback(result);
495                                     }
496                                 }
497                             });
498                         },
499                         onFailure : function(result) {
500                             log("getPowerStatus: On Failure 2");
501                             delete result.returnValue;
502                             if(typeof errorCallback === 'function') {
503                                 checkErrorCodeNText(result, "PGPS", "Power.getPowerStatus returns failure.");
504                                 errorCallback(result);
505                             }
506                         }
507                     });
508                 },
509                 onFailure : function(result) {
510                     log("getPowerStatus: On Failure");
511                     delete result.returnValue;
512                     //TODO; Is this an error case?
513                     if(typeof errorCallback === 'function') {
514                         checkErrorCodeNText(result, "PGPS", "Power.getPowerStatus returns failure.");
515                         errorCallback(result);
516                     }
517                 }
518             });
519         
520         log("Power.getPowerStatus Done");
521         
522     };
523     
524     /**
525      * Controls all "on timer". This API enables/disables all "on timer" at once. Values of each "on timer" which was set by Power.addOnTimer() are not changed when option.clearOnTimer is false.
526      * 
527      * @class Power
528      * @param {Function} successCallback success callback function.
529      * @param {Function} errorCallback failure callback function.     
530      * @param {Object} options
531      * <div align=left>
532      * <table class="hcap_spec" width=400>
533      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
534      *   <tbody>
535      *       <tr><th>allOnTimer</th><th>Boolean</th><th>true : enabled / false : disabled </th><th>required</th></tr>
536      *       <tr class="odd"><th>clearOnTimer</th><th>Boolean</th><th>true : removes all "on Timer" / false : do nothing. (default) </th><th>optional</th></tr>
537      *   </tbody>
538      * </table>
539      * </div>
540      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
541      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
542      * @example
543      * // Javascript code
544      * function enableAllOnTimer () {
545      *   var options = {
546      *      allOnTimer : true
547      *   };
548      *     
549      *   function successCb() {
550      *      // Do something
551      *   }
552      *
553      *   function failureCb(cbObject) {
554      *      var errorCode = cbObject.errorCode;
555      *      var errorText = cbObject.errorText;
556      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
557      *   }
558      *
559      *   var power = new Power();
560      *   power.enableAllOnTimer(successCb, failureCb, options);
561      * }
562      * @since 1.0
563      * @since 1.3 optons.clearOnTimer
564      * @see
565      * <a href="Power%23getPowerStatus.html">Power.getPowerStatus()</a><br>
566      */
567     Power.prototype.enableAllOnTimer = function (successCallback, errorCallback, options) {
568     
569         log("enableAllOnTimer: " + JSON.stringify(options));
570         
571         var op = null;
572         switch(options.allOnTimer) {
573             case true :
574                 op = "on";
575                 break;
576             case false :
577                 op = "off";
578                 break;
579             
580             default:
581                 if (typeof errorCallback === 'function') {
582                     var result = {};
583                     checkErrorCodeNText(result, "PEAOT", "Power.enableAllOnTimer returns failure. Invalid option value.");
584                     errorCallback(result);
585                 }
586                 return;            
587         }
588           
589         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
590                 method : "set",
591                 parameters : {
592                     category : "time",
593                     settings : {
594                         "onTimerEnable": op
595                     }
596                 },
597                 onSuccess : function() {
598                     
599                     if (options.clearOnTimer === true) {
600                         
601                         var count = 0;
602                         var hour = ["0","0","0","0","0","0","0"],
603                             min = ["0","0","0","0","0","0","0"],
604                             week = ["0","0","0","0","0","0","0"],
605                             source = ["0","0","0","0","0","0","0"],
606                             schedule = [];
607                         
608                         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
609                             method : "set",
610                             parameters : {
611                                 category : "commercial",
612                                 settings : {
613                                 "multiOnTimerHour":hour,
614                                 "multiOnTimerMinute":min,
615                                 "multiOnTimerWeekday":week,
616                                 "multiOnTimerSource":source,
617                                 "onTimerCount":count,
618                                 "onTimerSchedule":schedule
619                                 }
620                             },
621                             onSuccess : function() {
622                                 log("enableAllOnTimer: On Success 2");
623                                 
624                                 if(typeof successCallback === 'function'){
625                                     successCallback();
626                                 }
627                             },
628                             onFailure : function(result) {
629                                 log("enableAllOnTimer: On Failure 2");
630                                 delete result.returnValue;
631                                 if (typeof errorCallback === 'function') {
632                                     checkErrorCodeNText(result, "PEAOT", "Power.enableAllOnTimer returns failure. / clearOnTimer");
633                                     errorCallback(result);
634                                 }
635                                     
636                             }
637                         });
638                         
639                     } else {
640                         
641                         if(typeof successCallback === 'function') {
642                             log("enableAllOnTimer: On Success");
643                             successCallback();
644                         }
645                     }
646                 },
647                 onFailure : function(result) {
648                     delete result.returnValue;
649                     if(typeof errorCallback === 'function') {
650                         log("enableAllOnTimer: On Failure");
651                         checkErrorCodeNText(result, "PEAOT", "Power.enableAllOnTimer returns failure.");
652                         errorCallback(result);
653                     }
654                 }
655             });
656         
657         log("Power.enableAllOnTimer Done");
658     
659     };
660         
661     /**
662      * Controls all "off timer". This API enables/disables all "off timer" at once. Values of each "off timer" which was set by Power.addOffTimer() are not changed when options.clearOffTimer is false.
663      *   
664      * @class Power
665      * @param {Function} successCallback success callback function.
666      * @param {Function} errorCallback failure callback function.     
667      * @param {Object} options
668      * <div align=left>
669      * <table class="hcap_spec" width=400>
670      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
671      *   <tbody>
672      *       <tr><th>allOffTimer</th><th>Boolean</th><th>true : enabled / false : disabled </th><th>required</th></tr>
673      *       <tr class="odd"><th>clearOffTimer</th><th>Boolean</th><th>true : removes all "off Timer" / false : do nothing. (default) </th><th>optional</th></tr>
674      *   </tbody>
675      * </table>
676      * </div>
677      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
678      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
679      * @example
680      * // Javascript code
681      * function enableAllOffTimer () {
682      *   var options = {
683      *      allOffTimer : true
684      *   };
685      *     
686      *   function successCb() {
687      *      // Do something
688      *   }
689      *
690      *   function failureCb(cbObject) {
691      *      var errorCode = cbObject.errorCode;
692      *      var errorText = cbObject.errorText;
693      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
694      *   }
695      *
696      *   var power = new Power();
697      *   power.enableAllOffTimer(successCb, failureCb, options);
698      * }
699      * @since 1.0
700      * @since 1.3 options.clearOffTimer
701      * @see
702      * <a href="Power%23getPowerStatus.html">Power.getPowerStatus()</a><br>
703      */
704     Power.prototype.enableAllOffTimer = function (successCallback, errorCallback, options) {
705     
706         log("enableAllOffTimer: " + JSON.stringify(options));
707         var op = null;
708         
709         switch(options.allOffTimer) {
710             case true :
711                 op = "on";
712                 break;
713             case false :
714                 op = "off";
715                 break;
716             default:
717                 if (typeof errorCallback === 'function') {
718                     var result = {};
719                     checkErrorCodeNText(result, "PEAOT", "Power.enableAllOffTimer returns failure. Invalid option value.");
720                     errorCallback(result);
721                 }
722                 return;            
723         }
724             
725         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
726                 method : "set",
727                 parameters : {
728                     category : "time",
729                     settings : {
730                         "offTimerEnable": op
731                     }
732                 },
733                 onSuccess : function() {
734                     
735                     if (options.clearOffTimer === true) {
736                         
737                         var count = 0;
738                         var hour = ["0","0","0","0","0","0","0"],
739                             min = ["0","0","0","0","0","0","0"],
740                             week = ["0","0","0","0","0","0","0"],
741                             schedule = [];
742                         
743                         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
744                             method : "set",
745                             parameters : {
746                                 category : "commercial",
747                                 settings : {
748                                     "multiOffTimerHour": hour,
749                                     "multiOffTimerMinute": min,
750                                     "multiOffTimerWeekday": week,
751                                     "offTimerCount": count,
752                                     "offTimerSchedule": schedule
753                                 }
754                             },
755                             onSuccess : function() {
756                                 log("enableAllOffTimer: On Success 2");
757                                 
758                                 if(typeof successCallback === 'function'){
759                                     successCallback();
760                                 }
761                             },
762                             onFailure : function(result) {
763                                 log("enableAllOffTimer: On Failure 2");
764                                 delete result.returnValue;
765                                 if (typeof errorCallback === 'function') {
766                                     checkErrorCodeNText(result, "PEAOT", "Power.enableAllOffTimer returns failure. / clearOffTimer");
767                                     errorCallback(result);
768                                 }
769                             }
770                         });
771                     } else {
772                         if(typeof successCallback === 'function') {
773                             log("enableAllOffTimer: On Success");
774                             successCallback();
775                         }
776                     }
777                 },
778                 onFailure : function(result) {
779                     delete result.returnValue;
780                     if(typeof errorCallback === 'function') {
781                         log("enableAllOffTimer: On Failure");
782                         checkErrorCodeNText(result, "PEAOT", "Power.enableAllOffTimer returns failure.");
783                         errorCallback(result);
784                     }
785                 }
786             });
787         
788         log("Power.enableAllOffTimer Done");
789     
790     };
791     
792     /**
793      * Enables or disables 'wake on LAN'. 
794      * @class Power
795      * @param {Function} successCallback success callback function.
796      * @param {Function} errorCallback failure callback function.
797      * @param {Object} options
798      * <div align=left>
799      * <table class="hcap_spec" width=400>
800      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
801      *   <tbody>
802      *       <tr><th>wakeOnLan</th><th>Boolean</th><th>true : enabled / false : disabled </th><th>required</th></tr>
803      *   </tbody>
804      * </table>
805      * </div>
806      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
807      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
808      * @example
809      * // Javascript code
810      * function enableWakeOnLan () {
811      *   var options = {
812      *      wakeOnLan : true
813      *   };
814      *     
815      *   function successCb() {
816      *      // Do something
817      *   }
818      *
819      *   function failureCb(cbObject) {
820      *      var errorCode = cbObject.errorCode;
821      *      var errorText = cbObject.errorText;
822      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
823      *   }
824      *
825      *   var power = new Power();
826      *   power.enableWakeOnLan(successCb, failureCb, options);
827      * }
828      * @since 1.0
829      * @see
830      * <a href="Power%23getPowerStatus.html">Power.getPowerStatus()</a><br>
831      */
832     Power.prototype.enableWakeOnLan = function (successCallback, errorCallback, options) {
833 
834         log("enableWakeOnLan: " + JSON.stringify(options));
835         var op = null;
836         
837         switch(options.wakeOnLan) {
838             case true :
839                 op = "1";
840                 break;
841             case false :
842                 op = "0";
843             break;            
844             default:
845                 if (typeof errorCallback === 'function') {
846                     var result = {};
847                     checkErrorCodeNText(result, "PSWOL", "Power.enableWakeOnLan returns failure. Invalid option value.");
848                     errorCallback(result);
849                 }
850                 return;
851         }
852         
853         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
854             method : "set",
855             parameters : {
856                 category : "commercial",
857                 settings : {
858                     "wolEnable": op
859                 }
860             },
861             onSuccess : function() {
862                 if(typeof successCallback === 'function') {
863                     log("enableWakeOnLan: On Success");
864                     successCallback();
865                 }
866             },
867             onFailure : function(result) {
868                 delete result.returnValue;
869                 if(typeof errorCallback === 'function') {                    
870                     log("enableWakeOnLan: On Failure");
871                     checkErrorCodeNText(result, "PSWOL", "Power.enableWakeOnLan returns failure.");
872                     errorCallback(result);
873                 }
874             }
875         });
876     
877         log("Power.enableWakeOnLan Done");
878     
879     };
880     
881     
882     /**
883      * Adds 'on timer'. 
884      * @class Power
885      * @param {Function} successCallback success callback function.
886      * @param {Function} errorCallback failure callback function.     
887      * @param {Object} options
888      * <div align=left>
889      * <table class="hcap_spec" width=400>
890      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
891      *   <tbody>
892      *       <tr><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr>
893      *       <tr class="odd"><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr>
894      *       <tr><th>week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> <br>To use it on multiple days of week, set the sum of week. <br>For example, 1 + 64 (Power.TimerWeek.Monday + Power.TimerWeek.Sunday) means that this timer works on every Monday and Sunday.</th><th>required</th></tr>
895      *       <tr class="odd"><th>inputSource</th><th>String</th><th>Define the input source. ext://[externalInput]:[portNum]. (eg: "ext://hdmi:1")</th><th>required</th></tr>
896      *   </tbody>
897      * </table>
898      * </div>
899      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
900      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
901      * @example
902      * // Javascript code
903      * function addOnTimer () {
904      *   var options = {
905      *      hour : 9,
906      *      minute : 0,
907      *      week : Power.TimerWeek.MONDAY + Power.TimerWeek.FRIDAY,
908      *      inputSource : "ext://hdmi:1"
909      *   };
910      *     
911      *   function successCb() {
912      *      // Do something
913      *   }
914      *
915      *   function failureCb(cbObject) {
916      *      var errorCode = cbObject.errorCode;
917      *      var errorText = cbObject.errorText;
918      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
919      *   }
920      *
921      *   var power = new Power();
922      *   power.addOnTimer(successCb, failureCb, options);
923      * }
924      * @since 1.0
925      * @see
926      * <a href="Power%23getOnTimerList.html">Power.getOnTimerList()</a>, 
927      * <a href="InputSource.%23getInputSourceStatus.html">InputSource.getInputSourceStatus()</a><br>
928      */
929     Power.prototype.addOnTimer = function (successCallback, errorCallback, options) {
930     
931         log("addOnTimer: " + JSON.stringify(options));
932         
933         // bound check
934         if (options.hour === undefined || isNaN(options.hour) || typeof options.hour !== 'number' || options.hour < 0 || options.hour > 23 ||
935             options.minute === undefined || isNaN(options.minute) || typeof options.minute !== 'number' || options.minute < 0 || options.minute > 59 ||
936             options.week === undefined || isNaN(options.week) || typeof options.week !== 'number' || options.week < 0 || options.week > 127 ||
937             options.inputSource === undefined || typeof options.inputSource !== 'string' || options.inputSource.indexOf("ext://") !== 0) {
938         
939             if (typeof errorCallback === 'function') {
940                 var result = {};
941                 checkErrorCodeNText(result, "PAOT", "Power.addOnTimer returns failure. invalid parameters or out of range.");
942                 errorCallback(result);
943             }            
944             return;
945         }
946         
947         checkPlatformVersion(function(info) {
948             service.Request("luna://com.webos.service.eim/", {
949                 method: "getAllInputStatus",
950                 onSuccess: function(result) {
951                     log("getInputSourceStatus: On Success");                    
952                     if (result.returnValue === true) {
953                         var hasInputSource = false;
954 
955                         for (var i = 0; i < result.totalCount; i++) {
956                             var deviceName       = result.devices[i].deviceName.toLowerCase();
957                             var inputSourceParam = options.inputSource.substring(6).split(":"); //hdmi:1
958 
959                             var port = '1';
960                             if (isNaN(deviceName.substring(deviceName.length - 1, deviceName.length)) === false) //number
961                             {
962                                 deviceName = deviceName.substring(0, deviceName.length - 1);
963                                 port = result.devices[i].id.split("_")[1];
964                             }
965 
966                             if (deviceName === 'displayport')
967                                 deviceName = 'dp';
968 
969                             if (deviceName.toLowerCase().indexOf(inputSourceParam[0].toLowerCase()) >= 0 && port === inputSourceParam[1]) {
970                                 hasInputSource = true;
971                                 break;
972                             }
973                         }
974 
975                         if (hasInputSource === false) {
976                             log("addOnTimer: On Failure");
977                             delete result.returnValue;
978                             if (typeof errorCallback === 'function') {
979                                 checkErrorCodeNText(result, "PAOT", "Power.addOnTimer returns failure.");
980                                 errorCallback(result);
981                             }
982                             return;
983                         }
984 
985                         //1. timer enable / disable
986                         //2. set time information
987                         //3. set the number of timer.
988                         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
989                             method: "get",
990                             parameters: {
991                                 category: "commercial",
992                                 keys: ["multiOnTimerHour", "multiOnTimerMinute", "multiOnTimerWeekday", "multiOnTimerSource", "onTimerSchedule", "onTimerCount"]
993                             },
994                             onSuccess: function(result) {
995                                 //log("addOnTimer: get timer data " + JSON.stringify(result));
996                                 if (result.returnValue === true) {
997 
998                                     log("version : " + info.webOSVer);
999                                     // in exceptional case of luna result error
1000                                     if (typeof result.settings.multiOnTimerHour === 'string') {
1001                                         result.settings.multiOnTimerHour = JSON.parse(result.settings.multiOnTimerHour);
1002                                     }
1003 
1004                                     if (typeof result.settings.multiOnTimerMinute === 'string') {
1005                                         result.settings.multiOnTimerMinute = JSON.parse(result.settings.multiOnTimerMinute);
1006                                     }
1007 
1008                                     if (typeof result.settings.multiOnTimerWeekday === 'string') {
1009                                         result.settings.multiOnTimerWeekday = JSON.parse(result.settings.multiOnTimerWeekday);
1010                                     }
1011 
1012                                     if (typeof result.settings.multiOnTimerSource === 'string') {
1013                                         result.settings.multiOnTimerSource = JSON.parse(result.settings.multiOnTimerSource);
1014                                     }
1015 
1016                                     if (typeof result.settings.onTimerSchedule === 'string') {
1017                                         result.settings.onTimerSchedule = JSON.parse(result.settings.onTimerSchedule);
1018                                     }
1019                                     // end of exceptional case
1020 
1021                                     var index = (result.settings.onTimerSchedule === null || result.settings.onTimerSchedule === undefined ? 0 : result.settings.onTimerSchedule.length);
1022 
1023                                     if (result.settings.multiOnTimerHour.length <= index) {
1024                                         // out of range
1025                                         if (typeof errorCallback === 'function') {
1026                                             checkErrorCodeNText(result, "PSOT", "Power.addOnTimer returns failure. No space to add timer.");
1027                                             errorCallback(result);
1028                                         }
1029                                         return;
1030                                     }
1031 
1032                                     if (info.webOSVer === 3) {
1033                                         //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1034                                         //WEBOS 2.0 Sun(), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)
1035                                         if (options.week >= 64) //in case of choosing days including sunday                        
1036                                             options.week = 1 + (options.week - 64) * 2;
1037                                         else
1038                                             options.week = options.week * 2;
1039                                     }
1040 
1041                                     result.settings.multiOnTimerHour[index] = options.hour;
1042                                     result.settings.multiOnTimerMinute[index] = options.minute;
1043                                     result.settings.multiOnTimerWeekday[index] = options.week;
1044                                     result.settings.multiOnTimerSource[index] = convertExternal(options.inputSource);
1045                                     //result.settings.onTimerSchedule[index] = "" + padZero(options.hour, 2) +":"+ padZero(options.minute, 2) +", "+ convertWeekToStr(options.week);
1046 
1047                                     var seed = 360;
1048                                     result.settings.onTimerSchedule[index] = {
1049                                         "_id": "" + seed++,
1050                                         "hour": options.hour,
1051                                         "input": convertExternal(options.inputSource),
1052                                         "minute": options.minute,
1053                                         "weekday": options.week
1054                                     };
1055 
1056                                     service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1057                                         method: "set",
1058                                         parameters: {
1059                                             category: "commercial",
1060                                             settings: {
1061                                                 "multiOnTimerHour": result.settings.multiOnTimerHour,
1062                                                 "multiOnTimerMinute": result.settings.multiOnTimerMinute,
1063                                                 "multiOnTimerWeekday": result.settings.multiOnTimerWeekday,
1064                                                 "multiOnTimerSource": result.settings.multiOnTimerSource,
1065                                                 "onTimerCount": index + 1,
1066                                                 "onTimerSchedule": result.settings.onTimerSchedule
1067                                             }
1068                                         },
1069                                         onSuccess: function() {
1070                                             log("addOnTimer: On Success 2");
1071 
1072                                             if (typeof successCallback === 'function') {
1073                                                 successCallback();
1074                                             }
1075                                         },
1076                                         onFailure: function(result) {
1077                                             log("addOnTimer: On Failure 2");
1078                                             delete result.returnValue;
1079                                             if (typeof errorCallback === 'function') {
1080                                                 checkErrorCodeNText(result, "PAOT", "Power.addOnTimer returns failure.");
1081                                                 errorCallback(result);
1082                                             }
1083                                             return;
1084                                         }
1085                                     });
1086                                 }
1087                             },
1088                             onFailure: function(result) {
1089                                 log("addOnTimer: On Failure");
1090                                 delete result.returnValue;
1091                                 if (typeof errorCallback === 'function') {
1092                                     checkErrorCodeNText(result, "PAOT", "Power.addOnTimer returns failure.");
1093                                     errorCallback(result);
1094                                 }
1095                                 return;
1096                             }
1097                         });
1098                     } // if (result.returnValue === true) {
1099                 },
1100                 onFailure: function(result) {
1101                     log("getInputSourceStatus: On Failure");
1102                     delete result.returnValue;
1103                     if (typeof errorCallback === 'function') {
1104                         checkErrorCodeNText(result, "PAOT", "Power.addOnTimer returns failure on gathering input list.");
1105                         errorCallback(result);                        
1106                     }
1107                     return;
1108                 }
1109             });
1110         }); // check version
1111  
1112         log("Power.addOnTimer Done");
1113     };
1114     
1115     /**
1116      * Deletes 'on timer'. The timer in the list that matches the parameter will be removed.
1117      * @class Power
1118      * @param {Function} successCallback success callback function.
1119      * @param {Function} errorCallback failure callback function.     
1120      * @param {Object} options
1121      * <div align=left>
1122      * <table class="hcap_spec" width=400>
1123      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
1124      *   <tbody>
1125      *       <tr><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr>
1126      *       <tr class="odd"><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr>
1127      *       <tr><th>week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> <br>To use it on multiple day of week, set the sum of week. <br>For example, 1 + 64 (Power.TimerWeek.Monday + Power.TimerWeek.Sunday) means that this timer works on every Monday and Sunday.</th><th>required</th></tr>
1128      *       <tr class="odd"><th>inputSource</th><th>String</th><th>Define the input source. ext://[externalInput]:[portNum]. (eg: "ext://hdmi:1")</th><th>required</th></tr>
1129      *   </tbody>
1130      * </table>
1131      * </div>
1132      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
1133      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
1134      * @example
1135      * // Javascript code
1136      * function deleteOnTimer () {
1137      *   var options = {
1138      *      hour : 9,
1139      *      minute : 0,
1140      *      week : Power.TimerWeek.MONDAY + Power.TimerWeek.FRIDAY,
1141      *      inputSource : "ext://hdmi:1"
1142      *   };
1143      *     
1144      *   function successCb() {
1145      *      // Do something
1146      *   }
1147      *
1148      *   function failureCb(cbObject) {
1149      *      var errorCode = cbObject.errorCode;
1150      *      var errorText = cbObject.errorText;
1151      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1152      *   }
1153      *
1154      *   var power = new Power();
1155      *   power.deleteOnTimer(successCb, failureCb, options);
1156      * }
1157      * @since 1.0
1158      * @see
1159      * <a href="Power%23getOnTimerList.html">Power.getOnTimerList()</a>, 
1160      * <a href="InputSource.%23getInputSourceStatus.html">InputSource.getInputSourceStatus()</a><br>
1161      */
1162     Power.prototype.deleteOnTimer = function (successCallback, errorCallback, options) {
1163     
1164         log("deleteOnTimer: " + JSON.stringify(options));
1165                 
1166         // bound check
1167         if (options.hour === undefined || isNaN(options.hour) || typeof options.hour !== 'number' || options.hour < 0 || options.hour > 23 ||
1168             options.minute === undefined || isNaN(options.minute) || typeof options.minute !== 'number' || options.minute < 0 || options.minute > 59 ||
1169             options.week === undefined || isNaN(options.week) || typeof options.week !== 'number' || options.week < 0 || options.week > 127 ||
1170             options.inputSource === undefined || typeof options.inputSource !== 'string' || options.inputSource.indexOf("ext://") !== 0) {
1171             
1172             if (typeof errorCallback === 'function') {
1173                 var result = {};
1174                 checkErrorCodeNText(result, "PDOT", "Power.deleteOnTimer returns failure. invalid parameters or out of range.");
1175                 errorCallback(result);
1176             }
1177             
1178             return;
1179         }
1180         
1181         //1. timer enable / disable
1182         //2. set time information
1183         //3. set the number of timer.
1184         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1185             method : "get",
1186             parameters : {
1187                 category : "commercial",
1188                 keys : ["multiOnTimerHour", "multiOnTimerMinute", "multiOnTimerWeekday", "multiOnTimerSource", "onTimerSchedule", "onTimerCount" ]
1189             },
1190             onSuccess : function(result) {
1191                 //log("deleteOnTimer: get timer data " + JSON.stringify(result));
1192                 
1193                 if (result.returnValue === true) {
1194                     checkPlatformVersion(function(info){
1195                         
1196                         log("version : " + info.webOSVer);
1197                         
1198                         // in exceptional case of luna result error
1199                         if ( typeof result.settings.multiOnTimerHour === 'string') {
1200                             result.settings.multiOnTimerHour = JSON.parse(result.settings.multiOnTimerHour);
1201                         }
1202                         
1203                         if ( typeof result.settings.multiOnTimerMinute === 'string') {
1204                             result.settings.multiOnTimerMinute = JSON.parse(result.settings.multiOnTimerMinute);
1205                         }
1206                         
1207                         if ( typeof result.settings.multiOnTimerWeekday === 'string') {
1208                             result.settings.multiOnTimerWeekday = JSON.parse(result.settings.multiOnTimerWeekday);
1209                         }
1210                         
1211                         if ( typeof result.settings.multiOnTimerSource === 'string') {
1212                             result.settings.multiOnTimerSource = JSON.parse(result.settings.multiOnTimerSource);
1213                         }
1214                         
1215                         if ( typeof result.settings.onTimerSchedule === 'string') {
1216                             result.settings.onTimerSchedule = JSON.parse(result.settings.onTimerSchedule);
1217                         }
1218                         // end of exceptional case
1219                         
1220                         var addIndex = 0,
1221                             count = (result.settings.onTimerSchedule === null || result.settings.onTimerSchedule === undefined ? 0 : result.settings.onTimerSchedule.length );
1222                         var hour = ["0","0","0","0","0","0","0"],
1223                             min = ["0","0","0","0","0","0","0"],
1224                             week = ["0","0","0","0","0","0","0"],
1225                             source = ["0","0","0","0","0","0","0"],
1226                             schedule = [];
1227                         var inputSource = convertExternal(options.inputSource);
1228                         var deleted = false;
1229 
1230                         if (info.webOSVer === 3) {
1231                             //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1232                             //WEBOS 2.0 Sun(), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)
1233                             if (options.week >= 64) //in case of choosing days including sunday                        
1234                                 options.week = 1 + (options.week - 64) * 2;
1235                             else
1236                                 options.week = options.week * 2;                            
1237                         }
1238 
1239                         for (var i=0; i<count; i++) {
1240                             
1241                             log("deleteOnTimer: " + inputSource);
1242                             
1243                             if (result.settings.onTimerSchedule[i] === null) {
1244                                 continue;
1245                             }
1246                             
1247                             log("options.week : " + options.week + " result.settings.onTimerSchedule[" + i + "].weekday : " + result.settings.onTimerSchedule[i].weekday);
1248 
1249                             if (deleted === false &&
1250                                 options.hour === result.settings.onTimerSchedule[i].hour &&
1251                                 options.minute === result.settings.onTimerSchedule[i].minute &&
1252                                 options.week === result.settings.onTimerSchedule[i].weekday &&
1253                                 inputSource === result.settings.onTimerSchedule[i].input) {
1254                                 // do nothing
1255                                     log("deleteOnTimer: index " + i);
1256                                     deleted = true;                                
1257                             } else {
1258                                 hour[addIndex] = result.settings.multiOnTimerHour[i];
1259                                 min[addIndex] = result.settings.multiOnTimerMinute[i];
1260                                 week[addIndex] = result.settings.multiOnTimerWeekday[i];
1261                                 source[addIndex] = result.settings.multiOnTimerSource[i];
1262                                 schedule[addIndex] =  result.settings.onTimerSchedule[i];
1263                                 addIndex++;
1264                             }
1265                         }
1266                         
1267                         if (deleted === true) {
1268                             count--;
1269                         }
1270                         
1271                         if (count === 0) {
1272                             schedule = [];
1273                         }
1274                         
1275                         if (result.settings.onTimerSchedule.length === count) {
1276                             if (typeof errorCallback === 'function') {
1277                                 checkErrorCodeNText(result, "PDOT", "Power.deleteOnTimer returns failure. There is no 'on timer' matched in the list.");
1278                                 errorCallback(result);
1279                             }
1280                             return;
1281                         }
1282                                         
1283                         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1284                             method : "set",
1285                             parameters : {
1286                                 category : "commercial",
1287                                 settings : {
1288                                     "multiOnTimerHour":hour,
1289                                     "multiOnTimerMinute":min,
1290                                     "multiOnTimerWeekday":week,
1291                                     "multiOnTimerSource":source,
1292                                     "onTimerCount":count,
1293                                     "onTimerSchedule":schedule
1294                                 }
1295                             },
1296                             onSuccess : function() {
1297                                 log("deleteOnTimer: On Success 2");
1298                                 
1299                                 if(typeof successCallback === 'function'){
1300                                     successCallback();
1301                                 }
1302                             },
1303                             onFailure : function(result) {
1304                                 log("deleteOnTimer: On Failure 2");
1305                                 delete result.returnValue;
1306                                 if (typeof errorCallback === 'function') {
1307                                     checkErrorCodeNText(result, "PDOT", "Power.deleteOnTimer returns failure.");
1308                                     errorCallback(result);
1309                                 }
1310                             }
1311                         });
1312                     });
1313                     
1314                 }
1315             },
1316             onFailure : function(result) {
1317                 log("deleteOnTimer: On Failure");
1318                 delete result.returnValue;
1319                 if(typeof errorCallback === 'function') {
1320                     checkErrorCodeNText(result, "PDOT", "Power.deleteOnTimer returns failure.");
1321                     errorCallback(result);
1322                 }
1323             }
1324         });
1325         
1326         log("Power.deleteOnTimer Done");
1327     };
1328     
1329     /**
1330      * Adds 'off timer'. 
1331      * @class Power
1332      * @param {Function} successCallback success callback function.
1333      * @param {Function} errorCallback failure callback function.     
1334      * @param {Object} options
1335      * <div align=left>
1336      * <table class="hcap_spec" width=400>
1337      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
1338      *   <tbody>
1339      *       <tr><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr>
1340      *       <tr class="odd"><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr>
1341      *       <tr><th>week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> <br>To use it on multiple days of week, set the sum of week. <br>For example, 1 + 64 (Power.TimerWeek.Monday + Power.TimerWeek.Sunday) means that this timer works on every Monday and Sunday.</th><th>required</th></tr>
1342      *   </tbody>
1343      * </table>
1344      * </div>
1345      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
1346      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
1347      * @example
1348      * // Javascript code
1349      * function addOffTimer () {
1350      *   var options = {
1351      *      hour : 9,
1352      *      minute : 0,
1353      *      week : Power.TimerWeek.MONDAY + Power.TimerWeek.FRIDAY
1354      *   };
1355      *     
1356      *   function successCb() {
1357      *      // Do something
1358      *   }
1359      *
1360      *   function failureCb(cbObject) {
1361      *      var errorCode = cbObject.errorCode;
1362      *      var errorText = cbObject.errorText;
1363      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1364      *   }
1365      *
1366      *   var power = new Power();
1367      *   power.addOffTimer(successCb, failureCb, options);
1368      * }
1369      * @since 1.0
1370      * @see
1371      * <a href="Power%23getOffTimerList.html">Power.getOffTimerList()</a><br>
1372      */
1373     Power.prototype.addOffTimer = function (successCallback, errorCallback, options) {
1374         
1375         log("addOffTimer: " + JSON.stringify(options));
1376             
1377         // bound check
1378         if (options.hour === undefined || isNaN(options.hour) || typeof options.hour !== 'number' || options.hour < 0 || options.hour > 23 ||
1379                 options.minute === undefined || isNaN(options.minute) || typeof options.minute !== 'number' || options.minute < 0 || options.minute > 59 ||
1380                 options.week === undefined || isNaN(options.week) || typeof options.week !== 'number' || options.week < 0 || options.week > 127 ) {
1381             
1382             if (typeof errorCallback === 'function') {
1383                 var result = {};
1384                 checkErrorCodeNText(result, "PAOT", "Power.addOffTimer returns failure. Invalid parameter.");
1385                 errorCallback(result);
1386             }            
1387             return;
1388         }
1389         
1390         //1. timer enable / disable
1391         //2. set time information
1392         //3. set the number of timer.
1393         
1394         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1395             method : "get",
1396             parameters : {
1397                 category : "commercial",
1398                 keys : ["multiOffTimerHour", "multiOffTimerMinute", "multiOffTimerWeekday", "offTimerSchedule", "offTimerCount" ]
1399             },
1400             onSuccess : function(result) {
1401                 //log("addOffTimer: get timer data " + JSON.stringify(result));
1402 
1403                 if (result.returnValue === true) {
1404 
1405                     // in exceptional case of luna result error
1406                     if (typeof result.settings.multiOffTimerHour === 'string') {
1407                         result.settings.multiOffTimerHour = JSON.parse(result.settings.multiOffTimerHour);
1408                     }
1409 
1410                     if (typeof result.settings.multiOffTimerMinute === 'string') {
1411                         result.settings.multiOffTimerMinute = JSON.parse(result.settings.multiOffTimerMinute);
1412                     }
1413 
1414                     if (typeof result.settings.multiOffTimerWeekday === 'string') {
1415                         result.settings.multiOffTimerWeekday = JSON.parse(result.settings.multiOffTimerWeekday);
1416                     }
1417 
1418                     if (typeof result.settings.offTimerSchedule === 'string') {
1419                         result.settings.offTimerSchedule = JSON.parse(result.settings.offTimerSchedule);
1420                     }
1421                     // end of exceptional case
1422 
1423                     var index = (result.settings.offTimerSchedule === null || result.settings.offTimerSchedule === undefined ? 0 : result.settings.offTimerSchedule.length);
1424 
1425                     if (result.settings.multiOffTimerHour.length <= index) {
1426                         // out of range
1427                         if (typeof errorCallback === 'function') {
1428                             checkErrorCodeNText(result, "PAOT", "Power.addOffTimer returns failure. No space to add timer.");
1429                             errorCallback(result);
1430                         }
1431                         return;
1432                     }
1433 
1434                     checkPlatformVersion(function(info) {
1435 
1436                         log("version : " + info.webOSVer);
1437 
1438                         if (info.webOSVer === 3) {                        
1439                             //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1440                             //WEBOS 2.0 Sun(), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)
1441                             if (options.week >= 64) //in case of choosing days including sunday                        
1442                                 options.week = 1 + (options.week - 64) * 2;
1443                             else
1444                                 options.week = options.week * 2;
1445                         }
1446                     
1447                         result.settings.multiOffTimerHour[index] = options.hour;
1448                         result.settings.multiOffTimerMinute[index] = options.minute;
1449                         result.settings.multiOffTimerWeekday[index] = options.week;
1450 
1451                         log("add hour: " + options.hour + ", min : " + options.minute + ", week : " + options.week);
1452                         //result.settings.offTimerSchedule[index] = "" + padZero(options.hour, 2) +":"+ padZero(options.minute, 2) +", "+ convertWeekToStr(options.week);
1453 
1454                         var seed = 360;
1455                         result.settings.offTimerSchedule[index] = {
1456                             "_id": "" + seed++,
1457                             "hour": options.hour,
1458                             "minute": options.minute,
1459                             "weekday": options.week
1460                         };
1461 
1462                         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1463                             method: "set",
1464                             parameters: {
1465                                 category: "commercial",
1466                                 settings: {
1467                                     "multiOffTimerHour": result.settings.multiOffTimerHour,
1468                                     "multiOffTimerMinute": result.settings.multiOffTimerMinute,
1469                                     "multiOffTimerWeekday": result.settings.multiOffTimerWeekday,
1470                                     "offTimerCount": index + 1,
1471                                     "offTimerSchedule": result.settings.offTimerSchedule
1472                                 }
1473                             },
1474                             onSuccess: function() {
1475                                 log("addOffTimer: On Success 2");
1476                                 if (typeof successCallback === 'function') {
1477                                     successCallback();
1478                                 }
1479                             },
1480                             onFailure: function(result) {
1481                                 log("addOffTimer: On Failure 2");
1482                                 delete result.returnValue;
1483                                 if (typeof errorCallback === 'function') {
1484                                     checkErrorCodeNText(result, "PAOT", "Power.addOffTimer returns failure.");
1485                                     errorCallback(result);
1486                                 }
1487                             }
1488                         });
1489 
1490                     });
1491                 }
1492             },
1493             onFailure : function(result) {
1494                 log("addOffTimer: On Failure");
1495                 delete result.returnValue;
1496                 if(typeof errorCallback === 'function') {
1497                     checkErrorCodeNText(result, "PAOT", "Power.addOffTimer returns failure.");
1498                     errorCallback(result);
1499                 }
1500             }
1501         });
1502         
1503         log("Power.addOffTimer Done");
1504     };
1505     
1506     /**
1507      * Deletes 'off timer'. The timer in the list that matches the parameter will be removed.
1508      * @class Power
1509      * @param {Function} successCallback success callback function.
1510      * @param {Function} errorCallback failure callback function.     
1511      * @param {Object} options
1512      * <div align=left>
1513      * <table class="hcap_spec" width=400>
1514      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
1515      *   <tbody>
1516      *       <tr><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr>
1517      *       <tr class="odd"><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr>
1518      *       <tr><th>week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> <br>To use it on multiple day of week, set the sum of week. <br>For example, 1 + 64 (Power.TimerWeek.Monday + Power.TimerWeek.Sunday) means that this timer works on every Monday and Sunday.</th><th>required</th></tr>
1519      *   </tbody>
1520      * </table>
1521      * </div>
1522      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
1523      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
1524      * @example
1525      * // Javascript code
1526      * function deleteOffTimer () {
1527      *   var options = {
1528      *      hour : 9,
1529      *      minute : 0,
1530      *      week : Power.TimerWeek.MONDAY + Power.TimerWeek.FRIDAY
1531      *   };
1532      *     
1533      *   function successCb() {
1534      *      // Do something
1535      *   }
1536      *
1537      *   function failureCb(cbObject) {
1538      *      var errorCode = cbObject.errorCode;
1539      *      var errorText = cbObject.errorText;
1540      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1541      *   }
1542      *
1543      *   var power = new Power();
1544      *   power.deleteOffTimer(successCb, failureCb, options);
1545      * }
1546      * @since 1.0
1547      * @see
1548      * <a href="Power%23getOffTimerList.html">Power.getOffTimerList()</a>, 
1549      * <a href="InputSource.%23getInputSourceStatus.html">InputSource.getInputSourceStatus()</a><br>
1550      */
1551     Power.prototype.deleteOffTimer = function (successCallback, errorCallback, options) {
1552     
1553         log("deleteOffTimer: " + JSON.stringify(options));
1554         
1555         // bound check        
1556         if (options.hour === undefined || isNaN(options.hour) || typeof options.hour !== 'number' || options.hour < 0 || options.hour > 23 ||
1557             options.minute === undefined || isNaN(options.minute) || typeof options.minute !== 'number' || options.minute < 0 || options.minute > 59 ||
1558             options.week === undefined || isNaN(options.week) || typeof options.week !== 'number' || options.week < 0 || options.week > 127 ) {
1559             
1560             if (typeof errorCallback === 'function') {
1561                 var result = {};
1562                 checkErrorCodeNText(result, "PDOT", "Power.deleteOffTimer returns failure. invalid parameters or out of range.");
1563                 errorCallback(result);
1564             }
1565             
1566             return;
1567         }
1568         
1569         //1. timer enable / disable
1570         //2. set time information
1571         //3. set the number of timer.
1572         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1573             method : "get",
1574             parameters : {
1575                 category : "commercial",
1576                 keys : ["multiOffTimerHour", "multiOffTimerMinute", "multiOffTimerWeekday", "offTimerSchedule", "offTimerCount" ]
1577             },
1578             onSuccess : function(result) {
1579                 //log("deleteOffTimer: get timer data " + JSON.stringify(result));
1580                 
1581                 if (result.returnValue === true) {
1582                     
1583                     // in exceptional case of luna result error
1584                     if ( typeof result.settings.multiOffTimerHour === 'string') {
1585                         result.settings.multiOffTimerHour = JSON.parse(result.settings.multiOffTimerHour);
1586                     }
1587                     
1588                     if ( typeof result.settings.multiOffTimerMinute === 'string') {
1589                         result.settings.multiOffTimerMinute = JSON.parse(result.settings.multiOffTimerMinute);
1590                     }
1591                     
1592                     if ( typeof result.settings.multiOffTimerWeekday === 'string') {
1593                         result.settings.multiOffTimerWeekday = JSON.parse(result.settings.multiOffTimerWeekday);
1594                     }
1595                     
1596                     if ( typeof result.settings.offTimerSchedule === 'string') {
1597                         result.settings.offTimerSchedule = JSON.parse(result.settings.offTimerSchedule);
1598                     }
1599                     // end of exceptional case
1600                     
1601                     var addIndex = 0,
1602                         count = (result.settings.offTimerSchedule === null || result.settings.offTimerSchedule === undefined ? 0 : result.settings.offTimerSchedule.length);
1603                     var hour = ["0","0","0","0","0","0","0"],
1604                         min = ["0","0","0","0","0","0","0"],
1605                         week = ["0","0","0","0","0","0","0"],
1606                         schedule = [];
1607                     
1608                     //console.log("result.settings.offTimerSchedule.length  in " + result.settings.offTimerSchedule.length);
1609                     var deleted = false;
1610                     
1611 
1612                     checkPlatformVersion(function(info) {
1613 
1614                         log("version : " + info.webOSVer);
1615 
1616                         if (info.webOSVer === 3) {
1617                             //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1618                             //WEBOS 2.0 Sun(), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)
1619                             if (options.week >= 64) //in case of choosing days including sunday                        
1620                                 options.week = 1 + (options.week - 64) * 2;
1621                             else
1622                                 options.week = options.week * 2;                            
1623                         }                        
1624                     });
1625 
1626                     for (var i = 0; i < count; i++) {
1627 
1628                         //console.log("result.settings.offTimerSchedule.length  in " + JSON.stringify(result.settings.offTimerSchedule[i]));
1629                         if (result.settings.offTimerSchedule[i] === null) {
1630                             continue;
1631                         }
1632 
1633                         log("options.week : " + options.week + " result.settings.offTimerSchedule[" + i + "].weekday : " + result.settings.offTimerSchedule[i].weekday);
1634 
1635                         if (deleted === false &&
1636                             options.hour === result.settings.offTimerSchedule[i].hour &&
1637                             options.minute === result.settings.offTimerSchedule[i].minute &&
1638                             options.week === result.settings.offTimerSchedule[i].weekday ) {
1639                             // do nothing
1640                             //log("deleteOffTimer: index " + i);
1641                             deleted = true;
1642                         } else {
1643                             hour[addIndex] = result.settings.multiOffTimerHour[i];
1644                             min[addIndex] = result.settings.multiOffTimerMinute[i];
1645                             week[addIndex] = result.settings.multiOffTimerWeekday[i];
1646                             schedule[addIndex] = result.settings.offTimerSchedule[i];
1647                             addIndex++;
1648                         }
1649                     }
1650                     
1651                     if (deleted === true) {
1652                         count--;
1653                     }
1654                     
1655                     if (count === 0) { 
1656                         schedule = [];
1657                     }
1658                     
1659                     if (result.settings.offTimerSchedule.length === count) {
1660                         if (typeof errorCallback === 'function') {
1661                             checkErrorCodeNText(result, "PDOT", "Power.deleteOffTimer returns failure. There is no 'off timer' matched in the list.");
1662                             errorCallback(result);
1663                         }
1664                         return;
1665                     }
1666                                     
1667                     service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1668                         method : "set",
1669                         parameters : {
1670                             category : "commercial",
1671                             settings : {
1672                                 "multiOffTimerHour":hour,
1673                                 "multiOffTimerMinute":min,
1674                                 "multiOffTimerWeekday":week,
1675                                 "offTimerCount":count,
1676                                 "offTimerSchedule":schedule
1677                             }
1678                         },
1679                         onSuccess : function() {
1680                             log("deleteOffTimer: On Success 2");
1681                             
1682                             if(typeof successCallback === 'function'){
1683                                 successCallback();
1684                             }
1685                         },
1686                         onFailure : function(result) {
1687                             log("deleteOffTimer: On Failure 2");
1688                             delete result.returnValue;
1689                             if (typeof errorCallback === 'function') {
1690                                 checkErrorCodeNText(result, "PDOT", "Power.deleteOffTimer returns failure.");
1691                                 errorCallback(result);
1692                             }
1693                                 
1694                         }
1695                     });
1696                 }
1697             },
1698             onFailure : function(result) {
1699                 log("deleteOffTimer: On Failure");
1700                 delete result.returnValue;
1701                 if(typeof errorCallback === 'function') {
1702                     checkErrorCodeNText(result, "PDOT", "Power.deleteOffTimer returns failure.");
1703                     errorCallback(result);
1704                 }
1705             }
1706         });
1707         
1708         log("Power.deleteOffTimer Done");
1709     
1710     };
1711     
1712     /**
1713      * Gets 'on timer' list. 
1714      * @class Power
1715      * @param {Function} successCallback success callback function.
1716      * @param {Function} errorCallback failure callback function.
1717      * @return <p>{Object} list of timer object.</p>
1718      * <div align=left>
1719      * <table class="hcap_spec" width=400>
1720      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
1721      *   <tbody>
1722      *       <tr><th>timerList[]</th><th>Array</th><th>An array with the timer information object as its elements. </th></tr>
1723      *       <tr class="odd"><th>timerList[].hour</th><th>Number</th><th>hour (0~23) </th></tr>
1724      *       <tr><th>timerList[].minute</th><th>Number</th><th>minute (0~59) </th></tr>
1725      *       <tr class="odd"><th>timerList[].week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> </th></tr>
1726      *       <tr><th>timerList[].inputSource</th><th>String</th><th>Input source</th></tr>
1727      *   </tbody>
1728      * </table>
1729      * </div>
1730      *
1731      * @example
1732      * // Javascript code
1733      * function getOnTimerList () {
1734      *   function successCb(cbObject) {
1735      *      var timerList = cbObject.timerList;
1736      *      for ( var i = 0; i < timerList.length; i++) {
1737      *         console.log("timerList[" + i + "] : " + JSON.stringify(timerList[i]));
1738      *         console.log("timerList[" + i + "].hour : " + timerList[i].hour);
1739      *         console.log("timerList[" + i + "].minute : " + timerList[i].minute);
1740      *         console.log("timerList[" + i + "].week : " + timerList[i].week);
1741      *         console.log("timerList[" + i + "].inputSource : " + timerList[i].inputSource);
1742      *      }
1743      *
1744      *      // Do something
1745      *         ...
1746      *   }
1747      *
1748      *   function failureCb(cbObject) {
1749      *      var errorCode = cbObject.errorCode;
1750      *      var errorText = cbObject.errorText;
1751      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1752      *   }
1753      *
1754      *   var power = new Power();
1755      *   power.getOnTimerList(successCb, failureCb);
1756      * }
1757      * @since 1.0
1758      * @see
1759      * <a href="Power%23setOnTimer.html">Power.setOnTimer()</a><br>
1760      */
1761     Power.prototype.getOnTimerList = function(successCallback, errorCallback) {
1762 
1763         log("getOnTimerList: ");
1764 
1765         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1766             method: "get",
1767             parameters: {
1768                 category: "commercial",
1769                 keys: ["onTimerSchedule"]
1770             },
1771             onSuccess: function(result) {
1772 
1773                 if (result.returnValue === true) {
1774 
1775                     checkPlatformVersion(function(info) {
1776 
1777                         log("version : " + info.webOSVer);
1778 
1779                         var cbObj = {};
1780 
1781                         if (typeof result.settings.onTimerSchedule === 'string') {
1782                             result.settings.onTimerSchedule = JSON.parse(result.settings.onTimerSchedule);
1783                         }
1784 
1785                         var timerList = new Array(result.settings.onTimerSchedule === null || result.settings.onTimerSchedule === undefined ? 0 : result.settings.onTimerSchedule.length);
1786                         //console.log("timerList " + timerList);
1787                         //console.log("timerList.length " + timerList.length);
1788                         for (var index = 0, i = 0; i < timerList.length; i++) {
1789                             if (result.settings.onTimerSchedule[i] === null || result.settings.onTimerSchedule[i] === undefined) {
1790                                 continue;
1791                             }
1792                             timerList[index] = {
1793                                 hour: 0,
1794                                 minute: 0,
1795                                 week: 0,
1796                                 inputSource: 0
1797                             };
1798 
1799                             if (info.webOSVer === 3) {
1800                                 //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1801                                 //WEBOS 2.0 Sun(64), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)                                
1802                                 var tempWeek = result.settings.onTimerSchedule[i].weekday;
1803 
1804                                 if (tempWeek % 2) //in case of choosing days including sunday      
1805                                 {
1806                                     var remainder = tempWeek % 2;
1807                                     tempWeek = 64 + ((tempWeek - remainder) / 2);
1808                                 } else
1809                                     tempWeek = tempWeek / 2;
1810                             } else
1811                                 result.settings.onTimerSchedule[i].weekday;
1812 
1813                             timerList[index].hour = result.settings.onTimerSchedule[i].hour;
1814                             timerList[index].minute = result.settings.onTimerSchedule[i].minute;
1815                             timerList[index].week = tempWeek;
1816                             timerList[index++].inputSource = convertExternal(result.settings.onTimerSchedule[i].input);
1817                         }
1818 
1819                         cbObj.timerList = timerList;
1820 
1821                         if (typeof successCallback === 'function') {
1822                             successCallback(cbObj);
1823                         }
1824 
1825                     });
1826                 }
1827             },
1828             onFailure: function(result) {
1829                 log("getOnTimerList: On Failure");
1830                 delete result.returnValue;
1831                 if (typeof errorCallback === 'function') {
1832                     checkErrorCodeNText(result, "PGOTL", "Power.getOnTimerList returns failure.");
1833                     errorCallback(result);
1834                 }
1835             }
1836         });
1837 
1838         log("Power.getOnTimerList Done");
1839 
1840     };
1841     
1842     /**
1843      * Gets 'off timer' list. 
1844      * @class Power
1845      * @param {Function} successCallback success callback function.
1846      * @param {Function} errorCallback failure callback function.
1847      * @return <p>{Object} list of timer object.</p>
1848      * <div align=left>
1849      * <table class="hcap_spec" width=400>
1850      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
1851      *   <tbody>
1852      *       <tr><th>timerList[]</th><th>Array</th><th>An array with the timer information object as its elements. </th></tr>  
1853      *       <tr class="odd"><th>timerList[].hour</th><th>Number</th><th>hour (0~23) </th></tr>
1854      *       <tr><th>timerList[].minute</th><th>Number</th><th>minute (0~59) </th></tr>
1855      *       <tr class="odd"><th>timerList[].week</th><th>Number</th><th>week <a href="Power.TimerWeek.html#constructor">Power.TimerWeek</a> </th></tr>
1856      *   </tbody>
1857      * </table>
1858      * </div>
1859      *
1860      * @example
1861      * // Javascript code
1862      * function getOffTimerList () {
1863      *   function successCb(cbObject) {
1864      *      var timerList = cbObject.timerList;
1865      *      for ( var i = 0; i < timerList.length; i++) {
1866      *         console.log("timerList[" + i + "] : " + JSON.stringify(timerList[i]));
1867      *         console.log("timerList[" + i + "].hour : " + timerList[i].hour);
1868      *         console.log("timerList[" + i + "].minute : " + timerList[i].minute);
1869      *         console.log("timerList[" + i + "].week : " + timerList[i].week);
1870      *      }
1871      *
1872      *      // Do something
1873      *         ...
1874      *   }
1875      *
1876      *   function failureCb(cbObject) {
1877      *      var errorCode = cbObject.errorCode;
1878      *      var errorText = cbObject.errorText;
1879      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1880      *   }
1881      *
1882      *   var power = new Power();
1883      *   power.getOffTimerList(successCb, failureCb);
1884      * }
1885      * @since 1.0
1886      * @see
1887      * <a href="Power%23setOffTimer.html">Power.setOffTimer()</a><br>
1888      */
1889     Power.prototype.getOffTimerList = function(successCallback, errorCallback) {
1890 
1891         log("getOffTimerList: ");
1892 
1893         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
1894             method: "get",
1895             parameters: {
1896                 category: "commercial",
1897                 keys: ["offTimerSchedule"]
1898             },
1899             onSuccess: function(result) {
1900                 log("getOffTimerList: On Success");
1901 
1902                 checkPlatformVersion(function(info) {
1903 
1904                     log("version : " + info.webOSVer);
1905 
1906                     if (result.returnValue === true) {
1907                         var cbObj = {};
1908 
1909                         if (typeof result.settings.offTimerSchedule === 'string') {
1910                             result.settings.offTimerSchedule = JSON.parse(result.settings.offTimerSchedule);
1911                         }
1912 
1913                         var timerList = new Array(result.settings.offTimerSchedule === null || result.settings.offTimerSchedule === undefined ? 0 : result.settings.offTimerSchedule.length);
1914 
1915                         //console.log("timerList " + timerList);
1916                         //console.log("timerList.length " + timerList.length);
1917 
1918                         for (var index = 0, i = 0; i < timerList.length; i++) {
1919                             if (result.settings.offTimerSchedule[i] === null || result.settings.offTimerSchedule[i] === undefined) {
1920                                 continue;
1921                             }
1922                             timerList[index] = {
1923                                 hour: 0,
1924                                 minute: 0,
1925                                 week: 0
1926                             };
1927 
1928                             if (info.webOSVer === 3) {
1929                                 //WEBOS 3.0 Sun(1), Mon(2), Thes(4), Wen(8), Thur(16), Fri(32). Sat(64)
1930                                 //WEBOS 2.0 Sun(64), Mon(1), Thes(2), Wen(4), Thur(8), Fri(16). Sat(32)                                
1931                                 var tempWeek = result.settings.offTimerSchedule[i].weekday;
1932 
1933                                 if (tempWeek % 2) //in case of choosing days including sunday      
1934                                 {
1935                                     var remainder = tempWeek % 2;
1936                                     tempWeek = 64 + ((tempWeek - remainder) / 2);
1937                                 } else
1938                                     tempWeek = tempWeek / 2;
1939                             } else
1940                                 tempWeek = result.settings.offTimerSchedule[i].weekday;
1941 
1942                             timerList[index].hour = result.settings.offTimerSchedule[i].hour;
1943                             timerList[index].minute = result.settings.offTimerSchedule[i].minute;
1944                             timerList[index++].week = tempWeek;                                            
1945                         }
1946 
1947                         cbObj.timerList = timerList;
1948 
1949                         if (typeof successCallback === 'function') {
1950                             successCallback(cbObj);
1951                         }
1952                     }
1953                 });
1954             },
1955             onFailure: function(result) {
1956                 log("getOffTimerList: On Failure");
1957                 delete result.returnValue;
1958                 if (typeof errorCallback === 'function') {
1959                     checkErrorCodeNText(result, "PGOTL", "Power.getOffTimerList returns failure.");
1960                     errorCallback(result);
1961                 }
1962             }
1963         });
1964 
1965         log("Power.getOffTimerList Done");
1966     };
1967     
1968     /**
1969      * Turns on/off the display panel. This will only affect the panel, not the main power. 
1970      * @class Power
1971      * @param {Function} successCallback success callback function.
1972      * @param {Function} errorCallback failure callback function.
1973      * @param {Object} options
1974      * <div align=left>
1975      * <table class="hcap_spec" width=400>
1976      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
1977      *   <tbody>
1978      *       <tr><th>displayMode</th><th>String</th><th><a href="Power.DisplayMode.html#constructor">Power.DisplayMode</a> </th><th>required</th></tr>
1979      *   </tbody>
1980      * </table>
1981      * </div>
1982      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
1983      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
1984      * @example
1985      * // Javascript code
1986      * function setDisplayMode () {
1987      *   var options = {
1988      *      displayMode : Power.DisplayMode.DISPLAY_OFF
1989      *   };
1990      *     
1991      *   function successCb() {
1992      *      // Do something
1993      *   }
1994      *
1995      *   function failureCb(cbObject) {
1996      *      var errorCode = cbObject.errorCode;
1997      *      var errorText = cbObject.errorText;
1998      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
1999      *   }
2000      *
2001      *   var power = new Power();
2002      *   power.setDisplayMode(successCb, failureCb, options);
2003      * }
2004      * @since 1.0
2005      * @see
2006      * <a href="Power%23getPowerStatus.html">Power.getPowerStatus()</a><br>
2007      */
2008     Power.prototype.setDisplayMode = function (successCallback, errorCallback, options) {
2009     
2010         log("setDisplayMode: " + JSON.stringify(options));
2011         
2012         var command = null;
2013         
2014         switch (options.displayMode) {
2015             case Power.DisplayMode.DISPLAY_OFF :
2016                 command = "turnOffScreen";
2017                 break;
2018             case Power.DisplayMode.DISPLAY_ON :
2019                 command = "turnOnScreen";
2020                 break;            
2021             default:
2022                 if (typeof errorCallback === 'function') {
2023                     var result = {};
2024                     checkErrorCodeNText(result, "PSDM", "Power.setDisplayMode returns failure. Invalid option value.");
2025                     errorCallback(result);
2026                 }
2027                 return;            
2028         }
2029         
2030         log("setDisplayMode: " + command);
2031         
2032         if (command === null && typeof errorCallback === 'function') {
2033             var result = {};
2034             checkErrorCodeNText(result, "PSDM", "Power.setDisplayMode returns failure. command was not defined.");
2035             errorCallback(result);
2036             log("Power.setDisplayMode invalid ");
2037             return;
2038         }
2039         
2040         /*
2041         service.Request("luna://com.webos.service.tvpower/power/", {
2042         */
2043         service.Request("luna://com.webos.service.tv.signage/", {
2044             method : "getPowerState",
2045             onSuccess : function(result) {
2046                 log("setDisplayMode: On Success");
2047                 
2048                 if (result.returnValue === true && result.state === options.displayMode) {
2049                     // no need to do any action.
2050                     if (typeof successCallback === 'function') {
2051                         log("setDisplayMode: no need to do any action.");
2052                         successCallback();
2053                     }
2054                     return;
2055                 }
2056                 /*
2057                 service.Request("luna://com.webos.service.tvpower/power/", {
2058                 */
2059                 service.Request("luna://com.webos.service.tv.signage/", {
2060                     method : command,
2061                     onSuccess : function(result) {
2062                         log("setDisplayMode: On Success");
2063                         
2064                         if (result.returnValue === true) {
2065                             if (typeof successCallback === 'function') {
2066                                 successCallback();
2067                             }
2068                         }
2069                     },
2070                     onFailure : function(result) {
2071                         log("setDisplayMode: On Failure");
2072                         delete result.returnValue;
2073                         if (typeof errorCallback === 'function') {
2074                             checkErrorCodeNText(result, "PSDM", "Power.setDisplayMode returns failure.");
2075                             errorCallback(result);
2076                         }
2077                     }
2078                 });
2079             },
2080         
2081             onFailure : function(result) {
2082                 log("setDisplayMode: On Failure 2");
2083                 delete result.returnValue;
2084                 if(typeof errorCallback === 'function') {
2085                     checkErrorCodeNText(result, "PSDM", "Power.setDisplayMode returns failure.");
2086                     errorCallback(result);
2087                 }
2088             }
2089         });
2090         
2091         log("Power.setDisplayMode Done");
2092     };
2093     
2094     /**
2095      * Executes power related command. 
2096      * @class Power
2097      * @param {Function} successCallback success callback function.
2098      * @param {Function} errorCallback failure callback function.     
2099      * @param {Object} options
2100      * <div align=left>
2101      * <table class="hcap_spec" width=400>
2102      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
2103      *   <tbody>
2104      *       <tr><th>powerCommand</th><th>String</th><th><a href="Power.PowerCommand.html#constructor">Power.PowerCommand</a> </th><th>required</th></tr>
2105      *   </tbody>
2106      * </table>
2107      * </div>
2108      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
2109      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
2110      * @example
2111      * // Javascript code
2112      * function executePowerCommand () {
2113      *   var options = {
2114      *      powerCommand : Power.PowerCommand.REBOOT
2115      *   };   
2116      *     
2117      *   function successCb() {
2118      *      // Do something
2119      *   }
2120      *
2121      *   function failureCb(cbObject) {
2122      *      var errorCode = cbObject.errorCode;
2123      *      var errorText = cbObject.errorText;
2124      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
2125      *   }
2126      *
2127      *   var power = new Power();
2128      *   power.executePowerCommand(successCb, failureCb, options);
2129      * }
2130      * @since 1.0
2131      * @see
2132      * <a href="Power%23getPowerStatus.html">Power.getPowerStatus()</a><br>
2133      */
2134     Power.prototype.executePowerCommand = function (successCallback, errorCallback, options) {
2135     
2136         log("executePowerCommand: " + JSON.stringify(options));
2137         
2138         if ( options.powerCommand === undefined || typeof options.powerCommand !== 'string' || options.powerCommand === null || options.powerCommand.length <= 0) {
2139             
2140             if (typeof errorCallback === 'function') {
2141                 var result = {};
2142                 checkErrorCodeNText(result, "PEPM", "Power.executePowerCommand returns failure. invalid argument or out of range. ");
2143                 errorCallback(result);
2144             }
2145             return;
2146         }
2147                 
2148         if ((options.powerCommand !== Power.PowerCommand.REBOOT) && (options.powerCommand !== Power.PowerCommand.SHUTDOWN)) {
2149             var result = {};
2150             checkErrorCodeNText(result, "PEPM", "Power.executePowerCommand returns failure. invalid argument.");
2151             errorCallback(result);
2152             return;
2153         }        
2154         
2155         /*
2156         service.Request("luna://com.webos.service.tvpower/power/", {
2157         */
2158         service.Request("luna://com.webos.service.tv.signage/", {
2159                 method : options.powerCommand,
2160                 parameters : {
2161                     reason : "unknown"
2162                 },
2163                 onSuccess : function(result) {
2164                     log("executePowerCommand: On Success");
2165                     
2166                     if (result.returnValue === true) {
2167                         if (typeof successCallback === 'function') {
2168                             successCallback();
2169                         }
2170                     }
2171                 },
2172                 onFailure : function(result) {
2173                     log("executePowerCommand: On Failure");
2174                     delete result.returnValue;
2175                     if (typeof errorCallback === 'function') {
2176                         checkErrorCodeNText(result, "PEPM", "Power.executePowerCommand returns failure.");
2177                         errorCallback(result);
2178                     }
2179                 }
2180             });
2181         
2182         log("Power.executePowerCommand Done");
2183         
2184     };
2185 
2186 
2187 	/**
2188      * Sets DPMWakeup, Each <a href="Power.DPMSignalType.html#constructor">DPMSignalType</a> has a set of predefined DPMSignalType properties.
2189      * @class Power
2190      * @param {Function} successCallback success callback function.
2191      * @param {Function} errorCallback failure callback function.
2192      * @param {Object} options
2193      * <div align=left>
2194      * <table class="hcap_spec" width=400>
2195      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
2196      *   <tbody>
2197      *       <tr><th>DPMSignalType</th><th>String</th><th><a href="Power.DPMSignalType.html#constructor">DPMSignalType</a></th><th>required</th></tr>
2198      *   </tbody>
2199      * </table>
2200      * </div>
2201      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
2202      * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p>
2203      * 
2204      * @example
2205      * // Javascript code
2206      * function setDPMWakeup () {
2207      *  var options = {};
2208 	 *  options.dpmSignalType = Power.DPMSignalType.CLOCK;
2209 	 *  function successCb(cbObject) {
2210 	 *     console.log("sucess");
2211 	 *     // Do something
2212 	 *  }
2213      *  
2214 	 *  function failureCb(cbObject) {
2215 	 *     var errorCode = cbObject.errorCode;
2216 	 *     var errorText = cbObject.errorText;
2217 	 *     console.log ("Error Code [" + errorCode + "]: " + errorText);
2218 	 *  }
2219      *  
2220 	 *  var power = new Power();
2221 	 *  power.setDPMWakeup(successCb, failureCb, options);
2222 	 * }
2223      * @since 1.4
2224      * @see
2225      * <a href="Power%23getDPMWakeup.html">Power.getDPMWakeup()</a><br>
2226      */
2227 	Power.prototype.setDPMWakeup = function (successCallback, errorCallback, options) {
2228     	var signalType = null;
2229         
2230         switch (options.dpmSignalType) {
2231             case Power.DPMSignalType.CLOCK :
2232                 signalType = "clock";
2233                 break;
2234             case Power.DPMSignalType.CLOCK_WITH_DATA :
2235                 signalType = "clockAndData";
2236                 break;
2237         }
2238         
2239         log("setDPMWakeup: " + signalType);
2240         
2241         if (signalType === null && typeof errorCallback === 'function') {
2242             var result = {};
2243             checkErrorCodeNText(result, "PSDW", "Power.setDPMWakeup returns failure. command was not defined.");
2244             errorCallback(result);
2245             log("Power.setDPMWakeup invalid ");
2246             return;
2247         }      
2248         
2249         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2250             method : "set",
2251             parameters : {
2252                 category : "commercial",
2253                 settings : {
2254                     "dpmWakeUpControl" : signalType 
2255                 }
2256             },
2257             onSuccess : function(result) {
2258                 log("setDPMWakeup: On Success");
2259 
2260                 if (result.returnValue === true) {
2261                     if(typeof successCallback === 'function') {
2262                         successCallback();
2263                     }
2264                 }
2265             },
2266             onFailure : function(result) {
2267                 log("setDPMWakeup: On Failure");
2268                 delete result.returnValue;
2269                 if (typeof errorCallback === 'function') {
2270                     checkErrorCodeNText(result, "PSDW", "Power.setDPMWakeup returns failure.");
2271                     errorCallback(result);
2272                 }
2273             }
2274         });
2275         
2276         log("Power.setDPMWakeup Done");
2277     };
2278 
2279 	/**
2280      * Gets DPMWakeup Info, Each <a href="Power.DPMSignalType.html#constructor">DPMSignalType</a> has a set of predefined DPMSignalType properties.
2281      * @class Power
2282      * @param {Function} successCallback success callback function.
2283      * @param {Function} errorCallback failure callback function.
2284      * @return {Object} options
2285      * <div align=left>
2286      * <table class="hcap_spec" width=400>
2287      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
2288      *   <tbody>
2289      *		 <tr><th>dpmSignalType</th><th>String</th><th><a href="Power.DPMSignalType.html#constructor">DPMSignalType</a></th></tr>
2290      *   </tbody>
2291      * </table>
2292      * </div>
2293      *
2294 	 * @example
2295      * // Javascript code
2296      * function getDPMWakeup () {
2297 	 *  function successCb(cbObject) {
2298 	 *     console.log("cbObject : " + JSON.stringify(cbObject));
2299 	 *     // Do something
2300 	 *  }
2301      *  
2302 	 *  function failureCb(cbObject) {
2303 	 *     var errorCode = cbObject.errorCode;
2304 	 *     var errorText = cbObject.errorText;
2305 	 *     console.log ("Error Code [" + errorCode + "]: " + errorText);
2306 	 *  }
2307      *  
2308 	 *  var power = new Power();
2309 	 *  power.getDPMWakeup(successCb, failureCb);
2310 	 * }
2311      * @since 1.4
2312      * @see
2313      * <a href="Power%23setDPMWakeup.html">Power.setDPMWakeup()</a><br>
2314      */
2315 	Power.prototype.getDPMWakeup = function (successCallback, errorCallback) {
2316         
2317         log("getDPMWakeup: ");
2318         
2319             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2320                 method : "get",
2321                 parameters : {
2322                     category : "commercial",
2323                     keys : ["dpmWakeUpControl"]
2324                 },
2325                 onSuccess : function(result) {
2326                     log("getDPMWakeup: On Success");
2327                     
2328                     if (result.returnValue === true) {
2329                         var cbObj = {};
2330                         cbObj.dpmSignalType = result.settings.dpmWakeUpControl;
2331                     
2332                         if (typeof successCallback === 'function') {
2333                             successCallback(cbObj);
2334                         }
2335                     }
2336                 },
2337                 onFailure : function(result) {
2338                     log("getDPMWakeup: On Failure");
2339                     delete result.returnValue;
2340                     if (typeof errorCallback === 'function') {
2341                         checkErrorCodeNText(result, "PGDW", "Power.getDPMWakeup returns failure.");
2342                         errorCallback(result);
2343                     }
2344                 }
2345             });
2346         
2347         log("Power.getDPMWakeup Done");
2348     };
2349 
2350 	/**
2351      * Sets PMMode, Each <a href="Power.PMMode.html#constructor">PMMode</a> has a set of predefined PMMode properties.
2352      * @class Power
2353      * @param {Function} successCallback success callback function.
2354      * @param {Function} errorCallback failure callback function.
2355      * @param {Object} options
2356      * <div align=left>
2357      * <table class="hcap_spec" width=400>
2358      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
2359      *   <tbody>
2360      *       <tr><th>mode</th><th>String</th><th><a href="Power.PMMode.html#constructor">PMMode</a> (ScreenOffBacklight is only for outdoor model)</th><th>required</th></tr>
2361      *   </tbody>
2362      * </table>
2363      * </div>
2364      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
2365      * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p>
2366      * 
2367      * @example
2368      * // Javascript code
2369      * function setPMMode () {
2370      *  var options = {};
2371 	 *  options.mode = "Power.PMMode.PowerOff";
2372      *
2373 	 *  function successCb(cbObject) {
2374 	 *     console.log("sucess");
2375 	 *     // Do something
2376 	 *  }
2377      *
2378 	 *  function failureCb(cbObject) {
2379 	 *     var errorCode = cbObject.errorCode;
2380 	 *     var errorText = cbObject.errorText;
2381 	 *     console.log ("Error Code [" + errorCode + "]: " + errorText);
2382 	 *  }
2383      *
2384 	 *  var power = new Power();
2385 	 *  power.setPMMode(successCb, failureCb);
2386 	 * }
2387      * @since 1.4
2388      * @see
2389      * <a href="Power%23getPMMode.html">Power.getPMMode()</a><br>
2390      */
2391 	Power.prototype.setPMMode = function (successCallback, errorCallback, options) {
2392     	var mode = null;
2393         
2394         switch (options.mode) {
2395             case Power.PMMode.PowerOff :
2396                 mode = "powerOff";
2397                 break;
2398             case Power.PMMode.SustainAspectRatio :
2399                 mode = "sustainAspectRatio";
2400                 break;
2401             case Power.PMMode.ScreenOff :
2402                 mode = "screenOff";
2403                 break;
2404             case Power.PMMode.ScreenOffAlways :
2405                 mode = "screenOffAlways";
2406                 break;
2407             case Power.PMMode.ScreenOffBacklight :
2408                 mode = "screenOffBacklight";
2409                 break;
2410         }
2411         
2412         log("setPMMode: " + mode);
2413         
2414         if (mode === null && typeof errorCallback === 'function') {
2415             var result = {};
2416             checkErrorCodeNText(result, "PSPM", "Power.setPMMode returns failure. command was not defined.");
2417             errorCallback(result);
2418             log("Power.setPMMode invalid ");
2419             return;
2420         }      
2421         
2422         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2423             method : "set",
2424             parameters : {
2425                 category : "commercial",
2426                 settings : {
2427                     "pmMode" : mode 
2428                 }
2429             },
2430             onSuccess : function(result) {
2431                 log("setPMMode: On Success");
2432 
2433                 if (result.returnValue === true) {
2434                     if(typeof successCallback === 'function') {
2435                         successCallback();
2436                     }
2437                 }
2438             },
2439             onFailure : function(result) {
2440                 log("setPMMode: On Failure");
2441                 delete result.returnValue;
2442                 if (typeof errorCallback === 'function') {
2443                     checkErrorCodeNText(result, "PSPM", "Power.setPMMode returns failure.");
2444                     errorCallback(result);
2445                 }
2446             }
2447         });
2448         
2449         log("Power.setPMMode Done");
2450     };
2451 
2452 	/**
2453      * Gets PMMode Info, <a href="Power.PMMode.html#constructor">PMMode</a> has a set of predefined PMMode properties.
2454      * @class Power
2455      * @param {Function} successCallback success callback function.
2456      * @param {Function} errorCallback failure callback function.
2457      * @return {Object} options
2458      * <div align=left>
2459      * <table class="hcap_spec" width=400>
2460      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
2461      *   <tbody>
2462      *       <tr><th>mode</th><th>String</th><th><a href="Power.PMMode.html#constructor">PMMode</a></th></tr>
2463      *   </tbody>
2464      * </table>
2465      * </div>
2466      *
2467 	 * @example
2468      * // Javascript code
2469      * function getPMMode () {
2470 	 *		function successCb(cbObject) {
2471 	 *			console.log("cbObject : " + JSON.stringify(cbObject));
2472 	 *			// Do something
2473 	 *		}
2474 	 *		function failureCb(cbObject) {
2475 	 *			var errorCode = cbObject.errorCode;
2476 	 *			var errorText = cbObject.errorText;
2477 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
2478 	 *			}
2479 	 *		var power = new Power();
2480 	 *		power.getPMMode(successCb, failureCb);
2481 	 * }
2482      * @since 1.4
2483      * @see
2484      * <a href="Power%23setPMMode.html">Power.setPMMode()</a><br>
2485      */
2486 	Power.prototype.getPMMode = function (successCallback, errorCallback) {
2487         
2488         log("getPMMode: ");
2489         
2490             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2491                 method : "get",
2492                 parameters : {
2493                     category : "commercial",
2494                     keys : ["pmMode"]
2495                 },
2496                 onSuccess : function(result) {
2497                     log("getPMMode: On Success");
2498                     
2499                     if (result.returnValue === true) {
2500                         var cbObj = {};
2501                         cbObj.mode = result.settings.pmMode;
2502                     
2503                         if (typeof successCallback === 'function') {
2504                             successCallback(cbObj);
2505                         }
2506                     }
2507                 },
2508                 onFailure : function(result) {
2509                     log("getPMMode: On Failure");
2510                     delete result.returnValue;
2511                     if (typeof errorCallback === 'function') {
2512                         checkErrorCodeNText(result, "PGPM", "Power.getPMMode returns failure.");
2513                         errorCallback(result);
2514                     }
2515                 }
2516             });
2517         
2518         log("Power.getPMMode Done");
2519     };
2520     /**
2521      * Sets PowerOnDelay
2522      * @class Power
2523      * @param {Function} successCallback success callback function.
2524      * @param {Function} errorCallback failure callback function.
2525      * @param {Object} options
2526      * <div align=left>
2527      * <table class="hcap_spec" width=400>
2528      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
2529      *   <tbody>
2530      *       <tr><th>delayTime</th><th>Number</th><th>Delay Time (0 ~ 250)</th><th>required</th></tr>
2531      *   </tbody>
2532      * </table>
2533      * </div>
2534      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
2535      * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p>
2536      * 
2537      * @example
2538      * // Javascript code
2539      * function setPowerOnDelay () {
2540      *		var options = {};
2541 	 *		options.delayTime = 20;
2542 	 *		function successCb(cbObject) {
2543 	 *			console.log("sucess");
2544 	 *			// Do something
2545 	 *		}
2546 	 *		function failureCb(cbObject) {
2547 	 *			var errorCode = cbObject.errorCode;
2548 	 *			var errorText = cbObject.errorText;
2549 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
2550 	 *			}
2551 	 *		var power = new Power();
2552 	 *		power.setPowerOnDelay(successCb, failureCb);
2553 	 * }
2554      * @since 1.4
2555      * @see
2556      * <a href="Power%23getPowerOnDelay.html">Power.getPowerOnDelay()</a><br>
2557      */
2558     Power.prototype.setPowerOnDelay = function (successCallback, errorCallback, options) {
2559         log("setPowerOnDelay: " + options.delayTime);
2560         
2561         if (options.delayTime === null && typeof errorCallback === 'function') {
2562             var result = {};
2563             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. command was not defined.");
2564             errorCallback(result);
2565             log("Power.setPowerOnDelay invalid ");
2566             return;
2567         }      
2568         
2569         if (typeof options.delayTime !== 'number') {
2570             var result = {};
2571             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. delayTime is not a number.");
2572             errorCallback(result);
2573             log("Power.setPowerOnDelay invalid type");
2574             return;
2575         }
2576         
2577         if ((options.delayTime < 0) || (options.delayTime > 250)) {
2578             var result = {};
2579             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. Out of range.");
2580             errorCallback(result);
2581             log("Power.setPowerOnDelay invalid range");
2582             return;
2583         }
2584         
2585         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2586             method : "set",
2587             parameters : {
2588                 category : "commercial",
2589                 settings : {
2590                     "powerOnDelay" : options.delayTime 
2591                 }
2592             },
2593             onSuccess : function(result) {
2594                 log("setPowerOnDelay: On Success");
2595 
2596                 if (result.returnValue === true) {
2597                     if(typeof successCallback === 'function') {
2598                         successCallback();
2599                     }
2600                 }
2601             },
2602             onFailure : function(result) {
2603                 log("setPowerOnDelay: On Failure");
2604                 delete result.returnValue;
2605                 if (typeof errorCallback === 'function') {
2606                     checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure.");
2607                     errorCallback(result);
2608                 }
2609             }
2610         });
2611         
2612         log("Power.setPowerOnDelay Done");
2613     };
2614 
2615 	/**
2616      * Gets PowerOnDelay
2617      * @class Power
2618      * @param {Function} successCallback success callback function.
2619      * @param {Function} errorCallback failure callback function.
2620      * @return {Object} options
2621      * <div align=left>
2622      * <table class="hcap_spec" width=400>
2623      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
2624      *   <tbody>
2625      *       <tr><th>delayTime</th><th>Number</th><th>Delay Time (0 ~ 250)</th></tr>
2626      *   </tbody>
2627      * </table>
2628      * </div>
2629      *
2630 	 * @example
2631      * // Javascript code
2632      * function getPowerOnDelay () {
2633 	 *		function successCb(cbObject) {
2634 	 *			console.log("cbObject : " + JSON.stringify(cbObject));
2635 	 *			// Do something
2636 	 *		}
2637 	 *		function failureCb(cbObject) {
2638 	 *			var errorCode = cbObject.errorCode;
2639 	 *			var errorText = cbObject.errorText;
2640 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
2641 	 *			}
2642 	 *		var power = new Power();
2643 	 *		power.getPowerOnDelay(successCb, failureCb);
2644 	 * }
2645      * @since 1.4
2646      * @see
2647      * <a href="Power%23setPowerOnDelay.html">Power.setPowerOnDelay()</a><br>
2648      */
2649     Power.prototype.getPowerOnDelay = function (successCallback, errorCallback) {
2650         
2651         log("getPowerOnDelay: ");
2652         
2653             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
2654                 method : "get",
2655                 parameters : {
2656                     category : "commercial",
2657                     keys : ["powerOnDelay"]
2658                 },
2659                 onSuccess : function(result) {
2660                     log("getPowerOnDelay: On Success");
2661                     
2662                     if (result.returnValue === true) {
2663                         var cbObj = {};
2664                         cbObj.delayTime = result.settings.powerOnDelay;
2665                     
2666                         if (typeof successCallback === 'function') {
2667                             successCallback(cbObj);
2668                         }
2669                     }
2670                 },
2671                 onFailure : function(result) {
2672                     log("getPowerOnDelay: On Failure");
2673                     delete result.returnValue;
2674                     if (typeof errorCallback === 'function') {
2675                         checkErrorCodeNText(result, "PGPD", "Power.getPowerOnDelay returns failure.");
2676                         errorCallback(result);
2677                     }
2678                 }
2679             });
2680         
2681         log("Power.getPowerOnDelay Done");
2682     };
2683 
2684 
2685     module.exports = Power;
2686 });
2687 
2688 Power = cordova.require('cordova/plugin/power'); // jshint ignore:line
2689 
2690