Skip to content

Commit e9c440d

Browse files
committed
Fix planning feature for Selector Switch
1 parent 484d6e0 commit e9c440d

File tree

2 files changed

+86
-28
lines changed

2 files changed

+86
-28
lines changed

main/Scheduler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ void CScheduler::CheckSchedules()
507507
fLevel = 100;
508508
ilevel = int(fLevel);
509509
}
510+
} else if (switchtype == STYPE_Selector) {
511+
if (itt->timerCmd == TCMD_ON) {
512+
switchcmd = "Set Level";
513+
ilevel = itt->Level;
514+
} else if (itt->timerCmd == TCMD_OFF) {
515+
ilevel = 0; // force level to a valid value for Selector
516+
}
510517
}
511518
if (!m_mainworker.SwitchLight(itt->RowID, switchcmd, ilevel, itt->Hue,false,0))
512519
{

www/app/LightsController.js

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ define(['app'], function (app) {
8888
if (bIsWhite==true) {
8989
tsettings.hue=1000;
9090
}
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();
9693
}
9794
}
9895
return tsettings;
@@ -235,20 +232,25 @@ define(['app'], function (app) {
235232
Command="Off";
236233
}
237234
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>';
246253
}
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>';
252254
}
253255
}
254256

@@ -357,7 +359,8 @@ define(['app'], function (app) {
357359
$("#lightcontent #timerparamstable #combotimehour").val(parseInt(data["3"].substring(0,2)));
358360
$("#lightcontent #timerparamstable #combotimemin").val(parseInt(data["3"].substring(3,5)));
359361
$('#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);
361364
var level=data["Level"];
362365
if ($.bIsLED) {
363366
$('#lightcontent #Brightness').val(level&255);
@@ -378,8 +381,12 @@ define(['app'], function (app) {
378381

379382
$('#lightcontent #picker').colpickSetColor(cHSB);
380383
}
381-
else if ($.isDimmer) {
384+
else if ($.isDimmer || $.isSelector) {
385+
$("#lightcontent #LevelDiv").hide();
382386
$("#lightcontent #timerparamstable #combolevel").val(level);
387+
if (command === 0) { // On
388+
$("#lightcontent #LevelDiv").show();
389+
}
383390
}
384391

385392
var timerType=data["TType"];
@@ -419,18 +426,29 @@ define(['app'], function (app) {
419426
$('#modal').hide();
420427
}
421428

422-
ShowTimers = function (id,name, isdimmer, stype,devsubtype)
429+
ShowTimers = function (id,name, isdimmer, stype, devsubtype)
423430
{
424431
if (typeof $scope.mytimer != 'undefined') {
425432
$interval.cancel($scope.mytimer);
426433
$scope.mytimer = undefined;
427434
}
428435
$.devIdx=id;
429436
$.isDimmer=isdimmer;
437+
$.isSelector = (devsubtype === "Selector Switch");
430438

431439
$.bIsRGBW=(devsubtype.indexOf("RGBW") >= 0);
432440
$.bIsLED=(devsubtype.indexOf("RGB") >= 0);
433441

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+
}
434452
var oTable;
435453

436454
$('#modal').show();
@@ -568,30 +586,63 @@ define(['app'], function (app) {
568586
});
569587

570588
$("#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;
573592
if (!$.bIsLED) {
574-
if ($.isDimmer) {
593+
if ($.isDimmer || $.isSelector) {
575594
if (cval==0) {
576595
bShowLevel=true;
577596
}
578597
}
579598
}
580599
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+
}
581607
$("#lightcontent #LevelDiv").show();
582608
}
583609
else {
584610
$("#lightcontent #LevelDiv").hide();
585611
}
586612
});
587613

588-
if (($.isDimmer)&&(!$.bIsLED)) {
614+
if (($.isDimmer) && (!$.bIsLED)) {
589615
$("#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 {
592643
$("#lightcontent #LevelDiv").hide();
593644
}
594-
645+
595646
$('#modal').hide();
596647
RefreshTimerTable(id);
597648
}

0 commit comments

Comments
 (0)