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) {
26 if (from_io_position == UNKNOWN_POSITION || to_io_position == UNKNOWN_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;
106 if (tilt_opt.has_value()) {
116 if (position_opt.has_value()) {
117 float const ha_pos = *position_opt;
144 if (dev.
position != UNKNOWN_POSITION) {
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;
163 }
else if (eff_target != UNKNOWN_POSITION && dev.
position != UNKNOWN_POSITION && eff_target != dev.
position) {
165 this->current_operation = operation_toward(invert, dev.
position, eff_target);
166 }
else if (eff_target != UNKNOWN_POSITION && dev.
position == UNKNOWN_POSITION) {
173 this->current_operation = operation_toward(invert, previous_io_position, eff_target);
174 }
else if (dev.
position != UNKNOWN_POSITION) {
183 if (dev.
position != UNKNOWN_POSITION) {
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_
virtual bool apply_optimistic_stop(const std::string &device_id)
Predict that a device has stopped (e.g.
virtual void queue_set_device_tilt(const std::string &device_id, uint8_t tilt_percent)
Queue an async tilt update; returns immediately, executed in loop().
virtual IoDevice * get_device(const std::string &device_id)
Retrieve a device by ID; returns nullptr if not found.
virtual void queue_set_device_position_and_tilt(const std::string &device_id, uint8_t position, uint8_t tilt_percent)
Queue an async combined position+tilt update; returns immediately, executed in loop().
virtual bool queue_device_command(const std::string &device_id, CoverCommand cmd)
Queue an async named command (STOP, FAVORITE, VENT, FORCE_OPEN); returns immediately,...
virtual bool apply_optimistic_tilt(const std::string &device_id, float tilt_percent)
Set an optimistic slat angle ahead of a confirming status poll, and notify.
virtual void queue_set_device_position(const std::string &device_id, uint8_t position)
Queue an async position update; returns immediately, executed in loop().
virtual bool apply_optimistic_target(const std::string &device_id, float target_io_position)
Set an optimistic target position ahead of a confirming poll/response, and notify.
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).
Conversions and renderers shared by the hub and its Home Assistant entities.
uint8_t round_percent(float fraction)
Convert a 0.0-1.0 HA fraction (position, tilt, or brightness) to a 0-100 IO percent.
@ 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?
static const char *const TAG
Runtime state of a paired IO‑Homecontrol device.
bool inverted
True if open/close positions are swapped (e.g., horizontal awning).
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.