Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
Loading...
Searching...
No Matches
platform_switch.cpp
Go to the documentation of this file.
1
/// @file platform_switch.cpp
2
/// @brief Experimental binary switch entity for IO-Homecontrol devices.
3
/// @ingroup hioc_platforms
4
5
#include "
platform_switch.h
"
6
#include "
entity_helpers.h
"
7
#include "esphome/core/log.h"
8
9
namespace
esphome
{
10
namespace
home_io_control
{
11
12
static
const
char
*
const
TAG
=
"home_io_control.switch"
;
13
14
void
IOHomeSwitch::setup
() {
15
// Register and subscribe exactly like covers so the controller keeps one shared view of all
16
// known IO-homecontrol devices, regardless of which ESPHome entity type wraps them.
17
this->
register_device_binding_
(
this
,
/*inverted=*/
false
, [
this
](
const
std::string &
id
,
const
IoDevice
&dev) {
18
this->
on_device_update_
(
id
, dev);
19
});
20
}
21
22
void
IOHomeSwitch::write_state
(
bool
state) {
23
// Switches stay semantic at the entity boundary and let the controller translate them to the
24
// transport-level 0/100 representation.
25
this->
parent_
->
queue_set_switch_state
(this->
device_id_
, state);
26
}
27
28
void
IOHomeSwitch::on_device_update_
(
const
std::string &
id
,
const
IoDevice
&dev) {
29
// Only publish a stable state for this device once it has stopped moving with a known position.
30
if
(!this->
passes_binary_update_filter_
(
id
, dev))
31
return
;
32
33
// Binary endpoints share the same on/off encoding as the light wrapper.
34
this->publish_state(dev.
position
<
detail::BINARY_ENTITY_ON_POSITION_THRESHOLD
);
35
}
36
37
void
IOHomeSwitch::dump_config
() {
38
LOG_SWITCH(
""
,
"IO-Homecontrol Binary Switch"
,
this
);
39
ESP_LOGCONFIG(
TAG
,
" Device ID: %s"
, this->
device_id_
.c_str());
40
this->
log_poll_interval_config_
(
TAG
);
41
ESP_LOGCONFIG(
TAG
,
" Status: experimental and untested"
);
42
}
43
44
}
// namespace home_io_control
45
}
// namespace esphome
esphome::home_io_control::DeviceBoundEntity::device_id_
std::string device_id_
Definition
platform_entity_base.h:116
esphome::home_io_control::DeviceBoundEntity::log_poll_interval_config_
void log_poll_interval_config_(const char *tag) const
Emit the shared two-branch poll-interval line for dump_config().
Definition
platform_entity_base.h:107
esphome::home_io_control::DeviceBoundEntity::register_device_binding_
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.
Definition
platform_entity_base.h:81
esphome::home_io_control::DeviceBoundEntity::parent_
IOHomeControlComponent * parent_
Definition
platform_entity_base.h:115
esphome::home_io_control::DeviceBoundEntity::passes_binary_update_filter_
bool passes_binary_update_filter_(const std::string &id, const IoDevice &dev) const
Shared inbound-update guard for binary endpoints.
Definition
platform_entity_base.h:101
esphome::home_io_control::IOHomeControlComponent::queue_set_switch_state
virtual void queue_set_switch_state(const std::string &device_id, bool on)
Async form of set_switch_state() that keeps radio work serialized on the main loop.
Definition
hub_operations.cpp:681
esphome::home_io_control::IOHomeSwitch::dump_config
void dump_config() override
Dump configuration to log.
Definition
platform_switch.cpp:37
esphome::home_io_control::IOHomeSwitch::on_device_update_
void on_device_update_(const std::string &id, const IoDevice &dev)
Callback when device state changes (e.g., from a remote).
Definition
platform_switch.cpp:28
esphome::home_io_control::IOHomeSwitch::write_state
void write_state(bool state) override
Write state change to the device.
Definition
platform_switch.cpp:22
esphome::home_io_control::IOHomeSwitch::setup
void setup() override
Initialize the switch entity.
Definition
platform_switch.cpp:14
entity_helpers.h
Conversions and renderers shared by the hub and its Home Assistant entities.
esphome::home_io_control::detail::BINARY_ENTITY_ON_POSITION_THRESHOLD
constexpr float BINARY_ENTITY_ON_POSITION_THRESHOLD
Shared 0-100 cutoff: values below this mean binary "on".
Definition
entity_helpers.h:29
esphome::home_io_control
Definition
device_registry.cpp:13
esphome::home_io_control::TAG
static constexpr const char * TAG
Definition
device_registry.cpp:15
esphome::home_io_control::TAG
static const char *const TAG
Definition
platform_switch.cpp:12
esphome
Definition
device_registry.cpp:12
platform_switch.h
Experimental binary switch entity for IO‑Homecontrol devices.
esphome::home_io_control::IoDevice
Runtime state of a paired IO‑Homecontrol device.
Definition
proto_device_model.h:321
esphome::home_io_control::IoDevice::position
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.
Definition
proto_device_model.h:326
components
home_io_control
platform_switch.cpp
Generated by
1.18.0