feat: add native ntfy transport with full test suite#81
Open
lollox80 wants to merge 2 commits intorhizomatics:mainfrom
Open
feat: add native ntfy transport with full test suite#81lollox80 wants to merge 2 commits intorhizomatics:mainfrom
lollox80 wants to merge 2 commits intorhizomatics:mainfrom
Conversation
New NtfyTransport (206 lines) for push notifications via the official ntfy HA integration (2025.5+). Uses ntfy.publish action with device_id target. Features: priority mapping (5 levels, integer 1-5), ntfy_priority override with validation and clamping, action buttons (max 3, validated), camera snapshot with graceful fallback, delay parsing (10m/1h30m/HH:MM), sequence_id for update/cancel, email forwarding, click URL, icon, Markdown rendering, boolify() for YAML string safety. Test suite: 30+ tests covering _parse_delay(), deliver() happy path, all priority mappings, ntfy_priority override, all optional fields, action truncation, ntfy_* key isolation, camera snapshot flow, boolify correctness for YAML strings, error handling. Co-Authored-By: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
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.
PR: feat: add native ntfy transport
Branch:
feat/ntfy-transportTarget:
rhizomatics/supernotify:mainFile aggiunto:
custom_components/supernotify/transports/ntfy.pyMotivation
ntfy became an official Home Assistant integration in version 2025.5. It provides
a privacy-first, self-hostable push notification service with a rich action API:
priority levels, action buttons, scheduled delivery, image attachments, and
message update/cancellation via
sequence_id.The existing
generictransport can callntfy.publish, but it cannot:camera.snapshotserviceboolify()for YAML boolean stringsA native transport handles all of this cleanly and establishes the pattern
for similar services (Pushover, Gotify).
Changes
custom_components/supernotify/transports/ntfy.py(new file, ~210 lines)NtfyTransportclass withname = TRANSPORT_NTFYsupported_features:MESSAGE | TITLE | IMAGES | ACTIONSdefault_config: actionntfy.publish,TargetRequired.NEVERcritical→5,high→4,medium→3,low→2,minimum→1raw_data.pop()before service call_parse_delay(): converts"10m"/"1h30m"→"HH:MM"format required by HA_validate_actions(): drops malformed action buttons with a warning (max 3)camera.snapshotviahass_api, attaches via public URLraw_datakeys passed through to allow forward-compatible extensionscustom_components/supernotify/const.py(existing file)TRANSPORT_NTFY = "ntfy"constantTRANSPORT_NTFYtoTRANSPORT_VALUESlistcustom_components/supernotify/notify.py(existing file)NtfyTransportimportNtfyTransportin transport registryData keys
All keys are optional unless noted. Keys with prefix
ntfy_are extractedby the transport and never forwarded to
ntfy.publish.ntfy_device_idstrdevice_idof the ntfy topic configured in HAntfy_priorityint1–5ntfy_tagslist[str][]["warning", "house"]ntfy_clickstr(URL)ntfy_attach_imageboolfalsemedia.camera_entity_id)ntfy_filenamestrsnapshot.jpgntfy_iconstr(URL)ntfy_markdownboolfalsentfy_delaystr"10m","1h30m","HH:MM"ntfy_sequence_idstrntfy_emailstrntfy_actionslist[dict][]Testing
Tested on Home Assistant 2026.3.4 with the ntfy official integration connected
to a self-hosted ntfy instance (ntfy v2.x).
Functional tests performed:
criticaltriggers urgent priority (bypasses DND)minimumdelivers silently with no vibrationntfy_tags: emoji tags visible in notificationntfy_click: tap opens correct URLntfy_attach_image: true+camera.ezviz_ingresso→ snapshot attachedntfy_actionswith 3 buttons:view,http(webhook),http(snooze)ntfy_delay: "30m"— notification delivered after 30 minutesntfy_sequence_id— second call with same ID updates the notificationntfy_device_idmissing →return Falsewith warning in logntfy_actionswith malformed entry → entry skipped, valid ones delivered"true"/"false"forntfy_attach_image,ntfy_markdown—boolify()handles correctlyntfy_priority: 99out of range → fallback to automatic mapping, warning loggedExample configuration:
Example call:
Expected behavior:
criticalbypasses Do Not Disturb on mobileHow to get the device_id
Or: Settings → Devices & Services → ntfy → click the topic device.
Notes
TargetRequired.NEVER: the topic target is conveyed viantfy_device_idindata,not via HA's standard
targetfield. This avoids the transport being suppressedwhen no person target is present in the notification call.
camera.snapshotto/config/www/(accessible at/local/),then attaches via
hass_api.abs_url(). This works for both cloud and local ntfy._parse_delay()accepts both"10m"/"1h30m"shorthand and"HH:MM"/"HH:MM:SS".Unrecognized formats are passed through with a warning.