diff --git a/esphome/components/haier/button/__init__.py b/esphome/components/haier/button/__init__.py index 28bb5045c36..a38cb696944 100644 --- a/esphome/components/haier/button/__init__.py +++ b/esphome/components/haier/button/__init__.py @@ -1,12 +1,10 @@ -import esphome.codegen as cg from esphome.components import button import esphome.config_validation as cv +from esphome.types import ConfigType -from ..climate import CONF_HAIER_ID, HonClimate, haier_ns +from ..climate import CONF_HAIER_ID, HonClimate CODEOWNERS = ["@paveldn"] -SelfCleaningButton = haier_ns.class_("SelfCleaningButton", button.Button) -SteriCleaningButton = haier_ns.class_("SteriCleaningButton", button.Button) # Haier buttons @@ -20,19 +18,18 @@ CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(CONF_HAIER_ID): cv.use_id(HonClimate), cv.Optional(CONF_SELF_CLEANING): button.button_schema( - SelfCleaningButton, + button.ApplyButton, icon=ICON_SPRAY_BOTTLE, ), cv.Optional(CONF_STERI_CLEANING): button.button_schema( - SteriCleaningButton, + button.ApplyButton, icon=ICON_SPRAY_BOTTLE, ), } ) -async def to_code(config): - for button_type in [CONF_SELF_CLEANING, CONF_STERI_CLEANING]: - if conf := config.get(button_type): - btn = await button.new_button(conf) - await cg.register_parented(btn, config[CONF_HAIER_ID]) +async def to_code(config: ConfigType) -> None: + buttons = button.sub_buttons(config, parent=config[CONF_HAIER_ID]) + await buttons(CONF_SELF_CLEANING, None, apply="start_self_cleaning()") + await buttons(CONF_STERI_CLEANING, None, apply="start_steri_cleaning()") diff --git a/esphome/components/haier/button/self_cleaning.cpp b/esphome/components/haier/button/self_cleaning.cpp deleted file mode 100644 index bf4baa716e6..00000000000 --- a/esphome/components/haier/button/self_cleaning.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "self_cleaning.h" - -namespace esphome::haier { - -void SelfCleaningButton::press_action() { this->parent_->start_self_cleaning(); } - -} // namespace esphome::haier diff --git a/esphome/components/haier/button/self_cleaning.h b/esphome/components/haier/button/self_cleaning.h deleted file mode 100644 index fc5a73b1e88..00000000000 --- a/esphome/components/haier/button/self_cleaning.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../hon_climate.h" - -namespace esphome::haier { - -class SelfCleaningButton final : public button::Button, public Parented { - public: - SelfCleaningButton() = default; - - protected: - void press_action() override; -}; - -} // namespace esphome::haier diff --git a/esphome/components/haier/button/steri_cleaning.cpp b/esphome/components/haier/button/steri_cleaning.cpp deleted file mode 100644 index 8c4f5808b21..00000000000 --- a/esphome/components/haier/button/steri_cleaning.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "steri_cleaning.h" - -namespace esphome::haier { - -void SteriCleaningButton::press_action() { this->parent_->start_steri_cleaning(); } - -} // namespace esphome::haier diff --git a/esphome/components/haier/button/steri_cleaning.h b/esphome/components/haier/button/steri_cleaning.h deleted file mode 100644 index 4799c0e2aed..00000000000 --- a/esphome/components/haier/button/steri_cleaning.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../hon_climate.h" - -namespace esphome::haier { - -class SteriCleaningButton final : public button::Button, public Parented { - public: - SteriCleaningButton() = default; - - protected: - void press_action() override; -}; - -} // namespace esphome::haier diff --git a/esphome/components/haier/select/__init__.py b/esphome/components/haier/select/__init__.py index 4198ba82081..3f6c5b6bd02 100644 --- a/esphome/components/haier/select/__init__.py +++ b/esphome/components/haier/select/__init__.py @@ -9,12 +9,9 @@ from ..climate import ( CONF_HORIZONTAL_AIRFLOW, CONF_VERTICAL_AIRFLOW, HonClimate, - haier_ns, ) CODEOWNERS = ["@paveldn"] -VerticalAirflowSelect = haier_ns.class_("VerticalAirflowSelect", select.Select) -HorizontalAirflowSelect = haier_ns.class_("HorizontalAirflowSelect", select.Select) # Same order as VERTICAL_SWING_MODES_ORDER and HORIZONTAL_SWING_MODES_ORDER in hon_climate.h AIRFLOW_VERTICAL_DIRECTION_OPTIONS = [ @@ -39,12 +36,12 @@ CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(CONF_HAIER_ID): cv.use_id(HonClimate), cv.Optional(CONF_VERTICAL_AIRFLOW): select.select_schema( - VerticalAirflowSelect, + select.ApplySelect, icon="mdi:arrow-expand-vertical", entity_category=ENTITY_CATEGORY_CONFIG, ), cv.Optional(CONF_HORIZONTAL_AIRFLOW): select.select_schema( - HorizontalAirflowSelect, + select.ApplySelect, icon="mdi:arrow-expand-horizontal", entity_category=ENTITY_CATEGORY_CONFIG, ), @@ -59,9 +56,13 @@ async def to_code(config: ConfigType) -> None: CONF_VERTICAL_AIRFLOW, hub.set_vertical_airflow_select, options=AIRFLOW_VERTICAL_DIRECTION_OPTIONS, + apply="set_vertical_airflow(" + "haier::airflow_order_at(haier::VERTICAL_SWING_MODES_ORDER, index))", ) await selects( CONF_HORIZONTAL_AIRFLOW, hub.set_horizontal_airflow_select, options=AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS, + apply="set_horizontal_airflow(" + "haier::airflow_order_at(haier::HORIZONTAL_SWING_MODES_ORDER, index))", ) diff --git a/esphome/components/haier/select/horizontal_airflow.h b/esphome/components/haier/select/horizontal_airflow.h deleted file mode 100644 index 54f46bfcb19..00000000000 --- a/esphome/components/haier/select/horizontal_airflow.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../hon_climate.h" - -namespace esphome::haier { - -class HorizontalAirflowSelect : public select::Select, public Parented { - protected: - void control(size_t index) override { - this->parent_->set_horizontal_airflow(airflow_order_at(HORIZONTAL_SWING_MODES_ORDER, index)); - } -}; - -} // namespace esphome::haier diff --git a/esphome/components/haier/select/vertical_airflow.h b/esphome/components/haier/select/vertical_airflow.h deleted file mode 100644 index 81ac1b39d2c..00000000000 --- a/esphome/components/haier/select/vertical_airflow.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../hon_climate.h" - -namespace esphome::haier { - -class VerticalAirflowSelect : public select::Select, public Parented { - protected: - void control(size_t index) override { - this->parent_->set_vertical_airflow(airflow_order_at(VERTICAL_SWING_MODES_ORDER, index)); - } -}; - -} // namespace esphome::haier diff --git a/esphome/components/hoermann_hcp/button/hoermann_hcp_button.h b/esphome/components/hoermann_hcp/button/hoermann_hcp_button.h deleted file mode 100644 index e9ebceee889..00000000000 --- a/esphome/components/hoermann_hcp/button/hoermann_hcp_button.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../hoermann_hcp.h" - -namespace esphome::hoermann_hcp { - -// The door commands the cover has no equivalent for. A refused command is already reported by the hub and -// leaves nothing to correct here, because a button carries no state of its own. -class HoermannHcpButton : public button::Button { - public: - explicit HoermannHcpButton(HoermannHcp *parent) : parent_(parent) {} - - protected: - HoermannHcp *const parent_; -}; - -class HoermannHcpVentButton final : public HoermannHcpButton { - public: - using HoermannHcpButton::HoermannHcpButton; - - protected: - void press_action() override { this->parent_->vent_door(); } -}; - -class HoermannHcpHalfOpenButton final : public HoermannHcpButton { - public: - using HoermannHcpButton::HoermannHcpButton; - - protected: - void press_action() override { this->parent_->half_open_door(); } -}; - -} // namespace esphome::hoermann_hcp diff --git a/esphome/components/tfluna/button/reset_button.cpp b/esphome/components/tfluna/button/reset_button.cpp deleted file mode 100644 index b973f668642..00000000000 --- a/esphome/components/tfluna/button/reset_button.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "reset_button.h" - -namespace esphome::tfluna { - -void ResetButton::press_action() { this->parent_->factory_reset(); } - -} // namespace esphome::tfluna diff --git a/esphome/components/tfluna/button/reset_button.h b/esphome/components/tfluna/button/reset_button.h deleted file mode 100644 index a52f479eea0..00000000000 --- a/esphome/components/tfluna/button/reset_button.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../tfluna.h" - -namespace esphome::tfluna { - -class ResetButton : public button::Button, public Parented { - protected: - void press_action() override; -}; - -} // namespace esphome::tfluna diff --git a/esphome/components/tfluna/button/restart_button.cpp b/esphome/components/tfluna/button/restart_button.cpp deleted file mode 100644 index 546be2742d8..00000000000 --- a/esphome/components/tfluna/button/restart_button.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "restart_button.h" - -namespace esphome::tfluna { - -void RestartButton::press_action() { this->parent_->restart(); } - -} // namespace esphome::tfluna diff --git a/esphome/components/tfluna/button/restart_button.h b/esphome/components/tfluna/button/restart_button.h deleted file mode 100644 index 7caaebe6b38..00000000000 --- a/esphome/components/tfluna/button/restart_button.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../tfluna.h" - -namespace esphome::tfluna { - -class RestartButton : public button::Button, public Parented { - protected: - void press_action() override; -}; - -} // namespace esphome::tfluna