Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_hub_controls.cpp
Go to the documentation of this file.
1/// @file platform_hub_controls.cpp
2/// @brief Hub-level control entities: arming switches and the pairing-result text sensor.
3/// @ingroup hioc_platforms
4
6
7#include "esphome/core/log.h"
8
9namespace esphome {
10namespace home_io_control {
11
12// Each dump_config() keeps its own log tag as a `static` function-local constant: the ESPHome
13// LOG_SWITCH / LOG_TEXT_SENSOR macros expand to a bare `TAG` identifier, so one shared file-scope
14// constant could not carry the different values. Values are unchanged from the former per-entity
15// files. (`static` so clang-tidy's identifier-naming check treats it as a StaticConstant.)
16
18 if (this->parent_ == nullptr)
19 return;
20 this->subscribe_armed([this](bool armed) { this->publish_state(armed); });
21}
22
24 if (this->parent_ != nullptr)
25 this->arm(state);
26 this->publish_state(state);
27}
28
30 static const char *const TAG = "home_io_control.key_extraction_switch";
31 LOG_SWITCH("", "IO-Homecontrol Recover System Key (Key Extraction)", this);
32 ESP_LOGCONFIG(TAG, " Arms for 10 minutes: start your existing hub's add-device search while it is on");
33}
34
36 static const char *const TAG = "home_io_control.oneway_key_switch";
37 LOG_SWITCH("", "IO-Homecontrol Recover 1W Controller Key", this);
38 ESP_LOGCONFIG(TAG, " Receive-only: listens for an add-controller broadcast, never transmits");
39}
40
42 if (this->parent_ == nullptr)
43 return;
44
45 this->parent_->set_pairing_result_callback([this]() { this->on_pairing_result_(); });
46}
47
49 // [[maybe_unused]]: LOG_TEXT_SENSOR consumes TAG only in the firmware build; the host stub
50 // expands it away, and there is no ESP_LOGCONFIG line here to reference it.
51 [[maybe_unused]] static const char *const TAG = "home_io_control.pairing_result";
52 LOG_TEXT_SENSOR("", "IO-Homecontrol Last Pairing Result", this);
53}
54
56 if (this->parent_ == nullptr)
57 return;
58 this->publish_state(this->parent_->pairing_telemetry().result_sensor_string());
59}
60
62 if (this->parent_ == nullptr)
63 return;
64
65 this->parent_->set_device_event_callback([this]() { this->on_device_event_(); });
66}
67
69 // [[maybe_unused]]: see IOHomePairingResultTextSensor::dump_config().
70 [[maybe_unused]] static const char *const TAG = "home_io_control.device_event";
71 LOG_TEXT_SENSOR("", "IO-Homecontrol Last Device Event", this);
72}
73
75 if (this->parent_ == nullptr)
76 return;
77 this->publish_state(this->parent_->last_device_event());
78}
79
80} // namespace home_io_control
81} // namespace esphome
virtual void arm(bool state)=0
Arm or disarm this switch's listener on the hub.
void write_state(bool state) final
Forward the toggle to the hub and publish the state.
virtual void subscribe_armed(std::function< void(bool)> callback)=0
Subscribe callback to the hub's armed-state changes for this listener.
void setup() final
Register the armed-state callback so this entity mirrors the hub's own disarm events.
void dump_config() override
Dump configuration to the log.
void set_device_event_callback(std::function< void()> cb)
Register a callback invoked after every recorded device event, used by the "Last Device Event" text s...
Definition hub_core.h:437
const PairingTelemetry & pairing_telemetry() const
Definition hub_core.h:411
void set_pairing_result_callback(std::function< void()> cb)
Register a callback invoked once, right after every discover_and_pair() attempt completes — used by t...
Definition hub_core.h:417
const std::string & last_device_event() const
Definition hub_core.h:425
void setup() override
Register the device-event callback.
void dump_config() override
Dump text-sensor configuration to the log.
void on_device_event_()
Publish the hub's latest recorded device event.
void setup() override
Register the pairing-result callback.
void on_pairing_result_()
Publish the latest pairing telemetry result string.
void dump_config() override
Dump text-sensor configuration to the log.
void dump_config() override
Dump configuration to the log.
std::string result_sensor_string() const
Render the frozen v1; machine-readable result string.
Hub-level control entities: the discovery button, the scan-paired-devices button, the two arming swit...