Skip to content

Commit 8a049f5

Browse files
authored
Gree: Fix reporting vertical swing (#2125)
toCommonSwingV() is only called when SwingAuto is false, but it converts kGreeSwingLastPos to kAuto. It doesn't make sense, because: 1. kGreeSwingLastPos means that swinging is stopped (i.e. the shutter remains in its last position), which corresponds to kOff. 2. kAuto shouldn't be returned from this function at all, because it's handled separately in toCommon() when SwingAuto is true. 3. As can be seen in setSwingVertical(), when automatic is false, the valid set of positions includes kGreeSwingLastPos, but not kGreeSwingAuto. Fix the logic by amending toCommonSwingV() according to the considerations above. It fixes parsing of received IR packets when the user disables vertical swinging from the remote (tested with YAP1FB). For consistency and robustness, educate setSwingVertical() and convertSwingV() about the supported kGreeSwingLastPos mode. Add a unit test for the described bug.
1 parent 850a45f commit 8a049f5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/ir_Gree.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ void IRGreeAC::setSwingVertical(const bool automatic, const uint8_t position) {
375375
uint8_t new_position = position;
376376
if (!automatic) {
377377
switch (position) {
378+
case kGreeSwingLastPos:
378379
case kGreeSwingUp:
379380
case kGreeSwingMiddleUp:
380381
case kGreeSwingMiddle:
@@ -503,6 +504,7 @@ uint8_t IRGreeAC::convertFan(const stdAc::fanspeed_t speed) {
503504
/// @return The native equivalent of the enum.
504505
uint8_t IRGreeAC::convertSwingV(const stdAc::swingv_t swingv) {
505506
switch (swingv) {
507+
case stdAc::swingv_t::kOff: return kGreeSwingLastPos;
506508
case stdAc::swingv_t::kHighest: return kGreeSwingUp;
507509
case stdAc::swingv_t::kHigh: return kGreeSwingMiddleUp;
508510
case stdAc::swingv_t::kMiddle: return kGreeSwingMiddle;
@@ -562,7 +564,7 @@ stdAc::swingv_t IRGreeAC::toCommonSwingV(const uint8_t pos) {
562564
case kGreeSwingMiddle: return stdAc::swingv_t::kMiddle;
563565
case kGreeSwingMiddleDown: return stdAc::swingv_t::kLow;
564566
case kGreeSwingDown: return stdAc::swingv_t::kLowest;
565-
default: return stdAc::swingv_t::kAuto;
567+
default: return stdAc::swingv_t::kOff;
566568
}
567569
}
568570

test/ir_Gree_test.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,11 @@ TEST(TestGreeClass, toCommon) {
701701
ASSERT_FALSE(ac.toCommon().filter);
702702
ASSERT_FALSE(ac.toCommon().beep);
703703
ASSERT_EQ(-1, ac.toCommon().clock);
704+
705+
// Test kGreeSwingLastPos following the pattern in IRac::gree().
706+
ASSERT_EQ(kGreeSwingLastPos, ac.convertSwingV(stdAc::swingv_t::kOff));
707+
ac.setSwingVertical(false, kGreeSwingLastPos);
708+
ASSERT_EQ(stdAc::swingv_t::kOff, ac.toCommon().swingv);
704709
}
705710

706711
TEST(TestGreeClass, Issue814Power) {

0 commit comments

Comments
 (0)