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->parent_->add_device(this->device_id_, device_type_, subtype_, /*inverted=*/false);
18 this->parent_->set_device_status_poll_interval(this->device_id_, this->status_poll_interval_ms_);
19 this->parent_->register_device_callback(
20 [this](const std::string &id, const IoDevice &dev) { this->on_device_update_(id, dev); });
21 this->set_timeout("init_status", detail::INITIAL_STATUS_REQUEST_DELAY_MS,
22 [this]() { this->parent_->queue_request_device_status(this->device_id_); });
23}
24
25void IOHomeSwitch::write_state(bool state) {
26 // Switches stay semantic at the entity boundary and let the controller translate them to the
27 // transport-level 0/100 representation.
28 this->parent_->queue_set_switch_state(this->device_id_, state);
29}
30
31void IOHomeSwitch::on_device_update_(const std::string &id, const IoDevice &dev) {
32 if (id != this->device_id_)
33 return;
34
35 // Like the light entity, only publish a stable state once the device has stopped moving.
36 if (dev.position == UNKNOWN_POSITION || !dev.is_stopped)
37 return;
38
39 // Binary endpoints share the same on/off encoding as the light wrapper.
41}
42
44 LOG_SWITCH("", "IO-Homecontrol Binary Switch", this);
45 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
46 if (this->status_poll_interval_ms_ == 0) {
47 ESP_LOGCONFIG(TAG, " Status Poll Interval: default single settle poll");
48 } else {
49 ESP_LOGCONFIG(TAG, " Status Poll Interval: %u ms", this->status_poll_interval_ms_);
50 }
51 ESP_LOGCONFIG(TAG, " Status: experimental and untested");
52}
53
54} // namespace home_io_control
55} // 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:35
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.