Skip to content

fix(websocket): report device triggers that fail to attach - #435

Open
Swamp-Ig wants to merge 3 commits into
zachowj:mainfrom
Swamp-Ig:fix-device-trigger-attach-failure
Open

Swamp-Ig wants to merge 3 commits into
zachowj:mainfrom
Swamp-Ig:fix-device-trigger-attach-failure

Conversation

@Swamp-Ig

Copy link
Copy Markdown
Contributor

Found while working on the discovery PRs (#427–#429).

nodered/device/trigger replied success even when Home Assistant couldn't attach the trigger. async_initialize_triggers doesn't raise when attaching fails: it logs the error and returns None. The handler then registered a subscription that would never fire, and the device node showed "registered". One way this happens is when the device's config entry has failed to load. Validation skips the checks that need the integration, so the config passes, and attaching then fails.

Contrib already handles an error reply here: the node shows error_registering and logs the message with node.error. So no contrib change is needed.

Summary

e883abe Report device triggers that fail to attach

If async_initialize_triggers returns None, the handler now replies with a trigger_not_attached error and doesn't store a subscription. HA has already logged the reason, so the message points to the HA log. This is the actual bug fix.

42bdfe2 Tidy device trigger error handling

Removes the except vol.MultipleInvalid block, since it's a subclass of vol.Invalid and both blocks did the same thing. Invalid trigger configs are now logged as a single error line instead of a traceback. Runtime errors still log the traceback.

533ff9a Reply invalid_config for unknown device action domains

nodered/device/action looked up the device automation platform outside the try. So an unknown domain (raised as InvalidDeviceAutomationConfig) fell through to the generic home_assistant_error reply instead of invalid_config. The lookup has moved inside the try. Contrib doesn't check the code, so this only changes the reply's error code.

Test plan

  • Trigger that fails to attach: replies trigger_not_attached and stores no subscription (fails before this PR)
  • Unknown device action domain: replies invalid_config (fails before this PR)
  • Existing device trigger tests still pass, including vol.MultipleInvalid replying invalid_trigger
  • pre-commit and the test suite locally, 181 passed
  • CI green

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