Skip to content

Commit

Permalink
Initial select commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Dudnytskyi authored and paveldn committed Sep 7, 2024
1 parent b6b25c7 commit 4e0a085
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 104 deletions.
74 changes: 74 additions & 0 deletions components/haier/select/__init__.py
Original file line number Diff line number Diff line change
@@ -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))


49 changes: 3 additions & 46 deletions configs/select/airflow_horizontal.yaml
Original file line number Diff line number Diff line change
@@ -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
61 changes: 3 additions & 58 deletions configs/select/airflow_vertical.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e0a085

Please sign in to comment.