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