Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_light.cpp
Go to the documentation of this file.
1/// @file platform_light.cpp
2/// @brief Experimental binary light entity for IO-Homecontrol devices.
3/// @ingroup hioc_platforms
4
5#include "platform_light.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.light";
13
15 // Binary lights still need the shared device registry so discovery/status handling can find
16 // their node metadata the same way covers do.
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
20 // Subscribe to controller updates so HA state follows radio-originated changes too.
21 this->parent_->register_device_callback(
22 [this](const std::string &id, const IoDevice &dev) { this->on_device_update_(id, dev); });
23
24 // Ask for one delayed poll after boot, matching the cover platform behavior.
25 this->set_timeout("init_status", detail::INITIAL_STATUS_REQUEST_DELAY_MS,
26 [this]() { this->parent_->queue_request_device_status(this->device_id_); });
27}
28
29light::LightTraits IOHomeLight::get_traits() {
30 auto traits = light::LightTraits();
31 // Dimming is intentionally not exposed yet; would need real device to verify.
32 traits.set_supported_color_modes({light::ColorMode::ON_OFF});
33 return traits;
34}
35
36void IOHomeLight::write_state(light::LightState *state) {
37 bool on = false;
38 state->current_values_as_binary(&on);
39
40 if (this->suppress_write_) {
41 this->suppress_write_ = false;
42 return;
43 }
44
45 this->parent_->queue_set_light_state(this->device_id_, on);
46}
47
48void IOHomeLight::on_device_update_(const std::string &id, const IoDevice &dev) {
49 if (id != this->device_id_ || this->state_ == nullptr)
50 return;
51
52 // Ignore unknown or in-flight positions. For binary devices we only want to publish a stable
53 // HA state once the device reports a settled status.
54 if (dev.position == UNKNOWN_POSITION || !dev.is_stopped)
55 return;
56
57 // Binary endpoints report on/off via the shared 0-100 position field.
58 // Position < 50 is treated as "on", >= 50 as "off".
60 if (this->state_->current_values.is_on() == on && this->state_->remote_values.is_on() == on)
61 return;
62
63 // Update via LightState's call API, suppressing the write_state() echo to avoid re-sending.
64 this->suppress_write_ = true;
65 auto call = this->state_->make_call();
66 call.set_state(on);
67 call.set_save(false);
68 call.perform();
69}
70
72 ESP_LOGCONFIG(TAG, "IO-Homecontrol Binary Light");
73 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
74 if (this->status_poll_interval_ms_ == 0) {
75 ESP_LOGCONFIG(TAG, " Status Poll Interval: default single settle poll");
76 } else {
77 ESP_LOGCONFIG(TAG, " Status Poll Interval: %u ms", this->status_poll_interval_ms_);
78 }
79 ESP_LOGCONFIG(TAG, " Status: experimental and untested");
80}
81
82} // namespace home_io_control
83} // namespace esphome
void write_state(light::LightState *state) override
bool suppress_write_
Guard so that an inbound radio status does not echo back as a new outbound command.
void on_device_update_(const std::string &id, const IoDevice &dev)
Handle inbound device status updates.
void dump_config() override
Dump configuration to log.
light::LightTraits get_traits() override
Return traits: binary on/off only (no dimming).
void setup() override
Initialize the light 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 light 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.