diff --git a/esphome/components/midea/ac_automations.h b/esphome/components/midea/ac_automations.h index d4ed2e7168..5084fd1eec 100644 --- a/esphome/components/midea/ac_automations.h +++ b/esphome/components/midea/ac_automations.h @@ -56,6 +56,11 @@ template class PowerOffAction : public MideaActionBase { void play(Ts... x) override { this->parent_->do_power_off(); } }; +template class PowerToggleAction : public MideaActionBase { + public: + void play(Ts... x) override { this->parent_->do_power_toggle(); } +}; + } // namespace ac } // namespace midea } // namespace esphome diff --git a/esphome/components/midea/air_conditioner.h b/esphome/components/midea/air_conditioner.h index a6023b78bb..d809aa78f6 100644 --- a/esphome/components/midea/air_conditioner.h +++ b/esphome/components/midea/air_conditioner.h @@ -39,6 +39,7 @@ class AirConditioner : public ApplianceBase, void do_beeper_off() { this->set_beeper_feedback(false); } void do_power_on() { this->base_.setPowerState(true); } void do_power_off() { this->base_.setPowerState(false); } + void do_power_toggle() { this->base_.setPowerState(this->mode == ClimateMode::CLIMATE_MODE_OFF); } void set_supported_modes(const std::set &modes) { this->supported_modes_ = modes; } void set_supported_swing_modes(const std::set &modes) { this->supported_swing_modes_ = modes; } void set_supported_presets(const std::set &presets) { this->supported_presets_ = presets; } diff --git a/esphome/components/midea/climate.py b/esphome/components/midea/climate.py index 46c0019efa..80b1461576 100644 --- a/esphome/components/midea/climate.py +++ b/esphome/components/midea/climate.py @@ -113,7 +113,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_PERIOD, default="1s"): cv.time_period, cv.Optional(CONF_TIMEOUT, default="2s"): cv.time_period, cv.Optional(CONF_NUM_ATTEMPTS, default=3): cv.int_range(min=1, max=5), - cv.Optional(CONF_TRANSMITTER_ID): cv.use_id( + cv.OnlyWith(CONF_TRANSMITTER_ID, "remote_transmitter"): cv.use_id( remote_transmitter.RemoteTransmitterComponent ), cv.Optional(CONF_BEEPER, default=False): cv.boolean, @@ -163,6 +163,7 @@ BeeperOnAction = midea_ac_ns.class_("BeeperOnAction", automation.Action) BeeperOffAction = midea_ac_ns.class_("BeeperOffAction", automation.Action) PowerOnAction = midea_ac_ns.class_("PowerOnAction", automation.Action) PowerOffAction = midea_ac_ns.class_("PowerOffAction", automation.Action) +PowerToggleAction = midea_ac_ns.class_("PowerToggleAction", automation.Action) MIDEA_ACTION_BASE_SCHEMA = cv.Schema( { @@ -249,6 +250,16 @@ async def power_off_to_code(var, config, args): pass +# Power Toggle action +@register_action( + "power_toggle", + PowerToggleAction, + cv.Schema({}), +) +async def power_inv_to_code(var, config, args): + pass + + async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) diff --git a/tests/test1.yaml b/tests/test1.yaml index 7bb1fbe954..52aa03c371 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -1901,14 +1901,6 @@ script: preset: SLEEP switch: - - platform: template - name: MIDEA_AC_TOGGLE_LIGHT - turn_on_action: - midea_ac.display_toggle: - - platform: template - name: MIDEA_AC_SWING_STEP - turn_on_action: - midea_ac.swing_step: - platform: template name: MIDEA_AC_BEEPER_CONTROL optimistic: true @@ -2834,3 +2826,23 @@ button: id: scd40 - scd4x.factory_reset: id: scd40 + - platform: template + name: Midea Display Toggle + on_press: + midea_ac.display_toggle: + - platform: template + name: Midea Swing Step + on_press: + midea_ac.swing_step: + - platform: template + name: Midea Power On + on_press: + midea_ac.power_on: + - platform: template + name: Midea Power Off + on_press: + midea_ac.power_off: + - platform: template + name: Midea Power Inverse + on_press: + midea_ac.power_toggle: