Skip to content

Notification callback skipped for second listener when value is identical across listeners #18

Description

@ckaysen

When multiple entities (e.g. a binary_sensor and a switch in Home Assistant) register a notify callback for the same resource ID via add_notify_event(), only the first-registered callback receives the value change. The second (and any subsequent) listener never gets called, because _ihcvalues[ihcid] is updated inside the inner loop over callbacks, causing the equality check value != self._ihcvalues[ihcid] to be False for every listener after the first one in the same notification cycle.

Relevant code in ihccontroller.py, _notify_fn():

for ihcid, value in changes:
    if ihcid in self._ihcevents:
        for callback in self._ihcevents[ihcid]:
            if (
                ihcid not in self._ihcvalues
                or value != self._ihcvalues[ihcid]
            ):
                callback(ihcid, value)
            self._ihcvalues[ihcid] = value

Since self._ihcvalues[ihcid] = value is set inside the for callback loop, after the first callback executes, all later callbacks in the same loop see value == self._ihcvalues[ihcid] and are skipped.

Suggested fix: move self._ihcvalues[ihcid] = value outside the inner for callback loop, so the comparison happens once per resource change, not once per callback:

for ihcid, value in changes:
    if ihcid in self._ihcevents:
        if ihcid not in self._ihcvalues or value != self._ihcvalues[ihcid]:
            for callback in self._ihcevents[ihcid]:
                callback(ihcid, value)
        self._ihcvalues[ihcid] = value

Reproduction:

  1. Define the same IHC resource ID both as a binary_sensor (autosetup) and as the status id for a switch (manual setup with on_id/off_id) in HA's IHC integration (haihc-betatest / version 2.0).
  2. Restart Home Assistant.
  3. Change the underlying IHC resource value (e.g. toggle an alarm panel physically).
  4. Observe: the binary_sensor (registered first) updates correctly. The switch (registered second) never updates and stays "unknown" forever, even though debug logs confirm both listeners are correctly registered via add_notify_event().

Confirmed on:

  • IHC Controller HW 6.1, Firmware 2.7.220
  • Home Assistant 2026.x with haihc-betatest (IHC integration v2026.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions