Skip to content

Commit fc5fe6b

Browse files
committed
Merge pull request #567 from gaudryc/fix_some_selector_switch_misses
Fix some selector switch misses
2 parents 2b21484 + 333061a commit fc5fe6b

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

main/WebServer.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,7 +3466,7 @@ namespace http {
34663466
root["status"] = "OK";
34673467
root["title"] = "GetLightSwitches";
34683468
std::vector<std::vector<std::string> > result;
3469-
result = m_sql.safe_query("SELECT ID, Name, Type, SubType, Used, SwitchType FROM DeviceStatus ORDER BY Name");
3469+
result = m_sql.safe_query("SELECT ID, Name, Type, SubType, Used, SwitchType, Options FROM DeviceStatus ORDER BY Name");
34703470
if (result.size() > 0)
34713471
{
34723472
std::vector<std::vector<std::string> >::const_iterator itt;
@@ -3481,6 +3481,7 @@ namespace http {
34813481
int SubType = atoi(sd[3].c_str());
34823482
int used = atoi(sd[4].c_str());
34833483
_eSwitchType switchtype = (_eSwitchType)atoi(sd[5].c_str());
3484+
std::map<std::string, std::string> options = m_sql.BuildDeviceOptions(sd[6]);
34843485
bool bdoAdd=false;
34853486
switch (Type)
34863487
{
@@ -3528,9 +3529,28 @@ namespace http {
35283529
bool bIsDimmer = (
35293530
(switchtype == STYPE_Dimmer) ||
35303531
(switchtype == STYPE_BlindsPercentage) ||
3531-
(switchtype == STYPE_BlindsPercentageInverted)
3532+
(switchtype == STYPE_BlindsPercentageInverted) ||
3533+
(switchtype == STYPE_Selector)
35323534
);
35333535
root["result"][ii]["IsDimmer"] = bIsDimmer;
3536+
std::string dimmerLevels = bIsDimmer ? "all" : "none";
3537+
if (switchtype == STYPE_Selector) {
3538+
std::stringstream ss;
3539+
std::map<std::string, std::string> selectorStatuses;
3540+
GetSelectorSwitchStatuses(options, selectorStatuses);
3541+
bool levelOffHidden = options["LevelOffHidden"] == "true";
3542+
for(int i = 0; i < selectorStatuses.size(); i++) {
3543+
if (levelOffHidden && (i == 0)) {
3544+
continue;
3545+
}
3546+
if((levelOffHidden && (i > 1)) || (i > 0)) {
3547+
ss << ",";
3548+
}
3549+
ss << i * 10;
3550+
}
3551+
dimmerLevels = ss.str();
3552+
}
3553+
root["result"][ii]["DimmerLevels"] = dimmerLevels;
35343554
ii++;
35353555
}
35363556
break;

main/mainworker.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11682,6 +11682,15 @@ bool MainWorker::SwitchScene(const unsigned long long idx, const std::string &sw
1168211682
fLevel=100;
1168311683
ilevel=round(fLevel)+1;
1168411684
}
11685+
if (switchtype == STYPE_Selector) {
11686+
if (lstatus != "Set Level") {
11687+
ilevel = 0;
11688+
}
11689+
ilevel = round(ilevel/10.0f)*10; // select only multiples of 10
11690+
if (ilevel == 0) {
11691+
lstatus ="Off";
11692+
}
11693+
}
1168511694
}
1168611695

1168711696
int idx = atoi(sd[0].c_str());

www/app/DevicesController.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ define(['app'], function (app) {
269269
else {
270270
itemImage='<img src="images/push.png" title="Turn On" onclick="SwitchScene(' + item.idx + ',\'On\',ShowDevices);" class="lcursor">';
271271
}
272+
} else if (item.SubType === "Selector Switch") {
273+
var imagePath;
274+
if (item.CustomImage !== 0) {
275+
imagePath = (this.levelName === "Off") ? "images/" + item.Image + "48_Off.png" : "images/" + item.Image + "48_On.png";
276+
} else {
277+
imagePath = (this.levelName === "Off") ? "images/" + item.TypeImg + "48_Off.png" : "images/" + item.TypeImg + "48_On.png";
278+
}
279+
itemImage = '<img src="' + imagePath + '" width="16" height="16">';
272280
}
273281
if ((item.Type == "Group")||(item.Type == "Scene")) {
274282
itemSubIcons+='&nbsp;<img src="images/empty16.png">';

www/app/ScenesController.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,24 +566,29 @@ define(['app'], function (app) {
566566
}
567567
var bShowLevel=false;
568568
var bIsLED=false;
569+
var dimmerLevels = "none";
569570
$.each($.LightsAndSwitches, function(i,item){
570571
if (item.idx==DeviceIdx) {
571572
bShowLevel=item.isdimmer;
572573
bIsLED=(item.SubType.indexOf("RGB") >= 0);
574+
dimmerLevels = item.DimmerLevels;
573575
}
574576
});
575577

578+
$("#scenecontent #LedColor").hide();
579+
$("#scenecontent #LevelDiv").hide();
576580
if (bIsLED) {
577581
$("#scenecontent #LedColor").show();
578-
$("#scenecontent #LevelDiv").hide();
579-
}
580-
else {
581-
$("#scenecontent #LedColor").hide();
582+
} else {
582583
if (bShowLevel==true) {
583-
$("#scenecontent #LevelDiv").show();
584-
}
585-
else {
586-
$("#scenecontent #LevelDiv").hide();
584+
var levelDiv$ = $("#scenecontent #LevelDiv");
585+
levelDiv$.find("option").show().end().show();
586+
if (dimmerLevels !== "all") {
587+
levelDiv$.find("option").hide();
588+
$.each(dimmerLevels.split(','), function(i, level) {
589+
levelDiv$.find("option[value=\"" + level + "\"]").show();
590+
});
591+
}
587592
}
588593
}
589594
}
@@ -718,7 +723,8 @@ define(['app'], function (app) {
718723
idx: item.idx,
719724
name: item.Name,
720725
SubType: item.SubType,
721-
isdimmer: item.IsDimmer
726+
isdimmer: item.IsDimmer,
727+
DimmerLevels: item.DimmerLevels
722728
}
723729
);
724730
});

www/html5.appcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# ref 1233
2+
# ref 1234
33

44
CACHE:
55
# CSS

0 commit comments

Comments
 (0)