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 (issue #27: a 1W remote
10/// mistaken for 2W learning mode; a busy channel; a foreign controller mid-pairing; dead RF)
11/// from a hex-dump exercise into a self-explaining WARN line.
12
13#include "pairing_telemetry.h"
14#include "proto_frame.h"
15
16#include <cstdint>
17#include <string>
18
19namespace esphome {
20namespace home_io_control {
21namespace advisor {
22
23/// @brief Actionable diagnosis derived from a completed pairing attempt's telemetry.
24enum class PairingAdviceCode : uint8_t {
25 NONE, ///< Nothing actionable to report.
26 ONE_WAY_PAIRING_TRAFFIC, ///< A 1W remote is pairing to the target — not 2W learning mode.
27 CHANNEL_BUSY_LBT_DELAYED, ///< LBT retries were consumed while a source kept repeating; the
28 ///< reported subject_node is a best-effort correlation (LBT's
29 ///< carrier-sense doesn't parse frames, so the actual jammer may
30 ///< not be among the parsed events attributed here).
31 FOREIGN_CONTROLLER_PAIRING, ///< A discovery response was seen addressed to another controller.
32 RF_SILENT, ///< Nothing at all was heard during the whole window.
33};
34
35/// @brief One piece of advice, with the node/RSSI it pertains to (if any).
38 uint8_t subject_node[NODE_ID_SIZE]{}; ///< Node the advice is about; zero if not applicable.
39 int16_t rssi{0}; ///< RSSI associated with the observation; zero if not applicable.
40};
41
42/// @brief Maximum number of advice entries a single attempt can produce (one slot per non-NONE code).
43static constexpr uint8_t PAIRING_ADVICE_MAX = 4;
44
45/// @brief Inspect a completed pairing attempt's telemetry and produce actionable advice.
46///
47/// Read-only: never mutates telemetry, never touches the radio or pairing state machine.
48/// @param telemetry Completed (or in-progress) telemetry for one pairing attempt.
49/// @param own_node_id This controller's node ID, used to detect discovery responses addressed
50/// to a different controller.
51/// @param out Output buffer, must hold at least PAIRING_ADVICE_MAX entries.
52/// @return Number of advice entries written to `out` (0 if nothing actionable was found).
53uint8_t analyze_pairing_telemetry(const PairingTelemetry &telemetry, const uint8_t own_node_id[NODE_ID_SIZE],
55
56/// @return Short, stable code string for the `;advice=` result-sensor field (e.g. "1w_traffic").
58
59/// @return The full actionable, human-readable WARN message for one piece of advice.
60std::string pairing_advice_message(const PairingAdvice &advice);
61
62} // namespace advisor
63} // namespace home_io_control
64} // 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 is pairing to the target — not 2W learning mode.
@ 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.
static constexpr uint8_t NODE_ID_SIZE
Device/node addresses are 3 bytes (e.g., "123ABC").
Definition proto_sizes.h:20
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.