Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to make climate mode configurable #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion components/daikin_s21/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import climate, sensor
from esphome.const import CONF_ID
from esphome.const import CONF_ID, CONF_SUPPORTED_MODES
from .. import (
daikin_s21_ns,
CONF_S21_ID,
S21_CLIENT_SCHEMA,
DaikinS21Client,
)
from esphome.components.climate import ClimateMode

CONF_ROOM_TEMPERATURE_SENSOR = "room_temperature_sensor"
CONF_SETPOINT_INTERVAL = "setpoint_interval"
Expand All @@ -22,6 +23,15 @@
uart_ns = cg.esphome_ns.namespace("uart")
UARTComponent = uart_ns.class_("UARTComponent")

SUPPORTED_CLIMATE_MODES_OPTIONS = {
"OFF": ClimateMode.CLIMATE_MODE_OFF, # always available
"AUTO": ClimateMode.CLIMATE_MODE_AUTO, # always available
"COOL": ClimateMode.CLIMATE_MODE_COOL,
"HEAT": ClimateMode.CLIMATE_MODE_HEAT,
"DRY": ClimateMode.CLIMATE_MODE_DRY,
"FAN_ONLY": ClimateMode.CLIMATE_MODE_FAN_ONLY,
}

CONFIG_SCHEMA = cv.All(
climate.CLIMATE_SCHEMA.extend(
{
Expand All @@ -30,6 +40,9 @@
cv.Optional(
CONF_SETPOINT_INTERVAL, default="300s"
): cv.positive_time_period_seconds,
cv.Optional(CONF_SUPPORTED_MODES): cv.ensure_list(
cv.enum(SUPPORTED_CLIMATE_MODES_OPTIONS, upper=True)
),
}
)
.extend(cv.polling_component_schema("5s"))
Expand All @@ -49,3 +62,12 @@ async def to_code(config):
cg.add(var.set_room_sensor(sens))
if CONF_SETPOINT_INTERVAL in config:
cg.add(var.set_setpoint_interval(config[CONF_SETPOINT_INTERVAL]))

if CONF_SUPPORTED_MODES in config:
cg.add(var.set_supported_modes(config[CONF_SUPPORTED_MODES])) else:
cg.add(var.set_supported_modes([
ClimateMode.CLIMATE_MODE_COOL,
ClimateMode.CLIMATE_MODE_HEAT,
ClimateMode.CLIMATE_MODE_DRY,
ClimateMode.CLIMATE_MODE_FAN_ONLY,
]))
30 changes: 15 additions & 15 deletions components/daikin_s21/climate/daikin_s21_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,32 @@ void DaikinS21Climate::dump_config() {
this->dump_traits_(TAG);
}

climate::ClimateTraits DaikinS21Climate::traits() {
auto traits = climate::ClimateTraits();
void DaikinS21Climate::set_supported_modes(const std::set<climate::ClimateMode> &modes) {
this->traits_.set_supported_modes(modes);
this->traits_.add_supported_mode(climate::CLIMATE_MODE_OFF); // Always available
this->traits_.add_supported_mode(climate::CLIMATE_MODE_AUTO); // Always available
}

traits.set_supports_action(true);
climate::ClimateTraits DaikinS21Climate::traits() {

traits.set_supports_current_temperature(true);
traits.set_visual_min_temperature(SETPOINT_MIN);
traits.set_visual_max_temperature(SETPOINT_MAX);
traits.set_visual_temperature_step(SETPOINT_STEP);
traits.set_supports_two_point_target_temperature(false);
this->traits_.set_supports_action(true);

traits.set_supported_modes(
{climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_HEAT_COOL,
climate::CLIMATE_MODE_COOL, climate::CLIMATE_MODE_HEAT,
climate::CLIMATE_MODE_FAN_ONLY, climate::CLIMATE_MODE_DRY});
this->traits_.set_supports_current_temperature(true);
this->traits_.set_visual_min_temperature(SETPOINT_MIN);
this->traits_.set_visual_max_temperature(SETPOINT_MAX);
this->traits_.set_visual_temperature_step(SETPOINT_STEP);
this->traits_.set_supports_two_point_target_temperature(false);

traits.set_supported_custom_fan_modes({"Automatic", "1", "2", "3", "4", "5"});
this->traits_.set_supported_custom_fan_modes({"Automatic", "1", "2", "3", "4", "5"});

traits.set_supported_swing_modes({
this->traits_.set_supported_swing_modes({
climate::CLIMATE_SWING_OFF,
climate::CLIMATE_SWING_BOTH,
climate::CLIMATE_SWING_VERTICAL,
climate::CLIMATE_SWING_HORIZONTAL,
});

return traits;
return this->traits_;
}

bool DaikinS21Climate::use_room_sensor() {
Expand Down
4 changes: 4 additions & 0 deletions components/daikin_s21/climate/daikin_s21_climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class DaikinS21Climate : public climate::Climate,
bool e2d_swing_v(climate::ClimateSwingMode mode);
bool e2d_swing_h(climate::ClimateSwingMode mode);

void set_supported_modes(const std::set<esphome::climate::ClimateMode> &modes);

protected:
esphome::climate::ClimateTraits traits_;

sensor::Sensor *room_sensor_{nullptr};
float expected_s21_setpoint;
uint8_t skip_setpoint_checks = 0;
Expand Down