      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
    2229         var ret = { };
    2230         checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2");
    2231         errorCallback(ret);
    2232         return;
    2233
    2234         var signalType = null;
    2235
    2236         switch (options.dpmSignalType) {
    2237             case Power.DPMSignalType.CLOCK :
    2238                 signalType = "clock";
    2239                 break;
    2240             case Power.DPMSignalType.CLOCK_WITH_DATA :
    2241                 signalType = "clockAndData";
    2242                 break;
    2243         }
    2244
    2245         log("setDPMWakeup: " + signalType);
    2246
    2247         if (signalType === null && typeof errorCallback === 'function') {
    2248             var result = {};
    2249             checkErrorCodeNText(result, "PSDW", "Power.setDPMWakeup returns failure. command was not defined.");
    2250             errorCallback(result);
    2251             log("Power.setDPMWakeup invalid ");
    2252             return;
    2253         }
    2254
    2255         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2256             method : "set",
    2257             parameters : {
    2258                 category : "commercial",
    2259                 settings : {
    2260                     "dpmWakeUpControl" : signalType
    2261                 }
    2262             },
    2263             onSuccess : function(result) {
    2264                 log("setDPMWakeup: On Success");
    2265
    2266                 if (result.returnValue === true) {
    2267                     if(typeof successCallback === 'function') {
    2268                         successCallback();
    2269                     }
    2270                 }
    2271             },
    2272             onFailure : function(result) {
    2273                 log("setDPMWakeup: On Failure");
    2274                 delete result.returnValue;
    2275                 if (typeof errorCallback === 'function') {
    2276                     checkErrorCodeNText(result, "PSDW", "Power.setDPMWakeup returns failure.");
    2277                     errorCallback(result);
    2278                 }
    2279             }
    2280         });
    2281
    2282         log("Power.setDPMWakeup Done");
    2283     };
    2284
    2285 	/**
    2286      * Gets DPMWakeup Info, Each <a href="Power.DPMSignalType.html#constructor">DPMSignalType</a> has a set of predefined DPMSignalType properties.
    2287      * @class Power
    2288      * @param {Function} successCallback success callback function.
    2289      * @param {Function} errorCallback failure callback function.
    2290      * @return {Object} options
    2291      * <div align=left>
    2292      * <table class="hcap_spec" width=400>
    2293      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
    2294      *   <tbody>
    2295      *		 <tr><th>dpmSignalType</th><th>String</th><th><a href="Power.DPMSignalType.html#constructor">DPMSignalType</a></th></tr>
    2296      *   </tbody>
    2297      * </table>
    2298      * </div>
    2299      *
    2300 	 * @example
    2301      * // Javascript code
    2302      * function getDPMWakeup () {
    2303 	 *  function successCb(cbObject) {
    2304 	 *     console.log("cbObject : " + JSON.stringify(cbObject));
    2305 	 *     // Do something
    2306 	 *  }
    2307      *
    2308 	 *  function failureCb(cbObject) {
    2309 	 *     var errorCode = cbObject.errorCode;
    2310 	 *     var errorText = cbObject.errorText;
    2311 	 *     console.log ("Error Code [" + errorCode + "]: " + errorText);
    2312 	 *  }
    2313      *
    2314 	 *  var power = new Power();
    2315 	 *  power.getDPMWakeup(successCb, failureCb);
    2316 	 * }
    2317      * @since 1.4
    2318      * @see
    2319      * <a href="Power%23setDPMWakeup.html">Power.setDPMWakeup()</a><br>
    2320      */
    2321 	Power.prototype.getDPMWakeup = function (successCallback, errorCallback) {
    2322
    2323         var ret = { };
    2324         checkErrorCodeNText(ret, "ERROR", "This function is not supported on webOS 3.2");
    2325         errorCallback(ret);
    2326         return;
    2327
    2328         log("getDPMWakeup: ");
    2329
    2330             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2331                 method : "get",
    2332                 parameters : {
    2333                     category : "commercial",
    2334                     keys : ["dpmWakeUpControl"]
    2335                 },
    2336                 onSuccess : function(result) {
    2337                     log("getDPMWakeup: On Success");
    2338
    2339                     if (result.returnValue === true) {
    2340                         var cbObj = {};
    2341                         cbObj.dpmSignalType = result.settings.dpmWakeUpControl;
    2342
    2343                         if (typeof successCallback === 'function') {
    2344                             successCallback(cbObj);
    2345                         }
    2346                     }
    2347                 },
    2348                 onFailure : function(result) {
    2349                     log("getDPMWakeup: On Failure");
    2350                     delete result.returnValue;
    2351                     if (typeof errorCallback === 'function') {
    2352                         checkErrorCodeNText(result, "PGDW", "Power.getDPMWakeup returns failure.");
    2353                         errorCallback(result);
    2354                     }
    2355                 }
    2356             });
    2357
    2358         log("Power.getDPMWakeup Done");
    2359     };
    2360
    2361 	/**
    2362      * Sets PMMode, Each <a href="Power.PMMode.html#constructor">PMMode</a> has a set of predefined PMMode properties.
    2363      * @class Power
    2364      * @param {Function} successCallback success callback function.
    2365      * @param {Function} errorCallback failure callback function.
    2366      * @param {Object} options
    2367      * <div align=left>
    2368      * <table class="hcap_spec" width=400>
    2369      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
    2370      *   <tbody>
    2371      *       <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>
    2372      *   </tbody>
    2373      * </table>
    2374      * </div>
    2375      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
    2376      * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p>
    2377      *
    2378      * @example
    2379      * // Javascript code
    2380      * function setPMMode () {
    2381      *  var options = {};
    2382 	 *  options.mode = "powerOff";
    2383      *
    2384 	 *  function successCb(cbObject) {
    2385 	 *     console.log("sucess");
    2386 	 *     // Do something
    2387 	 *  }
    2388      *
    2389 	 *  function failureCb(cbObject) {
    2390 	 *     var errorCode = cbObject.errorCode;
    2391 	 *     var errorText = cbObject.errorText;
    2392 	 *     console.log ("Error Code [" + errorCode + "]: " + errorText);
    2393 	 *  }
    2394      *
    2395 	 *  var power = new Power();
    2396 	 *  power.setPMMode(successCb, failureCb, options);
    2397 	 * }
    2398      * @since 1.4
    2399      * @see
    2400      * <a href="Power%23getPMMode.html">Power.getPMMode()</a><br>
    2401      */
    2402 	Power.prototype.setPMMode = function (successCallback, errorCallback, options) {
    2403     	var mode = null;
    2404
    2405         switch (options.mode) {
    2406             case Power.PMMode.PowerOff :
    2407                 mode = "powerOff";
    2408                 break;
    2409             case Power.PMMode.SustainAspectRatio :
    2410                 mode = "sustainAspectRatio";
    2411                 break;
    2412             case Power.PMMode.ScreenOff :
    2413                 mode = "screenOff";
    2414                 break;
    2415             case Power.PMMode.ScreenOffAlways :
    2416                 mode = "screenOffAlways";
    2417                 break;
    2418             case Power.PMMode.ScreenOffBacklight :
    2419                 mode = "screenOffBacklight";
    2420                 break;
    2421         }
    2422
    2423         log("setPMMode: " + mode);
    2424
    2425         if (mode === null && typeof errorCallback === 'function') {
    2426             var result = {};
    2427             checkErrorCodeNText(result, "PSPM", "Power.setPMMode returns failure. command was not defined.");
    2428             errorCallback(result);
    2429             log("Power.setPMMode invalid ");
    2430             return;
    2431         }
    2432
    2433         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2434             method : "set",
    2435             parameters : {
    2436                 category : "commercial",
    2437                 settings : {
    2438                     "pmMode" : mode
    2439                 }
    2440             },
    2441             onSuccess : function(result) {
    2442                 log("setPMMode: On Success");
    2443
    2444                 if (result.returnValue === true) {
    2445                     if(typeof successCallback === 'function') {
    2446                         successCallback();
    2447                     }
    2448                 }
    2449             },
    2450             onFailure : function(result) {
    2451                 log("setPMMode: On Failure");
    2452                 delete result.returnValue;
    2453                 if (typeof errorCallback === 'function') {
    2454                     checkErrorCodeNText(result, "PSPM", "Power.setPMMode returns failure.");
    2455                     errorCallback(result);
    2456                 }
    2457             }
    2458         });
    2459
    2460         log("Power.setPMMode Done");
    2461     };
    2462
    2463 	/**
    2464      * Gets PMMode Info, <a href="Power.PMMode.html#constructor">PMMode</a> has a set of predefined PMMode properties.
    2465      * @class Power
    2466      * @param {Function} successCallback success callback function.
    2467      * @param {Function} errorCallback failure callback function.
    2468      * @return {Object} options
    2469      * <div align=left>
    2470      * <table class="hcap_spec" width=400>
    2471      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
    2472      *   <tbody>
    2473      *       <tr><th>mode</th><th>String</th><th><a href="Power.PMMode.html#constructor">PMMode</a></th></tr>
    2474      *   </tbody>
    2475      * </table>
    2476      * </div>
    2477      *
    2478 	 * @example
    2479      * // Javascript code
    2480      * function getPMMode () {
    2481 	 *		function successCb(cbObject) {
    2482 	 *			console.log("cbObject : " + JSON.stringify(cbObject));
    2483 	 *			// Do something
    2484 	 *		}
    2485 	 *		function failureCb(cbObject) {
    2486 	 *			var errorCode = cbObject.errorCode;
    2487 	 *			var errorText = cbObject.errorText;
    2488 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
    2489 	 *			}
    2490 	 *		var power = new Power();
    2491 	 *		power.getPMMode(successCb, failureCb);
    2492 	 * }
    2493      * @since 1.4
    2494      * @see
    2495      * <a href="Power%23setPMMode.html">Power.setPMMode()</a><br>
    2496      */
    2497 	Power.prototype.getPMMode = function (successCallback, errorCallback) {
    2498
    2499         log("getPMMode: ");
    2500
    2501             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2502                 method : "get",
    2503                 parameters : {
    2504                     category : "commercial",
    2505                     keys : ["pmMode"]
    2506                 },
    2507                 onSuccess : function(result) {
    2508                     log("getPMMode: On Success");
    2509
    2510                     if (result.returnValue === true) {
    2511                         var cbObj = {};
    2512                         cbObj.mode = result.settings.pmMode;
    2513
    2514                         if (typeof successCallback === 'function') {
    2515                             successCallback(cbObj);
    2516                         }
    2517                     }
    2518                 },
    2519                 onFailure : function(result) {
    2520                     log("getPMMode: On Failure");
    2521                     delete result.returnValue;
    2522                     if (typeof errorCallback === 'function') {
    2523                         checkErrorCodeNText(result, "PGPM", "Power.getPMMode returns failure.");
    2524                         errorCallback(result);
    2525                     }
    2526                 }
    2527             });
    2528
    2529         log("Power.getPMMode Done");
    2530     };
    2531     /**
    2532      * Sets PowerOnDelay
    2533      * @class Power
    2534      * @param {Function} successCallback success callback function.
    2535      * @param {Function} errorCallback failure callback function.
    2536      * @param {Object} options
    2537      * <div align=left>
    2538      * <table class="hcap_spec" width=400>
    2539      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
    2540      *   <tbody>
    2541      *       <tr><th>delayTime</th><th>Number</th><th>Delay Time (0 ~ 250)</th><th>required</th></tr>
    2542      *   </tbody>
    2543      * </table>
    2544      * </div>
    2545      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
    2546      * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p>
    2547      *
    2548      * @example
    2549      * // Javascript code
    2550      * function setPowerOnDelay () {
    2551      *		var options = {};
    2552 	 *		options.delayTime = 20;
    2553 	 *		function successCb(cbObject) {
    2554 	 *			console.log("sucess");
    2555 	 *			// Do something
    2556 	 *		}
    2557 	 *		function failureCb(cbObject) {
    2558 	 *			var errorCode = cbObject.errorCode;
    2559 	 *			var errorText = cbObject.errorText;
    2560 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
    2561 	 *			}
    2562 	 *		var power = new Power();
    2563 	 *		power.setPowerOnDelay(successCb, failureCb, options);
    2564 	 * }
    2565      * @since 1.4
    2566      * @see
    2567      * <a href="Power%23getPowerOnDelay.html">Power.getPowerOnDelay()</a><br>
    2568      */
    2569     Power.prototype.setPowerOnDelay = function (successCallback, errorCallback, options) {
    2570         log("setPowerOnDelay: " + options.delayTime);
    2571
    2572         if (options.delayTime === null && typeof errorCallback === 'function') {
    2573             var result = {};
    2574             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. command was not defined.");
    2575             errorCallback(result);
    2576             log("Power.setPowerOnDelay invalid ");
    2577             return;
    2578         }
    2579
    2580         if (typeof options.delayTime !== 'number') {
    2581             var result = {};
    2582             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. delayTime is not a number.");
    2583             errorCallback(result);
    2584             log("Power.setPowerOnDelay invalid type");
    2585             return;
    2586         }
    2587
    2588         if ((options.delayTime < 0) || (options.delayTime > 250)) {
    2589             var result = {};
    2590             checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure. Out of range.");
    2591             errorCallback(result);
    2592             log("Power.setPowerOnDelay invalid range");
    2593             return;
    2594         }
    2595
    2596         service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2597             method : "set",
    2598             parameters : {
    2599                 category : "commercial",
    2600                 settings : {
    2601                     "powerOnDelay" : options.delayTime
    2602                 }
    2603             },
    2604             onSuccess : function(result) {
    2605                 log("setPowerOnDelay: On Success");
    2606
    2607                 if (result.returnValue === true) {
    2608                     if(typeof successCallback === 'function') {
    2609                         successCallback();
    2610                     }
    2611                 }
    2612             },
    2613             onFailure : function(result) {
    2614                 log("setPowerOnDelay: On Failure");
    2615                 delete result.returnValue;
    2616                 if (typeof errorCallback === 'function') {
    2617                     checkErrorCodeNText(result, "PSPD", "Power.setPowerOnDelay returns failure.");
    2618                     errorCallback(result);
    2619                 }
    2620             }
    2621         });
    2622
    2623         log("Power.setPowerOnDelay Done");
    2624     };
    2625
    2626 	/**
    2627      * Gets PowerOnDelay
    2628      * @class Power
    2629      * @param {Function} successCallback success callback function.
    2630      * @param {Function} errorCallback failure callback function.
    2631      * @return {Object} options
    2632      * <div align=left>
    2633      * <table class="hcap_spec" width=400>
    2634      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
    2635      *   <tbody>
    2636      *       <tr><th>delayTime</th><th>Number</th><th>Delay Time (0 ~ 250)</th></tr>
    2637      *   </tbody>
    2638      * </table>
    2639      * </div>
    2640      *
    2641 	 * @example
    2642      * // Javascript code
    2643      * function getPowerOnDelay () {
    2644 	 *		function successCb(cbObject) {
    2645 	 *			console.log("cbObject : " + JSON.stringify(cbObject));
    2646 	 *			// Do something
    2647 	 *		}
    2648 	 *		function failureCb(cbObject) {
    2649 	 *			var errorCode = cbObject.errorCode;
    2650 	 *			var errorText = cbObject.errorText;
    2651 	 *			console.log ("Error Code [" + errorCode + "]: " + errorText);
    2652 	 *			}
    2653 	 *		var power = new Power();
    2654 	 *		power.getPowerOnDelay(successCb, failureCb);
    2655 	 * }
    2656      * @since 1.4
    2657      * @see
    2658      * <a href="Power%23setPowerOnDelay.html">Power.setPowerOnDelay()</a><br>
    2659      */
    2660     Power.prototype.getPowerOnDelay = function (successCallback, errorCallback) {
    2661
    2662         log("getPowerOnDelay: ");
    2663
    2664             service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", {
    2665                 method : "get",
    2666                 parameters : {
    2667                     category : "commercial",
    2668                     keys : ["powerOnDelay"]
    2669                 },
    2670                 onSuccess : function(result) {
    2671                     log("getPowerOnDelay: On Success");
    2672
    2673                     if (result.returnValue === true) {
    2674                         var cbObj = {};
    2675                         cbObj.delayTime = result.settings.powerOnDelay;
    2676
    2677                         if (typeof successCallback === 'function') {
    2678                             successCallback(cbObj);
    2679                         }
    2680                     }
    2681                 },
    2682                 onFailure : function(result) {
    2683                     log("getPowerOnDelay: On Failure");
    2684                     delete result.returnValue;
    2685                     if (typeof errorCallback === 'function') {
    2686                         checkErrorCodeNText(result, "PGPD", "Power.getPowerOnDelay returns failure.");
    2687                         errorCallback(result);
    2688                     }
    2689                 }
    2690             });
    2691
    2692         log("Power.getPowerOnDelay Done");
    2693     };
    2694
    2695      /**
    2696      * Gets On/Off Time Schedule
    2697      * @class Time
    2698      * @param {Function} successCallback success callback function.
    2699      * @param {Function} errorCallback failure callback function.
    2700      * @return {Object}
    2701      * <div align=left>
    2702      * <table class="hcap_spec" width=400>
    2703      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
    2704      *   <tbody>
    2705      *       <tr><th>onOffTimeScheduleList[]</th><th>Array</th><th>on/Off Time schedule list</th></tr>
    2706      *       <tr class="odd"><tr><th>onOffTimeScheduleList[]._id</th><th>String</th><th>schedule id</th></tr>
    2707      *       <tr><th>onOffTimeScheduleList[].day</th><th>String</th><th>day</th></tr>
    2708      *       <tr class="odd"><tr><th>onOffTimeScheduleList[].offTime.hour</th><th>Number</th><th>off Time hour</th></tr>
    2709      *       <tr><th>onOffTimeScheduleList[].offTime.minute</th><th>Number</th><th>off Time minute</th></tr>
    2710      *       <tr class="odd"><tr><th>onOffTimeScheduleList[].onTime.hour</th><th>Number</th><th>on Time hour</th></tr>
    2711      *       <tr><th>onOffTimeScheduleList[].onTime.minute</th><th>Number</th><th>on Time minute</th></tr>
    2712      *   </tbody>
    2713      * </table>
    2714      *
    2715      * @example
    2716      * // Javascript code
    2717      *  function getOnOffTimeSchedule () {
    2718      *      function successCb(cbObject) {
    2719      *          console.log("cbObject : " + JSON.stringify(cbObject));
    2720      *          for (var i = cbObject.onOffTimeScheduleList.length-1; i>=0; i--) {
    2721      *              console.log("onOffTimeScheduleList[" + i + "]._id : " + cbObject.onOffTimeScheduleList[i]._id);
    2722      *              console.log("onOffTimeScheduleList[" + i + "].day : " + cbObject.onOffTimeScheduleList[i].day);
    2723      *              console.log("onOffTimeScheduleList[" + i + "].offTime.hour : " + cbObject.onOffTimeScheduleList[i].offTime.hour);
    2724      *              console.log("onOffTimeScheduleList[" + i + "].offTime.minute : " + cbObject.onOffTimeScheduleList[i].offTime.minute);
    2725      *              console.log("onOffTimeScheduleList[" + i + "].onTime.hour : " + cbObject.onOffTimeScheduleList[i].onTime.hour);
    2726      *              console.log("onOffTimeScheduleList[" + i + "].onTime.minute : " + cbObject.onOffTimeScheduleList[i].onTime.minute);
    2727      *          }
    2728      *      }
    2729      *      function failureCb(cbObject) {
    2730      *          var errorCode = cbObject.errorCode;
    2731      *          var errorText = cbObject.errorText;
    2732      *          console.log ("Error Code [" + errorCode + "]: " + errorText);
    2733      *      }
    2734      *      var power = new Power();
    2735      *      power.getOnOffTimeSchedule(successCb, failureCb);
    2736      *  }
    2737      * @since 1.5
    2738      * @see
    2739      * <a href="Power%23setOnOffTimeSchedule.html">Power.setOnOffTimeSchedule()</a><br>
    2740      * <a href="Power%23unsetOnOffTimeSchedule.html">Power.unsetOnOffTimeSchedule()</a><br>
    2741      */
    2742
    2743     Power.prototype.getOnOffTimeSchedule = function (successCallback, errorCallback) {
    2744         log("getOnOffTimeSchedule: ");
    2745
    2746         service.Request("luna://com.webos.service.commercial.signage.storageservice/", {
    2747             method : "getOnOffTimeSchedule",
    2748             parameters: {},
    2749             onSuccess : function(result) {
    2750                 log("getOnOffTimeSchedule: On Success");
    2751
    2752                 if (result.returnValue === true) {
    2753                     if (typeof successCallback === 'function') {
    2754                         var cbObj = {};
    2755                         cbObj.onOffTimeScheduleList = result.settings.onOffTimeSchedule;
    2756
    2757                         if (typeof successCallback === 'function') {
    2758                             successCallback(cbObj);
    2759                         }
    2760                     }
    2761                 }
    2762             },
    2763             onFailure : function(result) {
    2764                 log("getOnOffTimeSchedule: On Failure");
    2765                 delete result.returnValue;
    2766                 if (typeof errorCallback === 'function') {
    2767                     checkErrorCodeNText(result, "TGAS", "Power.getOnOffTimeSchedule returns failure.");
    2768                     errorCallback(result);
    2769                 }
    2770             }
    2771         });
    2772
    2773         log("Power.getOnOffTimeSchedule Done");
    2774     };
    2775
    2776     /**
    2777      * Sets On/Off time schedule
    2778      * @class Time
    2779      * @param {Function} successCallback success callback function.
    2780      * @param {Function} errorCallback failure callback function.
    2781      * @param {Object} options
    2782      * <div align=left>
    2783      * <table class="hcap_spec" width=400>
    2784      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
    2785      *   <tbody>
    2786      *       <tr><th>onOffTimeSchedule[]</th><th>Array</th><th>on/Off Time Schedule list</th></tr>
    2787      *       <tr class="odd"><tr><th>onOffTimeSchedule[].day</th><th>String</th><th>day</th></tr>
    2788      *       <tr><th>onOffTimeSchedule[].onTime.hour</th><th>Number</th><th>onTime hour</th></tr>
    2789      *       <tr class="odd"><tr><th>onOffTimeSchedule[].onTime.minute</th><th>Number</th><th>onTime minute</th></tr>
    2790      *       <tr><th>onOffTimeSchedule[].offTime.hour</th><th>Number</th><th>offTime hour</th></tr>
    2791      *       <tr class="odd"><tr><th>onOffTimeSchedule[].offTime.minute</th><th>Number</th><th>offTime minute</th></tr>
    2792      *   </tbody>
    2793      * </table>
    2794      *
    2795      * @example
    2796      * // Javascript code
    2797      *  function setOnOffTimeSchedule () {
    2798      *      var params = {
    2799      *           "onOffTimeSchedule":[
    2800      *               {
    2801      *                   "day":"fri",
    2802      *                   "onTime":{
    2803      *                       "hour":12,
    2804      *                       "minute":0
    2805      *                   },
    2806      *                   "offTime":{
    2807      *                       "hour":21,
    2808      *                       "minute":0
    2809      *                   }
    2810      *               },
    2811      *               {
    2812      *                   "day":"mon",
    2813      *                   "onTime":{
    2814      *                       "hour":7,
    2815      *                       "minute":0
    2816      *                   },
    2817      *                   "offTime":{
    2818      *                       "hour":18,
    2819      *                       "minute":0
    2820      *                   }
    2821      *               }
    2822      *           ]
    2823      *      }
    2824      *      function successCb(cbObject) {
    2825      *          console.log("success");
    2826      *          // Do something
    2827      *      }
    2828      *      function failureCb(cbObject) {
    2829      *          var errorCode = cbObject.errorCode;
    2830      *          var errorText = cbObject.errorText;
    2831      *          console.log ("Error Code [" + errorCode + "]: " + errorText);
    2832      *      }
    2833      *      var power = new Power();
    2834      *      power.setOnOffTimeSchedule(successCb, failureCb, params);
    2835      *  }
    2836      * @since 1.5
    2837      * @see
    2838      * <a href="Power%23getOnOffTimeSchedule.html">Power.getOnOffTimeSchedule()</a><br>
    2839      * <a href="Power%23unsetOnOffTimeSchedule.html">Power.unsetOnOffTimeSchedule()</a><br>
    2840      */
    2841
    2842     Power.prototype.setOnOffTimeSchedule = function (successCallback, errorCallback, params) {
    2843         log("setOnOffTimeSchedule: ");
    2844
    2845         service.Request("luna://com.webos.service.commercial.signage.storageservice/", {
    2846             method : "setOnOffTimeSchedule",
    2847             parameters : params,
    2848             onSuccess : function(result) {
    2849                 log("setOnOffTimeSchedule: On Success");
    2850
    2851                 if (result.returnValue === true) {
    2852                     if (typeof successCallback === 'function') {
    2853                         if (typeof successCallback === 'function') {
    2854                             successCallback();
    2855                         }
    2856                     }
    2857                 }
    2858             },
    2859             onFailure : function(result) {
    2860                 log("setOnOffTimeSchedule: On Failure");
    2861                 delete result.returnValue;
    2862                 if (typeof errorCallback === 'function') {
    2863                     checkErrorCodeNText(result, "TGAS", "Power.setOnOffTimeSchedule returns failure.");
    2864                     errorCallback(result);
    2865                 }
    2866             }
    2867         });
    2868
    2869         log("Power.setOnOffTimeSchedule Done");
    2870     };
    2871
    2872     /**
    2873      * Unset On/Off time schedule List
    2874      * @class Time
    2875      * @param {Function} successCallback success callback function.
    2876      * @param {Function} errorCallback failure callback function.
    2877      * @return {Object}
    2878      * <div align=left>
    2879      *
    2880      * @example
    2881      * // Javascript code
    2882      *  function unsetOnOffTimeSchedule () {
    2883      *      function successCb(cbObject) {
    2884      *          console.log("success");
    2885      *          // Do something
    2886      *      }
    2887      *      function failureCb(cbObject) {
    2888      *          var errorCode = cbObject.errorCode;
    2889      *          var errorText = cbObject.errorText;
    2890      *          console.log ("Error Code [" + errorCode + "]: " + errorText);
    2891      *      }
    2892      *      var power = new Power();
    2893      *      power.unsetOnOffTimeSchedule(successCb, failureCb);
    2894      *  }
    2895      * @since 1.5
    2896      * @see
    2897      * <a href="Power%23setOnOffTimeSchedule.html">Power.setOnOffTimeSchedule()</a><br>
    2898      * <a href="Power%23getOnOffTimeSchedule.html">Power.getOnOffTimeSchedule()</a><br>
    2899      */
    2900
    2901     Power.prototype.unsetOnOffTimeSchedule = function (successCallback, errorCallback) {
    2902         log("unsetOnOffTimeSchedule: ");
    2903         service.Request("luna://com.webos.service.commercial.signage.storageservice/", {
    2904             method : "unsetOnOffTimeSchedule",
    2905             parameters : {},
    2906             onSuccess : function(result) {
    2907                 log("unsetOnOffTimeSchedule: On Success");
    2908
    2909                 if (result.returnValue === true) {
    2910                     if (typeof successCallback === 'function') {
    2911                         if (typeof successCallback === 'function') {
    2912                             successCallback();
    2913                         }
    2914                     }
    2915                 }
    2916             },
    2917             onFailure : function(result) {
    2918                 log("unsetOnOffTimeSchedule: On Failure");
    2919                 delete result.returnValue;
    2920                 if (typeof errorCallback === 'function') {
    2921                     checkErrorCodeNText(result, "TGAS", "Power.unsetOnOffTimeSchedule returns failure.");
    2922                     errorCallback(result);
    2923                 }
    2924             }
    2925         });
    2926
    2927         log("Power.unsetHolidaySchedule Done");
    2928     };
    2929
    2930     module.exports = Power;
    2931 });
    2932
    2933 Power = cordova.require('cordova/plugin/power'); // jshint ignore:line
    2934
    2935