Skip to content

HA publish: only active plants eligible, mark inactive ones, add active/inactive filter #625

Description

@nolte

Summary

The HA-Veröffentlichung settings tab (/settings#ha-publishPFLANZEN) lists every plant instance — including plants that are no longer active (harvested, senesced, died, or otherwise removed). A user shouldn't be pushing dead/removed plants to Home Assistant, and the flat list gives no way to tell active from inactive. Requested improvements:

  1. Treat only active plants as eligible for HA publishing (default view = active only).
  2. Mark inactive plants clearly when they are shown.
  3. Offer the user a filter to switch between active-only and all (incl. inactive).

Grounding

  • The selection list is built in src/frontend/src/pages/auth/HaPublishSettingsTab.tsx:47-48:
    const plants = await listPlantInstances(0, PAGE_LIMIT);
    return plants.map((p) => ({ key: p.key, label: getPlantLabel(p) }));   // status dropped
    It maps each plant to { key, label } only — the lifecycle status is discarded, and the only existing filter is a text search on the label (:147-150).
  • The status data is already served. PlantResponse exposes removed_on: date | None and termination_type: TerminationType | None (src/backend/app/api/v1/plant_instances/schemas.py:62-63). An active plant is one with removed_on == null and no termination_type; an inactive one has been removed/terminated.
  • So this is primarily a frontend change: thread the status fields into the row, filter/mark by them, and adjust the "N von M veröffentlicht" count accordingly.

Proposed change

Frontend (HaPublishSettingsTab.tsx):

  • Carry removed_on / termination_type (or a derived isActive boolean) onto the row model instead of dropping them at :48.
  • Default the plant list to active plants only.
  • Add a filter control (e.g. a segmented toggle or checkbox: "Nur aktive" / "Alle anzeigen", i18n DE/EN) that reveals inactive plants on demand.
  • When inactive plants are shown, mark them with a chip/badge (e.g. "Inaktiv" / "Entfernt am …" using removed_on / the termination_type label) and visually de-emphasize the row.
  • Make the "N von M veröffentlicht" counter and the bulk select-all operate over the currently visible (filtered) set, consistent with the existing search-filter behaviour.
  • Mobile-first, i18n-complete.

Optional backend hardening (separate consideration): when a currently-published plant becomes inactive, the HA publish sync could stop exporting it (or retire its HA entity) so Home Assistant doesn't keep a stale sensor for a removed plant. Note this as a follow-up rather than bundling it in.

Acceptance criteria

  • The PFLANZEN list under HA-Veröffentlichung shows only active plants by default (verified on a tenant that has both active and removed plants).
  • A filter lets the user switch to showing all plants; inactive plants are visibly marked (badge + de-emphasis) and, where available, show why/when they became inactive.
  • The published-count and select-all reflect the currently visible/filtered set.
  • Selecting/publishing still works for active plants; the toggle state persists as before.
  • eslint / tsc / vitest pass; tests cover the active-default, the filter toggle, and the inactive marking.

Notes

  • No new backend endpoint required for the core request — removed_on / termination_type are already in PlantResponse.
  • Aligns with the project's usability direction (don't surface irrelevant/dead entities; give the user a clear filter).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew functionality.featConventional Commits type `feat` — new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions