Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
pairing_advisor.h
Go to the documentation of this file.
1#pragma once
2
3/// @file pairing_advisor.h
4/// @brief Read-only advisor that turns PairingTelemetry into actionable diagnostics.
5/// @ingroup hioc_hub
6///
7/// PairingAdvisor is a pure, stateless consumer of a completed PairingTelemetry attempt: it
8/// never touches the radio or the pairing state machine, only inspects the events already
9/// recorded. It exists to convert the most common field failures (a 1W remote's PROG gesture
10/// overheard while no device answers, issues #27/#121; a busy channel; a foreign controller
11/// mid-pairing; dead RF)
12/// from a hex-dump exercise into a self-explaining WARN line.
13
14#include "pairing_telemetry.h"
15#include "proto_frame.h"
16
17#include <cstdint>
18#include <string>
19
20namespace esphome {
21namespace home_io_control {
22namespace advisor {
23
24/// @brief Actionable diagnosis derived from a completed pairing attempt's telemetry.
25enum class PairingAdviceCode : uint8_t {
26 NONE, ///< Nothing actionable to report.
27 ONE_WAY_PAIRING_TRAFFIC, ///< A 1W remote's PROG gesture was overheard. Proves a gesture happened,
28 ///< not the device's state: the same frames also precede successful
29 ///< pairings (issue #19).
30 CHANNEL_BUSY_LBT_DELAYED, ///< LBT retries were consumed while a source kept repeating; the
31 ///< reported subject_node is a best-effort correlation (LBT's
32 ///< carrier-sense doesn't parse frames, so the actual jammer may
33 ///< not be among the parsed events attributed here).
34 FOREIGN_CONTROLLER_PAIRING, ///< A discovery response was seen addressed to another controller.
35 RF_SILENT, ///< Nothing at all was heard during the whole window.
36};
37
38/// @brief One piece of advice, with the node/RSSI it pertains to (if any).
41 uint8_t subject_node[NODE_ID_SIZE]{}; ///< Node the advice is about; zero if not applicable.
42 int16_t rssi{0}; ///< RSSI associated with the observation; zero if not applicable.
43};
44
45/// @brief Maximum number of advice entries a single attempt can produce (one slot per non-NONE code).
46static constexpr uint8_t PAIRING_ADVICE_MAX = 4;
47
48/// @brief Inspect a completed pairing attempt's telemetry and produce actionable advice.
49///
50/// Read-only: never mutates telemetry, never touches the radio or pairing state machine.
51/// @param telemetry Completed (or in-progress) telemetry for one pairing attempt.
52/// @param own_node_id This controller's node ID, used to detect discovery responses addressed
53/// to a different controller.
54/// @param out Output buffer, must hold at least PAIRING_ADVICE_MAX entries.
55/// @return Number of advice entries written to `out` (0 if nothing actionable was found).
56uint8_t analyze_pairing_telemetry(const PairingTelemetry &telemetry, const uint8_t own_node_id[NODE_ID_SIZE],
57 PairingAdvice out[PAIRING_ADVICE_MAX]);
58
59/// @return Short, stable code string for the `;advice=` result-sensor field (e.g. "1w_traffic").
61
62/// @return The full actionable, human-readable WARN message for one piece of advice.
63std::string pairing_advice_message(const PairingAdvice &advice);
64
65} // namespace advisor
66} // namespace home_io_control
67} // namespace esphome
Fixed-size per-attempt telemetry recorder for the pairing flow.
std::string pairing_advice_message(const PairingAdvice &advice)
static constexpr uint8_t PAIRING_ADVICE_MAX
Maximum number of advice entries a single attempt can produce (one slot per non-NONE code).
const char * pairing_advice_code_name(PairingAdviceCode code)
PairingAdviceCode
Actionable diagnosis derived from a completed pairing attempt's telemetry.
@ RF_SILENT
Nothing at all was heard during the whole window.
@ FOREIGN_CONTROLLER_PAIRING
A discovery response was seen addressed to another controller.
@ ONE_WAY_PAIRING_TRAFFIC
A 1W remote's PROG gesture was overheard.
@ CHANNEL_BUSY_LBT_DELAYED
LBT retries were consumed while a source kept repeating; the reported subject_node is a best-effort c...
uint8_t analyze_pairing_telemetry(const PairingTelemetry &telemetry, const uint8_t own_node_id[NODE_ID_SIZE], PairingAdvice out[PAIRING_ADVICE_MAX])
Inspect a completed pairing attempt's telemetry and produce actionable advice.
@ NONE
target_fw is unknown, or its required bootloader matches bootloader_version.
Structured per-attempt telemetry recorder for the pairing flow.
IO-Homecontrol 2W frame container: control bytes, IoFrame and (de)serialization.
One piece of advice, with the node/RSSI it pertains to (if any).
uint8_t subject_node[NODE_ID_SIZE]
Node the advice is about; zero if not applicable.
int16_t rssi
RSSI associated with the observation; zero if not applicable.