7#include "esphome/core/log.h"
12static const char *
const TAG =
"home_io_control.cover";
25cover::CoverOperation operation_toward(
bool invert,
float from_io_position,
float to_io_position) {
27 from_io_position == to_io_position) {
28 return cover::COVER_OPERATION_IDLE;
30 const bool opening = invert ? (to_io_position > from_io_position) : (to_io_position < from_io_position);
31 return opening ? cover::COVER_OPERATION_OPENING : cover::COVER_OPERATION_CLOSING;
45 auto traits = cover::CoverTraits();
46 traits.set_supports_position(
true);
47 traits.set_supports_stop(
true);
49 traits.set_is_assumed_state(
false);
63 return dev !=
nullptr && dev->inverted;
76 if (call.get_stop()) {
82 const auto &tilt_opt = call.get_tilt();
83 const auto &position_opt = call.get_position();
95 if (position_opt.has_value() && tilt_opt.has_value() && this->supports_tilt()) {
96 float const ha_pos = *position_opt;
102 this->
parent_->queue_set_device_position_and_tilt(this->
device_id_, io_pos, tilt);
106 if (tilt_opt.has_value()) {
116 if (position_opt.has_value()) {
117 float const ha_pos = *position_opt;
150 ha_pos = 1.0F - (dev.
position / 100.0F);
153 this->position = ha_pos;
157 this->tilt = eff_tilt / 100.0F;
162 this->current_operation = cover::COVER_OPERATION_IDLE;
165 this->current_operation = operation_toward(invert, dev.
position, eff_target);
173 this->current_operation = operation_toward(invert, previous_io_position, eff_target);
189 this->publish_state();
193 LOG_COVER(
"",
"IO-Homecontrol Cover",
this);
194 ESP_LOGCONFIG(
TAG,
" Device ID: %s", this->
device_id_.c_str());
void log_poll_interval_config_(const char *tag) const
Emit the shared two-branch poll-interval line for dump_config().
void register_device_binding_(Component *self, bool inverted, std::function< void(const std::string &, const IoDevice &)> on_update, bool schedule_initial_poll=true)
Perform the shared setup() registration ritual.
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.
float effective_target(const IoDevice &dev)
The main-position target a consumer should act on: the prediction when one stands,...
@ STOP
Stop movement immediately.
bool effective_is_stopped(const IoDevice &dev)
Whether a consumer should treat the device as at rest, prediction first.
float effective_tilt(const IoDevice &dev)
The slat angle a consumer should act on, prediction first.
bool device_supports_tilt(DeviceType type)
Does this device type support tilt (slat angle) control?
Runtime state of a paired IO‑Homecontrol device.
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.