|
Home IO Control
ESPHome add-on for IO-Homecontrol devices
|
Owns the per-hub device table, update callbacks, and linked-remote associations. More...
#include <device_registry.h>
Public Member Functions | |
| void | add (const std::string &device_id) |
| Register a device by ID with default metadata (UNKNOWN type, subtype 0, not inverted). | |
| void | add (const std::string &device_id, const DeviceConfig &cfg) |
| Register a device with full YAML-derived metadata. | |
| void | put (const std::string &device_id, IoDevice device) |
| Insert or overwrite a device entry without deduplication or hex-validation checks. | |
| IoDevice * | get (const std::string &device_id) |
| Retrieve a registered device by ID. | |
| void | set_dimmable (const std::string &device_id, bool dimmable) |
| Set a device's dimmable flag (see IoDevice::dimmable). | |
| void | subscribe (DeviceUpdateCallback cb) |
| Register a callback that fires whenever a device's state changes. | |
| void | notify (const std::string &device_id) |
Invoke all registered callbacks for device_id. | |
| void | add_linked_remote (const std::string &remote_id, const std::string &device_id) |
| Record that a remote node controls a registered device. | |
| const std::vector< std::string > * | linked_devices (const std::string &remote_id) const |
| Retrieve the list of device IDs linked to a remote. | |
| void | add_linked_remote_class (DeviceType type, const std::string &device_id) |
| Record that a remote's typed-broadcast presses (e.g. | |
| const std::vector< std::string > * | linked_devices_for_class (DeviceType type) const |
| Retrieve the list of device IDs linked to a device class. | |
| bool | apply_optimistic_target (const std::string &device_id, float target_io_position) |
| Set an optimistic target position ahead of a confirming poll/response, and notify. | |
| bool | clear_optimistic_target (const std::string &device_id) |
| Clear a device's optimistic target (e.g. | |
| bool | apply_optimistic_tilt (const std::string &device_id, float tilt_percent) |
| Set an optimistic slat angle ahead of a confirming poll, and notify. | |
| size_t | size () const |
| size_t | linked_remote_count () const |
| void | for_each_linked_remote (const std::function< void(const std::string &, const std::vector< std::string > &)> &fn) const |
Invoke fn(remote_id, device_id_list) for every linked-remote entry. | |
| std::map< std::string, IoDevice >::iterator | begin () |
| Mutable begin iterator over (device_id, IoDevice) pairs (supports range-for in the poll loop). | |
| std::map< std::string, IoDevice >::iterator | end () |
| Mutable end iterator over (device_id, IoDevice) pairs. | |
Owns the per-hub device table, update callbacks, and linked-remote associations.
All of the hub's add/get/subscribe/notify operations go through this class — IOHomeControlComponent holds no device state of its own. The class has no ESPHome dependencies beyond logging and is directly host-testable.
Definition at line 40 of file device_registry.h.
| void esphome::home_io_control::DeviceRegistry::add | ( | const std::string & | device_id | ) |
Register a device by ID with default metadata (UNKNOWN type, subtype 0, not inverted).
No-op when device_id is already registered. Warns and returns when the hex string is invalid.
| device_id | Hexadecimal node ID string (e.g. "ABC123"). |
Definition at line 17 of file device_registry.cpp.
| void esphome::home_io_control::DeviceRegistry::add | ( | const std::string & | device_id, |
| const DeviceConfig & | cfg ) |
Register a device with full YAML-derived metadata.
No-op when device_id is already registered. Warns and returns when the hex string is invalid.
| device_id | Hexadecimal node ID string. |
| cfg | Device type/subtype/inversion/optimistic-state metadata. |
Definition at line 19 of file device_registry.cpp.
| void esphome::home_io_control::DeviceRegistry::add_linked_remote | ( | const std::string & | remote_id, |
| const std::string & | device_id ) |
Record that a remote node controls a registered device.
When activity from the remote is overheard, a status poll is scheduled for the linked device.
| remote_id | Node ID of the remote control. |
| device_id | Node ID of the device it controls. |
Definition at line 57 of file device_registry.cpp.
| void esphome::home_io_control::DeviceRegistry::add_linked_remote_class | ( | DeviceType | type, |
| const std::string & | device_id ) |
Record that a remote's typed-broadcast presses (e.g.
"all awnings") should also apply to device_id, matching how 1W remotes address a device class rather than a single node. Independent of add_linked_remote()'s id-keyed map — a device may be linked both ways; callers dedup (see IOHomeControlComponent's 1W dispatch) so it is only touched once per press.
| type | Device class the broadcast targets. |
| device_id | Node ID of the device to add to that class. |
Definition at line 66 of file device_registry.cpp.
| bool esphome::home_io_control::DeviceRegistry::apply_optimistic_target | ( | const std::string & | device_id, |
| float | target_io_position ) |
Set an optimistic target position ahead of a confirming poll/response, and notify.
No-op (and returns false) when the device is unknown or has optimistic_state == false. Never touches position — only the caller's later poll/response settles that. Used by both the 1W linked-remote path and HA-issued 2W cover commands so the entity shows movement direction immediately instead of only after the confirming update arrives.
| device_id | Device to update. |
| target_io_position | Target position in IO units (0=open, 100=closed). |
Definition at line 75 of file device_registry.cpp.
| bool esphome::home_io_control::DeviceRegistry::apply_optimistic_tilt | ( | const std::string & | device_id, |
| float | tilt_percent ) |
Set an optimistic slat angle ahead of a confirming poll, and notify.
No-op (and returns false) when the device is unknown, has optimistic_state == false, or is not a tilt-capable type. Nothing else can fill the gap: unlike a position command, a tilt command's own reply carries no slat angle this hub can use. The EXECUTE ack lays its payload out differently from a status reply and is not decoded for tilt at all (see the offset constants in hub_status.cpp and tests/corpus/captures/issues/issue_60_tilt_execute_ack_tilt_block*.yaml), so without this the entity would keep showing the pre-command angle until the next status poll seconds later.
Deliberately does not touch is_stopped, unlike apply_optimistic_target(): the HA movement animation is derived from main-position delta, and a tilt-only command does not move the main position — marking the device as moving would animate an open/close that is not happening. The EXECUTE ack settles is_stopped from the wire a fraction of a second later.
| device_id | Device to update. |
| tilt_percent | Slat angle in the same percent scale as IoDevice::tilt (0-100). |
Definition at line 106 of file device_registry.cpp.
|
inline |
Mutable begin iterator over (device_id, IoDevice) pairs (supports range-for in the poll loop).
Definition at line 151 of file device_registry.h.
| bool esphome::home_io_control::DeviceRegistry::clear_optimistic_target | ( | const std::string & | device_id | ) |
Clear a device's optimistic target (e.g.
on STOP), and notify.
No-op (and returns false) when the device is unknown or has optimistic_state == false.
| device_id | Device to update. |
Definition at line 95 of file device_registry.cpp.
|
inline |
Mutable end iterator over (device_id, IoDevice) pairs.
Definition at line 153 of file device_registry.h.
| void esphome::home_io_control::DeviceRegistry::for_each_linked_remote | ( | const std::function< void(const std::string &, const std::vector< std::string > &)> & | fn | ) | const |
Invoke fn(remote_id, device_id_list) for every linked-remote entry.
| fn | Callable receiving the remote ID and its associated device ID list. |
Definition at line 128 of file device_registry.cpp.
|
nodiscard |
Retrieve a registered device by ID.
Definition at line 37 of file device_registry.cpp.
|
nodiscard |
Retrieve the list of device IDs linked to a remote.
Definition at line 61 of file device_registry.cpp.
|
nodiscard |
Retrieve the list of device IDs linked to a device class.
Definition at line 70 of file device_registry.cpp.
|
inlinenodiscard |
Definition at line 143 of file device_registry.h.
| void esphome::home_io_control::DeviceRegistry::notify | ( | const std::string & | device_id | ) |
Invoke all registered callbacks for device_id.
No-op when device_id is not in the registry.
| device_id | Device whose state just changed. |
Definition at line 49 of file device_registry.cpp.
| void esphome::home_io_control::DeviceRegistry::put | ( | const std::string & | device_id, |
| IoDevice | device ) |
Insert or overwrite a device entry without deduplication or hex-validation checks.
Used by the pairing flow which already validated the device during discovery.
| device_id | Hexadecimal node ID string. |
| device | Fully-built device to store. |
Definition at line 35 of file device_registry.cpp.
| void esphome::home_io_control::DeviceRegistry::set_dimmable | ( | const std::string & | device_id, |
| bool | dimmable ) |
Set a device's dimmable flag (see IoDevice::dimmable).
No-op when the device is unknown. Called by platform_light.cpp's setup() right after registration, since dimmable is a light-platform YAML choice, not something add()'s shared cover/light/switch/lock signature should carry for every entity type.
| device_id | Device to update. |
| dimmable | New value for IoDevice::dimmable. |
Definition at line 42 of file device_registry.cpp.
|
inlinenodiscard |
Definition at line 140 of file device_registry.h.
| void esphome::home_io_control::DeviceRegistry::subscribe | ( | DeviceUpdateCallback | cb | ) |
Register a callback that fires whenever a device's state changes.
| cb | Callable with signature void(const std::string &device_id, const IoDevice &device). |
Definition at line 47 of file device_registry.cpp.