7#include "esphome/core/log.h"
12static const char *
const TAG =
"home_io_control.cover";
23 auto traits = cover::CoverTraits();
24 traits.set_supports_position(
true);
25 traits.set_supports_stop(
true);
27 traits.set_is_assumed_state(
false);
41 return dev !=
nullptr && dev->inverted;
47 return cover::COVER_OPERATION_IDLE;
51 return (current_io_position > this->
last_io_position_) ? cover::COVER_OPERATION_OPENING
52 : cover::COVER_OPERATION_CLOSING;
55 return (current_io_position < this->
last_io_position_) ? cover::COVER_OPERATION_OPENING
56 : cover::COVER_OPERATION_CLOSING;
64 if (call.get_stop()) {
70 const auto &tilt_opt = call.get_tilt();
71 const auto &position_opt = call.get_position();
83 if (position_opt.has_value() && tilt_opt.has_value() && this->supports_tilt()) {
84 float const ha_pos = *position_opt;
90 this->
parent_->queue_set_device_position_and_tilt(this->
device_id_, io_pos, tilt);
94 if (tilt_opt.has_value()) {
104 if (position_opt.has_value()) {
105 float const ha_pos = *position_opt;
132 ha_pos = 1.0F - (dev.
position / 100.0F);
135 this->position = ha_pos;
139 this->tilt = dev.
tilt / 100.0F;
144 this->current_operation = cover::COVER_OPERATION_IDLE;
148 this->current_operation =
149 (dev.
target > dev.
position) ? cover::COVER_OPERATION_OPENING : cover::COVER_OPERATION_CLOSING;
152 this->current_operation =
153 (dev.
target < dev.
position) ? cover::COVER_OPERATION_OPENING : cover::COVER_OPERATION_CLOSING;
165 this->publish_state();
169 LOG_COVER(
"",
"IO-Homecontrol Cover",
this);
170 ESP_LOGCONFIG(
TAG,
" Device ID: %s", this->
device_id_.c_str());
void register_device_binding_(Component *self, bool inverted, std::function< void(const std::string &, const IoDevice &)> on_update)
Perform the shared setup() registration ritual.
void log_poll_interval_config_(const char *tag) const
Emit the shared two-branch poll-interval line for dump_config().
IOHomeControlComponent * parent_
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.
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 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).
Internal helpers shared by the hub implementation .cpp files.
uint8_t round_percent(float fraction)
Convert a 0.0-1.0 HA fraction (position, tilt, or brightness) to a 0-100 IO percent.
static constexpr float UNKNOWN_POSITION
Sentinel value meaning "position is not known yet".
@ UNKNOWN
Unknown/unspecified device.
static constexpr const char * TAG
bool default_inverted_for_type(DeviceType type)
Determine whether a device type has inverted position mapping by default.
@ STOP
Stop movement immediately.
bool device_supports_tilt(DeviceType type)
Does this device type support tilt (slat angle) control?
Runtime state of a paired IO‑Homecontrol device.
float target
Target position the device is moving toward.
float tilt
Current tilt: 0=closed, 100=open, or UNKNOWN_POSITION.
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.
bool is_stopped
True if device is not moving.