feat: add HA Event entity for command errors#432
Merged
nanomad merged 5 commits intoSAIC-iSmart-API:developfrom Mar 14, 2026
Merged
feat: add HA Event entity for command errors#432nanomad merged 5 commits intoSAIC-iSmart-API:developfrom
nanomad merged 5 commits intoSAIC-iSmart-API:developfrom
Conversation
Closes SAIC-iSmart-API#272. When a command to the vehicle fails, a JSON event is now published to the command/error topic so Home Assistant users can build automations around command failures. Changes: - Add _publish_event() to HA discovery base for MQTT Event entities - Register a "Command error" diagnostic event entity in discovery - Publish error events from all failure paths in VehicleCommandHandler - Wrap error event publishing in try-except to prevent masking original errors - Cover the "no handler found" path with error events too Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
56b3bf6 to
f41fa80
Compare
Replace repeated publish_str + LOG + publish_command_error calls across all except blocks with a single __report_command_failure method. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Log the original error before attempting any MQTT publish - Wrap both publish_str and publish_json in try-except - Make exc optional so "no handler found" uses LOG.error (no traceback) - Use safe "unexpected error" detail for the catch-all exception path Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover all error paths in VehicleCommandHandler: - Success path (no error event) - No handler found (error event without traceback) - MqttGatewayException, SaicApiException, unexpected Exception - SaicLogoutException: relogin success/failure, retry failure - Resilience: publish_str/publish_json failures don't propagate - Event payload structure and topic verification Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restructure tests to avoid accessing private name-mangled attributes and asserting on typed Publisher methods. Drive exceptions through saic_api mocks instead of patching internal command handlers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
event.command_error) that fires whenever a vehicle command failsevent_type,command(topic), anddetail(error message) so users can build HA automations around command failuresCloses #272
Test plan
eventtype with correctevent_typesconfigresulttopic behavior is unchangedruff check,mypy, andpytest— all pass🤖 Generated with Claude Code