From 2e666807eb91c6f343bea9063d47a5758dd70fb6 Mon Sep 17 00:00:00 2001 From: crankyoldgit Date: Wed, 26 Jul 2023 16:08:15 +1000 Subject: [PATCH] [BUG] Ensure `IRCoolixAC::toCommon()` returns `kNoTempValue` when no sensor temp is detected. It seems we were reporting an incorrect sensor temp (31) which normally means "There is no sensor temp.", instead of `kNoTempValue`. Fixes #2012 --- src/ir_Coolix.cpp | 3 +++ test/ir_Coolix_test.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/ir_Coolix.cpp b/src/ir_Coolix.cpp index 3fb4e8d0a..6769ebb79 100644 --- a/src/ir_Coolix.cpp +++ b/src/ir_Coolix.cpp @@ -549,6 +549,9 @@ stdAc::state_t IRCoolixAC::toCommon(const stdAc::state_t *prev) const { result.mode = toCommonMode(getMode()); result.degrees = getTemp(); result.sensorTemperature = getSensorTemp(); + if (result.sensorTemperature == kCoolixSensorTempIgnoreCode) { + result.sensorTemperature = kNoTempValue; + } result.iFeel = getZoneFollow(); result.fanspeed = toCommonFanSpeed(getFan()); return result; diff --git a/test/ir_Coolix_test.cpp b/test/ir_Coolix_test.cpp index ba3610bc7..101fab654 100644 --- a/test/ir_Coolix_test.cpp +++ b/test/ir_Coolix_test.cpp @@ -492,6 +492,9 @@ TEST(TestCoolixACClass, SetGetClearSensorTempAndZoneFollow) { EXPECT_EQ( "Power: On, Mode: 3 (Heat), Fan: 6 (Zone Follow), Temp: 24C, " "Zone Follow: On, Sensor Temp: 19C", ac.toString()); + // For #Issue2012 + EXPECT_EQ(19, ac.getSensorTemp()); + EXPECT_EQ(19, ac.toCommon().sensorTemperature); } TEST(TestCoolixACClass, SpecialModesAndReset) { @@ -1068,3 +1071,36 @@ TEST(TestDecodeCoolix48, SyntheticSelfDecode) { "m552s5244", irsend.outputStr()); } + +// Test for issue https://github.com/crankyoldgit/IRremoteESP8266/issues/2012#issuecomment-1650098971 +TEST(TestCoolixACClass, Issue2012) { + IRrecv irrecv(kGpioUnused); + IRCoolixAC ac(kGpioUnused); + + ac.stateReset(); + ac.setRaw(0xB21FD8); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 26C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + + ac.setRaw(0xB21F98); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 27C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + + ac.setRaw(0xB21F88); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 28C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + ac.setRaw(0xB27BE0); + EXPECT_EQ( + "Power: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); +}