diff --git a/components/panasonic_heatpump/number/__init__.py b/components/panasonic_heatpump/number/__init__.py new file mode 100644 index 0000000..d6139c0 --- /dev/null +++ b/components/panasonic_heatpump/number/__init__.py @@ -0,0 +1,225 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import number +from esphome.const import ( + UNIT_CENTIMETER, + UNIT_PERCENT, +) +from .. import CONF_PANASONIC_HEATPUMP_ID, PanasonicHeatpumpComponent, panasonic_heatpump_ns + + +CONF_SET_Z1_HEAT_REQUEST_TEMPERATURE = "set_z1_heat_request_temperature" +CONF_SET_Z1_COOL_REQUEST_TEMPERATURE = "set_z1_cool_request_temperature" +CONF_SET_Z2_HEAT_REQUEST_TEMPERATURE = "set_z2_heat_request_temperature" +CONF_SET_Z2_COOL_REQUEST_TEMPERATURE = "set_z2_cool_request_temperature" +CONF_SET_DHW_TEMP = "set_DHW_temp" +CONF_SET_MAX_PUMP_DUTY = "set_max_pump_duty" +CONF_SET_ZONE1_HEAT_TARGET_HIGH = "set_zone1_heat_target_high" +CONF_SET_ZONE1_HEAT_TARGET_LOW = "set_zone1_heat_target_low" +CONF_SET_ZONE1_HEAT_OUTSIDE_LOW = "set_zone1_heat_outside_low" +CONF_SET_ZONE1_HEAT_OUTSIDE_HIGH = "set_zone1_heat_outside_high" +CONF_SET_ZONE2_HEAT_TARGET_HIGH = "set_zone2_heat_target_high" +CONF_SET_ZONE2_HEAT_TARGET_LOW = "set_zone2_heat_target_low" +CONF_SET_ZONE2_HEAT_OUTSIDE_LOW = "set_zone2_heat_outside_low" +CONF_SET_ZONE2_HEAT_OUTSIDE_HIGH = "set_zone2_heat_outside_high" +CONF_SET_ZONE1_COOL_TARGET_HIGH = "set_zone1_cool_target_high" +CONF_SET_ZONE1_COOL_TARGET_LOW = "set_zone1_cool_target_low" +CONF_SET_ZONE1_COOL_OUTSIDE_LOW = "set_zone1_cool_outside_low" +CONF_SET_ZONE1_COOL_OUTSIDE_HIGH = "set_zone1_cool_outside_high" +CONF_SET_ZONE2_COOL_TARGET_HIGH = "set_zone2_cool_target_high" +CONF_SET_ZONE2_COOL_TARGET_LOW = "set_zone2_cool_target_low" +CONF_SET_ZONE2_COOL_OUTSIDE_LOW = "set_zone2_cool_outside_low" +CONF_SET_ZONE2_COOL_OUTSIDE_HIGH = "set_zone2_cool_outside_high" +CONF_SET_FLOOR_HEAT_DELTA = "set_floor_heat_delta" +CONF_SET_FLOOR_COOL_DELTA = "set_floor_cool_delta" +CONF_SET_DHW_HEAT_DELTA = "set_dhw_heat_delta" +CONF_SET_HEATER_DELAY_TIME = "set_heater_delay_time" +CONF_SET_HEATER_START_DELTA = "set_heater_start_delta" +CONF_SET_HEATER_STOP_DELTA = "set_heater_stop_delta" +CONF_SET_BUFFER_DELTA = "set_buffer_delta" +CONF_SET_HEATINGOFFOUTDOORTEMP = "set_heatingoffoutdoortemp" +CONF_SET_BIVALENT_START_TEMPERATURE = "set_bivalent_start_temperature" +CONF_SET_BIVALENT_STOP_TEMPERATURE = "set_bivalent_stop_temperature" + +TYPES = [ + CONF_SET_Z1_HEAT_REQUEST_TEMPERATURE, + CONF_SET_Z1_COOL_REQUEST_TEMPERATURE, + CONF_SET_Z2_HEAT_REQUEST_TEMPERATURE, + CONF_SET_Z2_COOL_REQUEST_TEMPERATURE, + CONF_SET_DHW_TEMP, + CONF_SET_MAX_PUMP_DUTY, + CONF_SET_ZONE1_HEAT_TARGET_HIGH, + CONF_SET_ZONE1_HEAT_TARGET_LOW, + CONF_SET_ZONE1_HEAT_OUTSIDE_LOW, + CONF_SET_ZONE1_HEAT_OUTSIDE_HIGH, + CONF_SET_ZONE2_HEAT_TARGET_HIGH, + CONF_SET_ZONE2_HEAT_TARGET_LOW, + CONF_SET_ZONE2_HEAT_OUTSIDE_LOW, + CONF_SET_ZONE2_HEAT_OUTSIDE_HIGH, + CONF_SET_ZONE1_COOL_TARGET_HIGH, + CONF_SET_ZONE1_COOL_TARGET_LOW, + CONF_SET_ZONE1_COOL_OUTSIDE_LOW, + CONF_SET_ZONE1_COOL_OUTSIDE_HIGH, + CONF_SET_ZONE2_COOL_TARGET_HIGH, + CONF_SET_ZONE2_COOL_TARGET_LOW, + CONF_SET_ZONE2_COOL_OUTSIDE_LOW, + CONF_SET_ZONE2_COOL_OUTSIDE_HIGH, + CONF_SET_FLOOR_HEAT_DELTA, + CONF_SET_FLOOR_COOL_DELTA, + CONF_SET_DHW_HEAT_DELTA, + CONF_SET_HEATER_DELAY_TIME, + CONF_SET_HEATER_START_DELTA, + CONF_SET_HEATER_STOP_DELTA, + CONF_SET_BUFFER_DELTA, + CONF_SET_HEATINGOFFOUTDOORTEMP, + CONF_SET_BIVALENT_START_TEMPERATURE, + CONF_SET_BIVALENT_STOP_TEMPERATURE, +] + +PanasonicHeatpumpNumber = panasonic_heatpump_ns.class_("PanasonicHeatpumpNumber", number.Number) + +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(CONF_PANASONIC_HEATPUMP_ID): cv.use_id(PanasonicHeatpumpComponent), + + cv.Optional(CONF_SET_Z1_HEAT_REQUEST_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_Z1_COOL_REQUEST_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_Z2_HEAT_REQUEST_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_Z2_COOL_REQUEST_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_DHW_TEMP): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_MAX_PUMP_DUTY): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_HEAT_TARGET_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_HEAT_TARGET_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_HEAT_OUTSIDE_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_HEAT_OUTSIDE_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_HEAT_TARGET_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_HEAT_TARGET_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_HEAT_OUTSIDE_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_HEAT_OUTSIDE_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_COOL_TARGET_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_COOL_TARGET_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_COOL_OUTSIDE_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE1_COOL_OUTSIDE_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_COOL_TARGET_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_COOL_TARGET_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_COOL_OUTSIDE_LOW): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_ZONE2_COOL_OUTSIDE_HIGH): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_FLOOR_HEAT_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_FLOOR_COOL_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_DHW_HEAT_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_HEATER_DELAY_TIME): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_HEATER_START_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_HEATER_STOP_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_BUFFER_DELTA): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_HEATINGOFFOUTDOORTEMP): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_BIVALENT_START_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + cv.Optional(CONF_SET_BIVALENT_STOP_TEMPERATURE): number.number_schema( + PanasonicHeatpumpNumber, + unit_of_measurement=UNIT_CENTIMETER, + ), + } +) + +async def to_code(config): + hub = await cg.get_variable(config[CONF_PANASONIC_HEATPUMP_ID]) + for key in TYPES: + await setup_conf(config, key, hub) + +async def setup_conf(parent_config, key, hub): + if child_config := parent_config.get(key): + var = await number.new_number(child_config, min_value=0, max_value=100, step=.1) + await cg.register_parented(var, parent_config[CONF_PANASONIC_HEATPUMP_ID]) + cg.add(getattr(hub, f"set_{key}_number")(var)) diff --git a/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp b/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp new file mode 100644 index 0000000..54a41db --- /dev/null +++ b/components/panasonic_heatpump/number/panasonic_heatpump_number.cpp @@ -0,0 +1,14 @@ +#include "panasonic_heatpump_number.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + void PanasonicHeatpumpNumber::control(float value) + { + this->publish_state(value); + this->parent_->number_control(this, value); + } + } // namespace panasonic_heatpump +} // namespace esphome diff --git a/components/panasonic_heatpump/number/panasonic_heatpump_number.h b/components/panasonic_heatpump/number/panasonic_heatpump_number.h new file mode 100644 index 0000000..50fec1d --- /dev/null +++ b/components/panasonic_heatpump/number/panasonic_heatpump_number.h @@ -0,0 +1,19 @@ +#pragma once +#include "esphome/components/number/number.h" +#include "../panasonic_heatpump.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + class PanasonicHeatpumpNumber : public number::Number, public Parented + { + public: + PanasonicHeatpumpNumber() = default; + + protected: + void control(float value) override; + }; + } // namespace panasonic_heatpump +} // namespace esphome diff --git a/components/panasonic_heatpump/panasonic_heatpump.cpp b/components/panasonic_heatpump/panasonic_heatpump.cpp index d347017..78adb55 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.cpp +++ b/components/panasonic_heatpump/panasonic_heatpump.cpp @@ -1,5 +1,8 @@ #include "panasonic_heatpump.h" +#define RESPONSE_DATA_SIZE 203 +#define REQUEST_DATA_SIZE 111 + namespace esphome { @@ -7,9 +10,6 @@ namespace esphome { static const char *const TAG = "panasonic_heatpump"; - static const uint8_t RESPONSE_DATA_SIZE = 203; - static const uint8_t REQUEST_DATA_SIZE = 111; - void PanasonicHeatpumpComponent::dump_config() { ESP_LOGCONFIG(TAG, "Panasonic Heatpump"); @@ -423,5 +423,27 @@ namespace esphome delay(10); } } + +#ifdef USE_NUMBER + void PanasonicHeatpumpComponent::number_control(number::Number* object, float value) + { + // if (object == top0_number_) + // this->send_request(value); + } +#endif +#ifdef USE_SELECT + void PanasonicHeatpumpComponent::select_control(select::Select* object, const std::string &value) + { + // if (object == top1_select_) + // this->send_request(value); + } +#endif +#ifdef USE_SWITCH + void PanasonicHeatpumpComponent::switch_control(switch::Switch* object, bool state) + { + // if (object == top2_switch_) + // this->send_request(value); + } +#endif } // namespace panasonic_heatpump -} // namespace esphome \ No newline at end of file +} // namespace esphome diff --git a/components/panasonic_heatpump/panasonic_heatpump.h b/components/panasonic_heatpump/panasonic_heatpump.h index efbbf08..ca95b58 100644 --- a/components/panasonic_heatpump/panasonic_heatpump.h +++ b/components/panasonic_heatpump/panasonic_heatpump.h @@ -13,6 +13,15 @@ #ifdef USE_TEXT_SENSOR #include "esphome/components/text_sensor/text_sensor.h" #endif +#ifdef USE_NUMBER +#include "esphome/components/number/number.h" +#endif +#ifdef USE_SELECT +#include "esphome/components/select/select.h" +#endif +#ifdef USE_SWITCH +#include "esphome/components/switch/switch.h" +#endif #include "decode.h" #include #include @@ -158,6 +167,15 @@ namespace esphome SUB_TEXT_SENSOR(top114); SUB_TEXT_SENSOR(top124); #endif +#ifdef USE_NUMBER + // SUB_NUMBER(top0); +#endif +#ifdef USE_SELECT + // SUB_SELECT(top1); +#endif +#ifdef USE_SWITCH + // SUB_SWITCH(top2); +#endif PanasonicHeatpumpComponent() = default; float get_setup_priority() const override { return setup_priority::LATE; } @@ -166,6 +184,15 @@ namespace esphome void set_uart_hp(uart::UARTComponent *uart) { this->uart_hp_ = uart; } void set_uart_wm(uart::UARTComponent *uart) { this->uart_wm_ = uart; } +#ifdef USE_NUMBER + void number_control(number::Number* object, float value); +#endif +#ifdef USE_SELECT + void select_control(select::Select* object, const std::string &value); +#endif +#ifdef USE_SWITCH + void switch_control(switch::Switch* object, bool state); +#endif protected: uart::UARTComponent *uart_hp_; @@ -183,4 +210,4 @@ namespace esphome void log_uart_hex(std::string prefix, std::vector bytes, uint8_t separator); }; } // namespace panasonic_heatpump -} // namespace esphome \ No newline at end of file +} // namespace esphome diff --git a/components/panasonic_heatpump/select/__init__.py b/components/panasonic_heatpump/select/__init__.py new file mode 100644 index 0000000..3b641f4 --- /dev/null +++ b/components/panasonic_heatpump/select/__init__.py @@ -0,0 +1,67 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import select +from esphome.const import ( + UNIT_PERCENT, +) +from .. import CONF_PANASONIC_HEATPUMP_ID, PanasonicHeatpumpComponent, panasonic_heatpump_ns + + +CONF_SET_QUIET_MODE = "set_quiet_mode" +CONF_SET_POWERFUL_MODE = "set_powerful_mode" +CONF_SET_OPERATION_MODE = "set_operation_mode" +CONF_SET_ZONES = "set_zones" +CONF_SET_EXTERNAL_PAD_HEATER = "set_external_pad_heater" +CONF_SET_POWERFUL_MODE = "set_powerful_mode" +CONF_SET_BIVALENT_MODE = "set_bivalent_mode" + +TYPES = [ + CONF_SET_QUIET_MODE, + CONF_SET_POWERFUL_MODE, + CONF_SET_OPERATION_MODE, + CONF_SET_ZONES, + CONF_SET_EXTERNAL_PAD_HEATER, + CONF_SET_POWERFUL_MODE, + CONF_SET_BIVALENT_MODE, +] + +PanasonicHeatpumpSelect = panasonic_heatpump_ns.class_("PanasonicHeatpumpSelect", select.Select) + +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(CONF_PANASONIC_HEATPUMP_ID): cv.use_id(PanasonicHeatpumpComponent), + + cv.Optional(CONF_SET_QUIET_MODE): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_POWERFUL_MODE): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_OPERATION_MODE): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_ZONES): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_EXTERNAL_PAD_HEATER): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_POWERFUL_MODE): select.select_schema( + PanasonicHeatpumpSelect, + ), + cv.Optional(CONF_SET_BIVALENT_MODE): select.select_schema( + PanasonicHeatpumpSelect, + ), + } +) + +async def to_code(config): + hub = await cg.get_variable(config[CONF_PANASONIC_HEATPUMP_ID]) + for key in TYPES: + await setup_conf(config, key, hub) + +async def setup_conf(parent_config, key, hub): + if child_config := parent_config.get(key): + var = await select.new_select(child_config, options=["dummy1", "dummy2"]) + await cg.register_parented(var, parent_config[CONF_PANASONIC_HEATPUMP_ID]) + cg.add(getattr(hub, f"set_{key}_select")(var)) diff --git a/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp b/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp new file mode 100644 index 0000000..4353937 --- /dev/null +++ b/components/panasonic_heatpump/select/panasonic_heatpump_select.cpp @@ -0,0 +1,14 @@ +#include "panasonic_heatpump_select.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + void PanasonicHeatpumpSelect::control(const std::string &value) + { + this->publish_state(value); + this->parent_->select_control(this, value); + } + } // namespace panasonic_heatpump +} // namespace esphome diff --git a/components/panasonic_heatpump/select/panasonic_heatpump_select.h b/components/panasonic_heatpump/select/panasonic_heatpump_select.h new file mode 100644 index 0000000..675c1f3 --- /dev/null +++ b/components/panasonic_heatpump/select/panasonic_heatpump_select.h @@ -0,0 +1,19 @@ +#pragma once +#include "esphome/components/select/select.h" +#include "../panasonic_heatpump.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + class PanasonicHeatpumpSelect : public select::Select, public Parented + { + public: + PanasonicHeatpumpSelect() = default; + + protected: + void control(const std::string &value) override; + }; + } // namespace panasonic_heatpump +} // namespace esphome diff --git a/components/panasonic_heatpump/switch/__init__.py b/components/panasonic_heatpump/switch/__init__.py new file mode 100644 index 0000000..8d1b9dc --- /dev/null +++ b/components/panasonic_heatpump/switch/__init__.py @@ -0,0 +1,77 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import switch +from esphome.const import ( + UNIT_PERCENT, +) +from .. import CONF_PANASONIC_HEATPUMP_ID, PanasonicHeatpumpComponent, panasonic_heatpump_ns + + +CONF_SET_HEATPUMP_STATE = "set_heatpump_state" +CONF_SET_HOLIDAY_MODE = "set_holiday_mode" +CONF_SET_FORCE_DHW = "set_force_DHW" +CONF_SET_FORCE_DEFROST = "set_force_defrost" +CONF_SET_FORCE_STERILIZATION = "set_force_sterilization" +CONF_SET_PUMP = "set_pump" +CONF_SET_MAIN_SCHEDULE = "set_main_schedule" +CONF_SET_ALT_EXTERNAL_SENSOR = "set_alt_external_sensor" +CONF_SET_BUFFER = "set_buffer" + +TYPES = [ + CONF_SET_HEATPUMP_STATE, + CONF_SET_HOLIDAY_MODE, + CONF_SET_FORCE_DHW, + CONF_SET_FORCE_DEFROST, + CONF_SET_FORCE_STERILIZATION, + CONF_SET_PUMP, + CONF_SET_MAIN_SCHEDULE, + CONF_SET_ALT_EXTERNAL_SENSOR, + CONF_SET_BUFFER, +] + +PanasonicHeatpumpSwitch = panasonic_heatpump_ns.class_("PanasonicHeatpumpSwitch", switch.Switch) + +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(CONF_PANASONIC_HEATPUMP_ID): cv.use_id(PanasonicHeatpumpComponent), + + cv.Optional(CONF_SET_HEATPUMP_STATE): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_HOLIDAY_MODE): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_FORCE_DHW): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_FORCE_DEFROST): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_FORCE_STERILIZATION): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_PUMP): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_MAIN_SCHEDULE): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_ALT_EXTERNAL_SENSOR): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + cv.Optional(CONF_SET_BUFFER): switch.switch_schema( + PanasonicHeatpumpSwitch, + ), + } +) + +async def to_code(config): + hub = await cg.get_variable(config[CONF_PANASONIC_HEATPUMP_ID]) + for key in TYPES: + await setup_conf(config, key, hub) + +async def setup_conf(parent_config, key, hub): + if child_config := parent_config.get(key): + var = await switch.new_switch(child_config) + await cg.register_parented(var, parent_config[CONF_PANASONIC_HEATPUMP_ID]) + cg.add(getattr(hub, f"set_{key}_switch")(var)) diff --git a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp new file mode 100644 index 0000000..2c4f3ac --- /dev/null +++ b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.cpp @@ -0,0 +1,14 @@ +#include "panasonic_heatpump_switch.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + void PanasonicHeatpumpSwitch::write_state(bool state) + { + this->publish_state(state); + this->parent_->switch_control(this, state); + } + } // namespace panasonic_heatpump +} // namespace esphome diff --git a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h new file mode 100644 index 0000000..3686116 --- /dev/null +++ b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h @@ -0,0 +1,19 @@ +#pragma once +#include "esphome/components/switch/switch.h" +#include "../panasonic_heatpump.h" + + +namespace esphome +{ + namespace panasonic_heatpump + { + class PanasonicHeatpumpSwitch : public switch::Switch, public Parented + { + public: + PanasonicHeatpumpSwitch() = default; + + protected: + void write_state(bool state) override; + }; + } // namespace panasonic_heatpump +} // namespace esphome