From 4e0a085af2b02ac8f97f7998803b3ddf0ca62fb2 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Fri, 23 Aug 2024 13:56:23 +0200 Subject: [PATCH] Initial select commit --- components/haier/select/__init__.py | 74 ++++++++++++++++++++++++++ configs/select/airflow_horizontal.yaml | 49 ++--------------- configs/select/airflow_vertical.yaml | 61 ++------------------- 3 files changed, 80 insertions(+), 104 deletions(-) create mode 100644 components/haier/select/__init__.py diff --git a/components/haier/select/__init__.py b/components/haier/select/__init__.py new file mode 100644 index 0000000..f94ff40 --- /dev/null +++ b/components/haier/select/__init__.py @@ -0,0 +1,74 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import select +from esphome.const import ( + ENTITY_CATEGORY_CONFIG, +) +from ..climate import ( + CONF_HAIER_ID, + HonClimate, + haier_ns, + CONF_VERTICAL_AIRFLOW, + CONF_HORIZONTAL_AIRFLOW, +) + +CODEOWNERS = ["@paveldn"] +VerticalAirflowSelect = haier_ns.class_("VerticalAirflowSelect", select.Select) +HorizontalAirflowSelect = haier_ns.class_("HorizontalAirflowSelect", select.Select) + +# Additional icons +ICON_ARROW_HORIZONTAL = "mdi:arrow-expand-horizontal" +ICON_ARROW_VERTICAL = "mdi:arrow-expand-vertical" + +AIRFLOW_VERTICAL_DIRECTION_OPTIONS = [ + "Auto", + "Health Up", + "Max Up", + "Up", + "Center", + "Down", + "Max Down", + "Health Down", +] + +AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS = [ + "Auto", + "Max Left", + "Left", + "Center", + "Right", + "Max Right", +] + +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(CONF_HAIER_ID): cv.use_id(HonClimate), + cv.Optional(CONF_VERTICAL_AIRFLOW): select.select_schema( + VerticalAirflowSelect, + icon=ICON_ARROW_VERTICAL, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + cv.Optional(CONF_HORIZONTAL_AIRFLOW): select.select_schema( + HorizontalAirflowSelect, + icon=ICON_ARROW_HORIZONTAL, + entity_category=ENTITY_CATEGORY_CONFIG, + ), + } +) + +async def to_code(config): + full_id, parent = await cg.get_variable_with_full_id(config[CONF_HAIER_ID]) + + if conf := config.get(CONF_VERTICAL_AIRFLOW): + pass + #sel_var = await select.new_select(conf, options=AIRFLOW_VERTICAL_DIRECTION_OPTIONS) + #await cg.register_parented(sel_var, parent) + #cg.add(getattr(parent, f"set_{CONF_VERTICAL_AIRFLOW}_select")(sel_var)) + + if conf := config.get(CONF_HORIZONTAL_AIRFLOW): + pass + #sel_var = await select.new_select(conf, options=AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS) + #await cg.register_parented(sel_var, parent) + #cg.add(getattr(parent, f"set_{CONF_HORIZONTAL_AIRFLOW}_select")(sel_var)) + + diff --git a/configs/select/airflow_horizontal.yaml b/configs/select/airflow_horizontal.yaml index 8749118..4df5215 100644 --- a/configs/select/airflow_horizontal.yaml +++ b/configs/select/airflow_horizontal.yaml @@ -1,47 +1,4 @@ select: - - platform: template - id: ${device_id}_horizontal_direction - name: ${device_name} airflow horizontal - entity_category: config - icon: mdi:arrow-expand-horizontal - update_interval: 5s - options: - - Max Left - - Left - - Center - - Right - - Max Right - - Auto - lambda: >- - switch (id(${device_id}).get_horizontal_airflow().value_or(esphome::haier::hon_protocol::HorizontalSwingMode::CENTER)) - { - case esphome::haier::hon_protocol::HorizontalSwingMode::MAX_LEFT: - return std::string("Max Left"); - case esphome::haier::hon_protocol::HorizontalSwingMode::LEFT: - return std::string("Left"); - default: - case esphome::haier::hon_protocol::HorizontalSwingMode::CENTER: - return std::string("Center"); - case esphome::haier::hon_protocol::HorizontalSwingMode::RIGHT: - return std::string("Right"); - case esphome::haier::hon_protocol::HorizontalSwingMode::MAX_RIGHT: - return std::string("Max Right"); - case esphome::haier::hon_protocol::HorizontalSwingMode::AUTO: - return std::string("Auto"); - } - set_action: - - climate.haier.set_horizontal_airflow: - id: ${device_id} - horizontal_airflow: !lambda >- - if (x == "Max Left") - return esphome::haier::hon_protocol::HorizontalSwingMode::MAX_LEFT; - else if (x == "Left") - return esphome::haier::hon_protocol::HorizontalSwingMode::LEFT; - else if (x == "Right") - return esphome::haier::hon_protocol::HorizontalSwingMode::RIGHT; - else if (x == "Max Right") - return esphome::haier::hon_protocol::HorizontalSwingMode::MAX_RIGHT; - else if (x == "Auto") - return esphome::haier::hon_protocol::HorizontalSwingMode::AUTO; - else - return esphome::haier::hon_protocol::HorizontalSwingMode::CENTER; + - platform: haier + horizontal_airflow: + name: ${device_name} airflow horizontal diff --git a/configs/select/airflow_vertical.yaml b/configs/select/airflow_vertical.yaml index 7ec6b94..eca2292 100644 --- a/configs/select/airflow_vertical.yaml +++ b/configs/select/airflow_vertical.yaml @@ -1,59 +1,4 @@ select: - - platform: template - id: ${device_id}_vertical_direction - name: ${device_name} airflow vertical - entity_category: config - icon: mdi:arrow-expand-vertical - update_interval: 5s - options: - - Health Up - - Max Up - - Up - - Center - - Down - - Max Down - - Health Down - - Auto - lambda: >- - switch (id(${device_id}).get_vertical_airflow().value_or(esphome::haier::hon_protocol::VerticalSwingMode::CENTER)) - { - case esphome::haier::hon_protocol::VerticalSwingMode::HEALTH_UP: - return std::string("Health Up"); - case esphome::haier::hon_protocol::VerticalSwingMode::MAX_UP: - return std::string("Max Up"); - case esphome::haier::hon_protocol::VerticalSwingMode::UP: - return std::string("Up"); - default: - case esphome::haier::hon_protocol::VerticalSwingMode::CENTER: - return std::string("Center"); - case esphome::haier::hon_protocol::VerticalSwingMode::DOWN: - return std::string("Down"); - case esphome::haier::hon_protocol::VerticalSwingMode::MAX_DOWN: - return std::string("Max Down"); - case esphome::haier::hon_protocol::VerticalSwingMode::HEALTH_DOWN: - return std::string("Health Down"); - case esphome::haier::hon_protocol::VerticalSwingMode::AUTO: - case esphome::haier::hon_protocol::VerticalSwingMode::AUTO_SPECIAL: - return std::string("Auto"); - } - set_action: - - climate.haier.set_vertical_airflow: - id: ${device_id} - vertical_airflow: !lambda >- - if (x == "Health Up") - return esphome::haier::hon_protocol::VerticalSwingMode::HEALTH_UP; - else if (x == "Max Up") - return esphome::haier::hon_protocol::VerticalSwingMode::MAX_UP; - else if (x == "Up") - return esphome::haier::hon_protocol::VerticalSwingMode::UP; - else if (x == "Down") - return esphome::haier::hon_protocol::VerticalSwingMode::DOWN; - else if (x == "Max Down") - return esphome::haier::hon_protocol::VerticalSwingMode::MAX_DOWN; - else if (x == "Health Down") - return esphome::haier::hon_protocol::VerticalSwingMode::HEALTH_DOWN; - else if (x == "Auto") - return esphome::haier::hon_protocol::VerticalSwingMode::AUTO; - else - return esphome::haier::hon_protocol::VerticalSwingMode::CENTER; - + - platform: haier + vertical_airflow: + name: ${device_name} airflow vertical