Skip to content

feat(admin): mode-aware HA entity entry rework in the camera editor - #579

Merged
badbread merged 1 commit into
mainfrom
feat/ha-entity-entry-rework
Aug 8, 2026
Merged

feat(admin): mode-aware HA entity entry rework in the camera editor#579
badbread merged 1 commit into
mainfrom
feat/ha-entity-entry-rework

Conversation

@badbread

@badbread badbread commented Aug 8, 2026

Copy link
Copy Markdown
Owner

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-list PUT /cameras/:id/ha/links contract are unchanged. No migration, no server change.

What changed (all in services/api/src/admin.html)

Mode-aware role copy. HA_ROLE_OPTS becomes haRoleOpts(isMotionMode), plus a matching haRoleHelp(role, isMotionMode). The open camera's mode is derived once in loadCameraHaLinks from the effective policy (profileById(cam.policy_id) || cam.policy, the same source the storage tab/banner use) into HA_CAM_MOTION_MODE:

  • Motion-mode camera: Motion sensor (triggers recording + marks the timeline)
  • Continuous camera: 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 / Controls segment toggle (reuses .seg-toggle/.seg-btn) driven by haPickerSetRole, 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_LINKS so each row keeps its real index (no in-place sort, so open style/control panels keep their indices). The device_class box moves out of the main row into the Icon & style panel (it only sets binary_sensor glyphs); it still persists via the whole-list Save links. Empty state is now actionable copy.

Unsaved-changes indicator. HA_DIRTY is 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

  • Extracted the inline <script> block and ran node --check — passes.
  • cargo check -p crumb-api with the new admin.html embedded (include_str!) — builds clean.
  • Every new on*= handler resolves (haOpenPicker, haPickerSetRole, haRoleOpts/haRoleHelp, haMarkDirty, haEnsureDomain, existing setters).
  • Leak scan of the commit patch: clean (no RFC1918 IPs / internal hostnames).

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.

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>
@badbread
badbread merged commit 50ae8e8 into main Aug 8, 2026
8 checks passed
@badbread
badbread deleted the feat/ha-entity-entry-rework branch August 8, 2026 17:57
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.

HA entity entry in the camera editor is unclear and the motion role copy is wrong for 24/7 cameras

1 participant