Skip to content

Commit

Permalink
Coolix: Improve ZoneFollow mode setting and detection.
Browse files Browse the repository at this point in the history
Includes unit test for detection.

Ref: #1318 (comment)
  • Loading branch information
crankyoldgit committed Nov 18, 2020
1 parent a2d18df commit 7f46bad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/ir_Coolix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ IRCoolixAC::IRCoolixAC(const uint16_t pin, const bool inverted,
/// Reset the internal state to a fixed known good state.
void IRCoolixAC::stateReset(void) {
setRaw(kCoolixDefaultState);
savedFan = getFan();
clearSensorTemp();
powerFlag = false;
turboFlag = false;
Expand Down Expand Up @@ -240,6 +241,8 @@ void IRCoolixAC::setSensorTempRaw(const uint8_t code) { _.SensorTemp = code; }

/// Set the sensor temperature.
/// @param[in] temp The temperature in degrees celsius.
/// @warning Do not send messages with a Sensor Temp more frequently than once
/// per minute, otherwise the A/C unit will ignore them.
void IRCoolixAC::setSensorTemp(const uint8_t temp) {
setSensorTempRaw(std::min(temp, kCoolixSensorTempMax));
setZoneFollow(true); // Setting a Sensor temp means you want to Zone Follow.
Expand Down Expand Up @@ -336,15 +339,17 @@ void IRCoolixAC::setClean(void) {

/// Get the Zone Follow setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRCoolixAC::getZoneFollow(void) const { return zoneFollowFlag; }
bool IRCoolixAC::getZoneFollow(void) const {
return _.ZoneFollow1 && _.ZoneFollow2;
}

/// Change the Zone Follow setting.
/// @note Internal use only.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRCoolixAC::setZoneFollow(const bool on) {
zoneFollowFlag = on;
_.ZoneFollow1 = on;
_.ZoneFollow2 = on;
setFan(on ? kCoolixFanZoneFollow : savedFan);
}

/// Clear the Sensor Temperature setting..
Expand Down Expand Up @@ -429,6 +434,8 @@ void IRCoolixAC::setFan(const uint8_t speed, const bool modecheck) {
newspeed = kCoolixFanAuto;
break;
}
// Keep a copy of the last non-ZoneFollow fan setting.
savedFan = (_.Fan == kCoolixFanZoneFollow) ? savedFan : _.Fan;
_.Fan = newspeed;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Coolix.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class IRCoolixAC {
bool ledFlag;
bool cleanFlag;
bool sleepFlag;
bool zoneFollowFlag;
bool swingFlag;
uint8_t savedFan;

void setTempRaw(const uint8_t code);
uint8_t getTempRaw(void) const;
Expand Down
7 changes: 7 additions & 0 deletions test/ir_Coolix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ TEST(TestCoolixACClass, SetGetClearSensorTempAndZoneFollow) {
ircoolix.clearSensorTemp();
EXPECT_FALSE(ircoolix.getZoneFollow());
EXPECT_LT(kCoolixSensorTempMax, ircoolix.getSensorTemp());

// toString.
// For https://github.com/crankyoldgit/IRremoteESP8266/issues/1318#issuecomment-729663834
ircoolix.setRaw(0xBAD34E);
EXPECT_EQ(
"Power: On, Mode: 3 (Heat), Fan: 6 (Zone Follow), Temp: 24C, "
"Zone Follow: On, Sensor Temp: 19C", ircoolix.toString());
}

TEST(TestCoolixACClass, SpecialModesAndReset) {
Expand Down

0 comments on commit 7f46bad

Please sign in to comment.