Skip to content

feat(export): write exported card YAML back to an existing Lovelace card - #15

Draft
wimpie70 wants to merge 10 commits into
tinkersoder:mainfrom
wimpie70:feat/export-update-ha-card
Draft

wimpie70 wants to merge 10 commits into
tinkersoder:mainfrom
wimpie70:feat/export-update-ha-card

Conversation

@wimpie70

@wimpie70 wimpie70 commented Nov 7, 2026

Copy link
Copy Markdown

Summary

Resolves #14 (stacked on #13, #11, #9, and #7).

  • Extends FoundCard and scanDashboards() with urlPath, cardIndex, and dashboardMode.
  • Adds replaceCardAtIndex() (src/haimport/cards.ts) and updateDashboardCard() (src/haimport/scan.ts) to replace a discovered ha-floorplan or picture-elements card in place and save via lovelace/config/save.
  • Adds Update card in HA… in ExportModal: scans Lovelace dashboards, lists matching cards (disabling read-only YAML-mode dashboards), confirms with the user, and overwrites the selected card in place.

Test plan

  • tsc --noEmit, vitest run (36 tests including replaceCardAtIndex coverage)
  • npm run build & npm run build:hacs

Willem added 10 commits November 4, 2026 13:02
window.floorplanStudio.registerPlugin({id, apiVersion, provides}) lets
third-party integrations contribute device sources, toolbar actions and
style defaults without integration-specific code in this repo:

- deviceSources: live fetch(ws)/offline parse providers shown in the
  generic Devices modal (was the RAMSES modal). The bundled ramses
  source registers through the same public API as the reference impl.
- actions: toolbar items emitting floorplan-studio:action CustomEvents
  ({pluginId, actionId, projectId, floorId, selection}) — documented,
  bubbles+composed so they escape the card shadow root.
- iconMap / markerDefaults / stateRulePresets (role-bound): merged as
  plugin < user opts < device hints; css injected once, re-attached to
  the card's shadow root in HACS mode.
- apiVersion + ignored-unknown-provides-keys for independent versioning.

importProject() merges a project fragment in one undo step and
projects.* (active/list/get/save/remove/open) replace the direct
IndexedDB pokes integrations needed before. callWS() exposes the active
HA link; documented events: action / project-imported / plugins-changed.

Also: registry fallback now reads parent_device_id alongside via_device
(HA 2026.9 child devices), and devices carry suggested=false for
gateways instead of a hardcoded group check in the planner.
The editor ships zero integration-specific code — the plugin API is
the contract, and integrations own their mapping in their own repo.
Ramses Extras ships its provider as a Lovelace resource from
floorplan_helper (wimpie70/ramses_extras), registered under the same
plugin id so it supersedes nothing and is versioned with the
integration it talks to.

src/examples/mqtt.ts is the new bundled reference implementation:
entity-registry platform filter → device grouping → neutral
ImportDevice shape. It is deliberately generic — change PLATFORM and
it is a zwave/zigbee/ble source.

haimport's WsCall/liveWsCaller imports move to ../ha/wsCaller where
the helper actually lives (fetch.ts only re-exported it).
Flat per-action toolbar buttons do not scale once several
integrations register — one "Integrations" dropdown now lists every
toolbar-located plugin action grouped by plugin id. The location
contract stays: 'toolbar' renders here, 'marker-menu'/'room-menu'
remain reserved for contextual menus.
The example source now reads the device + entity registries — every
HA instance has devices, so the reference implementation always has
something to show, even where mqtt/zwave/etc. aren't configured.
Devices are grouped by integration (entity platform), which doubles
as the foundation for a "coverage map" showing which integrations
have registered providers.
The device import moves from a modal wizard into the editor's
"things to place" palette, as a tab next to Entities and Layers:

- Devices tab: source picker + refresh (auto-fetches on open), a
  checklist with inline placement badges (room name / staged / on
  plan), select-by-group buttons, a collapsed Options details, and
  one "Place N markers" commit. Paste / file / project merge stays
  in the modal, reachable via "More…".
- "Import card" leaves the toolbar for the Projects modal as
  "New from HA card…" — it produces a project, so it belongs with
  project lifecycle next to New / Import JSON.
- New store field leftTab tracks the active palette section.

The Devices toolbar button remains as a shortcut that selects the
Devices tab.
Preview now behaves like an exported card: tap, hold (500ms) and
double (cancels the pending tap) fire the marker's actions — toggle,
more-info (hass-more-info event), call-service with YAML-parsed
serviceData, navigate (location-changed), url. Service calls resolve
to the hass object in card mode or HaClient standalone; with no HA
link they log instead of silently dropping.
…eometry

Adds `provides.roomSources` (`RoomSourceProvider`) to the plugin manifest API:
integrations return floor/room polygons only (`{ floors: [{ name, canvas, rooms }] }`),
while Floorplan Studio owns room merging (`planRoomSourceMerge` / `applyRoomSourceMerge`)
and runs its single client-side marker placement planner (`planDeviceImport`) over the
merged geometry.

In `DevicePanel`, when the active plugin offers a `roomSource`, an
"Also import rooms from source" checkbox previews device room-match badges
against the incoming rooms and commits both new rooms and markers in a
single undo step.
…mation

- `DeviceSourceProvider.coversIntegrations?: string[]` + `getCoveredIntegrations()`
  in the plugin registry map HA integration domains to registered rich
  device providers.
- `DevicePanel` includes a collapsible `Integrations (N)` coverage map
  listing every HA integration owning devices with its device count and a
  `plugin` (green) vs `registry` badge. Clicking a covered row switches to
  that plugin's source; clicking an uncovered row switches to the HA
  registry source and selects that integration's devices.
- Adds `spin` to `StateRule.animation`: `ruleSpinDuration()` scales the
  icon rotation period inversely with numeric entity state (e.g. fan speed
  percentage 0..100 -> 2.4s..0.55s) without rotating the marker's label.
Adds an "Update card in HA…" delivery path in `ExportModal`:
- Reuses `scanDashboards()` to list existing `ha-floorplan` and
  `picture-elements` cards across Lovelace dashboards, recording each
  card's dashboard `url_path`, 0-based discovery index, and `mode`.
- YAML-mode dashboards are shown as disabled (`[YAML mode — read-only]`);
  storage-mode dashboards can be overwritten in place after confirmation
  via `replaceCardAtIndex()` and `lovelace/config/save`.
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.

feat(export): Write exported card YAML back to an existing Lovelace card in Home Assistant

1 participant