Skip to content

Commit

Permalink
Merge branch 'main' into refactor_request
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Feb 7, 2024
2 parents 95f74f4 + c8a6b07 commit 3bcd080
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 16 deletions.
30 changes: 25 additions & 5 deletions components/samsung_ac/converions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,35 @@ namespace esphome
}
}

climate::ClimateFanMode fanmode_to_climatefanmode(FanMode fanmode)
optional<climate::ClimateFanMode> fanmode_to_climatefanmode(FanMode fanmode)
{
switch (fanmode)
{
case FanMode::Low:
return climate::ClimateFanMode::CLIMATE_FAN_LOW;
case FanMode::Mid:
return climate::ClimateFanMode::CLIMATE_FAN_MIDDLE;
case FanMode::Hight:
case FanMode::High:
return climate::ClimateFanMode::CLIMATE_FAN_HIGH;
default:
case FanMode::Turbo:
return nullopt;
case FanMode::Auto:
default:
return climate::ClimateFanMode::CLIMATE_FAN_AUTO;
}
}

std::string fanmode_to_custom_climatefanmode(FanMode fanmode)
{
switch (fanmode)
{
case FanMode::Turbo:
return "Turbo";
default:
return "";
}
}

FanMode climatefanmode_to_fanmode(climate::ClimateFanMode fanmode)
{
switch (fanmode)
Expand All @@ -101,13 +114,20 @@ namespace esphome
case climate::ClimateFanMode::CLIMATE_FAN_MIDDLE:
return FanMode::Mid;
case climate::ClimateFanMode::CLIMATE_FAN_HIGH:
return FanMode::Hight;
return FanMode::High;
case climate::ClimateFanMode::CLIMATE_FAN_AUTO:
default:
return FanMode::Auto;
}
}


FanMode customfanmode_to_fanmode(const std::string &value)
{
if (value == "Turbo")
return FanMode::Turbo;
return FanMode::Auto;
}

AltMode preset_to_altmode(climate::ClimatePreset preset)
{
switch (preset)
Expand Down
8 changes: 5 additions & 3 deletions components/samsung_ac/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

namespace esphome
{
namespace samsung_ac{

namespace samsung_ac
{
Mode str_to_mode(const std::string &value);
std::string mode_to_str(Mode mode);

optional<climate::ClimateMode> mode_to_climatemode(Mode mode);
Mode climatemode_to_mode(climate::ClimateMode mode);

climate::ClimateFanMode fanmode_to_climatefanmode(FanMode fanmode);
optional<climate::ClimateFanMode> fanmode_to_climatefanmode(FanMode fanmode);
std::string fanmode_to_custom_climatefanmode(FanMode fanmode);
FanMode climatefanmode_to_fanmode(climate::ClimateFanMode fanmode);
FanMode customfanmode_to_fanmode(const std::string &value);

optional<climate::ClimatePreset> altmode_to_preset(AltMode mode);
std::string altmode_to_custompreset(AltMode mode);
Expand Down
4 changes: 2 additions & 2 deletions components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace esphome
Auto = 0,
Low = 1,
Mid = 2,
Hight = 3,
// Turbo = 4,
High = 3,
Turbo = 4,
Off = 5
};

Expand Down
13 changes: 9 additions & 4 deletions components/samsung_ac/protocol_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ namespace esphome
return 1;
case FanMode::Mid:
return 2;
case FanMode::Hight:
case FanMode::High:
return 3;
case FanMode::Turbo:
return 4;
case FanMode::Auto:
default:
return 0;
Expand Down Expand Up @@ -466,9 +468,10 @@ namespace esphome
return FanMode::Low;
case 2: // Mid
return FanMode::Mid;
case 3: // Hight
case 3: // High
return FanMode::High;
case 4: // Turbo
return FanMode::Hight;
return FanMode::Turbo;
case 10: // AutoLow
case 11: // AutoMid
case 12: // AutoHigh
Expand Down Expand Up @@ -573,7 +576,9 @@ namespace esphome
else if (message.value == 2)
mode = FanMode::Mid;
else if (message.value == 3)
mode = FanMode::Hight;
mode = FanMode::High;
else if (message.value == 4)
mode = FanMode::Turbo;
target->set_fanmode(source, mode);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace esphome
{
switch (value)
{
case FanMode::Hight:
case FanMode::High:
return NonNasaFanspeed::High;
case FanMode::Mid:
return NonNasaFanspeed::Medium;
Expand Down Expand Up @@ -357,7 +357,7 @@ namespace esphome
{
case NonNasaFanspeed::Fresh:
case NonNasaFanspeed::High:
return FanMode::Hight;
return FanMode::High;
case NonNasaFanspeed::Medium:
return FanMode::Mid;
case NonNasaFanspeed::Low:
Expand Down
10 changes: 10 additions & 0 deletions components/samsung_ac/samsung_ac_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ namespace esphome

traits.set_supported_fan_modes(fan);

std::set<std::string> customFan;
customFan.insert("Turbo");
traits.set_supported_custom_fan_modes(customFan);

std::set<climate::ClimatePreset> preset;
preset.insert(climate::ClimatePreset::CLIMATE_PRESET_NONE);
preset.insert(climate::ClimatePreset::CLIMATE_PRESET_SLEEP);
Expand Down Expand Up @@ -93,6 +97,12 @@ namespace esphome
device->write_fanmode(climatefanmode_to_fanmode(fanmodeOpt.value()));
}

auto customFanmodeOpt = call.get_custom_fan_mode();
if (customFanmodeOpt.has_value())
{
device->write_fanmode(customfanmode_to_fanmode(customFanmodeOpt.value()));
}

auto presetOpt = call.get_preset();
if (presetOpt.has_value())
{
Expand Down
9 changes: 9 additions & 0 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ namespace esphome
if (climate != nullptr)
{
climate->fan_mode = fanmode_to_climatefanmode(value);

auto fanmode = fanmode_to_climatefanmode(value);
if (fanmode.has_value()) {
climate->fan_mode = fanmode;
climate->custom_fan_mode.reset();
} else {
climate->fan_mode.reset();
climate->custom_fan_mode = fanmode_to_custom_climatefanmode(value);
}
climate->publish_state();
}
}
Expand Down

0 comments on commit 3bcd080

Please sign in to comment.