From 7838ff6439393a883b1d6ecf6007d351e21ba5b8 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Sat, 12 Jun 2021 00:37:43 +0200 Subject: [PATCH] Kelon: Add utility method to ensure power on/off --- src/ir_Kelon.cpp | 27 +++++++++++++++++++++++++++ src/ir_Kelon.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/src/ir_Kelon.cpp b/src/ir_Kelon.cpp index 1e6fd9b2c..d9cf98e6c 100644 --- a/src/ir_Kelon.cpp +++ b/src/ir_Kelon.cpp @@ -122,6 +122,33 @@ void IRKelonAC::send(const uint16_t repeat) { _.TimerHalfHour = 0; } +/// Ensures the AC is on or off by exploiting the fact that setting +/// it to "smart" will always turn it on if it's off. +/// This method will send 2 commands to ensure the AC is on, 3 to +/// ensure it is off. +/// @param[in] on Whether to ensure the AC is on or off +void IRKelonAC::ensurePower(bool on) { + // Try to avoid turning on the compressor for this operation. + // "Dry grade", when in "smart" mode, acts as a temperature offset that + // the user can configure if they feel too cold or too hot. By setting it + // to +2 we're setting the temperature to ~28°C, which will effectively + // set the AC to fan mode. + int8_t previousDry = getDryGrade(); + setDryGrade(2); + setMode(kKelonModeSmart); + send(); + + setDryGrade(previousDry); + setMode(_previousMode); + send(); + + // Now we're sure it's on. Turn it back off. + if (!on) { + setTogglePower(true); + send(); + } +} + #endif // SEND_KELON /// Set up hardware to be able to send a message. diff --git a/src/ir_Kelon.h b/src/ir_Kelon.h index 26be2e6c2..0784c2d6c 100644 --- a/src/ir_Kelon.h +++ b/src/ir_Kelon.h @@ -81,6 +81,12 @@ class IRKelonAC { /// Only ever needs to be run once per object instantiation, if at all. int8_t calibrate() { return _irsend.calibrate(); } + /// Since the AC does not support actually setting the power state to a known + /// value, this utility allow ensuring the AC is on or off by exploiting + /// the fact that the AC, according to the user manual, will always turn on + /// when setting it to "smart" or "super" mode. + void ensurePower(bool on); + #endif