Home IO Control
ESPHome add-on for IO-Homecontrol devices
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 "hub_internal.h"
7#include "esphome/core/log.h"
8
9namespace esphome {
10namespace home_io_control {
11
12static const char *const TAG = "home_io_control.switch";
13
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
22void 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
28void 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.
35}
36
38 LOG_SWITCH("", "IO-Homecontrol Binary Switch", this);
39 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
41 ESP_LOGCONFIG(TAG, " Status: experimental and untested");
42}
43
44} // namespace home_io_control
45} // namespace esphome
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().
bool passes_binary_update_filter_(const std::string &id, const IoDevice &dev) const
Shared inbound-update guard for binary endpoints.
void dump_config() override
Dump configuration to log.
void on_device_update_(const std::string &id, const IoDevice &dev)
Callback when device state changes (e.g., from a remote).
void write_state(bool state) override
Write state change to the device.
void setup() override
Initialize the switch entity.
Internal helpers shared by the hub implementation .cpp files.
constexpr float BINARY_ENTITY_ON_POSITION_THRESHOLD
Shared 0-100 cutoff: values below this mean binary "on".
static constexpr const char * TAG
Experimental binary switch entity for IO‑Homecontrol devices.
Runtime state of a paired IO‑Homecontrol device.
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.