feat(admin): mode-aware HA entity entry rework in the camera editor - #579
Merged
Conversation
Rework the per-camera Home Assistant link editor so adding an entity is obvious and the role copy is honest regardless of record mode. Presentation and copy only: roles (motion|sensor|actuator), device_class, and the whole-list PUT /cameras/:id/ha/links contract are unchanged. - Mode-aware role copy: the motion role no longer says "triggers recording" on a Continuous (24/7) camera, where a linked binary sensor feeds the additive motion source (timeline + notifications) rather than starting a recording. Derived from the camera's effective policy mode. - One primary "+ Add Home Assistant entity" action replaces the three ghost buttons; the picker gains a Motion/Reading/Control segment toggle with a mode-aware helper line. - Rows are grouped under role headers (Motion & contact / Sensor readings / Controls), keeping each link's real HA_LINKS index so all handlers stay wired. - The device_class box moves into the Icon & style panel (it only sets binary_sensor glyphs); still saved via Save links. - Save links gains an "Unsaved changes" indicator, set on any whole-list mutation and cleared on a successful save. Updates the COMPONENT-MAP HA row and adds a DECISIONS entry for the mode-aware labeling so it is not "unified" back to a static label later. Signed-off-by: badbread <badbread@users.noreply.github.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.
Fixes #578.
Reworks the per-camera Home Assistant link editor so adding an entity is obvious and the role copy is honest regardless of record mode. Presentation, copy, and flow only — roles (
motion|sensor|actuator),device_class, and the whole-listPUT /cameras/:id/ha/linkscontract are unchanged. No migration, no server change.What changed (all in
services/api/src/admin.html)Mode-aware role copy.
HA_ROLE_OPTSbecomeshaRoleOpts(isMotionMode), plus a matchinghaRoleHelp(role, isMotionMode). The open camera's mode is derived once inloadCameraHaLinksfrom the effective policy (profileById(cam.policy_id) || cam.policy, the same source the storage tab/banner use) intoHA_CAM_MOTION_MODE:Motion sensor (triggers recording + marks the timeline)Motion sensor (marks the timeline, can notify)Sensor reading (shows on the video, status only)/Control (operate from the video: lights, locks, covers)are mode-independent.One obvious add flow. The three ghost buttons are replaced by a single primary + Add Home Assistant entity. The picker gains a
Motion & contact/Readings/Controlssegment toggle (reuses.seg-toggle/.seg-btn) driven byhaPickerSetRole, with a mode-aware helper line for the selected segment. Switching a segment lazily fetches that domain's entities (haEnsureDomain).Row grouping + declutter. Rows render under three role headers, iterating
HA_LINKSso each row keeps its real index (no in-place sort, so open style/control panels keep their indices). Thedevice_classbox moves out of the main row into the Icon & style panel (it only setsbinary_sensorglyphs); it still persists via the whole-list Save links. Empty state is now actionable copy.Unsaved-changes indicator.
HA_DIRTYis set on any whole-list mutation (add, remove, role/label/class edit, control require-confirm / allowed-actions) and cleared on a successful save; the Save links button gains an "Unsaved changes" badge, updated in place so text inputs keep focus.Not built (flagged)
No schema gap blocks this. A per-link "notify" toggle would be genuinely new data (schema) and is intentionally left out of scope.
Verification
<script>block and rannode --check— passes.cargo check -p crumb-apiwith the newadmin.htmlembedded (include_str!) — builds clean.on*=handler resolves (haOpenPicker,haPickerSetRole,haRoleOpts/haRoleHelp,haMarkDirty,haEnsureDomain, existing setters).Docs: updated the COMPONENT-MAP Home Assistant row and added a DECISIONS entry for the mode-aware labeling so it is not later "unified" back to a static label.