ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
radio_frequency.cpp
Go to the documentation of this file.
1#include "radio_frequency.h"
2
3#include <cinttypes>
4
5#include "esphome/core/log.h"
6
7#ifdef USE_API
9#endif
10
12
13static const char *const TAG = "radio_frequency";
14
15// ========== RadioFrequencyCall ==========
16
18 this->frequency_hz_ = frequency_hz;
19 return *this;
20}
21
23 this->modulation_ = modulation;
24 return *this;
25}
26
27RadioFrequencyCall &RadioFrequencyCall::set_raw_timings(const std::vector<int32_t> &timings) {
28 this->raw_timings_ = &timings;
29 this->packed_data_ = nullptr;
30 this->base64url_ptr_ = nullptr;
31 return *this;
32}
33
35 this->base64url_ptr_ = &base64url;
36 this->raw_timings_ = nullptr;
37 this->packed_data_ = nullptr;
38 return *this;
39}
40
41RadioFrequencyCall &RadioFrequencyCall::set_raw_timings_packed(const uint8_t *data, uint16_t length, uint16_t count) {
42 this->packed_data_ = data;
43 this->packed_length_ = length;
44 this->packed_count_ = count;
45 this->raw_timings_ = nullptr;
46 this->base64url_ptr_ = nullptr;
47 return *this;
48}
49
51 this->repeat_count_ = count;
52 return *this;
53}
54
56 if (this->parent_ != nullptr) {
57 // Fire any on_control hooks (user-wired automations) before handing off to
58 // the platform-specific control() — gives users a chance to react to call
59 // parameters (e.g. retune an external RF front-end based on call.get_frequency()).
60 this->parent_->control_callback_.call(*this);
61 this->parent_->control(*this);
62 }
63}
64
65// ========== RadioFrequency ==========
66
68 ESP_LOGCONFIG(TAG,
69 "Radio Frequency '%s'\n"
70 " Supports Transmitter: %s\n"
71 " Supports Receiver: %s",
72 this->get_name().c_str(), YESNO(this->traits_.get_supports_transmitter()),
73 YESNO(this->traits_.get_supports_receiver()));
74 if (this->traits_.get_frequency_min_hz() > 0) {
75 if (this->traits_.get_frequency_min_hz() == this->traits_.get_frequency_max_hz()) {
76 ESP_LOGCONFIG(TAG, " Frequency: %" PRIu32 " Hz (fixed)", this->traits_.get_frequency_min_hz());
77 } else {
78 ESP_LOGCONFIG(TAG, " Frequency Range: %" PRIu32 " - %" PRIu32 " Hz", this->traits_.get_frequency_min_hz(),
79 this->traits_.get_frequency_max_hz());
80 }
81 }
82}
83
85
94
96 // Invoke local callbacks
97 this->receive_callback_.call(data);
98
99 // Forward received RF data to API server
100#if defined(USE_API) && defined(USE_RADIO_FREQUENCY)
101 if (api::global_api_server != nullptr) {
102#ifdef USE_DEVICES
103 uint32_t device_id = this->get_device_id();
104#else
105 uint32_t device_id = 0;
106#endif
108 }
109#endif
110 return false; // Don't consume the event, allow other listeners to process it
111}
112
113} // namespace esphome::radio_frequency
const StringRef & get_name() const
Definition entity_base.h:71
ESPDEPRECATED("Use get_icon_to() instead. Will be removed in ESPHome 2026.9.0", "2026.3.0") std uint32_t get_device_id() const
ESPDEPRECATED("object_id mangles names and all object_id methods are planned for removal " "(see https://github.com/esphome/backlog/issues/76). " "Now is the time to stop using object_id. If still needed, use get_object_id_to() " "which will remain available longer. get_object_id() will be removed in 2026.7.0", "2025.12.0") std uint32_t get_object_id_hash() const
Definition entity_base.h:89
void send_infrared_rf_receive_event(uint32_t device_id, uint32_t key, const std::vector< int32_t > *timings)
RadioFrequencyCall - Builder pattern for transmitting radio frequency signals.
RadioFrequencyCall & set_raw_timings_base64url(const std::string &base64url)
Set the raw timings from base64url-encoded little-endian int32 data.
RadioFrequencyCall & set_frequency(uint32_t frequency_hz)
Set the carrier frequency in Hz (e.g. 433920000 for 433.92 MHz)
const std::vector< int32_t > * raw_timings_
void perform()
Perform the transmission.
RadioFrequencyCall & set_raw_timings_packed(const uint8_t *data, uint16_t length, uint16_t count)
Set the raw timings from packed protobuf sint32 data (zigzag + varint encoded)
RadioFrequencyCall & set_modulation(RadioFrequencyModulation modulation)
Set the modulation type (defaults to OOK)
RadioFrequencyCall & set_repeat_count(uint32_t count)
Set the number of times to repeat transmission (1 = transmit once, 2 = transmit twice,...
RadioFrequencyCall & set_raw_timings(const std::vector< int32_t > &timings)
Set the raw timings from a vector (positive = mark, negative = space)
RadioFrequencyCall make_call()
Create a call object for transmitting.
uint32_t get_capability_flags() const
Get capability flags for this radio frequency instance.
LazyCallbackManager< void(const RadioFrequencyCall &)> control_callback_
LazyCallbackManager< void(remote_base::RemoteReceiveData)> receive_callback_
bool on_receive(remote_base::RemoteReceiveData data) override
Called when RF data is received (from RemoteReceiverListener)
virtual void control(const RadioFrequencyCall &call)=0
Perform the actual transmission (called by RadioFrequencyCall::perform()) Platforms must override thi...
uint32_t get_frequency_min_hz() const
Hardware-supported tunable frequency range in Hz.
const RawTimings & get_raw_data() const
Definition remote_base.h:58
uint16_t flags
APIServer * global_api_server
RadioFrequencyModulation
Modulation types supported by radio frequency implementations.
static void uint32_t
uint16_t length
Definition tt21100.cpp:0