Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_oneway_entities.cpp
Go to the documentation of this file.
1/// @file platform_oneway_entities.cpp
2/// @brief The per-identity 1W entities: command buttons, enrollment button, last-command sensor.
3/// @ingroup hioc_platforms
4
6
7#include "esphome/core/log.h"
8
9namespace esphome {
10namespace home_io_control {
11
13 // "not sent" rather than "failed": the hub knows only that nothing left the radio. It never
14 // knows that a command failed, because it never learns that one succeeded either.
15 if (!report.sequence_reserved)
16 return "not sent (no sequence reserved)";
17
18 std::string summary = report.intent.empty() ? "command" : report.intent;
19 summary += " -> ";
20 summary += device_type_name(report.target_type);
21 summary += " seq ";
22 summary += std::to_string(report.sequence);
23 if (!report.transmitted)
24 summary += " (not sent)";
25 return summary;
26}
27
29 ESP_LOGCONFIG("home_io_control.button", "IO-Homecontrol 1W Command Button");
30 ESP_LOGCONFIG("home_io_control.button", " Controller: %s", this->controller_id_.c_str());
31 ESP_LOGCONFIG("home_io_control.button", " Action: %s", oneway_button_action_name(this->action_));
32}
33
35 ESP_LOGCONFIG("home_io_control.button", "IO-Homecontrol 1W Enroll Button");
36 ESP_LOGCONFIG("home_io_control.button", " Controller: %s", this->controller_id_.c_str());
37}
38
40 if (this->parent_ == nullptr)
41 return;
42 this->parent_->add_oneway_command_report_callback([this](const OneWayCommandReport &report) {
43 // Every sensor sees every report; each keeps only its own identity's. Filtering here rather
44 // than at the hub keeps the hub from having to know which sensors exist.
45 if (report.controller_id != this->controller_id_)
46 return;
47 this->publish_state(format_oneway_command_report(report));
48 });
49}
50
52 ESP_LOGCONFIG("home_io_control.text_sensor", "IO-Homecontrol Last 1W Command Sensor");
53 ESP_LOGCONFIG("home_io_control.text_sensor", " Controller: %s", this->controller_id_.c_str());
54}
55
56} // namespace home_io_control
57} // namespace esphome
void setup() override
Subscribe to the hub's per-command reports.
void dump_config() override
Dump text-sensor configuration to the log.
const char * oneway_button_action_name(OneWayButtonAction action)
Human-readable name for a button action, as it appears in the diagnostic sensor.
const char * device_type_name(DeviceType type)
Convert a DeviceType to a lowercase string identifier.
std::string format_oneway_command_report(const OneWayCommandReport &report)
Build the sensor string for one command report.
The per-identity 1W entities: command buttons, the enrollment button, and the "Last 1W Command" diagn...
What a 1W command attempt did — the only feedback this feature can ever produce.
std::string intent
Decoded intent, e.g. "STOP" or "CLOSE".
bool sequence_reserved
True if a sequence was consumed (0 is a valid sequence).
DeviceType target_type
Device class addressed.
bool transmitted
True if at least one copy reached the radio.
std::string controller_id
Identity that transmitted (empty if unresolved).
uint16_t sequence
Sequence consumed; meaningless unless sequence_reserved.