Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
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 "
platform_entity_base.h
"
23
24
namespace
esphome
{
25
namespace
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.
33
class
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, stop, and optional tilt.
46
cover::CoverTraits
get_traits
()
override
;
47
48
/// @brief Enable or disable position inversion.
49
/// Some devices (e.g., horizontal awnings) report reversed open/close semantics.
50
/// @param invert True to invert the mapping (HA 1.0 → IO 0, HA 0.0 → IO 100).
51
void
set_invert_position
(
bool
invert) {
52
this->
invert_
= invert;
53
this->
invert_explicit_
=
true
;
54
}
55
/// @brief Opt this cover into the periodic rain sensor poll (from YAML `rain_sensor_poll_interval`).
56
/// @param interval_ms Poll interval in milliseconds; zero (the default) means no poll.
57
void
set_rain_sensor_poll_interval
(uint32_t interval_ms) { this->
rain_sensor_poll_interval_ms_
= interval_ms; }
58
/// @brief Query whether this device supports tilt (slat angle) control.
59
/// @return true if the YAML‑declared device type is tilt‑capable.
60
[[nodiscard]]
bool
supports_tilt
()
const
;
61
62
protected
:
63
/// @brief Handle cover commands from Home Assistant (open/close/stop/set_position).
64
/// @param call CoverCall containing the requested operation.
65
void
control
(
const
cover::CoverCall &call)
override
;
66
/// @brief Callback invoked when the underlying device state changes.
67
/// @param id Device ID that updated.
68
/// @param dev Updated IoDevice state.
69
void
on_device_update_
(
const
std::string &
id
,
const
IoDevice
&dev);
70
/// @brief Resolve the current inversion mode.
71
/// @return Explicit YAML override when set, otherwise the runtime device profile.
72
[[nodiscard]]
bool
effective_invert_
()
const
;
73
/// @brief Infer HA movement direction from successive IO positions when the protocol target is unknown.
74
/// @param invert Effective inversion mode for this device.
75
/// @param current_io_position Latest reported IO position (0=open, 100=closed).
76
/// @return OPENING, CLOSING, or IDLE when no direction can be inferred yet.
77
[[nodiscard]] cover::CoverOperation
infer_operation_from_position_delta_
(
bool
invert,
78
float
current_io_position)
const
;
79
80
bool
invert_
{
false
};
81
bool
invert_explicit_
{
false
};
82
float
last_io_position_
{UNKNOWN_POSITION};
83
uint32_t
rain_sensor_poll_interval_ms_
{0};
///< 0 = not opted in; no rain poll is scheduled.
84
};
85
86
}
// namespace home_io_control
87
}
// namespace esphome
esphome::home_io_control::DeviceBoundEntity
Mixin holding the hub-device binding shared by all IO-Homecontrol entity platforms.
Definition
platform_entity_base.h:38
esphome::home_io_control::IOHomeCover::set_invert_position
void set_invert_position(bool invert)
Enable or disable position inversion.
Definition
platform_cover.h:51
esphome::home_io_control::IOHomeCover::rain_sensor_poll_interval_ms_
uint32_t rain_sensor_poll_interval_ms_
0 = not opted in; no rain poll is scheduled.
Definition
platform_cover.h:83
esphome::home_io_control::IOHomeCover::infer_operation_from_position_delta_
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.
Definition
platform_cover.cpp:69
esphome::home_io_control::IOHomeCover::set_rain_sensor_poll_interval
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).
Definition
platform_cover.h:57
esphome::home_io_control::IOHomeCover::supports_tilt
bool supports_tilt() const
Query whether this device supports tilt (slat angle) control.
Definition
platform_cover.cpp:56
esphome::home_io_control::IOHomeCover::on_device_update_
void on_device_update_(const std::string &id, const IoDevice &dev)
Callback invoked when the underlying device state changes.
Definition
platform_cover.cpp:134
esphome::home_io_control::IOHomeCover::last_io_position_
float last_io_position_
Definition
platform_cover.h:82
esphome::home_io_control::IOHomeCover::effective_invert_
bool effective_invert_() const
Resolve the current inversion mode.
Definition
platform_cover.cpp:60
esphome::home_io_control::IOHomeCover::get_traits
cover::CoverTraits get_traits() override
Return the traits object describing this cover's capabilities.
Definition
platform_cover.cpp:47
esphome::home_io_control::IOHomeCover::setup
void setup() override
Initialize the cover entity (register device, subscribe to updates, schedule initial status poll).
Definition
platform_cover.cpp:36
esphome::home_io_control::IOHomeCover::get_setup_priority
float get_setup_priority() const override
Get setup priority (DATA so we have device registry available).
Definition
platform_cover.h:42
esphome::home_io_control::IOHomeCover::dump_config
void dump_config() override
Dump configuration to log.
Definition
platform_cover.cpp:195
esphome::home_io_control::IOHomeCover::invert_
bool invert_
Definition
platform_cover.h:80
esphome::home_io_control::IOHomeCover::IOHomeCover
IOHomeCover()=default
esphome::home_io_control::IOHomeCover::invert_explicit_
bool invert_explicit_
Definition
platform_cover.h:81
esphome::home_io_control::IOHomeCover::control
void control(const cover::CoverCall &call) override
Handle cover commands from Home Assistant (open/close/stop/set_position).
Definition
platform_cover.cpp:73
esphome::home_io_control
Definition
device_registry.cpp:15
esphome
Definition
device_registry.cpp:14
platform_entity_base.h
Shared device-binding mixins for IO-Homecontrol entity platforms.
esphome::home_io_control::IoDevice
Runtime state of a paired IO‑Homecontrol device.
Definition
proto_device_model.h:413
components
home_io_control
platform_cover.h
Generated by
1.18.0