Skip to content

fix(areas): auto-hide section when no areas are visible + audit test#281

Open
TheDave94 wants to merge 5 commits into
TheRealSimon42:mainfrom
TheDave94:chore/auto-hide-audit
Open

fix(areas): auto-hide section when no areas are visible + audit test#281
TheDave94 wants to merge 5 commits into
TheRealSimon42:mainfrom
TheDave94:chore/auto-hide-audit

Conversation

@TheDave94
Copy link
Copy Markdown

Summary

The project's promise is "if there's nothing to show, the section disappears". An audit of every section builder turned up one real bug:

`createAreasSection` always returned a section even with zero visible areas — a "lonely title" in the UI (heading card with no area tiles below it). This happens in installs where the user has hidden all their areas via `areas_display.hidden` and is using `custom_cards` exclusively.

All other section builders (`createWeatherSection`, `createEnergySection`, `createCustomCardsSection`) already auto-hide correctly via `return null`. `createAreasSection` now matches.

Behavior change

  • Before: `createAreasSection([], …)` → `{ type: 'grid', cards: [{ type: 'heading', heading: 'Areas' }] }`
  • After: `createAreasSection([], …)` → `null`

The caller in `OverviewViewStrategy` already handles `null` from the section-map lookup by skipping to the next section, so the return-type widening from `… | … []` to `… | … [] | null` is a no-op for the production path; the only visible change is the eliminated lonely-heading section.

Audit test

Also adds `tests/sections/AutoHideAudit.test.ts`: one test per builder pinning the null-on-empty contract. Locks this regression class shut so future builders can't reintroduce the same bug without a deliberate test update.

Depends on

Test plan

  • `npm test` → 32 passing
  • Dashboard with all areas hidden → "Areas" section no longer appears as a lonely heading

AI-drafted under human supervision by @TheDave94. Tested live on Home Assistant — fully when the relevant hardware is available, otherwise only along the code paths that don't require an actual sensor of that type.

AutoCoder and others added 5 commits May 18, 2026 11:28
…tions

Sets up a minimal vitest harness so future contributors can extend
test coverage incrementally:

