Skip to content

Commit

Permalink
MitsubishiAC: Add support for enabling Weekly Timer. (#1404)
Browse files Browse the repository at this point in the history
* Add `[s|g]etWeeklyTimerEnabled()`.
* Unit test coverage based on real data.
* Add comment on how to add Weekly Timer enabling by default via `IRac` class.

Fixes #1403
  • Loading branch information
crankyoldgit authored Feb 4, 2021
1 parent ab466e4 commit 991bed8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,8 @@ void IRac::mitsubishi(IRMitsubishiAC *ac,
const stdAc::swingh_t swingh,
const bool quiet, const int16_t clock) {
ac->begin();
// Uncomment next line if you *really* need the weekly timer enabled via IRac.
// ac->setWeeklyTimerEnabled(true); // Weekly Timer is disabled by default.
ac->setPower(on);
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
Expand Down
11 changes: 11 additions & 0 deletions src/ir_Mitsubishi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@ stdAc::state_t IRMitsubishiAC::toCommon(void) const {
return result;
}

/// Change the Weekly Timer Enabled setting.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRMitsubishiAC::setWeeklyTimerEnabled(const bool on) {
_.WeeklyTimer = on;
}

/// Get the value of the WeeklyTimer Enabled setting.
/// @return true, the setting is on. false, the setting is off.
bool IRMitsubishiAC::getWeeklyTimerEnabled(void) const { return _.WeeklyTimer; }

/// Convert the internal state into a human readable string.
/// @return A string containing the settings in human-readable form.
String IRMitsubishiAC::toString(void) const {
Expand Down Expand Up @@ -822,6 +832,7 @@ String IRMitsubishiAC::toString(void) const {
result += _.Timer;
result += ')';
}
result += addBoolToString(_.WeeklyTimer, kWeeklyTimerStr);
return result;
}

Expand Down
7 changes: 5 additions & 2 deletions src/ir_Mitsubishi.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ union Mitsubishi144Protocol{
// Byte 12
uint8_t StartClock:8;
// Byte 13
uint8_t Timer :3;
uint8_t :5;
uint8_t Timer :3;
uint8_t WeeklyTimer :1;
uint8_t :4;
// Byte 14~16
uint8_t pad1[3];
// Byte 17
Expand Down Expand Up @@ -277,6 +278,8 @@ class IRMitsubishiAC {
void setStopClock(const uint8_t clock);
uint8_t getTimer(void) const;
void setTimer(const uint8_t timer);
bool getWeeklyTimerEnabled(void) const;
void setWeeklyTimerEnabled(const bool on);
static uint8_t convertMode(const stdAc::opmode_t mode);
static uint8_t convertFan(const stdAc::fanspeed_t speed);
static uint8_t convertSwingV(const stdAc::swingv_t position);
Expand Down
3 changes: 2 additions & 1 deletion test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ TEST(TestIRac, Mitsubishi) {
char expected[] =
"Power: On, Mode: 3 (Cool), Temp: 20C, Fan: 2 (Medium), "
"Swing(V): 0 (Auto), Swing(H): 3 (Middle), "
"Clock: 14:30, On Timer: 00:00, Off Timer: 00:00, Timer: -";
"Clock: 14:30, On Timer: 00:00, Off Timer: 00:00, Timer: -, "
"Weekly Timer: Off";

ac.begin();
irac.mitsubishi(&ac,
Expand Down
35 changes: 32 additions & 3 deletions test/ir_Mitsubishi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,13 +1018,16 @@ TEST(TestMitsubishiACClass, HumanReadable) {
EXPECT_EQ(
"Power: On, Mode: 1 (Heat), Temp: 22C, Fan: 6 (Quiet), "
"Swing(V): 0 (Auto), Swing(H): 3 (Middle), "
"Clock: 17:10, On Timer: 00:00, Off Timer: 00:00, Timer: -",
"Clock: 17:10, On Timer: 00:00, Off Timer: 00:00, Timer: -, "
"Weekly Timer: Off",
ac.toString());
ac.setTemp(21.5);
ac.setWeeklyTimerEnabled(true);
EXPECT_EQ(
"Power: On, Mode: 1 (Heat), Temp: 21.5C, Fan: 6 (Quiet), "
"Swing(V): 0 (Auto), Swing(H): 3 (Middle), "
"Clock: 17:10, On Timer: 00:00, Off Timer: 00:00, Timer: -",
"Clock: 17:10, On Timer: 00:00, Off Timer: 00:00, Timer: -, "
"Weekly Timer: On",
ac.toString());
}

Expand Down Expand Up @@ -1536,7 +1539,8 @@ TEST(TestDecodeMitsubishiAC, Issue891) {
EXPECT_EQ(
"Power: Off, Mode: 3 (Cool), Temp: 24C, Fan: 0 (Auto), "
"Swing(V): 0 (Auto), Swing(H): 3 (Middle), "
"Clock: 00:00, On Timer: 00:00, Off Timer: 00:00, Timer: -",
"Clock: 00:00, On Timer: 00:00, Off Timer: 00:00, Timer: -, "
"Weekly Timer: Off",
ac.toString());
}

Expand Down Expand Up @@ -1783,3 +1787,28 @@ TEST(TestMitsubishiACClass, Issue1399) {
EXPECT_EQ(stdAc::swingv_t::kAuto, ac.toCommonSwingV(ac.getVane()));
EXPECT_EQ(kMitsubishiAcVaneSwing, ac.convertSwingV(stdAc::swingv_t::kAuto));
}

TEST(TestMitsubishiACClass, WeeklyTimerEnabled) {
IRMitsubishiAC ac(kGpioUnused);

ac.setWeeklyTimerEnabled(false);
EXPECT_FALSE(ac.getWeeklyTimerEnabled());
ac.setWeeklyTimerEnabled(true);
EXPECT_TRUE(ac.getWeeklyTimerEnabled());
ac.setWeeklyTimerEnabled(false);
EXPECT_FALSE(ac.getWeeklyTimerEnabled());

const uint8_t weekly_on[kMitsubishiACStateLength] = {
0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x04, 0x00,
0xC0, 0x5E, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x6A};

ac.setRaw(weekly_on);
EXPECT_TRUE(ac.getWeeklyTimerEnabled());

const uint8_t weekly_off[kMitsubishiACStateLength] = {
0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x04, 0x00,
0xC0, 0x5E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x62};

ac.setRaw(weekly_off);
EXPECT_FALSE(ac.getWeeklyTimerEnabled());
}

0 comments on commit 991bed8

Please sign in to comment.