Skip to content

Commit 386e2c6

Browse files
authored
Merge pull request #4528 from blazoncek/ir-bugfix
Fix for "Send notifications on button press or IR" does not work when using "JSON remote" #4519
2 parents 4d53e0a + 1e1ba9a commit 386e2c6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

wled00/ir.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,15 @@ static void decodeIRJson(uint32_t code)
611611
handleSet(nullptr, cmdStr, false); // no stateUpdated() call here
612612
}
613613
} else {
614-
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)
615-
if (jsonCmdObj[F("psave")].isNull()) deserializeState(jsonCmdObj, CALL_MODE_BUTTON_PRESET);
616-
else {
614+
// command is JSON object
615+
if (jsonCmdObj[F("psave")].isNull()) {
616+
if (irApplyToAllSelected && jsonCmdObj["seg"].is<JsonArray>()) {
617+
JsonObject seg = jsonCmdObj["seg"][0]; // take 1st segment from array and use it to apply to all selected segments
618+
seg.remove("id"); // remove segment ID if it exists
619+
jsonCmdObj["seg"] = seg; // replace array with object
620+
}
621+
deserializeState(jsonCmdObj, CALL_MODE_BUTTON_PRESET); // **will call stateUpdated() with correct CALL_MODE**
622+
} else {
617623
uint8_t psave = jsonCmdObj[F("psave")].as<int>();
618624
char pname[33];
619625
sprintf_P(pname, PSTR("IR Preset %d"), psave);
@@ -628,6 +634,7 @@ static void applyRepeatActions()
628634
{
629635
if (irEnabled == 8) {
630636
decodeIRJson(lastValidCode);
637+
stateUpdated(CALL_MODE_BUTTON_PRESET);
631638
return;
632639
} else switch (lastRepeatableAction) {
633640
case ACTION_BRIGHT_UP : incBrightness(); stateUpdated(CALL_MODE_BUTTON); return;
@@ -664,7 +671,7 @@ static void decodeIR(uint32_t code)
664671

665672
if (irEnabled == 8) { // any remote configurable with ir.json file
666673
decodeIRJson(code);
667-
stateUpdated(CALL_MODE_BUTTON);
674+
stateUpdated(CALL_MODE_BUTTON_PRESET);
668675
return;
669676
}
670677
if (code > 0xFFFFFF) return; //invalid code

0 commit comments

Comments
 (0)