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
4#include "platform_switch.h"
5#include "hub_internal.h"
6#include "esphome/core/log.h"
7
8namespace esphome {
9namespace home_io_control {
10
11static const char *const TAG = "home_io_control.switch";
12
14 // Register and subscribe exactly like covers so the controller keeps one shared view of all
15 // known IO-homecontrol devices, regardless of which ESPHome entity type wraps them.
16 this->parent_->add_device(this->device_id_, device_type_, subtype_, /*inverted=*/false);
17 this->parent_->set_device_status_poll_interval(this->device_id_, this->status_poll_interval_ms_);
18 this->parent_->register_device_callback(
19 [this](const std::string &id, const IoDevice &dev) { this->on_device_update_(id, dev); });
20 this->set_timeout("init_status", detail::INITIAL_STATUS_REQUEST_DELAY_MS,
21 [this]() { this->parent_->queue_request_device_status(this->device_id_); });
22}
23
24void IOHomeSwitch::write_state(bool state) {
25 // Switches stay semantic at the entity boundary and let the controller translate them to the
26 // transport-level 0/100 representation.
27 this->parent_->queue_set_switch_state(this->device_id_, state);
28}
29
30void IOHomeSwitch::on_device_update_(const std::string &id, const IoDevice &dev) {
31 if (id != this->device_id_)
32 return;
33
34 // Like the light entity, only publish a stable state once the device has stopped moving.
35 if (dev.position == UNKNOWN_POSITION || !dev.is_stopped)
36 return;
37
38 // Binary endpoints share the same on/off encoding as the light wrapper.
40}
41
43 LOG_SWITCH("", "IO-Homecontrol Binary Switch", this);
44 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
45 if (this->status_poll_interval_ms_ == 0) {
46 ESP_LOGCONFIG(TAG, " Status Poll Interval: default single settle poll");
47 } else {
48 ESP_LOGCONFIG(TAG, " Status Poll Interval: %u ms", this->status_poll_interval_ms_);
49 }
50 ESP_LOGCONFIG(TAG, " Status: experimental and untested");
51}
52
53} // namespace home_io_control
54} // namespace esphome
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 uint32_t INITIAL_STATUS_REQUEST_DELAY_MS
Delay before the first post-boot status request from an entity.
constexpr float BINARY_ENTITY_ON_POSITION_THRESHOLD
Shared 0-100 cutoff: values below this mean binary "on".
static constexpr float UNKNOWN_POSITION
Sentinel value meaning "position is not known yet".
static const char *const TAG
Definition hub_core.cpp:34
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.
bool is_stopped
True if device is not moving.