Skip to content

Commit

Permalink
LG2: Improve Light toggle msg handling. (#1738)
Browse files Browse the repository at this point in the history
Don't override previous settings if the current message being processed is a Light Toggle message.

Confirmed working.

Fixes #1737
  • Loading branch information
crankyoldgit authored Jan 18, 2022
1 parent 9228143 commit 030b403
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ir_LG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,18 @@ stdAc::state_t IRLgAc::toCommon(const stdAc::state_t *prev) const {
result.swingv = toCommonSwingV(getSwingV());
}
result.protocol = _protocol;
if (isLightToggle()) {
result.light = !result.light;
return result;
} else {
result.light = _light;
}
result.model = getModel();
result.power = getPower();
result.mode = toCommonMode(_.Mode);
result.celsius = true;
result.degrees = getTemp();
result.fanspeed = toCommonFanSpeed(_.Fan);
result.light = isLightToggle() ? !result.light : _light;
if (isSwingV()) result.swingv = toCommonSwingV(getSwingV());
if (isVaneSwingV())
result.swingv = toCommonVaneSwingV(VANESWINGVPOS(getVaneCode(_.raw)));
Expand Down
37 changes: 37 additions & 0 deletions test/ir_LG_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,40 @@ TEST(TestIRLgAcClass, SwingVOffAfterAuto) {
ASSERT_EQ("Model: 3 (AKB74955603), Swing(V): 21 (Off)",
IRAcUtils::resultAcToString(&ac._irsend.capture));
}

TEST(TestIRLgAcClass, Issue1737) {
// Simulate getting a light toggle while the ac class/prev state thinks the
// device is on.
IRLgAc ac(kGpioUnused);
ac.begin();

ac.setModel(lg_ac_remote_model_t::AKB74955603);
ac.setPower(true);
ac.setMode(kLgAcFan);
ac.setTemp(18);
ac.setFan(kLgAcFanLowest);
stdAc::state_t prev = ac.toCommon();
EXPECT_TRUE(prev.power);
EXPECT_TRUE(ac.toCommon().power);
EXPECT_TRUE(ac.toCommon(&prev).power);

ac.setRaw(kLgAcLightToggle);
EXPECT_TRUE(ac.isLightToggle());

EXPECT_FALSE(ac.toCommon().power); // No previous state, so should be false.
EXPECT_TRUE(ac.toCommon(&prev).power);

// A better simulation of the desired use case.
IRsendTest irsend(kGpioUnused);
IRrecv capture(kGpioUnused);
irsend.begin();
irsend.reset();
irsend.sendLG2(kLgAcLightToggle);
irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&irsend.capture));
ASSERT_EQ(LG2, irsend.capture.decode_type); // Not "LG"
ASSERT_EQ(kLgBits, irsend.capture.bits);
stdAc::state_t result;
ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev));
EXPECT_TRUE(result.power);
}

0 comments on commit 030b403

Please sign in to comment.