Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG2: Improve Light toggle msg handling. #1738

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}