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 (see default_inverted_for_type() in proto_frame.h). 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"
22#include "hub_core.h"
23
24namespace esphome {
25namespace home_io_control {
26
27/// @brief Cover entity representing an IO‑Homecontrol shutter/awning/blind.
28/// @ingroup hioc_platforms
29class IOHomeCover : public cover::Cover, public Component {
30 public:
31 IOHomeCover() { this->position = UNKNOWN_POSITION; }
32 /// @brief Initialize the cover entity (register device, subscribe to updates, schedule initial status poll).
33 void setup() override;
34 /// @brief Dump configuration to log.
35 void dump_config() override;
36 /// @brief Get setup priority (DATA so we have device registry available).
37 /// @return setup_priority::DATA.
38 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
39
40 /// @brief Return the traits object describing this cover's capabilities.
41 /// @return CoverTraits configured for position, stop, and optional tilt.
42 cover::CoverTraits get_traits() override;
43
44 /// @brief Set the parent controller component.
45 /// @param parent Pointer to the IOHomeControlComponent instance.
46 void set_parent(IOHomeControlComponent *parent) { this->parent_ = parent; }
47 /// @brief Set the unique device ID (from YAML).
48 /// @param id Hexadecimal node ID string (e.g., "123ABC").
49 void set_device_id(const std::string &id) { this->device_id_ = id; }
50 /// @brief Set the declared device type (from YAML).
51 /// @param type Device type enum.
52 void set_device_type(DeviceType type) { this->device_type_ = type; }
53 /// @brief Set the declared device subtype (from YAML).
54 /// @param subtype Subtype value.
55 void set_subtype(uint8_t subtype) { this->subtype_ = subtype; }
56 /// @brief Enable or disable position inversion.
57 /// Some devices (e.g., horizontal awnings) report reversed open/close semantics.
58 /// @param invert True to invert the mapping (HA 1.0 → IO 0, HA 0.0 → IO 100).
59 void set_invert_position(bool invert) {
60 this->invert_ = invert;
61 this->invert_explicit_ = true;
62 }
63 /// @brief Configure bounded follow-up polling while a state change is expected.
64 /// @param poll_interval_ms Poll interval in milliseconds; zero keeps the default single settle poll only.
65 void set_status_poll_interval(uint32_t poll_interval_ms) { this->status_poll_interval_ms_ = poll_interval_ms; }
66 /// @brief Query whether this device supports tilt (slat angle) control.
67 /// @return true if the underlying device type supports tilt.
68 [[nodiscard]] bool supports_tilt() const;
69
70 protected:
71 /// @brief Handle cover commands from Home Assistant (open/close/stop/set_position).
72 /// @param call CoverCall containing the requested operation.
73 void control(const cover::CoverCall &call) override;
74 /// @brief Callback invoked when the underlying device state changes.
75 /// @param id Device ID that updated.
76 /// @param dev Updated IoDevice state.
77 void on_device_update_(const std::string &id, const IoDevice &dev);
78 /// @brief Resolve the current inversion mode.
79 /// @return Explicit YAML override when set, otherwise the runtime device profile.
80 [[nodiscard]] bool effective_invert_() const;
81 /// @brief Infer HA movement direction from successive IO positions when the protocol target is unknown.
82 /// @param invert Effective inversion mode for this device.
83 /// @param current_io_position Latest reported IO position (0=open, 100=closed).
84 /// @return OPENING, CLOSING, or IDLE when no direction can be inferred yet.
85 [[nodiscard]] cover::CoverOperation infer_operation_from_position_delta_(bool invert,
86 float current_io_position) const;
87
89 std::string device_id_;
91 uint8_t subtype_{0};
93 bool invert_{false};
94 bool invert_explicit_{false};
96};
97
98} // namespace home_io_control
99} // namespace esphome
The main IO-Homecontrol component.
Definition hub_core.h:68
void set_invert_position(bool invert)
Enable or disable position inversion.
void set_subtype(uint8_t subtype)
Set the declared device subtype (from YAML).
void set_parent(IOHomeControlComponent *parent)
Set the parent controller component.
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.
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.
void set_status_poll_interval(uint32_t poll_interval_ms)
Configure bounded follow-up polling while a state change is expected.
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).
void set_device_type(DeviceType type)
Set the declared device type (from YAML).
float get_setup_priority() const override
Get setup priority (DATA so we have device registry available).
void dump_config() override
Dump configuration to log.
void control(const cover::CoverCall &call) override
Handle cover commands from Home Assistant (open/close/stop/set_position).
void set_device_id(const std::string &id)
Set the unique device ID (from YAML).
IO-Homecontrol ESPHome component — protocol controller.
static constexpr float UNKNOWN_POSITION
Sentinel value meaning "position is not known yet".
DeviceType
Device type identifiers reported by IO‑Homecontrol products.
@ UNKNOWN
Unknown/unspecified device.
Runtime state of a paired IO‑Homecontrol device.