@@ -88,11 +88,8 @@ define(['app'], function (app) {
88
88
if ( bIsWhite == true ) {
89
89
tsettings . hue = 1000 ;
90
90
}
91
- }
92
- else {
93
- if ( $ . isDimmer ) {
94
- tsettings . level = $ ( "#lightcontent #timerparamstable #combolevel" ) . val ( ) ;
95
- }
91
+ } else if ( $ . isDimmer || $ . isSelector ) {
92
+ tsettings . level = $ ( "#lightcontent #timerparamstable #combolevel" ) . val ( ) ;
96
93
}
97
94
}
98
95
return tsettings ;
@@ -235,20 +232,25 @@ define(['app'], function (app) {
235
232
Command = "Off" ;
236
233
}
237
234
var tCommand = Command ;
238
- if ( ( Command == "On" ) && ( $ . isDimmer ) ) {
239
- tCommand += " (" + item . Level + "%)" ;
240
- if ( $ . bIsLED ) {
241
- var hue = item . Hue ;
242
- var sat = 100 ;
243
- if ( hue == 1000 ) {
244
- hue = 0 ;
245
- sat = 0 ;
235
+ if ( ( Command == "On" ) && ( $ . isDimmer || $ . isSelector ) ) {
236
+ if ( $ . isSelector ) {
237
+ tCommand += " (" + $ . selectorSwitchLevels [ item . Level / 10 ] + ")" ;
238
+
239
+ } else {
240
+ tCommand += " (" + item . Level + "%)" ;
241
+ if ( $ . bIsLED ) {
242
+ var hue = item . Hue ;
243
+ var sat = 100 ;
244
+ if ( hue == 1000 ) {
245
+ hue = 0 ;
246
+ sat = 0 ;
247
+ }
248
+ var cHSB = [ ] ;
249
+ cHSB . h = hue ;
250
+ cHSB . s = sat ;
251
+ cHSB . b = item . Level ;
252
+ tCommand += '<div id="picker4" class="ex-color-box" style="background-color: #' + $ . colpickHsbToHex ( cHSB ) + ';"></div>' ;
246
253
}
247
- var cHSB = [ ] ;
248
- cHSB . h = hue ;
249
- cHSB . s = sat ;
250
- cHSB . b = item . Level ;
251
- tCommand += '<div id="picker4" class="ex-color-box" style="background-color: #' + $ . colpickHsbToHex ( cHSB ) + ';"></div>' ;
252
254
}
253
255
}
254
256
@@ -357,7 +359,8 @@ define(['app'], function (app) {
357
359
$ ( "#lightcontent #timerparamstable #combotimehour" ) . val ( parseInt ( data [ "3" ] . substring ( 0 , 2 ) ) ) ;
358
360
$ ( "#lightcontent #timerparamstable #combotimemin" ) . val ( parseInt ( data [ "3" ] . substring ( 3 , 5 ) ) ) ;
359
361
$ ( '#lightcontent #timerparamstable #randomness' ) . prop ( 'checked' , ( data [ "Random" ] == "Yes" ) ? true : false ) ;
360
- $ ( "#lightcontent #timerparamstable #combocommand" ) . val ( jQuery . inArray ( data [ "Command" ] , $ . myglobals . CommandStr ) ) ;
362
+ var command = jQuery . inArray ( data [ "Command" ] , $ . myglobals . CommandStr ) ;
363
+ $ ( "#lightcontent #timerparamstable #combocommand" ) . val ( command ) ;
361
364
var level = data [ "Level" ] ;
362
365
if ( $ . bIsLED ) {
363
366
$ ( '#lightcontent #Brightness' ) . val ( level & 255 ) ;
@@ -378,8 +381,12 @@ define(['app'], function (app) {
378
381
379
382
$ ( '#lightcontent #picker' ) . colpickSetColor ( cHSB ) ;
380
383
}
381
- else if ( $ . isDimmer ) {
384
+ else if ( $ . isDimmer || $ . isSelector ) {
385
+ $ ( "#lightcontent #LevelDiv" ) . hide ( ) ;
382
386
$ ( "#lightcontent #timerparamstable #combolevel" ) . val ( level ) ;
387
+ if ( command === 0 ) { // On
388
+ $ ( "#lightcontent #LevelDiv" ) . show ( ) ;
389
+ }
383
390
}
384
391
385
392
var timerType = data [ "TType" ] ;
@@ -419,18 +426,29 @@ define(['app'], function (app) {
419
426
$ ( '#modal' ) . hide ( ) ;
420
427
}
421
428
422
- ShowTimers = function ( id , name , isdimmer , stype , devsubtype )
429
+ ShowTimers = function ( id , name , isdimmer , stype , devsubtype )
423
430
{
424
431
if ( typeof $scope . mytimer != 'undefined' ) {
425
432
$interval . cancel ( $scope . mytimer ) ;
426
433
$scope . mytimer = undefined ;
427
434
}
428
435
$ . devIdx = id ;
429
436
$ . isDimmer = isdimmer ;
437
+ $ . isSelector = ( devsubtype === "Selector Switch" ) ;
430
438
431
439
$ . bIsRGBW = ( devsubtype . indexOf ( "RGBW" ) >= 0 ) ;
432
440
$ . bIsLED = ( devsubtype . indexOf ( "RGB" ) >= 0 ) ;
433
441
442
+ if ( $ . isSelector ) {
443
+ // backup selector switch level names before displaying edit edit form
444
+ $ . selectorSwitchLevels = [ ] ;
445
+ $ ( "#selector" + $ . devIdx + " label" ) . each ( function ( index , item ) {
446
+ $ . selectorSwitchLevels . push ( $ ( item ) . text ( ) ) ;
447
+ } ) ;
448
+ $ ( "#selector" + $ . devIdx + " option" ) . each ( function ( index , item ) {
449
+ $ . selectorSwitchLevels . push ( $ ( item ) . text ( ) ) ;
450
+ } ) ;
451
+ }
434
452
var oTable ;
435
453
436
454
$ ( '#modal' ) . show ( ) ;
@@ -568,30 +586,63 @@ define(['app'], function (app) {
568
586
} ) ;
569
587
570
588
$ ( "#lightcontent #timerparamstable #combocommand" ) . change ( function ( ) {
571
- var cval = $ ( "#lightcontent #timerparamstable #combocommand" ) . val ( ) ;
572
- var bShowLevel = false ;
589
+ var cval = $ ( "#lightcontent #timerparamstable #combocommand" ) . val ( ) ,
590
+ lval = $ ( "#lightcontent #timerparamstable #combolevel" ) . val ( ) ,
591
+ bShowLevel = false ;
573
592
if ( ! $ . bIsLED ) {
574
- if ( $ . isDimmer ) {
593
+ if ( $ . isDimmer || $ . isSelector ) {
575
594
if ( cval == 0 ) {
576
595
bShowLevel = true ;
577
596
}
578
597
}
579
598
}
580
599
if ( bShowLevel == true ) {
600
+ if ( lval == null ) {
601
+ if ( $ . isSelector ) {
602
+ $ ( "#lightcontent #timerparamstable #combolevel" ) . val ( 10 ) ; // first selector level value
603
+ } else {
604
+ $ ( "#lightcontent #timerparamstable #combolevel" ) . val ( 5 ) ; // first dimmer level value
605
+ }
606
+ }
581
607
$ ( "#lightcontent #LevelDiv" ) . show ( ) ;
582
608
}
583
609
else {
584
610
$ ( "#lightcontent #LevelDiv" ) . hide ( ) ;
585
611
}
586
612
} ) ;
587
613
588
- if ( ( $ . isDimmer ) && ( ! $ . bIsLED ) ) {
614
+ if ( ( $ . isDimmer ) && ( ! $ . bIsLED ) ) {
589
615
$ ( "#lightcontent #LevelDiv" ) . show ( ) ;
590
- }
591
- else {
616
+
617
+ } else if ( $ . isSelector ) {
618
+ // Replace dimmer levels by selector level names
619
+ var levelDiv$ = $ ( "#lightcontent #LevelDiv" ) ,
620
+ html = [ ] ;
621
+ $ . each ( $ . selectorSwitchLevels , function ( index , item ) {
622
+ var level = index * 10 ,
623
+ levelName = item ;
624
+ if ( level === 0 ) {
625
+ return ;
626
+ }
627
+ html . push ( '<option value="' ) ;
628
+ html . push ( level ) ;
629
+ html . push ( '">' ) ;
630
+ html . push ( levelName ) ;
631
+ html . push ( '</option>' ) ;
632
+ } ) ;
633
+ levelDiv$ . find ( 'select' )
634
+ . attr ( 'style' , '' )
635
+ . css ( { 'width' : 'auto' } )
636
+ . html ( html . join ( '' ) ) ;
637
+ levelDiv$ . find ( 'span[data-i18n="Level"]' )
638
+ . attr ( 'data-i18n' , "Level name" )
639
+ . html ( $ . t ( "Level name" ) ) ;
640
+ levelDiv$ . show ( ) ;
641
+
642
+ } else {
592
643
$ ( "#lightcontent #LevelDiv" ) . hide ( ) ;
593
644
}
594
-
645
+
595
646
$ ( '#modal' ) . hide ( ) ;
596
647
RefreshTimerTable ( id ) ;
597
648
}
0 commit comments