Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
esphome::home_io_control::DeviceRegistry Class Reference

Owns the per-hub device table, update callbacks, and linked-remote associations. More...

#include <device_registry.h>

Collaboration diagram for esphome::home_io_control::DeviceRegistry:

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.
IoDeviceget (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.

Detailed Description

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.

Member Function Documentation

◆ add() [1/2]

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.

Parameters
device_idHexadecimal node ID string (e.g. "ABC123").

Definition at line 17 of file device_registry.cpp.

Here is the call graph for this function:

◆ add() [2/2]

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.

Parameters
device_idHexadecimal node ID string.
cfgDevice type/subtype/inversion/optimistic-state metadata.

Definition at line 19 of file device_registry.cpp.

Here is the call graph for this function:

◆ add_linked_remote()

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.

Parameters
remote_idNode ID of the remote control.
device_idNode ID of the device it controls.

Definition at line 57 of file device_registry.cpp.

◆ add_linked_remote_class()

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.

Parameters
typeDevice class the broadcast targets.
device_idNode ID of the device to add to that class.

Definition at line 66 of file device_registry.cpp.

◆ apply_optimistic_target()

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.

Parameters
device_idDevice to update.
target_io_positionTarget position in IO units (0=open, 100=closed).
Returns
true if the optimistic state was applied.

Definition at line 75 of file device_registry.cpp.

Here is the call graph for this function:

◆ apply_optimistic_tilt()

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.

Parameters
device_idDevice to update.
tilt_percentSlat angle in the same percent scale as IoDevice::tilt (0-100).
Returns
true if the optimistic tilt was applied.

Definition at line 106 of file device_registry.cpp.

Here is the call graph for this function:

◆ begin()

std::map< std::string, IoDevice >::iterator esphome::home_io_control::DeviceRegistry::begin ( )
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.

◆ clear_optimistic_target()

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.

Parameters
device_idDevice to update.
Returns
true if the optimistic target was cleared.

Definition at line 95 of file device_registry.cpp.

Here is the call graph for this function:

◆ end()

std::map< std::string, IoDevice >::iterator esphome::home_io_control::DeviceRegistry::end ( )
inline

Mutable end iterator over (device_id, IoDevice) pairs.

Definition at line 153 of file device_registry.h.

◆ for_each_linked_remote()

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.

Parameters
fnCallable receiving the remote ID and its associated device ID list.

Definition at line 128 of file device_registry.cpp.

◆ get()

IoDevice * esphome::home_io_control::DeviceRegistry::get ( const std::string & device_id)
nodiscard

Retrieve a registered device by ID.

Returns
Pointer to the stored IoDevice, or nullptr when not found.

Definition at line 37 of file device_registry.cpp.

◆ linked_devices()

const std::vector< std::string > * esphome::home_io_control::DeviceRegistry::linked_devices ( const std::string & remote_id) const
nodiscard

Retrieve the list of device IDs linked to a remote.

Returns
Pointer to the device-ID list, or nullptr when the remote is unknown.

Definition at line 61 of file device_registry.cpp.

◆ linked_devices_for_class()

const std::vector< std::string > * esphome::home_io_control::DeviceRegistry::linked_devices_for_class ( DeviceType type) const
nodiscard

Retrieve the list of device IDs linked to a device class.

Returns
Pointer to the device-ID list, or nullptr when no device is linked to that class.

Definition at line 70 of file device_registry.cpp.

◆ linked_remote_count()

size_t esphome::home_io_control::DeviceRegistry::linked_remote_count ( ) const
inlinenodiscard
Returns
Number of distinct linked-remote entries.

Definition at line 143 of file device_registry.h.

◆ notify()

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.

Parameters
device_idDevice whose state just changed.

Definition at line 49 of file device_registry.cpp.

◆ put()

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.

Parameters
device_idHexadecimal node ID string.
deviceFully-built device to store.

Definition at line 35 of file device_registry.cpp.

◆ set_dimmable()

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.

Parameters
device_idDevice to update.
dimmableNew value for IoDevice::dimmable.

Definition at line 42 of file device_registry.cpp.

Here is the call graph for this function:

◆ size()

size_t esphome::home_io_control::DeviceRegistry::size ( ) const
inlinenodiscard
Returns
Number of registered devices.

Definition at line 140 of file device_registry.h.

◆ subscribe()

void esphome::home_io_control::DeviceRegistry::subscribe ( DeviceUpdateCallback cb)

Register a callback that fires whenever a device's state changes.

Parameters
cbCallable with signature void(const std::string &device_id, const IoDevice &device).

Definition at line 47 of file device_registry.cpp.


The documentation for this class was generated from the following files: