From 08894e1735b74da80a056fd8ca95ea04eb442a8e Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Fri, 23 Aug 2024 13:56:23 +0200 Subject: [PATCH 1/5] 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 From 57faa353e7d75dd30b529c0fd7e7410064e22199 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Sat, 7 Sep 2024 22:25:20 +0200 Subject: [PATCH 2/5] Preparation commit --- .vscode/settings.json | 5 +- components/haier/hon_climate.cpp | 20 ++++++ components/haier/hon_climate.h | 12 ++++ components/haier/select/__init__.py | 63 +++++++++++-------- .../haier/select/horizontal_airflow.cpp | 33 ++++++++++ components/haier/select/horizontal_airflow.h | 18 ++++++ components/haier/select/vertical_airflow.cpp | 12 ++++ components/haier/select/vertical_airflow.h | 18 ++++++ 8 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 components/haier/select/horizontal_airflow.cpp create mode 100644 components/haier/select/horizontal_airflow.h create mode 100644 components/haier/select/vertical_airflow.cpp create mode 100644 components/haier/select/vertical_airflow.h diff --git a/.vscode/settings.json b/.vscode/settings.json index c08e182..fe23763 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,10 @@ "istream": "cpp", "sstream": "cpp", "optional": "cpp", - "queue": "cpp" + "queue": "cpp", + "iosfwd": "cpp", + "xlocbuf": "cpp", + "atomic": "cpp" }, "files.trimTrailingWhitespace": true, "files.exclude": { diff --git a/components/haier/hon_climate.cpp b/components/haier/hon_climate.cpp index e7be1fa..125322d 100644 --- a/components/haier/hon_climate.cpp +++ b/components/haier/hon_climate.cpp @@ -5,6 +5,10 @@ #include "esphome/core/helpers.h" #include "hon_climate.h" #include "hon_packet.h" +#ifdef USE_SELECT +#include "select/vertical_airflow.h" +#include "select/horizontal_airflow.h" +#endif using namespace esphome::climate; using namespace esphome::uart; @@ -806,6 +810,22 @@ void HonClimate::set_quiet_mode_switch(switch_::Switch *sw) { } #endif // USE_SWITCH +#ifdef USE_SELECT +void HonClimate::set_vertical_airflow_select(select::Select *sel) { +// this->vertical_airflow_select_ = sel; +// if (this->current_vertical_swing_.has_value() && (this->vertical_airflow_select_ != nullptr)) { +// this->vertical_airflow_select_->publish_state(VerticalAirflowSelect::vertical_airflow_to_string(this->current_vertical_swing_.value())); +// } +} + +void HonClimate::set_horizontal_airflow_select(select::Select *sel) { +// this->horizontal_airflow_select_ = sel; +// if (this->horizontal_airflow_select_ != nullptr) { +// this->horizontal_airflow_select_->publish_state((uint8_t) this->settings_.last_horizontal_swing); +// } +} +#endif // USE_SELECT + haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *packet_buffer, uint8_t size) { size_t expected_size = 2 + this->status_message_header_size_ + this->real_control_packet_size_ + this->real_sensors_packet_size_; diff --git a/components/haier/hon_climate.h b/components/haier/hon_climate.h index 58173f8..07e4606 100644 --- a/components/haier/hon_climate.h +++ b/components/haier/hon_climate.h @@ -13,6 +13,9 @@ #ifdef USE_SWITCH #include "esphome/components/switch/switch.h" #endif +#ifdef USE_SELECT +#include "esphome/components/select/select.h" +#endif #include "esphome/core/automation.h" #include "haier_base.h" #include "hon_packet.h" @@ -100,6 +103,15 @@ class HonClimate : public HaierClimateBase { protected: switch_::Switch *beeper_switch_{nullptr}; switch_::Switch *quiet_mode_switch_{nullptr}; +#endif +#ifdef USE_SELECT +public: + void set_vertical_airflow_select(select::Select *sel); + void set_horizontal_airflow_select(select::Select *sel); + + protected: + select::Select *vertical_airflow_select_{nullptr}; + select::Select *horizontal_airflow_select_{nullptr}; #endif public: HonClimate(); diff --git a/components/haier/select/__init__.py b/components/haier/select/__init__.py index f94ff40..139b997 100644 --- a/components/haier/select/__init__.py +++ b/components/haier/select/__init__.py @@ -2,12 +2,14 @@ import esphome.config_validation as cv from esphome.components import select from esphome.const import ( + CONF_OPTIONS, ENTITY_CATEGORY_CONFIG, ) from ..climate import ( CONF_HAIER_ID, HonClimate, haier_ns, + hon_protocol_ns, CONF_VERTICAL_AIRFLOW, CONF_HORIZONTAL_AIRFLOW, ) @@ -16,29 +18,40 @@ VerticalAirflowSelect = haier_ns.class_("VerticalAirflowSelect", select.Select) HorizontalAirflowSelect = haier_ns.class_("HorizontalAirflowSelect", select.Select) +VerticalSwingMode = hon_protocol_ns.enum("VerticalSwingMode", True) +HorizontalSwingMode = hon_protocol_ns.enum("HorizontalSwingMode", True) + # 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_VERTICAL_DIRECTION_OPTIONS = { + "Auto": VerticalSwingMode.AUTO, + "Health Up": VerticalSwingMode.HEALTH_UP, + "Max Up": VerticalSwingMode.MAX_UP, + "Up": VerticalSwingMode.UP, + "Center": VerticalSwingMode.CENTER, + "Down": VerticalSwingMode.DOWN, + "Max Down": VerticalSwingMode.MAX_DOWN, + "Health Down": VerticalSwingMode.HEALTH_DOWN, +} + +AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS = { + "Auto": HorizontalSwingMode.AUTO, + "Max Left": HorizontalSwingMode.MAX_LEFT, + "Left": HorizontalSwingMode.LEFT, + "Center": HorizontalSwingMode.CENTER, + "Right": HorizontalSwingMode.RIGHT, + "Max Right": HorizontalSwingMode.MAX_RIGHT, +} -AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS = [ - "Auto", - "Max Left", - "Left", - "Center", - "Right", - "Max Right", -] +#def check_airflow_map(value, options_map): +# cv.check_not_templatable(value) +# option_key = cv.All(cv.string_strict) +# option_value = +# if value not in AIRFLOW_VERTICAL_DIRECTION_OPTIONS: +# raise cv.Invalid(f"Invalid airflow value {value}, must be one of: {', '.join(AIRFLOW_VERTICAL_DIRECTION_OPTIONS)}") +# return value CONFIG_SCHEMA = cv.Schema( { @@ -60,15 +73,13 @@ 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)) + sel_var = await select.new_select(conf, options=list(AIRFLOW_VERTICAL_DIRECTION_OPTIONS.keys())) + 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)) + sel_var = await select.new_select(conf, options=list(AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS.keys())) + await cg.register_parented(sel_var, parent) + cg.add(getattr(parent, f"set_{CONF_HORIZONTAL_AIRFLOW}_select")(sel_var)) diff --git a/components/haier/select/horizontal_airflow.cpp b/components/haier/select/horizontal_airflow.cpp new file mode 100644 index 0000000..4031f0f --- /dev/null +++ b/components/haier/select/horizontal_airflow.cpp @@ -0,0 +1,33 @@ +#include "horizontal_airflow.h" +#include + +namespace esphome { +namespace haier { + +void HorizontalAirflowSelect::control(const std::string &value) { + hon_protocol::HorizontalSwingMode state; + if (value == "Auto") { + state = hon_protocol::HorizontalSwingMode::AUTO; + } else if (value == "Max Left") { + state = hon_protocol::HorizontalSwingMode::MAX_LEFT; + } else if (value == "Left") { + state = hon_protocol::HorizontalSwingMode::LEFT; + } else if (value == "Center") { + state = hon_protocol::HorizontalSwingMode::CENTER; + } else if (value == "Right") { + state = hon_protocol::HorizontalSwingMode::RIGHT; + } else if (value == "Max Right") { + state = hon_protocol::HorizontalSwingMode::MAX_RIGHT; + } else { + ESP_LOGE("haier", "Invalid horizontal airflow mode: %s", value.c_str()); + return; + } + const esphome::optional current_state = this->parent_->get_horizontal_airflow(); + if (!current_state.has_value() || (current_state.value() != state)) { + this->parent_->set_horizontal_airflow(state); + } + this->publish_state(value); +} + +} // namespace haier +} // namespace esphome diff --git a/components/haier/select/horizontal_airflow.h b/components/haier/select/horizontal_airflow.h new file mode 100644 index 0000000..b707bdf --- /dev/null +++ b/components/haier/select/horizontal_airflow.h @@ -0,0 +1,18 @@ +#pragma once + +#include "esphome/components/select/select.h" +#include "../hon_climate.h" + +namespace esphome { +namespace haier { + +class HorizontalAirflowSelect : public select::Select, public Parented { + public: + HorizontalAirflowSelect() = default; + + protected: + void control(const std::string &value) override; +}; + +} // namespace haier +} // namespace esphome diff --git a/components/haier/select/vertical_airflow.cpp b/components/haier/select/vertical_airflow.cpp new file mode 100644 index 0000000..dac0dc9 --- /dev/null +++ b/components/haier/select/vertical_airflow.cpp @@ -0,0 +1,12 @@ +#include "vertical_airflow.h" +#include + +namespace esphome { +namespace haier { + +void VerticalAirflowSelect::control(const std::string &value) { + this->publish_state(value); +} + +} // namespace haier +} // namespace esphome diff --git a/components/haier/select/vertical_airflow.h b/components/haier/select/vertical_airflow.h new file mode 100644 index 0000000..cfaf745 --- /dev/null +++ b/components/haier/select/vertical_airflow.h @@ -0,0 +1,18 @@ +#pragma once + +#include "esphome/components/select/select.h" +#include "../hon_climate.h" + +namespace esphome { +namespace haier { + +class VerticalAirflowSelect : public select::Select, public Parented { + public: + VerticalAirflowSelect() = default; + + protected: + void control(const std::string &value) override; +}; + +} // namespace haier +} // namespace esphome From 2060961084db14cfceb2ae616fe43d740092068f Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Thu, 12 Sep 2024 07:22:20 +0200 Subject: [PATCH 3/5] max hon example fixed --- docs/examples/max-hon.yaml | 109 ++----------------------------------- docs/hon_example.rst | 109 ++----------------------------------- 2 files changed, 12 insertions(+), 206 deletions(-) diff --git a/docs/examples/max-hon.yaml b/docs/examples/max-hon.yaml index 4e40f4c..9a0963e 100644 --- a/docs/examples/max-hon.yaml +++ b/docs/examples/max-hon.yaml @@ -103,109 +103,12 @@ switch: name: Haier hOn Climate quiet mode select: - - platform: template - id: haier_ac_vertical_direction - name: Haier hOn Climate 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(haier_ac).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: haier_ac - 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: template - id: haier_ac_horizontal_direction - name: Haier hOn Climate 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(haier_ac).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: haier_ac - 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 + haier_id: haier_ac + vertical_airflow: + name: Haier hOn Climate airflow vertical + horizontal_airflow: + name: Haier hOn Climate airflow horizontal sensor: - platform: haier diff --git a/docs/hon_example.rst b/docs/hon_example.rst index 8609272..b990c3c 100644 --- a/docs/hon_example.rst +++ b/docs/hon_example.rst @@ -131,109 +131,12 @@ Maximum configuration witch will use all possible options will look like this: name: Haier hOn Climate quiet mode select: - - platform: template - id: haier_ac_vertical_direction - name: Haier hOn Climate 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(haier_ac).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: haier_ac - 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: template - id: haier_ac_horizontal_direction - name: Haier hOn Climate 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(haier_ac).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: haier_ac - 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 + haier_id: haier_ac + vertical_airflow: + name: Haier hOn Climate airflow vertical + horizontal_airflow: + name: Haier hOn Climate airflow horizontal sensor: - platform: haier From 39a017a24f2f169575693db0a3ed03c6e6291086 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Fri, 13 Sep 2024 07:52:55 +0200 Subject: [PATCH 4/5] Added vertical airflow select implementation --- components/haier/select/vertical_airflow.cpp | 25 ++++++++++++++++++++ docs/script/make_doc.py | 6 ++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/components/haier/select/vertical_airflow.cpp b/components/haier/select/vertical_airflow.cpp index dac0dc9..2ba65af 100644 --- a/components/haier/select/vertical_airflow.cpp +++ b/components/haier/select/vertical_airflow.cpp @@ -5,6 +5,31 @@ namespace esphome { namespace haier { void VerticalAirflowSelect::control(const std::string &value) { + hon_protocol::VerticalSwingMode state; + if (value == "Auto") { + state = hon_protocol::VerticalSwingMode::AUTO; + } else if (value == "Health Up") { + state = hon_protocol::VerticalSwingMode::HEALTH_UP; + } else if (value == "Max Up") { + state = hon_protocol::VerticalSwingMode::MAX_UP; + } else if (value == "Up") { + state = hon_protocol::VerticalSwingMode::UP; + } else if (value == "Center") { + state = hon_protocol::VerticalSwingMode::CENTER; + } else if (value == "Down") { + state = hon_protocol::VerticalSwingMode::DOWN; + } else if (value == "Max Down") { + state = hon_protocol::VerticalSwingMode::MAX_DOWN; + } else if (value == "Health Down") { + state = hon_protocol::VerticalSwingMode::HEALTH_DOWN; + } else { + ESP_LOGE("haier", "Invalid vertical airflow mode: %s", value.c_str()); + return; + } + const esphome::optional current_state = this->parent_->get_vertical_airflow(); + if (!current_state.has_value() || (current_state.value() != state)) { + this->parent_->set_vertical_airflow(state); + } this->publish_state(value); } diff --git a/docs/script/make_doc.py b/docs/script/make_doc.py index 2d9fd84..dc56e23 100644 --- a/docs/script/make_doc.py +++ b/docs/script/make_doc.py @@ -2,13 +2,13 @@ import os import sys -doc_file_path = [ +doc_file_path = [ "/".join(["esphome-docs", "climate", "haier.rst"]), "/".join(["esphome-docs", "sensor", "haier.rst"]), "/".join(["esphome-docs", "binary_sensor", "haier.rst"]), "/".join(["esphome-docs", "text_sensor", "haier.rst"]), "/".join(["esphome-docs", "button", "haier.rst"]), - "/".join(["esphome-docs", "switch", "haier.rst"]), + "/".join(["esphome-docs", "switch", "haier.rst"]), "esp32_backup.rst", "additional_information.rst", ] @@ -29,7 +29,7 @@ def process_esphome_refs(line, l_num): (":ref:`Text Sensor `", "`Text Sensor `_"), (":ref:`Button `", "`Button `_"), (":ref:`Switch `", "`Switch `_"), - + (":ref:`Select `", "`Select `_"), ] res = line for o, r in esphome_refs: From 7e0ad6b91534e213d16307016558c579d606adb7 Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Fri, 13 Sep 2024 08:09:43 +0200 Subject: [PATCH 5/5] Documentation genertation improvements --- README.rst | 17 +++++--- docs/esphome-docs/climate/haier.rst | 4 +- docs/script/make_doc.py | 43 ++++++++++++++++--- ...dditional_information.rst => see_also.rst} | 10 ++--- 4 files changed, 56 insertions(+), 18 deletions(-) rename docs/{additional_information.rst => see_also.rst} (62%) diff --git a/README.rst b/README.rst index 5b65850..f4c04fc 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,8 @@ Please, don't change. In case you need to make corrections or changes change source documentation in ./doc folder or script. +.. Generated from see_also.rst + .. Generated from esphome-docs/climate/haier.rst Haier Climate @@ -567,10 +569,9 @@ flash_4M.bin** After this, you can flash firmware using ESPHome tools (dashboard, website, esphome command, etc) -.. Generated from additional_information.rst -Additional information -====================== +See Also +======== - `FAQ <./docs/faq.rst>`_ - `HaierProtocol `_ @@ -578,8 +579,14 @@ Additional information - `Haier protocol overview <./docs/protocol_overview.rst>`_ - `Example of climate configuration for smartair2 protocol <./docs/smartair2_example.rst>`_ - `Example of climate configuration for hOn protocol <./docs/hon_example.rst>`_ +- `Esptool.py Documentation `_ +- `Sniffing serial communication <./docs/sniffing_serial_communication.rst>`_ - `ESPHome Haier Climate `_ - `ESPHome Haier Climate Sensors `_ - `ESPHome Haier Climate Binary Sensors `_ -- `Esptool.py Documentation `_ -- `Sniffing serial communication <./docs/sniffing_serial_communication.rst>`_ \ No newline at end of file +- `ESPHome Haier Climate Text Sensors `_ +- `ESPHome Haier Climate Buttons `_ +- `ESPHome Haier Climate Switches `_ +- `Climate Component `_ +- `API Reference `_ +- `Sensor Filters `_ diff --git a/docs/esphome-docs/climate/haier.rst b/docs/esphome-docs/climate/haier.rst index 56ed801..1a1f82f 100644 --- a/docs/esphome-docs/climate/haier.rst +++ b/docs/esphome-docs/climate/haier.rst @@ -53,7 +53,7 @@ Newer Haier models using a module called ESP32-for-Haier. It is an ESP32 single- Also, you can use any other ESP32, ESP8266, or an RPI pico W board. In this case, you will need to cut the original wire or make a connector yourself (the board has a JST SM04B-GHS-TB connector) -This component requires a :ref:`uart` to be setup. +This component requires a :ref:`UART bus ` to be setup. .. code-block:: yaml @@ -343,5 +343,5 @@ See Also - :doc:`Haier Climate Buttons ` - :doc:`Haier Climate Switches ` - :doc:`/components/climate/index` -- :apiref:`haier/climate/haier.h` +- :apiref:`haier/climate/haier_base.h` - :ghedit:`Edit` diff --git a/docs/script/make_doc.py b/docs/script/make_doc.py index dc56e23..d2d01be 100644 --- a/docs/script/make_doc.py +++ b/docs/script/make_doc.py @@ -3,6 +3,7 @@ import sys doc_file_path = [ + "see_also.rst", "/".join(["esphome-docs", "climate", "haier.rst"]), "/".join(["esphome-docs", "sensor", "haier.rst"]), "/".join(["esphome-docs", "binary_sensor", "haier.rst"]), @@ -10,32 +11,43 @@ "/".join(["esphome-docs", "button", "haier.rst"]), "/".join(["esphome-docs", "switch", "haier.rst"]), "esp32_backup.rst", - "additional_information.rst", ] def process_esphome_refs(line, l_num): esphome_refs = [ - (":ref:`uart`", "`UART Bus `_"), (":ref:`config-id`", "`ID `_"), (":ref:`config-time`", "`Time `_"), (":ref:`Automation `", "`Automation `_"), + (":ref:`lambdas `", "`lambdas `_"), (":ref:`haier-on_alarm_start`", "`on_alarm_start Trigger`_"), (":ref:`haier-on_alarm_end`", "`on_alarm_end Trigger`_"), (":ref:`haier-on_status_message`", "`on_status_message Trigger`_"), + (":ref:`UART bus `", "`UART Bus `_"), (":ref:`Climate `", "`Climate `_"), - (":ref:`lambdas `", "`lambdas `_"), (":ref:`Sensor `", "`Sensor `_"), (":ref:`Binary Sensor `", "`Binary Sensor `_"), (":ref:`Text Sensor `", "`Text Sensor `_"), (":ref:`Button `", "`Button `_"), (":ref:`Switch `", "`Switch `_"), (":ref:`Select `", "`Select `_"), + (":ghedit:`Edit`", ""), + (":doc:`/components/climate/index`", "`Climate Component `_"), + (":doc:`Haier Climate `", "`ESPHome Haier Climate `_"), + (":apiref:`haier/climate/haier_base.h`", "`API Reference `_"), + (":ref:`sensor-filters`", "`Sensor Filters `_"), + (":doc:`Haier Climate Sensors `", "`ESPHome Haier Climate Sensors `_"), + (":doc:`Haier Climate Binary Sensors `", "`ESPHome Haier Climate Binary Sensors `_"), + (":doc:`Haier Climate Text Sensors `", "`ESPHome Haier Climate Text Sensors `_"), + (":doc:`Haier Climate Buttons `", "`ESPHome Haier Climate Buttons `_"), + (":doc:`Haier Climate Switches `", "`ESPHome Haier Climate Switches `_"), ] res = line for o, r in esphome_refs: res = res.replace(o, r) if res.find(":ref:") != -1: print(f"\tWarning: ref found, line #{l_num}") + if res.find(":doc:") != -1: + print(f"\tWarning: doc found, line #{l_num}") return res def process_figure(section, output_file, pth): @@ -70,6 +82,17 @@ def process_section(section, output_file, pth): else: output_file.writelines(section) +def process_see_also(see_also_lines, output_file): + print("Processing See Also section") + output_file.write("\nSee Also\n") + output_file.write("========\n\n") + l_counter = 0 + for l in see_also_lines: + if l.find("") == -1: + l_counter += 1 + output_file.write(f"- {l}\n") + print(f"\tProcessed {l_counter} line(s)") + document_header = [ ".. This file is automatically generated by ./docs/script/make_doc.py Python script.\n", " Please, don't change. In case you need to make corrections or changes change\n", @@ -82,6 +105,7 @@ def process_section(section, output_file, pth): output_file_name = sys.argv[1] output_file = open(output_file_name, "w") output_file.writelines(document_header) +see_also_lines = [] for in_f in doc_file_path: print(f"Processing: {in_f}") output_file.write(f".. Generated from {in_f}\n\n") @@ -90,12 +114,20 @@ def process_section(section, output_file, pth): lines = input_file.readlines() is_seo = False is_section = False + is_in_see_also = False section = [] l_counter = 0 for line in lines: l_counter += 1 if line == "See Also\n": - break + is_in_see_also = True + continue + if is_in_see_also: + if line.startswith('- '): + processed_line = process_esphome_refs(line[2:].rstrip(), l_counter) + if processed_line and (processed_line not in see_also_lines): + see_also_lines.append(processed_line) + continue if is_section: if (line in ['\n', '\r\n']) or line.startswith(" "): section.append(line) @@ -116,4 +148,5 @@ def process_section(section, output_file, pth): continue l = process_esphome_refs(line, l_counter) output_file.write(l) - print(f"\tProcessed {l_counter} line(s)") \ No newline at end of file + print(f"\tProcessed {l_counter} line(s)") +process_see_also(see_also_lines, output_file) diff --git a/docs/additional_information.rst b/docs/see_also.rst similarity index 62% rename from docs/additional_information.rst rename to docs/see_also.rst index ec7d883..975dca5 100644 --- a/docs/additional_information.rst +++ b/docs/see_also.rst @@ -1,5 +1,5 @@ -Additional information -====================== +See Also +-------- - `FAQ <./docs/faq.rst>`_ - `HaierProtocol `_ @@ -7,8 +7,6 @@ Additional information - `Haier protocol overview <./docs/protocol_overview.rst>`_ - `Example of climate configuration for smartair2 protocol <./docs/smartair2_example.rst>`_ - `Example of climate configuration for hOn protocol <./docs/hon_example.rst>`_ -- `ESPHome Haier Climate `_ -- `ESPHome Haier Climate Sensors `_ -- `ESPHome Haier Climate Binary Sensors `_ - `Esptool.py Documentation `_ -- `Sniffing serial communication <./docs/sniffing_serial_communication.rst>`_ \ No newline at end of file +- `Sniffing serial communication <./docs/sniffing_serial_communication.rst>`_ +- :doc:`Haier Climate `