Always emit triggering room context for HA scene/script activations#375
Always emit triggering room context for HA scene/script activations#375jamesmulcahy wants to merge 3 commits intoNSPManager:develfrom
Conversation
When activating a Home Assistant script, always include scene_name, scene_id, and (where available) triggering_room_id/name and scene_room_id/name in the nspanelmanager variables context. Previously room context was only sent for room-specific scenes. Global scenes now also receive the room of the panel that triggered them, allowing HA scripts to take room-specific actions while remaining globally defined. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Example contexts: Triggering a room scene, from a panel in a different room Triggering a room scene, from a panels own room scenes Triggering a global scene |
|
@tpanajott As I started to integrate the room name into my HA scripts, I realized that I needed the triggering room name -- not just the room the scene was associated with. This is especially important for global scenes, which weren't otherwise emitting any room context. This new approach covers all three scenarios, as outlined with the examples above. |
| return std::unexpected(EntityManager::EntityError::NOT_FOUND); | ||
| } | ||
|
|
||
| std::optional<int32_t> EntityManager::get_room_id_for_panel_id(uint32_t nspanel_id) { |
There was a problem hiding this comment.
Instead of using std::optional here a better use would be std::expected.
There was a problem hiding this comment.
TIL: std:expected -- that didn't exist last time I wrote C++ :)
I pushed a commit on top to move to std::expected -- PTAL!
Aligns with the existing pattern used by all other EntityManager lookups. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
script., always includescene_name,scene_id,triggering_room_id,triggering_room_name,scene_room_id, andscene_room_namein thenspanelmanagervariables contextImplementation
activate(std::optional<int32_t> triggering_room_id)to theScenebase class; all scene subclasses updated to matchEntityManagerresolves the triggering room from thenspanel_idin the command via a newget_room_id_for_panel_id()helperScene::toggle()(no-arg) is retained to satisfyMqttManagerEntity's pure virtual, but all real activations now go throughactivate()directlyTest plan
triggering_room_idmatches panel's roomtriggering_room_*andscene_room_*populatedtriggering_room_*reflects the triggering panel's room,scene_room_*reflects the scene's own roomscene.entity type (non-script) — unaffected, no context sent🤖 Generated with Claude Code