Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
hub_core.cpp
Go to the documentation of this file.
1/// @file hub_core.cpp
2/// @brief Component lifecycle and main-loop scheduling.
3/// @ingroup hioc_hub
4///
5/// The core file owns the parts of IOHomeControlComponent that are primarily about
6/// runtime orchestration rather than protocol interpretation:
7/// - hardware/radio setup,
8/// - main loop scheduling,
9/// - device registry and callback fan-out.
10///
11/// Protocol exchange, pairing, inbound status handling, and outbound operations live
12/// in dedicated translation units so this file remains the place to understand how the
13/// component is brought up and driven over time.
14
15#include "hub_internal.h"
16
17#include "radio_sx1276.h"
18#include "radio_sx1262.h"
19#include "radio_lr1121.h"
20#include "tuning_config.h"
21#include "tuning_registry.h"
22
23#include <cinttypes>
24#include <new>
25#include <vector>
26
27namespace esphome {
28namespace home_io_control {
29
30namespace {
31
32constexpr uint32_t BLOCKING_WARNING_THRESHOLD_MS =
33 250; ///< setup() and exchanges can legitimately block longer than generic ESPHome components.
34
35} // namespace
36
37static const char *const TAG = detail::TAG;
38
39// === Setup ===
40
41/// Initialize the IO‑Homecontrol component and radio hardware.
42///
43/// This is the main setup entry point called by ESPHome during startup.
44/// The sequence:
45/// 1. Parse node_id and system_key from hex strings (fails early if malformed).
46/// 2. Initialize the SPI bus via spi_setup().
47/// 3. Construct the driver named by the required `radio_type` YAML field
48/// ("sx1276", "sx1262", or "lr1121").
49/// 4. Allocate the appropriate RadioDriver (SX1276 needs DIO0; SX1262/LR1121 need BUSY+DIO1,
50/// DIO1 carrying the LR1121's DIO9 IRQ line).
51/// 5. Call radio_->init() which performs chip reset, calibration, and register configuration.
52/// 6. Enter normal loop() operation with radio in RX mode.
53///
54/// @note Blocking operations in setup() temporarily raise the ESPHome WDT threshold
55/// to 250 ms (warn_if_blocking_over_) because radio init can
56/// exceed the default 30–50 ms budget.
58 // IO-homecontrol exchanges are intentionally blocking and often take a few hundred
59 // milliseconds, so use a higher warning threshold than ESPHome's generic 30-50 ms.
60 this->warn_if_blocking_over_ = BLOCKING_WARNING_THRESHOLD_MS;
61#ifdef IOHOME_UNSAFE_LOG_KEY_MATERIAL
62 // Loud, unconditional, every-boot warning so a build left with this flag on by accident can
63 // never stay quiet about it — see log_frame.h::render_frame_hex_redacted() for the full
64 // rationale and safe-use rules.
65 ESP_LOGE(detail::TAG, "########################################");
66 ESP_LOGE(detail::TAG, "IOHOME_UNSAFE_LOG_KEY_MATERIAL IS ENABLED -- FRAME LOGS EXPOSE YOUR SYSTEM KEY");
67 ESP_LOGE(detail::TAG, "This build is NOT safe to run normally or share logs from. Rebuild without this");
68 ESP_LOGE(detail::TAG, "flag as soon as you are done capturing.");
69 ESP_LOGE(detail::TAG, "########################################");
70#endif
71 ESP_LOGI(detail::TAG, "Initializing...");
72 if (!hex_to_bytes(this->node_id_str_, this->node_id_, NODE_ID_SIZE) ||
74 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) — ESPHome's own LOG_STR() macro.
75 this->mark_failed(LOG_STR("Invalid node_id or system_key configuration"));
76 return;
77 }
78
79 // Open the 1W identities' persistent sequence counters. Not done from the generated
80 // add_oneway_controller() wiring, which runs before preferences are usable.
81 this->oneway_transmitter_.setup();
82 this->oneway_transmitter_.set_command_report_callback([this](const OneWayCommandReport &report) {
83 for (const auto &callback : this->oneway_report_callbacks_)
84 callback(report);
85 });
86
87 this->spi_setup();
88
89 const char *chip_name_for_log = nullptr;
90 this->radio_ = this->select_and_construct_radio_(&chip_name_for_log);
91 if (this->radio_ == nullptr) {
92 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) — ESPHome's own LOG_STR() macro.
93 this->mark_failed(LOG_STR("Radio driver selection/allocation failed (see earlier log for details)"));
94 return;
95 }
96
97#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
98 // Boot-time bootloader-version excursion — deliberately before
99 // init(): nothing has configured the radio yet, so this costs one extra chip reset and needs no
100 // reboot afterward, unlike every other bootloader excursion this feature performs.
101 this->run_lr1121_boot_time_bootloader_read_();
102#endif
103
104 if (!this->radio_->init()) {
105 delete this->radio_;
106 this->radio_ = nullptr;
107#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
108 // Cache the verdict even on a failed init() — a null radio_ is exactly the case
109 // trigger_lr1121_firmware_update()'s guard 0 still allows an attempt for (reflashing is the
110 // recovery), and it needs a cached "installed version unknown" verdict to route through.
111 this->cache_lr1121_flash_verdict_();
112#endif
113 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) — ESPHome's own LOG_STR() macro.
114 this->mark_failed(LOG_STR("Radio hardware initialization failed (see earlier log for details)"));
115 return;
116 }
117
118#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
119 this->cache_lr1121_flash_verdict_();
120#endif
121
122 this->initialized_ = true;
124 this->exchange_engine_.reset_hop_timestamp();
126 if (this->tuning_.active) {
127 std::string const snapshot = tuning_config_full_snapshot(this->tuning_);
128 ESP_LOGI(detail::TAG, "%s", snapshot.c_str());
129 }
130 ESP_LOGI(detail::TAG, "Radio initialized (%s), Node ID: %s", chip_name_for_log, this->node_id_str_.c_str());
131}
132
133// See the declaration in hub_core.h for the full contract. `radio_type_` is one of "lr1121",
134// "sx1262", or "sx1276" — the YAML schema requires the field and validates it against exactly
135// those three values, so the fallthrough below is unreachable in a config-driven build and
136// exists only to fail loudly rather than guess if this method is ever called some other way.
138 if (this->radio_type_ == "lr1121") {
139 *chip_name_out = "LR1121";
140 if (this->busy_pin_ == nullptr || this->dio1_pin_ == nullptr) {
141 ESP_LOGE(detail::TAG, "LR1121 requires busy_pin and dio1_pin (dio1_pin carries the chip's DIO9 IRQ line)");
142 return nullptr;
143 }
144 auto *radio = new (std::nothrow)
145 RadioLR1121(this, this->rst_pin_, this->dio1_pin_, this->busy_pin_, this->tx_power_, this->tcxo_voltage_);
146 if (radio == nullptr)
147 ESP_LOGE(detail::TAG, "Failed to allocate LR1121 radio driver");
148 return radio;
149 }
150
151 if (this->radio_type_ == "sx1262") {
152 *chip_name_out = "SX1262";
153 if (this->busy_pin_ == nullptr || this->dio1_pin_ == nullptr) {
154 ESP_LOGE(detail::TAG, "SX1262 requires busy_pin and dio1_pin");
155 return nullptr;
156 }
157 auto *radio =
158 new (std::nothrow) RadioSX1262(this, this->rst_pin_, this->dio1_pin_, this->busy_pin_, this->tx_power_,
159 this->tcxo_voltage_, this->fem_en_pin_, this->vfem_pin_, this->fem_pa_pin_);
160 if (radio == nullptr)
161 ESP_LOGE(detail::TAG, "Failed to allocate SX1262 radio driver");
162 return radio;
163 }
164
165 if (this->radio_type_ == "sx1276") {
166 *chip_name_out = "SX1276";
167 if (this->dio0_pin_ == nullptr) {
168 ESP_LOGE(detail::TAG, "SX1276 requires dio0_pin");
169 return nullptr;
170 }
171 auto *radio = new (std::nothrow)
172 RadioSX1276(this, this->rst_pin_, this->dio0_pin_, this->dio4_pin_, this->tx_power_, this->pa_pin_);
173 if (radio == nullptr)
174 ESP_LOGE(detail::TAG, "Failed to allocate SX1276 radio driver");
175 return radio;
176 }
177
178 *chip_name_out = "unknown";
179 ESP_LOGE(detail::TAG, "Unrecognized radio_type '%s'", this->radio_type_.c_str());
180 return nullptr;
181}
182
183// === Tuning layer ===
184
185/// Apply the current tuning configuration to the active radio driver.
186///
187/// Only chip-specific parameters are forwarded; the rest are consumed by the
188/// pairing flow and LBT logic. This is called once at the end of setup() and
189/// again whenever a UI-driven change modifies a radio parameter.
191 if (this->radio_ == nullptr)
192 return;
193 this->radio_->apply_tuning(this->tuning_);
194}
195
196/// Update a numeric tuning parameter from a Home Assistant `number` entity.
197///
198/// Parses the parameter name and applies the new value to the in-memory tuning
199/// configuration. Radio-affecting parameters are forwarded to the active driver
200/// immediately; the change is logged in YAML-compatible form so it can be copied
201/// back into the configuration file.
202void IOHomeControlComponent::update_tuning_number(const std::string &name, float value) {
203 const TuningNumberParam *param = find_tuning_number(name);
204 if (param == nullptr) {
205 ESP_LOGW(detail::TAG, "Unknown tuning number parameter: %s", name.c_str());
206 return;
207 }
208 param->set(this->tuning_, value);
209 if (param->applies_to_radio)
211 ESP_LOGI(detail::TAG, "%s", tuning_update_log_line(name, std::to_string(static_cast<int>(value))).c_str());
212}
213
214/// Update a select tuning parameter from a Home Assistant `select` entity.
215///
216/// Parses the selected option string and applies it to the in-memory tuning
217/// configuration. Radio-affecting parameters are forwarded to the active driver
218/// immediately; the change is logged in YAML-compatible form.
219void IOHomeControlComponent::update_tuning_select(const std::string &name, const std::string &value) {
220 const TuningSelectParam *param = find_tuning_select(name);
221 if (param == nullptr) {
222 ESP_LOGW(detail::TAG, "Unknown tuning select parameter: %s", name.c_str());
223 return;
224 }
225 // Radio-affecting parameters re-apply only when the option string actually parsed; the
226 // update is still logged for any known parameter, matching the original dispatch.
227 if (param->set(this->tuning_, value) && param->applies_to_radio)
229 ESP_LOGI(detail::TAG, "%s", tuning_update_log_line(name, value).c_str());
230}
231
232/// Return the current value of a numeric tuning parameter.
233///
234/// Mirror of update_tuning_number(); used by IOHomeTuningNumber::setup() to publish
235/// the boot-time value so the Home Assistant slider reflects the active configuration
236/// (default or YAML override) without restating any default on the Python side.
237float IOHomeControlComponent::get_tuning_number_value(const std::string &name) const {
238 const TuningNumberParam *param = find_tuning_number(name);
239 if (param == nullptr) {
240 ESP_LOGW(detail::TAG, "Unknown tuning number parameter: %s", name.c_str());
241 return 0.0F;
242 }
243 return param->get(this->tuning_);
244}
245
246/// Return the current option string of a select tuning parameter.
247///
248/// Mirror of update_tuning_select(); used by IOHomeTuningSelect::setup() to publish the
249/// boot-time option so the Home Assistant dropdown reflects the active configuration. The
250/// returned strings match the YAML/UI option labels exactly. The command list is returned
251/// as a comma-separated preset string (e.g. "0x28,0x2E") matching the dropdown options.
252std::string IOHomeControlComponent::get_tuning_select_value(const std::string &name) const {
253 const TuningSelectParam *param = find_tuning_select(name);
254 if (param == nullptr) {
255 ESP_LOGW(detail::TAG, "Unknown tuning select parameter: %s", name.c_str());
256 return "";
257 }
258 return param->get(this->tuning_);
259}
260
261// === Protocol send/receive (thin wrappers delegating to ExchangeEngine) ===
262
263/// Delegate channel hop to ExchangeEngine (which owns last_hop_us_).
265
266/// Delegate LBT transmit to ExchangeEngine.
267bool IOHomeControlComponent::transmit_frame_(const IoFrame &frame, uint32_t freq, uint16_t preamble) {
268 return this->exchange_engine_.transmit_frame(frame, freq, preamble);
269}
270
271/// Delegate outbound exchange to ExchangeEngine and manage the busy_ flag.
273 uint8_t max_tries) {
274 this->busy_ = true;
275 ExchangeOutcome const outcome = this->exchange_engine_.send_and_receive(request, response, freq, max_tries);
276 this->busy_ = false;
277 return outcome;
278}
279
280/// Delegate inbound authentication to ExchangeEngine.
281bool IOHomeControlComponent::authenticate_request_(const IoFrame &request, uint32_t freq) {
282 return this->exchange_engine_.authenticate_request(request, freq);
283}
284
285void IOHomeControlComponent::notify_device_update_(const std::string &id) { this->registry_.notify(id); }
286
287// === Device management ===
288
289void IOHomeControlComponent::set_device_status_poll_interval(const std::string &device_id, uint32_t poll_interval_ms) {
290 if (this->get_device(device_id) == nullptr)
291 return;
292 this->poll_policy_.set_interval(device_id, poll_interval_ms);
293}
294
295void IOHomeControlComponent::schedule_background_poll_backoff_(const std::string &device_id, bool auth_like) {
296 uint32_t const now = millis();
297 uint32_t const backoff_ms = this->poll_policy_.on_exchange_failed(device_id, auth_like, now);
298 if (backoff_ms > 0) {
299 ESP_LOGD(TAG,
300 "Background status poll backoff for device %s: delay=%" PRIu32
301 " ms auth_like=%s status_failures=%u auth_failures=%u",
302 device_id.c_str(), backoff_ms, YESNO(auth_like), this->poll_policy_.get_status_poll_failures(device_id),
303 this->poll_policy_.get_auth_poll_failures(device_id));
304 }
305}
306
307void IOHomeControlComponent::add_device(const std::string &device_id) { this->registry_.add(device_id); }
308
309void IOHomeControlComponent::add_device(const std::string &device_id, const DeviceConfig &cfg) {
310 this->registry_.add(device_id, cfg);
311}
312
313IoDevice *IOHomeControlComponent::get_device(const std::string &device_id) { return this->registry_.get(device_id); }
314
315void IOHomeControlComponent::set_device_dimmable(const std::string &device_id, bool dimmable) {
316 this->registry_.set_dimmable(device_id, dimmable);
317}
318
319void IOHomeControlComponent::set_device_silent(const std::string &device_id, bool silent) {
320 this->registry_.set_silent(device_id, silent);
321}
322
323// === Main loop ===
324
326 if (!this->initialized_)
327 return;
328 if (this->radio_test_mode_)
329 return;
330
331 // Check for received packets (non-blocking)
332 if (!this->busy_) {
333 RadioRxPacket packet{};
334 if (this->radio_->check_for_packet(packet))
335 this->process_received_packet_(packet);
336 }
337
338 // A blocking exchange makes the radio deaf for 1–3 s. When a linked remote's press schedules a
339 // status poll, dispatching it while that same remote is still transmitting would blind the hub
340 // to the rest of the press — so background polls yield for a moment. Control operations never do.
341 if (!this->busy_ && !this->defer_background_poll_()) {
343 }
344
345 // Frequency hopping — protocol specifies 2.7ms per channel, but ESPHome calls
346 // loop() every ~16-30ms. This is acceptable for a controller: a directed start frame to a
347 // low-power target still goes out with LONG_PREAMBLE (1024 bytes ≈ 330ms airtime), long enough
348 // to be detected regardless of channel alignment; a start frame to an always-alive target uses
349 // the shorter normal_start_preamble (default 32 bytes), which such a receiver hears fine. This
350 // coarse idle hop causes no exchange to miss its channel either way, because every TX retunes
351 // explicitly to a named channel before sending. Precise hopping would only matter for a passive
352 // receiver scanning for unsolicited frames.
353 // Diagnostics build flag: park the receiver on one channel instead of hopping. A hopping monitor
354 // is on any given channel roughly a third of the time, so "the capture never shows frame X" is
355 // weak evidence — locking to the channel under study makes an absence mean something. Define it
356 // to the channel in Hz, e.g. -DIOHOME_LOCK_CHANNEL_HZ=868950000 for CH2, the command channel.
357 // Only useful for a passive monitor: a hub that cannot hop will miss replies on other channels.
358#ifdef IOHOME_LOCK_CHANNEL_HZ
359 if (!this->busy_ && this->radio_ != nullptr && this->radio_->get_current_freq() != IOHOME_LOCK_CHANNEL_HZ)
360 this->radio_->change_frequency(IOHOME_LOCK_CHANNEL_HZ);
361#else
362 if (!this->busy_) {
363 if (this->key_extraction_awaiting_reply_()) {
364 // The key-extraction responder is mid-attempt and expecting the hub's next CH2-only unicast
365 // frame (see wait_for_key_confirm_()'s doc comment in pairing_engine.cpp) — hold CH2 instead
366 // of running the generic idle-hop scan, which would otherwise cycle away from CH2 for 2/3 of
367 // every hop cycle with no key-extraction awareness at all. Frequency test first, deliberately:
368 // reception_in_progress() is not a free predicate (on SX1276 it can force a
369 // set_mode_standby()/set_mode_rx() cycle), so this branch must be as sparing as maybe_hop()
370 // itself, which only consults it once the dwell timer has already decided to hop.
371 if (this->radio_->get_current_freq() != FREQ_CH2 && !this->radio_->reception_in_progress())
372 this->radio_->change_frequency(FREQ_CH2);
373 // exchange_engine_'s last_hop_us_ goes stale while the hold is active (it bypasses
374 // hop_frequency(), which is what normally updates that timestamp). Harmless: once the hold
375 // ends, maybe_hop() will very likely hop on its next call instead of waiting out a full
376 // HOP_TIME_US — resuming idle scanning a little early is not a bug.
377 } else {
378 this->exchange_engine_.maybe_hop();
379 }
380 }
381#endif
382
383 // Periodic status polling
384 if (!this->busy_) {
385 auto due = this->poll_policy_.pop_due_device(millis());
386 if (due.has_value())
387 this->queue_request_device_status(*due);
388 }
389}
390
392 ESP_LOGCONFIG(detail::TAG, "IO-Homecontrol:");
393 ESP_LOGCONFIG(detail::TAG, " Node ID: %s", this->node_id_str_.c_str());
394 ESP_LOGCONFIG(detail::TAG, " Radio: %s", this->radio_type_.c_str());
395 ESP_LOGCONFIG(detail::TAG, " TX Power: %u dBm", this->tx_power_);
396 LOG_PIN(" RST Pin: ", this->rst_pin_);
397 if (this->dio0_pin_ != nullptr)
398 LOG_PIN(" DIO0 Pin: ", this->dio0_pin_);
399 if (this->dio1_pin_ != nullptr)
400 LOG_PIN(" DIO1 Pin: ", this->dio1_pin_);
401 if (this->dio4_pin_ != nullptr)
402 LOG_PIN(" DIO4 Pin: ", this->dio4_pin_);
403 if (this->busy_pin_ != nullptr)
404 LOG_PIN(" BUSY Pin: ", this->busy_pin_);
405 ESP_LOGCONFIG(detail::TAG, " Devices: %zu", this->registry_.size());
406 if (this->registry_.linked_remote_count() > 0) {
407 ESP_LOGCONFIG(detail::TAG, " Linked Remotes: %zu", this->registry_.linked_remote_count());
408 this->registry_.for_each_linked_remote([](const std::string &remote_id, const std::vector<std::string> &devices) {
409 for (const auto &device_id : devices)
410 ESP_LOGCONFIG("home_io_control", " - remote %s -> device %s", remote_id.c_str(), device_id.c_str());
411 });
412 }
413
415
416 if (this->radio_ != nullptr)
417 this->radio_->dump_debug();
418
419#ifdef IOHOME_LR1121_FIRMWARE_UPDATE
420 this->dump_lr1121_firmware_update_debug_();
421#endif
422}
423
425 if (this->oneway_controllers().empty())
426 return;
427 ESP_LOGCONFIG(detail::TAG, " 1W Controllers: %zu", this->oneway_controllers().all().size());
428 for (const auto &identity : this->oneway_controllers().all()) {
429 // A derived address is reproducible from the YAML, but nothing in the YAML shows it — so
430 // print it, and mark it derived, or a user debugging a collision has nowhere to look. Keys
431 // are never printed here (ADR 0011); only addresses and classes. The resolved ACEI and
432 // destination let a user eyeball this against a capture of their real remote (ADR 0031).
433 const OneWayWireProfile profile = resolve_oneway_wire_profile(identity.manufacturer);
434 ESP_LOGCONFIG(
435 detail::TAG, " - %s: node %s%s, class 0x%02X, acei 0x%02X%s, broadcast %s%s", identity.id.c_str(),
436 node_id_to_string(identity.node_id).c_str(), identity.node_id_derived ? " (derived)" : "",
437 static_cast<unsigned>(identity.io_device_type), static_cast<unsigned>(effective_execute_acei(identity)),
438 has_execute_acei_override(identity) ? " (override)" : "", identity.execute_broadcast_all ? "all" : "typed",
439 profile.profile_is_a_guess ? " [no vendor profile — Somfy-shaped]" : "");
440
441 // The VELUX enrollment gesture ignores io_device_type and sweeps a fixed class set instead —
442 // the most surprising resolved value on the identity, so print it (ADR 0032).
444 std::string classes;
445 char byte_hex[3];
446 for (const DeviceType c : effective_enrollment_classes(identity)) {
447 if (c == DeviceType::UNKNOWN)
448 continue;
449 snprintf(byte_hex, sizeof(byte_hex), "%02X", static_cast<unsigned>(c));
450 classes += classes.empty() ? "0x" : " 0x";
451 classes += byte_hex;
452 }
453 ESP_LOGCONFIG(detail::TAG, " enroll: VELUX KLI gesture, 0x30 sweep -> %s", classes.c_str());
454 }
455 }
456}
457
458} // namespace home_io_control
459} // namespace esphome
InternalGPIOPin * fem_en_pin_
Front-end module enable.
Definition hub_core.h:1055
InternalGPIOPin * fem_pa_pin_
Front-end module PA switch.
Definition hub_core.h:1057
void dump_oneway_controllers_config_() const
Emit the 1W controller identities to the config dump — node, class, and the resolved ACEI / broadcast...
Definition hub_core.cpp:424
InternalGPIOPin * dio4_pin_
SX1276 DIO4 preamble detect (optional).
Definition hub_core.h:1052
InternalGPIOPin * dio1_pin_
SX1262 DIO1 interrupt; also carries the LR1121's DIO9 IRQ line.
Definition hub_core.h:1053
void dump_config() override
Dump configuration and radio debug info to the log.
Definition hub_core.cpp:391
void update_tuning_select(const std::string &name, const std::string &value)
Receive a select tuning update from a HA select entity.
Definition hub_core.cpp:219
virtual IoDevice * get_device(const std::string &device_id)
Retrieve a device by ID; returns nullptr if not found.
Definition hub_core.cpp:313
virtual void queue_request_device_status(const std::string &device_id)
Queue an async status request; returns immediately, executed in loop().
void update_tuning_number(const std::string &name, float value)
Receive a numeric tuning update from a HA number entity.
Definition hub_core.cpp:202
virtual void add_device(const std::string &device_id)
Add a device to the registry by device ID only (undeclared/legacy path).
Definition hub_core.cpp:307
InternalGPIOPin * vfem_pin_
Front-end module power.
Definition hub_core.h:1056
TuningConfig tuning_
Runtime tuning overrides.
Definition hub_core.h:1073
ExchangeOutcome send_and_receive_(const IoFrame &request, IoFrame &response, uint32_t freq, uint8_t max_tries=EXCHANGE_RETRY_COUNT)
Main request/response exchange with retry and automatic authentication.
Definition hub_core.cpp:272
virtual void set_device_status_poll_interval(const std::string &device_id, uint32_t poll_interval_ms)
Configure the optional follow-up polling interval for a registered device.
Definition hub_core.cpp:289
void process_pending_operation_()
Pop next pending operation from the queue and execute it (set position, request status,...
void hop_frequency_()
Delegate channel hop to ExchangeEngine (which owns last_hop_us_).
Definition hub_core.cpp:264
virtual void set_device_dimmable(const std::string &device_id, bool dimmable)
Set a device's dimmable flag (see IoDevice::dimmable).
Definition hub_core.cpp:315
float get_tuning_number_value(const std::string &name) const
Current value of a numeric tuning parameter, used to seed a HA number entity on boot.
Definition hub_core.cpp:237
bool defer_background_poll_() const
Whether loop() should skip dispatching the queue this iteration because the pending work is a backgro...
Definition hub_core.h:819
void loop() override
Main loop: process pending operations and drive radio state machine.
Definition hub_core.cpp:325
void schedule_background_poll_backoff_(const std::string &device_id, bool auth_like)
Apply backoff after a failed background status poll and log the result.
Definition hub_core.cpp:295
OneWayTransmitter oneway_transmitter_
Owns the 1W controller identities, their rolling-sequence counters and the transmit burst.
Definition hub_core.h:1100
std::string radio_type_
"sx1276", "sx1262", or "lr1121"; required by the YAML schema.
Definition hub_core.h:1062
bool key_extraction_awaiting_reply_() const
True while the key-extraction responder is mid-attempt and still within its bounded CH2-hold window.
Definition hub_core.h:752
RadioDriver * select_and_construct_radio_(const char **chip_name_out)
Select and construct the radio driver named by the required radio_type config field.
Definition hub_core.cpp:137
bool transmit_frame_(const IoFrame &frame, uint32_t freq, uint16_t preamble)
Transmit a raw IoFrame on the current frequency with given preamble length.
Definition hub_core.cpp:267
bool radio_test_mode_
When true, loop() is suspended for loopback testing.
Definition hub_core.h:1072
ExchangeEngine exchange_engine_
Owns all authenticated exchange and LBT/hop logic.
Definition hub_core.h:1093
const OneWayControllerRegistry & oneway_controllers() const
Definition hub_core.h:297
virtual void set_device_silent(const std::string &device_id, bool silent)
Select a device's travel profile at runtime (see IOHomeCoverSilentSwitch).
Definition hub_core.cpp:319
InternalGPIOPin * dio0_pin_
SX1276 DIO0 interrupt.
Definition hub_core.h:1051
std::vector< OneWayCommandReportFn > oneway_report_callbacks_
Subscribers to the per-command 1W report; one per "Last 1W Command" sensor.
Definition hub_core.h:1121
void notify_device_update_(const std::string &id)
Fire all registered device update callbacks for the given device ID.
Definition hub_core.cpp:285
std::string get_tuning_select_value(const std::string &name) const
Current option string of a select tuning parameter, used to seed a HA select entity on boot.
Definition hub_core.cpp:252
void setup() override
Initialize hardware (radio and device registry).
Definition hub_core.cpp:57
uint8_t tcxo_voltage_
SX1262/LR1121 TCXO voltage setting (default 1.8 V).
Definition hub_core.h:1067
void process_received_packet_(const RadioRxPacket &packet)
Parse a received frame, merge supported device state or metadata, and notify callbacks.
bool authenticate_request_(const IoFrame &request, uint32_t freq)
Handle an inbound authenticated command from a device (status updates, etc.).
Definition hub_core.cpp:281
InternalGPIOPin * busy_pin_
SX1262/LR1121 BUSY pin.
Definition hub_core.h:1054
void register_management_actions_()
Register hub-level Home Assistant actions; called from setup().
Definition hub_core.h:970
void apply_tuning_to_radio_()
Apply the current tuning configuration to the active radio driver.
Definition hub_core.cpp:190
Abstract radio driver for IO-Homecontrol.
LR1121 implementation of RadioDriver.
SX1262 implementation of RadioDriver.
SX1276 implementation of RadioDriver.
Internal helpers shared by the hub implementation .cpp files.
constexpr const char * TAG
Shared log tag for hub-level messages.
static constexpr uint8_t NODE_ID_SIZE
Device/node addresses are 3 bytes (e.g., "123ABC").
Definition proto_sizes.h:20
DeviceType
Device type identifiers reported by IO‑Homecontrol products.
@ UNKNOWN
Unknown/unspecified device.
static constexpr const char * TAG
std::array< DeviceType, 3 > effective_enrollment_classes(const OneWayControllerIdentity &identity)
The device classes this identity's 0x30 enrollment sweep will actually target.
uint8_t effective_execute_acei(const OneWayControllerIdentity &identity)
The ACEI byte a given identity will put on air for a 1W EXECUTE frame.
ExchangeOutcome
Authenticated exchange engine — outbound and inbound protocol flows.
std::string tuning_config_full_snapshot(const TuningConfig &cfg)
Format the current tuning configuration as a full one-line snapshot.
const TuningSelectParam * find_tuning_select(const std::string &name)
Look up a select tuning parameter by name; returns nullptr if unknown.
static constexpr uint32_t FREQ_CH2
Channel 2: 868.95 MHz (1W and 2W, TX channel).
std::string tuning_update_log_line(const std::string &name, const std::string &value)
Format a single tuning update for the log.
std::string node_id_to_string(const uint8_t id[NODE_ID_SIZE])
Format a 3‑byte node ID as a 6‑character uppercase hex string.
const TuningNumberParam * find_tuning_number(const std::string &name)
Look up a numeric tuning parameter by name; returns nullptr if unknown.
static constexpr uint8_t AES_KEY_SIZE
AES-128 key size.
Definition proto_sizes.h:23
OneWayWireProfile resolve_oneway_wire_profile(uint8_t manufacturer)
Resolve an identity's 1W wire profile from its manufacturer byte.
bool has_execute_acei_override(const OneWayControllerIdentity &identity)
Whether this identity's ACEI comes from an explicit execute_acei: rather than the profile.
bool hex_to_bytes(const std::string &hex, uint8_t *out, uint8_t len)
Convert a hex string (e.g., "123ABC") to a byte array.
LR1121 radio driver for IO-Homecontrol.
SX1262 radio driver for IO-Homecontrol.
SX1276 radio driver for IO-Homecontrol.
YAML-declared device metadata for registration; defaults match an undeclared device.
Runtime state of a paired IO‑Homecontrol device.
Parsed IO‑Homecontrol frame (CTRL0/1 + addresses + command + data).
Definition proto_frame.h:88
What a 1W command attempt did — the only feedback this feature can ever produce.
Vendor-divergent 1W wire settings for a controller identity.
bool profile_is_a_guess
true when manufacturer matched no known 1W wire profile.
EnrollGesture enroll_gesture
Which enrollment gesture this manufacturer's actuators expect.
Raw packet received from the radio.
One numeric tuning parameter: its wire name plus accessors over TuningConfig.
float(* get)(const TuningConfig &)
Read the current value as a float.
bool applies_to_radio
True if changes must be re-applied to the radio.
void(* set)(TuningConfig &, float)
Write a new value (narrowed to the field type).
One select tuning parameter: its wire name plus string accessors over TuningConfig.
std::string(* get)(const TuningConfig &)
Read the current option string.
bool(* set)(TuningConfig &, const std::string &)
Parse/apply an option; false if unparseable.
bool applies_to_radio
True if changes must be re-applied to the radio.
Runtime tuning configuration for pairing and radio diagnostics.
Table-driven registry of runtime tuning parameters.