- vitest.config.ts with node env, v8 coverage, src/** include
- npm scripts: `test`, `test:watch`, `test:coverage`
- vitest + @vitest/coverage-v8 as devDependencies
- tests/sections/WeatherEnergySection.test.ts — 7 pure-function tests
  covering createWeatherSection / createEnergySection contracts
  (null cases, happy paths, link_dashboard parameter)
- validate.yml: new `tests` job runs `npm test` on every PR
- .gitignore: coverage/ output directory

No production code touched. Existing build (`npm run build`) unchanged.
Mirrors the SHA-pinning approach used in chore/pin-action-shas. Pre-
pins setup-node introduced by this PR so it's born hardened rather
than backfilled later.

- actions/checkout@v4 → 34e114876b0b11c390a56381ad16ebd13914f8d5
- hacs/action@main → dcb30e72781db3f207d5236b861172774ab0b485
- actions/setup-node@v4 → 49933ea5288caeca8642d1e84afbd3f7d6820020
GitHub deprecated Node 20 actions; v5 releases use Node 24.

- actions/checkout: v4 → v5 (93cb6efe18208431cddfb8368fd83d5badbf9bfd)
- actions/setup-node: v4 → v5 (a0853c24544627f65ddf259abe73b1d18a591444)
…utils

Builds on the vitest scaffold from TheRealSimon42#226. Two new test files plus a hass
fixture helper. Coverage:

- tests/fixtures/hass.ts — minimal hass-like object builder so tests don't
  re-invent the shape (entities + devices + areas + states + locale).
- tests/utils/entity-filter.test.ts — collectPersons / findWeatherEntity /
  findDummySensor covering happy path, empty registry, fallback chains.
- tests/sections/OverviewSection.test.ts — createCustomCardsSection edge
  cases (null on empty, default+custom heading, sub-headings from titles)
  plus snapshots of createOverviewSection for default config and
  show_clock_card=false.

Also adds Registry.resetForTesting() so tests can clear singleton state
between cases without the heavier vi.resetModules(). Production code never
calls it.

These tests are intentionally aimed at section builders and pure utils
(no DOM, no HTMLElement, no Lit) so they run in Node without an
environment shim. Strategy classes are not tested directly — they are
thin composers over the same builders.

Net: 16 → 24 passing tests, 2 snapshots locking in current section
output. Future refactors that change the rendered shape will surface
as snapshot diffs.
Audit found one real bug: createAreasSection always returned a section
even with zero visible areas — a "lonely title" in the UI (heading card
with nothing below it). All other section builders (weather, energy,
custom_cards, plus the deferred plants/agenda/todos/etc. from TheRealSimon42#270)
already auto-hide correctly via `return null`. Fixed createAreasSection
to match.

The OverviewViewStrategy caller already handles `null` from the
section-map lookup by skipping to the next section, so the return-type
widening from `… | … []` to `… | … [] | null` is a no-op for the
production path; the only behavior change is the eliminated empty-section
emission.

Also adds tests/sections/AutoHideAudit.test.ts which pins every existing
builder to the null-on-empty contract — locks this regression class
shut so future builders can't reintroduce the same bug without a
deliberate test update.

Net: 24 → 32 tests, full coverage of the auto-hide contract surface.
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 79 complexity · 10 duplication

Metric Results
Complexity 79
Duplication 10

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

TheDave94 pushed a commit to TheDave94/oriel-dashboard that referenced this pull request May 20, 2026
Brings into main the remaining open PRs that weren't part of the prior
consolidation (bb43b04):

Improvement PRs (8 — real content):
- TheRealSimon42#277 chore(ci): translation lint guard
- TheRealSimon42#278 test: section-builder + entity-filter unit tests + snapshots
- TheRealSimon42#279 feat(rooms): auto-detect humidifier/valve/water_heater
- TheRealSimon42#280 feat(editor): derive target_section dropdown from section meta
- TheRealSimon42#281 fix(areas): auto-hide section + audit test
- TheRealSimon42#282 feat(editor): wire show_window_contacts_in_rooms + show_door_contacts_in_rooms
- TheRealSimon42#283 feat: custom_sections — user-declared sections without forking
- TheRealSimon42#284 chore(ci): release-please + release-build + ESLint enforcement

Grouped PRs (7 — content already in main via bb43b04 consolidation;
recorded with `-s ours` so the merges land in history without
duplicate/regressive edits):
- TheRealSimon42#270 grouped/optional-overview-sections
- TheRealSimon42#271 grouped/live-overview-badges
- TheRealSimon42#272 grouped/battery-view-improvements
- TheRealSimon42#273 grouped/room-view-features
- TheRealSimon42#274 grouped/section-meta-security
- TheRealSimon42#275 grouped/covers-weather
- TheRealSimon42#276 grouped/persons-overview-tweaks

CI fixes uncovered during merge:
- Bump Node 20 → 22 in validate.yml + release-build.yml (ESLint 10 requires Node 22+)
- Load eslint-plugin-security (rules off) so source-level Codacy
  disable directives resolve cleanly
- Drop unused PropertyValues import in StrategyEditor.ts

Version 1.3.4-thedave-r2 → 1.4.0-thedave (minor bump: feat: custom_sections,
auto-detect humidifier/valve, editor coverage, release automation).

Dist rebuilt + tests + ESLint pass (0 errors, 0 warnings).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TheDave94 TheDave94 closed this May 20, 2026
@TheDave94 TheDave94 deleted the chore/auto-hide-audit branch May 20, 2026 22:44
@TheDave94 TheDave94 restored the chore/auto-hide-audit branch May 21, 2026 08:56
@TheDave94 TheDave94 reopened this May 21, 2026
@TheDave94
Copy link
Copy Markdown
Author

TheDave94 commented May 21, 2026

My main focus has shifted to a downstream project (Oriel Dashboard) — built on what simon42 established, taken in its own direction — but the work in this PR was always meant for simon42 and I'm happy to keep iterating on it here. Address review feedback, split bundled changes into smaller pieces, whatever helps the review. Just ping me.

TheDave94 pushed a commit to TheDave94/oriel-dashboard that referenced this pull request May 21, 2026
Brings into main the remaining open PRs that weren't part of the prior
consolidation (ee9c67c):

Improvement PRs (8 — real content):
- TheRealSimon42#277 chore(ci): translation lint guard
- TheRealSimon42#278 test: section-builder + entity-filter unit tests + snapshots
- TheRealSimon42#279 feat(rooms): auto-detect humidifier/valve/water_heater
- TheRealSimon42#280 feat(editor): derive target_section dropdown from section meta
- TheRealSimon42#281 fix(areas): auto-hide section + audit test
- TheRealSimon42#282 feat(editor): wire show_window_contacts_in_rooms + show_door_contacts_in_rooms
- TheRealSimon42#283 feat: custom_sections — user-declared sections without forking
- TheRealSimon42#284 chore(ci): release-please + release-build + ESLint enforcement

Grouped PRs (7 — content already in main via ee9c67c consolidation;
recorded with `-s ours` so the merges land in history without
duplicate/regressive edits):
- TheRealSimon42#270 grouped/optional-overview-sections
- TheRealSimon42#271 grouped/live-overview-badges
- TheRealSimon42#272 grouped/battery-view-improvements
- TheRealSimon42#273 grouped/room-view-features
- TheRealSimon42#274 grouped/section-meta-security
- TheRealSimon42#275 grouped/covers-weather
- TheRealSimon42#276 grouped/persons-overview-tweaks

CI fixes uncovered during merge:
- Bump Node 20 → 22 in validate.yml + release-build.yml (ESLint 10 requires Node 22+)
- Load eslint-plugin-security (rules off) so source-level Codacy
  disable directives resolve cleanly
- Drop unused PropertyValues import in StrategyEditor.ts

Version 1.3.4-thedave-r2 → 1.4.0-thedave (minor bump: feat: custom_sections,
auto-detect humidifier/valve, editor coverage, release automation).

Dist rebuilt + tests + ESLint pass (0 errors, 0 warnings).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TheDave94 TheDave94 closed this May 22, 2026
@TheDave94 TheDave94 deleted the chore/auto-hide-audit branch May 22, 2026 05:55
@TheDave94 TheDave94 restored the chore/auto-hide-audit branch May 23, 2026 20:45
@TheDave94 TheDave94 reopened this May 23, 2026
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.

1 participant