1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00
Files
esphome/esphome/components/haier/climate.py
Yaroslav Heriatovych fe4fb5f1ac Add Haier climate component (#4001)
* Basic functionality works

* Cleanup

* Add tests

* Separate header

* Fix send_data_

* Formatting fix

* Add __init__.py

* Fix type

* Add codeowners

* Rename supported_swing_modes

* Use multiple swing modes, same as midea platform

* Add CLIMATE_FAN_QUIET handler

* PR fixes
2023-02-23 02:05:33 +00:00

44 lines
1.4 KiB
Python

from esphome.components import climate
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import uart
from esphome.components.climate import ClimateSwingMode
from esphome.const import CONF_ID, CONF_SUPPORTED_SWING_MODES
DEPENDENCIES = ["uart"]
haier_ns = cg.esphome_ns.namespace("haier")
HaierClimate = haier_ns.class_(
"HaierClimate", climate.Climate, cg.PollingComponent, uart.UARTDevice
)
ALLOWED_CLIMATE_SWING_MODES = {
"BOTH": ClimateSwingMode.CLIMATE_SWING_BOTH,
"VERTICAL": ClimateSwingMode.CLIMATE_SWING_VERTICAL,
"HORIZONTAL": ClimateSwingMode.CLIMATE_SWING_HORIZONTAL,
}
validate_swing_modes = cv.enum(ALLOWED_CLIMATE_SWING_MODES, upper=True)
CONFIG_SCHEMA = cv.All(
climate.CLIMATE_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(HaierClimate),
cv.Optional(CONF_SUPPORTED_SWING_MODES): cv.ensure_list(
validate_swing_modes
),
}
)
.extend(cv.polling_component_schema("5s"))
.extend(uart.UART_DEVICE_SCHEMA),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await climate.register_climate(var, config)
await uart.register_uart_device(var, config)
if CONF_SUPPORTED_SWING_MODES in config:
cg.add(var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES]))