Skip to content

Commit

Permalink
Preparation commit
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Sep 7, 2024
1 parent 4e0a085 commit 3c62319
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 20 additions & 0 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_;
Expand Down
12 changes: 12 additions & 0 deletions components/haier/hon_climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
63 changes: 37 additions & 26 deletions components/haier/select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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(
{
Expand All @@ -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))


33 changes: 33 additions & 0 deletions components/haier/select/horizontal_airflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "horizontal_airflow.h"
#include <protocol/haier_protocol.h>

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<hon_protocol::HorizontalSwingMode> 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
18 changes: 18 additions & 0 deletions components/haier/select/horizontal_airflow.h
Original file line number Diff line number Diff line change
@@ -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<HonClimate> {
public:
HorizontalAirflowSelect() = default;

protected:
void control(const std::string &value) override;
};

} // namespace haier
} // namespace esphome
12 changes: 12 additions & 0 deletions components/haier/select/vertical_airflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "vertical_airflow.h"
#include <protocol/haier_protocol.h>

namespace esphome {
namespace haier {

void VerticalAirflowSelect::control(const std::string &value) {
this->publish_state(value);
}

} // namespace haier
} // namespace esphome
18 changes: 18 additions & 0 deletions components/haier/select/vertical_airflow.h
Original file line number Diff line number Diff line change
@@ -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<HonClimate> {
public:
VerticalAirflowSelect() = default;

protected:
void control(const std::string &value) override;
};

} // namespace haier
} // namespace esphome

0 comments on commit 3c62319

Please sign in to comment.