Skip to content

Add webhook-based event support for lock/unlock events#47

Open
jcoetsie wants to merge 1 commit into
lwestenberg:masterfrom
jcoetsie:feature/webhook-events
Open

Add webhook-based event support for lock/unlock events#47
jcoetsie wants to merge 1 commit into
lwestenberg:masterfrom
jcoetsie:feature/webhook-events

Conversation

@jcoetsie

@jcoetsie jcoetsie commented Apr 8, 2026

Copy link
Copy Markdown

Summary

  • Register a Home Assistant webhook endpoint during integration setup and create a corresponding Bold API webhook pointing to it, enabling real-time push notifications for lock events
  • Handle incoming webhook POSTs: parse payload, fire bold_lock_event HA events (for automations), and update lock entity state and changed_by attribute with user info
  • Clean up the Bold webhook on integration unload
  • Add changed_by property to BoldLockEntity so users can see who last locked/unlocked

Context

Closes #9 - This adds webhook-based event support so the integration can receive real-time lock/unlock notifications with user information, rather than relying solely on polling.

Companion PR: The library-side changes (webhook API methods) are in a separate PR on lwestenberg/bold_smart_lock.

Implementation details

  • Uses homeassistant.components.webhook for the HA-side webhook registration
  • Uses get_url(hass, prefer_external=True, allow_cloud=True) to determine the webhook URL
  • Gets organizationId from the v2 devices API (owner.organizationId)
  • Subscribes to all webhook topics: DeviceActivationEvents, DeviceDeactivationEvents, DeviceStatusEvents, DeviceTamperEvents
  • The Bold webhook payload schema is undocumented, so the handler extracts fields generically (trying multiple key names) and logs the full payload at debug level for future refinement
  • Updates manifest.json: adds webhook dependency, changes iot_class to cloud_push
  • Stores device_id -> entity mapping in hass.data so the webhook handler can route events to the correct lock entity

Files changed

  • __init__.py - Webhook setup/teardown/handler
  • lock.py - changed_by property, handle_webhook_event method, entity registration for webhook routing
  • const.py - New constants for webhook support
  • manifest.json - Add webhook dependency, update iot_class

Test plan

  • Verify integration sets up without errors when external URL is available
  • Verify integration sets up gracefully (with warning) when external URL is not available
  • Verify Bold webhook is created on setup with correct parameters
  • Verify Bold webhook is deleted on unload
  • Verify incoming webhook POST fires bold_lock_event HA event
  • Verify lock entity state updates on activation/deactivation webhook events
  • Verify changed_by attribute updates with user name from webhook payload
  • Verify invalid JSON payloads return 400 status
  • Verify existing lock/unlock functionality is unaffected

🤖 Generated with Claude Code

Register a Home Assistant webhook endpoint and create a corresponding
Bold API webhook during integration setup. Incoming events fire
bold_lock_event HA events and update lock entity state and changed_by
attribute with user info. Webhook is cleaned up on integration unload.

The webhook payload schema is undocumented, so the handler extracts
fields generically and logs the full payload at debug level.

Closes lwestenberg#9

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Receive lock/unlock events from Bold and update the state in Home Assistant

1 participant