Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_light.h
Go to the documentation of this file.
1#pragma once
2
3/// @file platform_light.h
4/// @brief Binary or dimmable light entity for IO‑Homecontrol devices.
5/// @ingroup hioc_platforms
6///
7/// Defaults to a minimal on/off representation (position < 50 is treated as on), validated on
8/// real hardware (a Somfy Izymo dimmer; see tests/corpus/captures/somfy_dimmer/). Setting
9/// `dimmable: true` in YAML switches to ColorMode::BRIGHTNESS, mapping HA's 0.0-1.0 brightness
10/// onto the same 0-100 IO position field platform_cover.cpp uses for position — confirmed on the
11/// same hardware to produce real intermediate brightness levels, not just the two binary
12/// extremes.
13///
14/// The protocol gives no machine-readable signal for whether a given LIGHT-type device actually
15/// supports intermediate positions (DISCOVER_RESP's subtype byte is manufacturer-opaque) — so
16/// `dimmable` is an explicit opt-in, not auto-detected. Devices that are genuinely binary-only
17/// should leave it unset/false.
18
19#include "esphome/core/component.h"
20#include "esphome/components/light/light_output.h"
22
23namespace esphome {
24namespace home_io_control {
25
26/// @brief Binary or dimmable light entity for IO‑Homecontrol devices.
27/// @ingroup hioc_platforms
28///
29/// The device-binding setters, setup() registration ritual and poll-interval dump line come
30/// from DeviceBoundEntity; only the on/off/brightness command and status decoding live here.
31class IOHomeLight : public light::LightOutput, public Component, public DeviceBoundEntity {
32 public:
33 /// @brief Initialize the light entity.
34 void setup() override;
35 /// @brief Dump configuration to log.
36 void dump_config() override;
37 /// @brief Get setup priority (DATA).
38 /// @return setup_priority::DATA.
39 [[nodiscard]] float get_setup_priority() const override { return setup_priority::DATA; }
40
41 /// @brief Enable brightness control (from YAML). Default false: binary on/off only.
42 /// @param dimmable True to expose ColorMode::BRIGHTNESS instead of ColorMode::ON_OFF.
43 void set_dimmable(bool dimmable) { this->dimmable_ = dimmable; }
44
45 /// @brief Return traits: ColorMode::BRIGHTNESS if dimmable, else ColorMode::ON_OFF.
46 light::LightTraits get_traits() override;
47 /// @brief Store the HA LightState object for state updates.
48 ///
49 /// LightState::setup() calls this first, then — moments later in that same call, before we get
50 /// a chance to do anything else — applies its own restore_mode (default ALWAYS_OFF) via a real
51 /// write_state() call, exactly as if HA had requested it. That's correct for a local PWM/LED
52 /// output (which needs some defined state immediately), but wrong for a radio-controlled device
53 /// with no local output to initialize: it would silently turn the light off (or on) on every
54 /// reflash regardless of the device's actual state. Arm suppress_write_ here so that one
55 /// boot-time write is swallowed the same way an inbound-update echo already is; the delayed
56 /// initial status poll (register_device_binding_(), same as covers) is the real source of truth.
57 /// @param state Pointer to LightState.
58 void setup_state(light::LightState *state) override {
59 this->state_ = state;
60 this->suppress_write_ = true;
61 }
62 void write_state(light::LightState *state) override;
63
64 protected:
65 /// @brief Handle inbound device status updates.
66 /// @param id Device ID.
67 /// @param dev Updated device state.
68 void on_device_update_(const std::string &id, const IoDevice &dev);
69
70 light::LightState *state_{nullptr};
71 bool dimmable_{false};
72 /// Guard so that an inbound radio status (or LightState's own boot-time restore_mode push —
73 /// see setup_state()) does not echo back as a new outbound command.
74 ///
75 /// This flag is a light-only asymmetry: LightState::make_call().perform() re-enters
76 /// write_state(), so both the inbound-update path and setup_state() must suppress that.
77 /// Switches publish state without re-entering write_state(), so they need no equivalent guard.
78 bool suppress_write_{false};
79};
80
81} // namespace home_io_control
82} // namespace esphome
Mixin holding the hub-device binding shared by all IO-Homecontrol entity platforms.
Binary or dimmable light entity for IO‑Homecontrol devices.
void write_state(light::LightState *state) override
bool suppress_write_
Guard so that an inbound radio status (or LightState's own boot-time restore_mode push — see setup_st...
void setup_state(light::LightState *state) override
Store the HA LightState object for state updates.
void on_device_update_(const std::string &id, const IoDevice &dev)
Handle inbound device status updates.
float get_setup_priority() const override
Get setup priority (DATA).
void dump_config() override
Dump configuration to log.
light::LightTraits get_traits() override
Return traits: ColorMode::BRIGHTNESS if dimmable, else ColorMode::ON_OFF.
void setup() override
Initialize the light entity.
void set_dimmable(bool dimmable)
Enable brightness control (from YAML).
Shared device-binding mixins for IO-Homecontrol entity platforms.
Runtime state of a paired IO‑Homecontrol device.