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

Coolix: Fix setPower(false) issue. #990

Merged
merged 2 commits into from
Nov 5, 2019
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
28 changes: 12 additions & 16 deletions src/ir_Coolix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ uint32_t IRCoolixAC::getRaw() { return remote_state; }

void IRCoolixAC::setRaw(const uint32_t new_code) {
if (!handleSpecialState(new_code)) {
// it isn`t special so might afect Temp|mode|Fan
// it isn`t special so might affect Temp|mode|Fan
if (new_code == kCoolixCmdFan) {
setMode(kCoolixFan);
} else {
// must be a command changing Temp|Mode|Fan
// it is safe to just copy to remote var
remote_state = new_code;
return;
}
}
// must be a command changing Temp|Mode|Fan
// it is safe to just copy to remote var
remote_state = new_code;
}

// Return true if the current state is a special state.
Expand Down Expand Up @@ -243,17 +243,13 @@ bool IRCoolixAC::getPower() {
}

void IRCoolixAC::setPower(const bool on) {
if (powerFlag) {
if (!on) {
updateSavedState();
remote_state = kCoolixOff;
}
} else {
if (on) {
// at this point remote_state must be ready
// to be transmitted
recoverSavedState();
}
if (!on) {
updateSavedState();
remote_state = kCoolixOff;
} else if (!powerFlag) {
// at this point remote_state must be ready
// to be transmitted
recoverSavedState();
}
powerFlag = on;
}
Expand Down
54 changes: 54 additions & 0 deletions test/ir_Coolix_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017-2018 David Conran

#include "ir_Coolix.h"
#include "IRac.h"
#include "IRsend.h"
#include "IRsend_test.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -746,3 +747,56 @@ TEST(TestCoolixACClass, Issue722) {
// 564,1620,566,1618,562 // Raw data matches what is expected.
"m560s1680m560s1680m560s105040", ac._irsend.outputStr());
}

TEST(TestCoolixACClass, Issue985) {
IRrecv irrecv(0);
IRCoolixAC ac(0);

// Test that if we ONLY turn the power off, it only sends a "power off" mesg.
// i.e. Code from: https://github.com/crankyoldgit/IRremoteESP8266/issues/985#issue-516210106
// First block in the first code included.
ac.setPower(false);
ac.send();

ac._irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decode(&ac._irsend.capture));
EXPECT_EQ(COOLIX, ac._irsend.capture.decode_type);
EXPECT_EQ(kCoolixBits, ac._irsend.capture.bits);
EXPECT_EQ(kCoolixOff, ac._irsend.capture.value);
EXPECT_EQ("Power: Off", IRAcUtils::resultAcToString(&ac._irsend.capture));

ac._irsend.reset();

// Turn the unit on, cool mode, and set the temp.
// Code from: https://github.com/crankyoldgit/IRremoteESP8266/issues/985#issue-516210106
// Second block in the first code included.
uint8_t aircon_temp = 20; // Random value chosen.
ac.setPower(true);
ac.setMode(kCoolixCool);
ac.setTemp(aircon_temp);
ac.send();

ac._irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decode(&ac._irsend.capture));
EXPECT_EQ(COOLIX, ac._irsend.capture.decode_type);
EXPECT_EQ(kCoolixBits, ac._irsend.capture.bits);
EXPECT_NE(kCoolixOff, ac._irsend.capture.value);
EXPECT_EQ(
"Power: On, Mode: 0 (Cool), Fan: 5 (Auto), Temp: 20C, Zone Follow: Off, "
"Sensor Temp: Off", IRAcUtils::resultAcToString(&ac._irsend.capture));

ac._irsend.reset();

// Now repeat the first block again.
// i.e. Code from: https://github.com/crankyoldgit/IRremoteESP8266/issues/985#issue-516210106
// First block in the first code included.
ac.setPower(false);
ac.send();

ac._irsend.makeDecodeResult();
ASSERT_TRUE(irrecv.decode(&ac._irsend.capture));
EXPECT_EQ(COOLIX, ac._irsend.capture.decode_type);
EXPECT_EQ(kCoolixBits, ac._irsend.capture.bits);
EXPECT_EQ(kCoolixOff, ac._irsend.capture.value);
EXPECT_EQ("Power: Off", IRAcUtils::resultAcToString(&ac._irsend.capture));
}