diff --git a/components/tcs_intercom/binary_sensor/__init__.py b/components/tcs_intercom/binary_sensor/__init__.py index 7046035..ae5170b 100644 --- a/components/tcs_intercom/binary_sensor/__init__.py +++ b/components/tcs_intercom/binary_sensor/__init__.py @@ -30,7 +30,10 @@ async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await binary_sensor.register_binary_sensor(var, config) - cg.add(var.set_command(config[CONF_COMMAND])) + + command_template = await cg.templatable(config[CONF_COMMAND], [(cg.uint32_t, "x")], cg.uint32_t) + cg.add(var.set_command_template(command_template)) + cg.add(var.set_auto_off(config[CONF_AUTO_OFF])) tcs_intercom = await cg.get_variable(config[CONF_TCS_ID]) cg.add(tcs_intercom.register_listener(var)) \ No newline at end of file diff --git a/components/tcs_intercom/binary_sensor/tcs_intercom_binary_sensor.h b/components/tcs_intercom/binary_sensor/tcs_intercom_binary_sensor.h index 27ec3b1..32d7583 100644 --- a/components/tcs_intercom/binary_sensor/tcs_intercom_binary_sensor.h +++ b/components/tcs_intercom/binary_sensor/tcs_intercom_binary_sensor.h @@ -16,7 +16,7 @@ namespace esphome protected: binary_sensor::BinarySensor *incoming_command_sensor_{nullptr}; - uint16_t command_; + uint32_t command_; }; } // namespace tcs_intercom diff --git a/components/tcs_intercom/tcs_intercom.cpp b/components/tcs_intercom/tcs_intercom.cpp index b06974a..276b2a5 100644 --- a/components/tcs_intercom/tcs_intercom.cpp +++ b/components/tcs_intercom/tcs_intercom.cpp @@ -257,7 +257,7 @@ namespace esphome { if (listener->command_ == command) { - ESP_LOGD(TAG, "Binary sensor fired! %x", listener->command_); + ESP_LOGD(TAG, "Binary sensor fired! %x", listener->command_value_); listener->turn_on(&listener->timer_, listener->auto_off_); } } diff --git a/components/tcs_intercom/tcs_intercom.h b/components/tcs_intercom/tcs_intercom.h index b18402d..0385774 100644 --- a/components/tcs_intercom/tcs_intercom.h +++ b/components/tcs_intercom/tcs_intercom.h @@ -16,14 +16,16 @@ namespace esphome class TCSIntercomListener { public: - void set_command(uint32_t command) { this->command_ = command; } + void set_command_template(std::function command_template) { command_template_ = command_template; } void set_auto_off(uint16_t auto_off) { this->auto_off_ = auto_off; } virtual void turn_on(uint32_t *timer, uint16_t auto_off) {}; virtual void turn_off(uint32_t *timer) {}; + std::function command_template_; + uint32_t command_value_{0}; + uint32_t timer_; - uint32_t command_; uint16_t auto_off_; };