Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_cover.h
Go to the documentation of this file.
1#pragma once
2
3/// @file platform_cover.h
4/// @brief ESPHome cover entity for IO‑Homecontrol devices.
5/// @ingroup hioc_platforms
6///
7/// Maps IO‑Homecontrol devices (shutters, awnings, blinds) to Home Assistant cover entities
8/// with position control and real‑time feedback.
9///
10/// Position mapping between Home Assistant and IO‑Homecontrol:
11/// HA: 1.0 = fully open, 0.0 = fully closed
12/// IO: 0 = fully open, 100 = fully closed
13/// The conversion is: ha_position = 1.0 - (io_position / 100.0)
14///
15/// @warning Some device types (e.g., horizontal awnings) have inverted position mapping
16/// by default (device_feature::INVERTED). The invert
17/// flag flips the HA↔IO conversion accordingly. Ensure the device's actual
18/// behavior matches the mapping, or set invert_position accordingly.
19
20#include "esphome/core/component.h"
21#include "esphome/components/cover/cover.h"
23
24namespace esphome {
25namespace home_io_control {
26
27/// @brief Cover entity representing an IO‑Homecontrol shutter/awning/blind.
28/// @ingroup hioc_platforms
29///
30/// The device-binding setters, setup() registration ritual and poll-interval dump line come
31/// from DeviceBoundEntity; the richer position/tilt/movement mapping and the invert option
32/// stay here.
33class IOHomeCover : public cover::Cover, public Component, public DeviceBoundEntity {
34 public:
35 IOHomeCover() = default;
36 /// @brief Initialize the cover entity (register device, subscribe to updates, schedule initial status poll).
37 void setup() override;
38 /// @brief Dump configuration to log.
39 void dump_config() override;
40 /// @brief Get setup priority (DATA so we have device registry available).
41 /// @return setup_priority::DATA.
42 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
43
44 /// @brief Return the traits object describing this cover's capabilities.
45 /// @return CoverTraits configured for position (with intermediate positions only), stop, optional
46 /// tilt, and assumed state for a cover that is only open or closed.
47 cover::CoverTraits get_traits() override;
48
49 /// @brief Enable or disable position inversion.
50 /// Some devices (e.g., horizontal awnings) report reversed open/close semantics.
51 /// @param invert True to invert the mapping (HA 1.0 → IO 0, HA 0.0 → IO 100).
52 void set_invert_position(bool invert) {
53 this->invert_ = invert;
54 this->invert_explicit_ = true;
55 }
56 /// @brief Opt this cover into the periodic rain sensor poll (from YAML `rain_sensor_poll_interval`).
57 /// @param interval_ms Poll interval in milliseconds; zero (the default) means no poll.
58 void set_rain_sensor_poll_interval(uint32_t interval_ms) { this->rain_sensor_poll_interval_ms_ = interval_ms; }
59 /// @brief Opt this cover into the periodic sun level poll (from YAML `sun_level_poll_interval`).
60 /// @param interval_ms Poll interval in milliseconds; 0 = not opted in.
61 void set_sun_level_poll_interval(uint32_t interval_ms) { this->sun_level_poll_interval_ms_ = interval_ms; }
62 /// @brief Opt this cover into the periodic battery level poll (from YAML `battery_level_poll_interval`).
63 /// @param interval_ms Poll interval in milliseconds; 0 = not opted in.
64 void set_battery_level_poll_interval(uint32_t interval_ms) { this->battery_level_poll_interval_ms_ = interval_ms; }
65 /// @brief Opt this cover into the status refresh at rest (from YAML `status_refresh_interval`).
66 /// @param interval_ms Refresh interval in milliseconds; zero (the default) means no refresh.
67 void set_status_refresh_interval(uint32_t interval_ms) { this->status_refresh_interval_ms_ = interval_ms; }
68 /// @brief Query whether this device takes intermediate positions (a slider) or only open / close / stop.
69 /// @return true if the device has device_feature::LEVELS.
70 [[nodiscard]] bool supports_intermediate_positions() const;
71 /// @brief Query whether this device supports tilt (slat angle) control.
72 /// @return true if the device has device_feature::TILT.
73 [[nodiscard]] bool supports_tilt() const;
74
75 protected:
76 /// @brief Handle cover commands from Home Assistant (open/close/stop/set_position).
77 /// @param call CoverCall containing the requested operation.
78 void control(const cover::CoverCall &call) override;
79 /// @brief Callback invoked when the underlying device state changes.
80 /// @param id Device ID that updated.
81 /// @param dev Updated IoDevice state.
82 void on_device_update_(const std::string &id, const IoDevice &dev);
83 /// @brief Resolve the current inversion mode.
84 /// @return Explicit YAML override when set, otherwise the runtime device profile.
85 [[nodiscard]] bool effective_invert_() const;
86 /// @brief Infer HA movement direction from successive IO positions when the protocol target is unknown.
87 /// @param invert Effective inversion mode for this device.
88 /// @param current_io_position Latest reported IO position (0=open, 100=closed).
89 /// @return OPENING, CLOSING, or IDLE when no direction can be inferred yet.
90 [[nodiscard]] cover::CoverOperation infer_operation_from_position_delta_(bool invert,
91 float current_io_position) const;
92
93 bool invert_{false};
94 bool invert_explicit_{false};
95 float last_io_position_{UNKNOWN_POSITION};
96 uint32_t rain_sensor_poll_interval_ms_{0}; ///< 0 = not opted in; no rain poll is scheduled.
97 uint32_t sun_level_poll_interval_ms_{0}; ///< 0 = not opted in; no sun level poll is scheduled.
98 uint32_t battery_level_poll_interval_ms_{0}; ///< 0 = not opted in; no battery level poll is scheduled.
99 uint32_t status_refresh_interval_ms_{0}; ///< 0 = not opted in; no status refresh is scheduled.
100};
101
102} // namespace home_io_control
103} // namespace esphome
Mixin holding the hub-device binding shared by all IO-Homecontrol entity platforms.
void set_invert_position(bool invert)
Enable or disable position inversion.
uint32_t rain_sensor_poll_interval_ms_
0 = not opted in; no rain poll is scheduled.
void set_battery_level_poll_interval(uint32_t interval_ms)
Opt this cover into the periodic battery level poll (from YAML battery_level_poll_interval).
cover::CoverOperation infer_operation_from_position_delta_(bool invert, float current_io_position) const
Infer HA movement direction from successive IO positions when the protocol target is unknown.
void set_rain_sensor_poll_interval(uint32_t interval_ms)
Opt this cover into the periodic rain sensor poll (from YAML rain_sensor_poll_interval).
bool supports_tilt() const
Query whether this device supports tilt (slat angle) control.
void on_device_update_(const std::string &id, const IoDevice &dev)
Callback invoked when the underlying device state changes.
uint32_t status_refresh_interval_ms_
0 = not opted in; no status refresh is scheduled.
bool supports_intermediate_positions() const
Query whether this device takes intermediate positions (a slider) or only open / close / stop.
bool effective_invert_() const
Resolve the current inversion mode.
cover::CoverTraits get_traits() override
Return the traits object describing this cover's capabilities.
void setup() override
Initialize the cover entity (register device, subscribe to updates, schedule initial status poll).
float get_setup_priority() const override
Get setup priority (DATA so we have device registry available).
uint32_t battery_level_poll_interval_ms_
0 = not opted in; no battery level poll is scheduled.
uint32_t sun_level_poll_interval_ms_
0 = not opted in; no sun level poll is scheduled.
void dump_config() override
Dump configuration to log.
void set_status_refresh_interval(uint32_t interval_ms)
Opt this cover into the status refresh at rest (from YAML status_refresh_interval).
void set_sun_level_poll_interval(uint32_t interval_ms)
Opt this cover into the periodic sun level poll (from YAML sun_level_poll_interval).
void control(const cover::CoverCall &call) override
Handle cover commands from Home Assistant (open/close/stop/set_position).
Shared device-binding mixins for IO-Homecontrol entity platforms.
Runtime state of a paired IO‑Homecontrol device.