Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_cover_controls.h
Go to the documentation of this file.
1#pragma once
2
3/// @file platform_cover_controls.h
4/// @brief Generated per-cover auxiliary entities: the command button (favorite / ventilation),
5/// the silent-operation toggle, the rain binary sensor and the battery sensors.
6/// @ingroup hioc_platforms
7///
8/// All are device-bound companions (DeviceBoundCompanion), generated alongside a `cover:` entity
9/// by cover.py when the device type supports them, and both act on an already-registered device
10/// rather than owning one. They live together here because they are the cover platform's small
11/// auxiliary surface, not full entity platforms of their own.
12
13#include <string>
14
15#include "esphome/components/binary_sensor/binary_sensor.h"
16#include "esphome/components/button/button.h"
17#include "esphome/components/switch/switch.h"
18#include "esphome/components/text_sensor/text_sensor.h"
19#include "esphome/core/component.h"
20#include "hub_core.h"
22#include "proto_device_model.h"
23
24namespace esphome {
25namespace home_io_control {
26
27/// @brief Button entity that sends one non-positional cover command on press.
28///
29/// One class covers both companions the cover platform generates: codegen calls set_command()
30/// with CoverCommand::FAVORITE for the favorite/"My"-position button (position-capable device
31/// types) and CoverCommand::VENT for the ventilation button (window-type devices —
32/// WINDOW_OPENER, VENTILATION_POINT — where the vent command moves the actuator to a predefined
33/// partially-open position suitable for air exchange). The press path, the parent/device guards
34/// and the log wording are identical for both; only the command byte differs.
35/// @ingroup hioc_platforms
36class IOHomeCoverCommandButton : public button::Button, public Component, public DeviceBoundCompanion {
37 public:
38 /// @brief Set which cover command a press sends.
39 /// @param command CoverCommand::FAVORITE for the favorite-position companion,
40 /// CoverCommand::VENT for the ventilation companion.
41 void set_command(CoverCommand command) { this->command_ = command; }
42
43 /// @brief Initialize the generated button.
44 void setup() override {}
45
46 /// @brief Dump button configuration to the log.
47 void dump_config() override;
48
49 /// @brief Get setup priority so the parent hub is available first.
50 /// @return setup_priority::DATA.
51 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
52
53 protected:
54 /// @brief Handle a Home Assistant button press by queueing this button's cover command, which
55 /// is then sent to the device via the authenticated exchange like any other cover command.
56 void press_action() override;
57
59};
60
61/// @brief Switch entity that selects a cover's travel profile at runtime.
62/// @ingroup hioc_platforms
63///
64/// ON sends position commands with the manufacturer app's "silent operation" extended block, which
65/// makes the motor travel more slowly; OFF sends the normal payload. Only generated when the cover
66/// declares `silent:` in YAML, so a config that never mentions it gains no entity — the YAML value
67/// is the boot state and this switch moves it afterwards.
68///
69/// Device-bound like IOHomeCoverCommandButton rather than hub-level like
70/// IOHomeAcceptForeignPairingSwitch: the setting is per actuator. Nothing on the wire reports a
71/// device's current profile, so this reflects only what this hub has been told to send — there is
72/// no readback to reconcile against, and none is faked.
73class IOHomeCoverSilentSwitch : public switch_::Switch, public Component, public DeviceBoundCompanion {
74 public:
75 /// @brief Publish the boot state declared in YAML so Home Assistant starts in sync.
76 void setup() override;
77
78 /// @brief Dump switch configuration to the log.
79 void dump_config() override;
80
81 /// @brief Get setup priority so the parent hub is available first.
82 /// @return setup_priority::DATA.
83 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
84
85 protected:
86 /// @brief Apply the requested travel profile to the bound device.
87 /// @param state True for silent (slower) operation.
88 void write_state(bool state) override;
89};
90
91/// @brief Binary sensor that reports whether the window currently limits its own opening for rain.
92/// @ingroup hioc_platforms
93///
94/// ON when the device's minimum limitation read at least the rain threshold, OFF when it read
95/// below it. Only generated when the cover declares `rain_sensor_poll_interval:`, which is also what
96/// schedules the poll that feeds it. It has no state until the first answered poll, and loses it
97/// again after several unanswered polls: "off" always means a device said so. Independent of the
98/// Active Issue sensor, which reports what the last move or a clamped command implied.
99class IOHomeRainBinarySensor : public binary_sensor::BinarySensor, public Component, public DeviceBoundCompanion {
100 public:
101 /// @brief Subscribe to the device's updates and publish what is already known.
102 void setup() override;
103
104 /// @brief Dump sensor configuration to the log.
105 void dump_config() override;
106
107 /// @brief Get setup priority so the parent hub is available first.
108 /// @return setup_priority::DATA.
109 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
110
111 protected:
112 /// @brief Publish a rain state: true for RAIN, false for DRY, no state for UNKNOWN.
114};
115
116/// @brief Binary sensor (`device_class: battery`) that is ON while the device reports a low battery.
117/// @ingroup hioc_platforms
118///
119/// Home Assistant's own low-battery convention, so generic battery tooling (low-battery
120/// notification blueprints, battery views) picks it up without per-entity setup. Generated with
121/// IOHomeBatteryTextSensor when the cover declares `battery: true`. It reads IoDevice::battery,
122/// which only status replies update: the boot poll, the settle polls after a move, and the
123/// device's own status updates. No state while the device reports no battery; the first status
124/// that shows none logs one INFO line, so a mains device with the key set explains itself.
125class IOHomeBatteryLowBinarySensor : public binary_sensor::BinarySensor, public Component, public DeviceBoundCompanion {
126 public:
127 /// @brief Subscribe to the device's updates and publish what is already known.
128 void setup() override;
129
130 /// @brief Dump sensor configuration to the log.
131 void dump_config() override;
132
133 /// @brief Get setup priority so the parent hub is available first.
134 /// @return setup_priority::DATA.
135 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
136
137 protected:
138 /// @brief Publish from a device record: ON for LOW_CHARGE, OFF for NORMAL/FULL, no state otherwise.
139 void publish_battery_(const IoDevice &dev);
140
141 bool logged_not_reported_{false}; ///< The "reports no battery" INFO line was written once already.
142};
143
144/// @brief Diagnostic text sensor naming the device's coarse battery level: "full", "normal" or "low".
145/// @ingroup hioc_platforms
146///
147/// Disabled by default: IOHomeBatteryLowBinarySensor is the entity automations should use. This
148/// one shows all three levels, which is useful while it is still open whether a device ever reports
149/// anything but "full". Publishes nothing while the device reports no battery.
150class IOHomeBatteryTextSensor : public text_sensor::TextSensor, public Component, public DeviceBoundCompanion {
151 public:
152 /// @brief Subscribe to the device's updates and publish what is already known.
153 void setup() override;
154
155 /// @brief Dump sensor configuration to the log.
156 void dump_config() override;
157
158 /// @brief Get setup priority so the parent hub is available first.
159 /// @return setup_priority::DATA.
160 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
161};
162
163} // namespace home_io_control
164} // namespace esphome
Mixin holding the parent + device-id binding shared by per-device entities that are not full entity p...
Binary sensor (device_class: battery) that is ON while the device reports a low battery.
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.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
bool logged_not_reported_
The "reports no battery" INFO line was written once already.
Diagnostic text sensor naming the device's coarse battery level: "full", "normal" or "low".
void setup() override
Subscribe to the device's updates and publish what is already known.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
void dump_config() override
Dump sensor configuration to the log.
Button entity that sends one non-positional cover command on press.
void setup() override
Initialize the generated button.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
void set_command(CoverCommand command)
Set which cover command a press sends.
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.
Switch entity that selects a cover's travel profile at runtime.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
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.
Binary sensor that reports whether the window currently limits its own opening for rain.
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.
float get_setup_priority() const override
Get setup priority so the parent hub is available first.
void setup() override
Subscribe to the device's updates and publish what is already known.
IO-Homecontrol ESPHome component — protocol controller.
RainSensorState
What the hub's latest minimum-limitation read says about a rain-protection limit.
CoverCommand
Named device commands for cover-type actuators.
@ FAVORITE
Move to stored favorite/"My" position.
Shared device-binding mixins for IO-Homecontrol entity platforms.
IO-Homecontrol device-type model, capabilities and runtime device state.
Runtime state of a paired IO‑Homecontrol device.