Skip to content

Commit

Permalink
ToshibaAC: More unit tests.
Browse files Browse the repository at this point in the history
* Add checks for if we handle toggling an IRac state correctly if we receive a IR swing toggle message.

Ref: #1424 (comment)
  • Loading branch information
crankyoldgit committed Mar 1, 2021
1 parent 690a07b commit b4596e6
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2383,3 +2383,59 @@ TEST(TestIRac, Issue1339) {
to_send.protocol = decode_type_t::HITACHI_AC1;
ASSERT_TRUE(irac.sendAc(to_send, NULL));
}

// See if we handle an inbound Swing Toggle IR command correctly.
// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1424#issuecomment-787998777
TEST(TestIRac, Issue1424) {
IRToshibaAC ac(kGpioUnused);
IRac irac(kGpioUnused);
IRrecv capture(kGpioUnused);

ac.begin();
irac.next.protocol = decode_type_t::TOSHIBA_AC; // Set a protocol to use.
irac.next.model = 1; // Some A/Cs have different models. Try just the first.
irac.next.mode = stdAc::opmode_t::kFan; // Run in Fan mode initially.
irac.next.celsius = true; // Use Celsius for temp units. False = Fahrenheit
irac.next.degrees = 19; // 19 degrees.
irac.next.fanspeed = stdAc::fanspeed_t::kAuto; // Start the fan at Auto.
irac.next.swingv = stdAc::swingv_t::kOff; // Don't swing the fan up or down.
irac.next.swingh = stdAc::swingh_t::kOff; // Don't swing the fan left/right.
irac.next.light = true; // Turn off any LED/Lights/Display that we can.
irac.next.beep = false; // Turn off any beep from the A/C if we can.
irac.next.econo = false; // Turn off any economy modes if we can.
irac.next.filter = false; // Turn off any Ion/Mold/Health filters if we can.
irac.next.turbo = false; // Don't use any turbo/powerful/etc modes.
irac.next.quiet = false; // Don't use any quiet/silent/etc modes.
irac.next.sleep = -1; // Don't set any sleep time or modes.
irac.next.clean = false; // Turn off any Cleaning options if we can.
irac.next.clock = -1; // Don't set any current time if we can avoid it.
irac.next.power = true; // Initially start with the unit on.

// Start with the SwingV being off.
stdAc::state_t copy_of_next_pre_send = irac.next;
irac.sendAc();
// Confirm nothing in the state changed with the send.
ASSERT_FALSE(IRac::cmpStates(irac.next, copy_of_next_pre_send));


irac.next.swingv = stdAc::swingv_t::kAuto; // Turn on the swing.
ASSERT_TRUE(IRac::cmpStates(irac.next, copy_of_next_pre_send));
copy_of_next_pre_send = irac.next;
irac.sendAc();
// Confirm it is NOT Off. i.e. On.
EXPECT_NE(stdAc::swingv_t::kOff, irac.next.swingv);
// Confirm nothing in the state changed with the send.
ASSERT_FALSE(IRac::cmpStates(irac.next, copy_of_next_pre_send));

stdAc::state_t copy_of_next_pre_receive = irac.next; // aka. Prev.
// Simulate receiving a Swing Toggle message.
const uint8_t swingToggleState[kToshibaACStateLengthShort] = {
0xF2, 0x0D, 0x01, 0xFE, 0x21, 0x04, 0x25};
ac.setRaw(swingToggleState, kToshibaACStateLengthShort);
// Import the new "state" to IRac.
irac.next = ac.toCommon(&copy_of_next_pre_receive);
// The toggle should have turned the effective "On" state to "Off".
EXPECT_EQ(irac.next.swingv, stdAc::swingv_t::kOff);
// Confirm the state really did change.
ASSERT_TRUE(IRac::cmpStates(irac.next, copy_of_next_pre_receive));
}

0 comments on commit b4596e6

Please sign in to comment.