mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 07:20:24 +00:00
[mitsubishi] Use the climate_ir traits() for supported modes (#19485)
This commit is contained in:
@@ -53,46 +53,6 @@ const uint8_t MITSUBISHI_BYTE04 = 0x00;
|
||||
const uint8_t MITSUBISHI_BYTE13 = 0x00;
|
||||
const uint8_t MITSUBISHI_BYTE16 = 0x00;
|
||||
|
||||
climate::ClimateTraits MitsubishiClimate::traits() {
|
||||
auto traits = climate::ClimateTraits();
|
||||
if (this->sensor_ != nullptr) {
|
||||
traits.add_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE);
|
||||
}
|
||||
traits.set_visual_min_temperature(MITSUBISHI_TEMP_MIN);
|
||||
traits.set_visual_max_temperature(MITSUBISHI_TEMP_MAX);
|
||||
traits.set_visual_temperature_step(1.0f);
|
||||
traits.set_supported_modes({climate::CLIMATE_MODE_OFF});
|
||||
|
||||
if (this->supports_cool_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_COOL);
|
||||
if (this->supports_heat_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_HEAT);
|
||||
|
||||
if (this->supports_cool_ && this->supports_heat_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL);
|
||||
|
||||
if (this->supports_dry_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_DRY);
|
||||
if (this->supports_fan_only_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_FAN_ONLY);
|
||||
|
||||
// Default to only 3 levels in ESPHome even if most unit supports 4. The 3rd level is not used.
|
||||
traits.set_supported_fan_modes(
|
||||
{climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH});
|
||||
if (this->fan_mode_ == MITSUBISHI_FAN_Q4L)
|
||||
traits.add_supported_fan_mode(climate::CLIMATE_FAN_QUIET);
|
||||
if (/*this->fan_mode_ == MITSUBISHI_FAN_5L ||*/ this->fan_mode_ >= MITSUBISHI_FAN_4L)
|
||||
traits.add_supported_fan_mode(climate::CLIMATE_FAN_MIDDLE); // Shouldn't be used for this but it helps
|
||||
|
||||
traits.set_supported_swing_modes({climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH,
|
||||
climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL});
|
||||
|
||||
traits.set_supported_presets({climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO,
|
||||
climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP});
|
||||
|
||||
return traits;
|
||||
}
|
||||
|
||||
void MitsubishiClimate::transmit_state() {
|
||||
// Byte 0-4: Constant: 0x23, 0xCB, 0x26, 0x01, 0x00
|
||||
// Byte 5: On=0x20, Off: 0x00
|
||||
|
||||
@@ -38,12 +38,14 @@ enum VerticalDirection : uint8_t {
|
||||
VERTICAL_DIRECTION_DOWN = 0x28,
|
||||
};
|
||||
|
||||
// Fan modes offered by every set_fan_mode option.
|
||||
static constexpr climate::ClimateFanModeMask MITSUBISHI_BASE_FAN_MODES{
|
||||
climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH};
|
||||
|
||||
class MitsubishiClimate final : public climate_ir::ClimateIR {
|
||||
public:
|
||||
MitsubishiClimate()
|
||||
: climate_ir::ClimateIR(MITSUBISHI_TEMP_MIN, MITSUBISHI_TEMP_MAX, 1.0f, true, true,
|
||||
{climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MIDDLE,
|
||||
climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH, climate::CLIMATE_FAN_QUIET},
|
||||
: climate_ir::ClimateIR(MITSUBISHI_TEMP_MIN, MITSUBISHI_TEMP_MAX, 1.0f, true, true, MITSUBISHI_BASE_FAN_MODES,
|
||||
{climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH, climate::CLIMATE_SWING_VERTICAL,
|
||||
climate::CLIMATE_SWING_HORIZONTAL},
|
||||
{climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST,
|
||||
@@ -54,7 +56,14 @@ class MitsubishiClimate final : public climate_ir::ClimateIR {
|
||||
void set_supports_fan_only(bool supports_fan_only) { this->supports_fan_only_ = supports_fan_only; }
|
||||
void set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; }
|
||||
|
||||
void set_fan_mode(SetFanMode fan_mode) { this->fan_mode_ = fan_mode; }
|
||||
void set_fan_mode(SetFanMode fan_mode) {
|
||||
this->fan_mode_ = fan_mode;
|
||||
this->fan_modes_ = MITSUBISHI_BASE_FAN_MODES;
|
||||
if (fan_mode == MITSUBISHI_FAN_Q4L)
|
||||
this->fan_modes_.insert(climate::CLIMATE_FAN_QUIET);
|
||||
if (fan_mode >= MITSUBISHI_FAN_4L)
|
||||
this->fan_modes_.insert(climate::CLIMATE_FAN_MIDDLE); // Shouldn't be used for this but it helps
|
||||
}
|
||||
|
||||
void set_horizontal_default(HorizontalDirection horizontal_direction) {
|
||||
this->default_horizontal_direction_ = horizontal_direction;
|
||||
@@ -74,8 +83,6 @@ class MitsubishiClimate final : public climate_ir::ClimateIR {
|
||||
|
||||
HorizontalDirection default_horizontal_direction_;
|
||||
VerticalDirection default_vertical_direction_;
|
||||
|
||||
climate::ClimateTraits traits() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::mitsubishi
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from tests.testing_helpers import ComponentManifestOverride
|
||||
|
||||
|
||||
def override_manifest(manifest: ComponentManifestOverride) -> None:
|
||||
# AUTO_LOAD sits on the climate platform, which the unit test build does not load.
|
||||
manifest.dependencies = manifest.dependencies + ["climate_ir", "climate"]
|
||||
@@ -0,0 +1,65 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "esphome/components/mitsubishi/mitsubishi.h"
|
||||
|
||||
namespace esphome::mitsubishi::testing {
|
||||
|
||||
TEST(MitsubishiClimateTest, HeatCoolOverrideAdvertisedWithoutHeat) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_supports_heat(false);
|
||||
climate.set_supports_cool(true);
|
||||
climate.set_supports_heat_cool(true);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_TRUE(traits.supports_mode(climate::CLIMATE_MODE_HEAT_COOL));
|
||||
EXPECT_FALSE(traits.supports_mode(climate::CLIMATE_MODE_HEAT));
|
||||
}
|
||||
|
||||
TEST(MitsubishiClimateTest, HeatCoolOverrideHiddenWithHeatAndCool) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_supports_heat(true);
|
||||
climate.set_supports_cool(true);
|
||||
climate.set_supports_heat_cool(false);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_FALSE(traits.supports_mode(climate::CLIMATE_MODE_HEAT_COOL));
|
||||
EXPECT_TRUE(traits.supports_mode(climate::CLIMATE_MODE_HEAT));
|
||||
EXPECT_TRUE(traits.supports_mode(climate::CLIMATE_MODE_COOL));
|
||||
}
|
||||
|
||||
TEST(MitsubishiClimateTest, FanModesFor3Levels) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_fan_mode(MITSUBISHI_FAN_3L);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_AUTO));
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_LOW));
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_MEDIUM));
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_HIGH));
|
||||
EXPECT_FALSE(traits.supports_fan_mode(climate::CLIMATE_FAN_MIDDLE));
|
||||
EXPECT_FALSE(traits.supports_fan_mode(climate::CLIMATE_FAN_QUIET));
|
||||
}
|
||||
|
||||
TEST(MitsubishiClimateTest, FanModesFor4Levels) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_fan_mode(MITSUBISHI_FAN_4L);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_MIDDLE));
|
||||
EXPECT_FALSE(traits.supports_fan_mode(climate::CLIMATE_FAN_QUIET));
|
||||
}
|
||||
|
||||
TEST(MitsubishiClimateTest, FanModesForQuietAnd4Levels) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_fan_mode(MITSUBISHI_FAN_Q4L);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_MIDDLE));
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_QUIET));
|
||||
}
|
||||
|
||||
TEST(MitsubishiClimateTest, FanModesFollowTheLastSetFanMode) {
|
||||
MitsubishiClimate climate;
|
||||
climate.set_fan_mode(MITSUBISHI_FAN_Q4L);
|
||||
climate.set_fan_mode(MITSUBISHI_FAN_3L);
|
||||
auto traits = climate.get_traits();
|
||||
EXPECT_FALSE(traits.supports_fan_mode(climate::CLIMATE_FAN_MIDDLE));
|
||||
EXPECT_FALSE(traits.supports_fan_mode(climate::CLIMATE_FAN_QUIET));
|
||||
EXPECT_TRUE(traits.supports_fan_mode(climate::CLIMATE_FAN_HIGH));
|
||||
}
|
||||
|
||||
} // namespace esphome::mitsubishi::testing
|
||||
Reference in New Issue
Block a user