Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_cover_controls.cpp
Go to the documentation of this file.
1/// @file platform_cover_controls.cpp
2/// @brief Generated per-cover auxiliary entities: command button, silent-operation toggle, rain and battery sensors.
3/// @ingroup hioc_platforms
4
6
7#include "esphome/core/log.h"
8
9namespace esphome {
10namespace home_io_control {
11
12// One tag for the merged command button. The former per-button tags (home_io_control.favorite_button
13// / home_io_control.vent_button) both retire with the class merge; a user greps for the entity by
14// name, not by log tag, and this reads correctly for either command.
15static const char *const TAG_COMMAND_BUTTON = "home_io_control.cover_command_button";
16static const char *const TAG_SILENT = "home_io_control.cover.silent";
17static const char *const TAG_RAIN = "home_io_control.cover.rain_sensor";
18static const char *const TAG_BATTERY = "home_io_control.cover.battery";
19
21 if (this->parent_ == nullptr) {
22 ESP_LOGW(TAG_COMMAND_BUTTON, "Ignoring %s press because the parent hub is not configured",
24 return;
25 }
26
27 if (this->parent_->get_device(this->device_id_) == nullptr) {
28 ESP_LOGW(TAG_COMMAND_BUTTON, "Ignoring %s press for %s because the device is not registered yet",
29 cover_command_name(this->command_), this->device_id_.c_str());
30 return;
31 }
32
34}
35
37 ESP_LOGCONFIG(TAG_COMMAND_BUTTON, "IO-Homecontrol %s Position Button", cover_command_name(this->command_));
38 ESP_LOGCONFIG(TAG_COMMAND_BUTTON, " Device ID: %s", this->device_id_.c_str());
39}
40
42 // The YAML value was already applied to the device at registration; mirror it outward so Home
43 // Assistant does not start out disagreeing with what the hub will actually send.
44 if (this->parent_ == nullptr)
45 return;
46 if (const IoDevice *dev = this->parent_->get_device(this->device_id_); dev != nullptr)
47 this->publish_state(dev->silent);
48}
49
51 if (this->parent_ == nullptr)
52 return;
53 this->parent_->set_device_silent(this->device_id_, state);
54 this->publish_state(state);
55 ESP_LOGI(TAG_SILENT, "Device %s: silent operation %s", this->device_id_.c_str(), state ? "on" : "off");
56}
57
59 ESP_LOGCONFIG(TAG_SILENT, "IO-Homecontrol Silent Operation:");
60 ESP_LOGCONFIG(TAG_SILENT, " Device ID: %s", this->device_id_.c_str());
61}
62
66
68 switch (state) {
70 this->publish_state(true);
71 break;
73 this->publish_state(false);
74 break;
76 // Nothing was read, or the last reads went unanswered; "dry" must mean a reply said so.
77 this->invalidate_state();
78 break;
79 }
80}
81
83 ESP_LOGCONFIG(TAG_RAIN, "IO-Homecontrol Rain Sensor:");
84 ESP_LOGCONFIG(TAG_RAIN, " Device ID: %s", this->device_id_.c_str());
85}
86
88 this->register_companion_binding_([this](const IoDevice &dev) { this->publish_battery_(dev); });
89}
90
92 switch (dev.battery) {
94 this->publish_state(true);
95 return;
98 this->publish_state(false);
99 return;
101 break;
102 }
103 // "off" must mean the device said its battery is fine, so no level means no state.
104 this->invalidate_state();
105 // last_status != 0: a status was decoded and carried no battery, rather than none read yet.
106 if (dev.last_status != 0 && !this->logged_not_reported_) {
107 this->logged_not_reported_ = true;
108 ESP_LOGI(TAG_BATTERY, "Device %s reports no battery state; it is probably mains powered", this->device_id_.c_str());
109 }
110}
111
113 ESP_LOGCONFIG(TAG_BATTERY, "IO-Homecontrol Battery Low:");
114 ESP_LOGCONFIG(TAG_BATTERY, " Device ID: %s", this->device_id_.c_str());
115}
116
118 this->register_companion_binding_([this](const IoDevice &dev) {
120 this->publish_state(battery_state_name(dev.battery));
121 });
122}
123
125 ESP_LOGCONFIG(TAG_BATTERY, "IO-Homecontrol Battery:");
126 ESP_LOGCONFIG(TAG_BATTERY, " Device ID: %s", this->device_id_.c_str());
127}
128
129} // namespace home_io_control
130} // namespace esphome
void register_companion_binding_(const std::function< void(const IoDevice &)> &publish)
Shared setup() body: subscribe to this device's updates and publish the initial state.
void setup() override
Subscribe to the device's updates and publish what is already known.
void dump_config() override
Dump sensor configuration to the log.
void publish_battery_(const IoDevice &dev)
Publish from a device record: ON for LOW_CHARGE, OFF for NORMAL/FULL, no state otherwise.
bool logged_not_reported_
The "reports no battery" INFO line was written once already.
void setup() override
Subscribe to the device's updates and publish what is already known.
void dump_config() override
Dump sensor configuration to the log.
virtual IoDevice * get_device(const std::string &device_id)
Retrieve a device by ID; returns nullptr if not found.
Definition hub_core.cpp:350
virtual bool queue_device_command(const std::string &device_id, CoverCommand cmd)
Queue an async named command (STOP, FAVORITE, VENT, FORCE_OPEN); returns immediately,...
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:356
void press_action() override
Handle a Home Assistant button press by queueing this button's cover command, which is then sent to t...
void dump_config() override
Dump button configuration to the log.
void write_state(bool state) override
Apply the requested travel profile to the bound device.
void setup() override
Publish the boot state declared in YAML so Home Assistant starts in sync.
void dump_config() override
Dump switch configuration to the log.
void dump_config() override
Dump sensor configuration to the log.
void publish_rain_state_(RainSensorState state)
Publish a rain state: true for RAIN, false for DRY, no state for UNKNOWN.
void setup() override
Subscribe to the device's updates and publish what is already known.
static const char *const TAG_COMMAND_BUTTON
RainSensorState
What the hub's latest minimum-limitation read says about a rain-protection limit.
@ UNKNOWN
No usable reading: never read, or the last reads went unanswered.
@ DRY
The device answered and reports no rain-sized opening limit.
@ RAIN
The device answered and reports an opening limit of rain size.
static const char *const TAG_SILENT
@ NORMAL_CHARGE
Battery neither low nor full.
@ NOT_REPORTED
The device does not report a battery (mains powered), or no status was read yet.
const char * cover_command_name(CoverCommand cmd)
Get a human-readable name for a CoverCommand.
static const char *const TAG_BATTERY
static const char *const TAG_RAIN
const char * battery_state_name(BatteryState state)
Get the name a battery level is published under.
Generated per-cover auxiliary entities: the command button (favorite / ventilation),...
Runtime state of a paired IO‑Homecontrol device.
uint32_t last_status
millis() timestamp of last received status.
RainSensorState rain_sensor
Rain state from the opt-in minimum-limitation poll.
BatteryState battery
Coarse battery level from byte 1 of the device's own status: a reply to a status poll or an authentic...