Skip to content

feat: add HA Event entity for vehicle messages#434

Merged
nanomad merged 5 commits intoSAIC-iSmart-API:developfrom
nanomad:feat/vehicle-message-event
Mar 14, 2026
Merged

feat: add HA Event entity for vehicle messages#434
nanomad merged 5 commits intoSAIC-iSmart-API:developfrom
nanomad:feat/vehicle-message-event

Conversation

@nanomad
Copy link
Contributor

@nanomad nanomad commented Mar 14, 2026

Summary

  • Adds a Home Assistant MQTT Event entity (event.vehicle_message) that fires when a new message arrives from the car
  • Event payload includes title, content, message_type, sender, and vin for use in HA automations
  • Deduplication is handled by the existing MessagePublisher timestamp guard — only genuinely new messages fire the event
  • Published alongside existing per-field info/lastMessage/* sensors

Test plan

  • 6 tests covering: new message fires event, duplicate/older messages don't, newer messages do, None fields become empty strings, payload structure
  • ruff check, poetry run mypy, pytest — all pass (161 tests)

🤖 Generated with Claude Code

nanomad and others added 5 commits March 14, 2026 10:00
Publishes a vehicle_message event to Home Assistant whenever a new
message arrives from the car (maintenance alerts, security
notifications, etc.). The event includes title, content, message_type,
sender, and vin attributes for use in automations.

Deduplication is handled by the existing MessagePublisher guard that
only processes messages with a newer timestamp than the last seen.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Document best-effort intent with comment
- Upgrade LOG.warning to LOG.exception with message ID and VIN context
- Add resilience test: event publish failure doesn't break processing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HA Event entities show "Unknown" when they receive a retained message
on connect because they cannot determine when the event occurred.

Add a retain parameter to publish_json (default True for backward
compat) and thread it through VehicleDataPublisher._publish. Both
command_error and vehicle_message events now publish with retain=False.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SAIC API returns message timestamps as naive datetimes, but
last_message_ts is initialized as UTC-aware. Comparing them raises
TypeError. Add _ensure_aware() to normalize naive datetimes to UTC
before comparison in both MessageHandler and MessagePublisher.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract ensure_datetime_aware to utils.py, remove duplicates
- Apply ensure_datetime_aware to max()/min() lambdas in message handler
- Thread retain parameter through _transform_and_publish for consistency
- Use LOG.exception consistently for event publish failures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nanomad nanomad merged commit 14a7ca8 into SAIC-iSmart-API:develop Mar 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet