Skip to content

Commit

Permalink
Merge pull request #114 from jbekkema/non_nasa_support
Browse files Browse the repository at this point in the history
Stabilise UI When Changing State for Non-NASA Devices
  • Loading branch information
lanwin authored Apr 12, 2024
2 parents 96528ca + 000edb2 commit ecd22be
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,6 @@ namespace esphome

if (nonpacket_.cmd == NonNasaCommand::Cmd20)
{
last_command20s_[nonpacket_.src] = nonpacket_.command20;
target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp);
target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp);
target->set_power(nonpacket_.src, nonpacket_.command20.power);
target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode));
target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed));
// TODO
target->set_altmode(nonpacket_.src, 0);
// TODO
target->set_swing_horizontal(nonpacket_.src, false);
target->set_swing_vertical(nonpacket_.src, false);

// We may occasionally not receive a control_acknowledgement message when sending a control
// packet, so as a backup approach check if the state of the device matches that of the
// sent control packet. This also serves as a backup approach if for some reason a device
Expand All @@ -566,6 +554,34 @@ namespace esphome
item.request.fanspeed == nonpacket_.command20.fanspeed &&
item.request.mode == nonpacket_.command20.mode &&
item.request.power == nonpacket_.command20.power; });

// If a state update comes through after a control message has been sent, but before it
// has been acknowledged, it should be ignored. This prevents the UI status bouncing
// between states after a command has been issued.
bool pending_control_message = false;
for (auto& item : nonnasa_requests)
{
if (item.time_sent > 0 && nonpacket_.src == item.request.dst)
{
pending_control_message = true;
break;
}
}

if (!pending_control_message)
{
last_command20s_[nonpacket_.src] = nonpacket_.command20;
target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp);
target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp);
target->set_power(nonpacket_.src, nonpacket_.command20.power);
target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode));
target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed));
// TODO
target->set_altmode(nonpacket_.src, 0);
// TODO
target->set_swing_horizontal(nonpacket_.src, false);
target->set_swing_vertical(nonpacket_.src, false);
}
}
else if (nonpacket_.cmd == NonNasaCommand::CmdC6)
{
Expand Down

0 comments on commit ecd22be

Please sign in to comment.