Skip to content

Change device trigger to use the new event listener and add support f…#197

Open
acdu1 wants to merge 2 commits intosanjoyg:mainfrom
acdu1:main
Open

Change device trigger to use the new event listener and add support f…#197
acdu1 wants to merge 2 commits intosanjoyg:mainfrom
acdu1:main

Conversation

@acdu1
Copy link
Copy Markdown
Contributor

@acdu1 acdu1 commented Apr 2, 2026

…or more events.

Describe your changes

Briefly describe your changes

✅ Changes made (issue #195 fix)

You can now use IKEA lights as device triggers in automations (also keeps existing controller button triggers).


🔁 device_trigger.py updates

  • Added:
    • CONTROLLER_TRIGGER_TYPES = ["single_click", "long_press", "double_click"]
    • LIGHT_TRIGGER_TYPES = ["turned_on", "turned_off"]
  • In async_get_triggers(...):
    • If entity domain is light, produce these two triggers:
      • turned_on
      • turned_off
    • Else existing controller button triggers continue as before.
  • In async_attach_trigger(...):
    • For light triggers, use Home Assistant state trigger:
      • state platform
      • entity_id = light entity
      • to = "on" or "off"
    • For controller events:
      • keeps old event path using dirigera_platform_event bus event.

🔁 hub_event_listener.py updates

  • Added helper _fire_dirigera_event(...) for unified event emission.
  • In on_message() deviceStateChanged path:
    • capture old isOn for light entity
    • apply state update
    • if isOn changed, fire turned_on / turned_off
    • also attempts cascade entity event where relevant
  • In _apply_scene_actions(...):
    • if scene patches light isOn, publish matching turned_on / turned_off event.

💡 What this solves

  • Enables direct light state automations:
    • “When [Dirigera light] turns on → do action”
    • “When [Dirigera light] turns off → do action”
  • Matches issue request behavior
  • Preserves existing set/controller-event handling in the integration.

🧪 Validation status

  • get_errors() shows no issues in modified files
  • Behavior is conceptually correct based on existing event flow (state and scene updates)

Checklist before submitting a pull request

  • Updated base lib and added the required version in the requirements.txt and manifest.json

Checklist for reviewer

  • Select "Squash and merge" to keep commit timeline clean

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant