Skip to content

v0.2.1 — in-panel YAML editing

Choose a tag to compare

@jpettitt jpettitt released this 22 May 04:15

Point release. Drop-in upgrade from v0.2.0 — no schema change, no migration. After updating, restart HA.

What's new

In-editor YAML view

Each rule now has a Show code editor / Show visual editor text toggle next to Cancel + Save in the rule editor — same pattern as HA's automation editor. The toggle round-trips: the form serializes to YAML on the way in, parses + re-hydrates back to the form on the way out. Save in code mode parses the YAML; the rule id is preserved so existing rules update in place rather than creating duplicates.

Use case: sharing a single rule. Edit the rule → Show code editor → Cmd-A, Cmd-C → paste into a gist.

Whole-config YAML view

A matching Show code editor toggle at the bottom of the panel itself. Entering code mode dumps every rule as a top-level rules: list, ready to paste into a gist. Save replaces the whole config atomically.

Use case: backing up the whole Smart Icons setup, importing a friend's setup, bulk-editing.

Atomic save

Whole-config saves go through a new smart_icons/replace_all WS command. The server validates every rule before touching storage — either the entire new set lands or nothing changes. No partial-update states on failure.

Clickable error highlighting

Every save failure renders as a clickable item under the textarea:

  • YAML syntax errors (line/col from the parser) — clicking jumps the textarea caret to the reported position.
  • Shape errors that name a rule (e.g. "Rule 2 is not a mapping") — clicking selects that rule's lines.
  • Server per-rule validation failures — each rule's error is its own clickable item.

The first error is auto-selected on display so you land directly on the problem. Every failure block leads with "Rules unchanged." so atomicity is explicit.

Discard-changes confirm

Toggling from code back to visual with unsaved YAML edits now opens a confirmation modal. A misclick can't silently drop your edits.

Configuration example

The format the whole-config view produces — paste this into a fresh editor's code view to add a temperature color scale:

```yaml
targets:

  • sensor.outdoor_temperature
    mode: thresholds
    thresholds:
  • lt: 32
    color: "#0000FF"
    icon: mdi:snowflake
  • lt: 75
    color: "#33cc66"
  • lt: 90
    color: "#FFA500"
  • color: "#FF0000"
    icon: mdi:fire
    ```

Internals

  • New `BulkReplaceError` exception + `RuleStore.async_replace_all` method. Admin-gated `smart_icons/replace_all` WS handler emits a custom error frame carrying `rule_errors: [{ index, message }]` for per-rule feedback.
  • Frontend panel bundle gains `js-yaml`. Panel bundle: ~60 KB → ~115 KB. Painter bundle untouched at 3.3 KB (still WS-free, still works for non-admin users).
  • 96 pytest + 67 Web Test Runner tests green; typecheck clean.

Design

Full design doc, including the as-designed vs as-shipped reconciliation: `docs/yaml-editing.md`.

Upgrade

Drop-in from v0.2.0. Rules in storage are unchanged; the new YAML view is purely a UI surface over the existing data.

Full Changelog: v0.2.0...v0.2.1