From eeeb5dd2564d91c58dcd0aad01eb7bcfd7c7cbbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Poczkodi?= Date: Fri, 1 Mar 2024 01:32:37 +0100 Subject: [PATCH] renamed transmit_cc1101 to transmit_rc_switch_raw_cc1101 to better reflect what it does, and begin_tx/end_tx can be used for the rest of the transmit_* actions --- esphome/components/cc1101/__init__.py | 25 ++++++++++++++++--- esphome/components/cc1101/cc1101.cpp | 14 ++++++----- esphome/components/cc1101/cc1101.h | 10 ++++++++ .../components/cc1101/test.esp32-c3-idf.yaml | 2 +- tests/components/cc1101/test.esp32-c3.yaml | 2 +- tests/components/cc1101/test.esp32-idf.yaml | 2 +- .../components/cc1101/test.esp32-s2-idf.yaml | 2 +- tests/components/cc1101/test.esp32-s2.yaml | 2 +- tests/components/cc1101/test.esp32.yaml | 2 +- tests/components/cc1101/test.esp8266.yaml | 2 +- 10 files changed, 47 insertions(+), 16 deletions(-) diff --git a/esphome/components/cc1101/__init__.py b/esphome/components/cc1101/__init__.py index 906ee1a05c..47e7a4d804 100644 --- a/esphome/components/cc1101/__init__.py +++ b/esphome/components/cc1101/__init__.py @@ -1,6 +1,7 @@ import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins +from esphome import automation, pins +from esphome.automation import maybe_simple_id from esphome.components import sensor from esphome.components import spi from esphome.components import remote_base @@ -74,6 +75,24 @@ async def to_code(config): cg.add(var.set_config_lqi_sensor(lqi)) +BeginTxAction = ns.class_("BeginTxAction", automation.Action) +EndTxAction = ns.class_("EndTxAction", automation.Action) + +CC1101_ACTION_SCHEMA = maybe_simple_id( + { + cv.Required(CONF_ID): cv.use_id(CC1101), + } +) + + +@automation.register_action("cc1101.begin_tx", BeginTxAction, CC1101_ACTION_SCHEMA) +@automation.register_action("cc1101.end_tx", EndTxAction, CC1101_ACTION_SCHEMA) +async def cc1101_action_to_code(config, action_id, template_arg, args): + var = cg.new_Pvariable(action_id, template_arg) + await cg.register_parented(var, config[CONF_ID]) + return var + + CC1101RawAction = ns.class_("CC1101RawAction", remote_base.RCSwitchRawAction) CC1101_TRANSMIT_SCHEMA = ( @@ -88,8 +107,8 @@ CC1101_TRANSMIT_SCHEMA = ( ) -@remote_base.register_action("cc1101", CC1101RawAction, CC1101_TRANSMIT_SCHEMA) -async def cc1101_action(var, config, args): +@remote_base.register_action("rc_switch_raw_cc1101", CC1101RawAction, CC1101_TRANSMIT_SCHEMA) +async def rc_switch_raw_cc1101_action(var, config, args): proto = await cg.templatable( config[CONF_PROTOCOL], args, diff --git a/esphome/components/cc1101/cc1101.cpp b/esphome/components/cc1101/cc1101.cpp index c06068f6f7..46f8475eb2 100644 --- a/esphome/components/cc1101/cc1101.cpp +++ b/esphome/components/cc1101/cc1101.cpp @@ -6,11 +6,13 @@ It can be compiled with Arduino and esp-idf framework and should support any esphome compatible board through the SPI Bus. - On ESP8266, you can use a single pin instead of GD0O and GD02 (gdo0 is an optional parameter). If assigned, - the pin direction will be reversed for the transfers. + On ESP8266, you can use a single pin instead of GD0O and GD02 (gdo0 is an optional parameter). If assigned, the pin + direction will be reversed for the transfers. - On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2. - If only TX works, they are probably switched. + On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2. If only TX works, they are + probably switched. + + Transfers, except transmit_rc_switch_raw_cc1101, must be surrounded with cc1101.begin_tx and cc1101.end_tx. The source code is a mashup of the following github projects with some special esphome sauce: @@ -593,14 +595,14 @@ void CC1101::set_rxbw_(uint32_t bw) { } void CC1101::set_tx_() { - ESP_LOGI(TAG, "CC1101 set_tx"); + ESP_LOGD(TAG, "CC1101 set_tx"); this->send_cmd_(CC1101_SIDLE); this->send_cmd_(CC1101_STX); this->trxstate_ = 1; } void CC1101::set_rx_() { - ESP_LOGI(TAG, "CC1101 set_rx"); + ESP_LOGD(TAG, "CC1101 set_rx"); this->send_cmd_(CC1101_SIDLE); this->send_cmd_(CC1101_SRX); this->trxstate_ = 2; diff --git a/esphome/components/cc1101/cc1101.h b/esphome/components/cc1101/cc1101.h index 16328fee9f..ca7c302415 100644 --- a/esphome/components/cc1101/cc1101.h +++ b/esphome/components/cc1101/cc1101.h @@ -90,6 +90,16 @@ class CC1101 : public PollingComponent, void end_tx(); }; +template class BeginTxAction : public Action, public Parented { + public: + void play(Ts... x) override { this->parent_->begin_tx(); } +}; + +template class EndTxAction : public Action, public Parented { + public: + void play(Ts... x) override { this->parent_->end_tx(); } +}; + template class CC1101RawAction : public remote_base::RCSwitchRawAction, public Parented { protected: void play(Ts... x) override { diff --git a/tests/components/cc1101/test.esp32-c3-idf.yaml b/tests/components/cc1101/test.esp32-c3-idf.yaml index 221da41500..0b9486d182 100644 --- a/tests/components/cc1101/test.esp32-c3-idf.yaml +++ b/tests/components/cc1101/test.esp32-c3-idf.yaml @@ -51,7 +51,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: transmitter_id: realtx code: '0111000110010011110110010100011111110001001011110111' protocol: diff --git a/tests/components/cc1101/test.esp32-c3.yaml b/tests/components/cc1101/test.esp32-c3.yaml index 221da41500..0b9486d182 100644 --- a/tests/components/cc1101/test.esp32-c3.yaml +++ b/tests/components/cc1101/test.esp32-c3.yaml @@ -51,7 +51,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: transmitter_id: realtx code: '0111000110010011110110010100011111110001001011110111' protocol: diff --git a/tests/components/cc1101/test.esp32-idf.yaml b/tests/components/cc1101/test.esp32-idf.yaml index e65990ca00..2277f37849 100644 --- a/tests/components/cc1101/test.esp32-idf.yaml +++ b/tests/components/cc1101/test.esp32-idf.yaml @@ -43,7 +43,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: code: '0111000110010011110110010100011111110001001011110111' protocol: pulse_length: 434 diff --git a/tests/components/cc1101/test.esp32-s2-idf.yaml b/tests/components/cc1101/test.esp32-s2-idf.yaml index d797e7ba25..b47b5dfd74 100644 --- a/tests/components/cc1101/test.esp32-s2-idf.yaml +++ b/tests/components/cc1101/test.esp32-s2-idf.yaml @@ -43,7 +43,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: code: '0111000110010011110110010100011111110001001011110111' protocol: pulse_length: 434 diff --git a/tests/components/cc1101/test.esp32-s2.yaml b/tests/components/cc1101/test.esp32-s2.yaml index d797e7ba25..b47b5dfd74 100644 --- a/tests/components/cc1101/test.esp32-s2.yaml +++ b/tests/components/cc1101/test.esp32-s2.yaml @@ -43,7 +43,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: code: '0111000110010011110110010100011111110001001011110111' protocol: pulse_length: 434 diff --git a/tests/components/cc1101/test.esp32.yaml b/tests/components/cc1101/test.esp32.yaml index e65990ca00..2277f37849 100644 --- a/tests/components/cc1101/test.esp32.yaml +++ b/tests/components/cc1101/test.esp32.yaml @@ -43,7 +43,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: code: '0111000110010011110110010100011111110001001011110111' protocol: pulse_length: 434 diff --git a/tests/components/cc1101/test.esp8266.yaml b/tests/components/cc1101/test.esp8266.yaml index 4361baa7ac..50e24a02ce 100644 --- a/tests/components/cc1101/test.esp8266.yaml +++ b/tests/components/cc1101/test.esp8266.yaml @@ -50,7 +50,7 @@ button: - platform: template name: "Gate" on_press: - - remote_transmitter.transmit_cc1101: + - remote_transmitter.transmit_rc_switch_raw_cc1101: code: '0111000110010011110110010100011111110001001011110111' protocol: pulse_length: 434