Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
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 the somfy_izymo_dimmer_* captures). 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"
21
#include "
platform_entity_base.h
"
22
23
namespace
esphome
{
24
namespace
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.
31
class
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
esphome::home_io_control::DeviceBoundEntity
Mixin holding the hub-device binding shared by all IO-Homecontrol entity platforms.
Definition
platform_entity_base.h:36
esphome::home_io_control::IOHomeLight
Binary or dimmable light entity for IO‑Homecontrol devices.
Definition
platform_light.h:31
esphome::home_io_control::IOHomeLight::dimmable_
bool dimmable_
Definition
platform_light.h:71
esphome::home_io_control::IOHomeLight::write_state
void write_state(light::LightState *state) override
Definition
platform_light.cpp:33
esphome::home_io_control::IOHomeLight::suppress_write_
bool suppress_write_
Guard so that an inbound radio status (or LightState's own boot-time restore_mode push — see setup_st...
Definition
platform_light.h:78
esphome::home_io_control::IOHomeLight::state_
light::LightState * state_
Definition
platform_light.h:70
esphome::home_io_control::IOHomeLight::setup_state
void setup_state(light::LightState *state) override
Store the HA LightState object for state updates.
Definition
platform_light.h:58
esphome::home_io_control::IOHomeLight::on_device_update_
void on_device_update_(const std::string &id, const IoDevice &dev)
Handle inbound device status updates.
Definition
platform_light.cpp:62
esphome::home_io_control::IOHomeLight::get_setup_priority
float get_setup_priority() const override
Get setup priority (DATA).
Definition
platform_light.h:39
esphome::home_io_control::IOHomeLight::dump_config
void dump_config() override
Dump configuration to log.
Definition
platform_light.cpp:101
esphome::home_io_control::IOHomeLight::get_traits
light::LightTraits get_traits() override
Return traits: ColorMode::BRIGHTNESS if dimmable, else ColorMode::ON_OFF.
Definition
platform_light.cpp:27
esphome::home_io_control::IOHomeLight::setup
void setup() override
Initialize the light entity.
Definition
platform_light.cpp:14
esphome::home_io_control::IOHomeLight::set_dimmable
void set_dimmable(bool dimmable)
Enable brightness control (from YAML).
Definition
platform_light.h:43
esphome::home_io_control
Definition
device_registry.cpp:13
esphome
Definition
device_registry.cpp:12
platform_entity_base.h
Shared device-binding mixins for IO-Homecontrol entity platforms.
esphome::home_io_control::IoDevice
Runtime state of a paired IO‑Homecontrol device.
Definition
proto_device_model.h:321
components
home_io_control
platform_light.h
Generated by
1.18.0