From 51affa3c3a2161d45083ead937f98a63c6bec3cb Mon Sep 17 00:00:00 2001 From: ElVit Date: Thu, 20 Feb 2025 10:40:21 +0100 Subject: [PATCH] Added id_ member to each control class --- components/panasonic_heatpump/number/__init__.py | 1 + .../panasonic_heatpump/number/panasonic_heatpump_number.h | 2 ++ components/panasonic_heatpump/select/__init__.py | 1 + .../panasonic_heatpump/select/panasonic_heatpump_select.h | 2 ++ components/panasonic_heatpump/switch/__init__.py | 3 ++- .../panasonic_heatpump/switch/panasonic_heatpump_switch.h | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/panasonic_heatpump/number/__init__.py b/components/panasonic_heatpump/number/__init__.py index 548c478..1c58739 100644 --- a/components/panasonic_heatpump/number/__init__.py +++ b/components/panasonic_heatpump/number/__init__.py @@ -286,3 +286,4 @@ async def to_code(config): await cg.register_component(var, child_config) await cg.register_parented(var, config[CONF_PANASONIC_HEATPUMP_ID]) cg.add(getattr(hub, f"set_{key}_number")(var)) + cg.add(var.set_id(index)) diff --git a/components/panasonic_heatpump/number/panasonic_heatpump_number.h b/components/panasonic_heatpump/number/panasonic_heatpump_number.h index bb3513c..5b535fd 100644 --- a/components/panasonic_heatpump/number/panasonic_heatpump_number.h +++ b/components/panasonic_heatpump/number/panasonic_heatpump_number.h @@ -13,9 +13,11 @@ namespace esphome public: PanasonicHeatpumpNumber() = default; void dump_config() override; + void set_id(int id) { this->id_ = id; } protected: void control(float value) override; + int id_; }; } // namespace panasonic_heatpump } // namespace esphome diff --git a/components/panasonic_heatpump/select/__init__.py b/components/panasonic_heatpump/select/__init__.py index 4fa60dd..28e635f 100644 --- a/components/panasonic_heatpump/select/__init__.py +++ b/components/panasonic_heatpump/select/__init__.py @@ -73,3 +73,4 @@ async def to_code(config): await cg.register_component(var, child_config) await cg.register_parented(var, config[CONF_PANASONIC_HEATPUMP_ID]) cg.add(getattr(hub, f"set_{key}_select")(var)) + cg.add(var.set_id(index)) diff --git a/components/panasonic_heatpump/select/panasonic_heatpump_select.h b/components/panasonic_heatpump/select/panasonic_heatpump_select.h index 85267ac..8f7ebe5 100644 --- a/components/panasonic_heatpump/select/panasonic_heatpump_select.h +++ b/components/panasonic_heatpump/select/panasonic_heatpump_select.h @@ -13,9 +13,11 @@ namespace esphome public: PanasonicHeatpumpSelect() = default; void dump_config() override; + void set_id(int id) { this->id_ = id; } protected: void control(const std::string &value) override; + int id_; }; } // namespace panasonic_heatpump } // namespace esphome diff --git a/components/panasonic_heatpump/switch/__init__.py b/components/panasonic_heatpump/switch/__init__.py index 0f3cd60..b718eab 100644 --- a/components/panasonic_heatpump/switch/__init__.py +++ b/components/panasonic_heatpump/switch/__init__.py @@ -86,9 +86,10 @@ CONFIG_SCHEMA = cv.Schema( async def to_code(config): hub = await cg.get_variable(config[CONF_PANASONIC_HEATPUMP_ID]) - for key in TYPES: + for index, key in enumerate(TYPES): if child_config := config.get(key): var = await switch.new_switch(child_config) await cg.register_component(var, child_config) await cg.register_parented(var, config[CONF_PANASONIC_HEATPUMP_ID]) cg.add(getattr(hub, f"set_{key}_switch")(var)) + cg.add(var.set_id(index)) diff --git a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h index 7fd5264..de9f4f7 100644 --- a/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h +++ b/components/panasonic_heatpump/switch/panasonic_heatpump_switch.h @@ -13,9 +13,11 @@ namespace esphome public: PanasonicHeatpumpSwitch() = default; void dump_config() override; + void set_id(int id) { this->id_ = id; } protected: void write_state(bool state) override; + int id_; }; } // namespace panasonic_heatpump } // namespace esphome