Skip to content

Contributing Cards

chochb edited this page Dec 1, 2026 · 2 revisions

Contributing cards

HA Panel renders every card natively in Kotlin, so each Lovelace card type (built-in or custom) needs its own implementation in the app (chochb/HA-Panel). This page describes the three ways to get a card supported, and contains a ready-to-use prompt for AI coding assistants.

Quickest: a card package (no app update)

Since app 2.27 many cards can be added as a card package – a JSON file that maps the unknown card type to cards the app already draws (tile, entities, grid, button, markdown …). Put it into /config/www/hapanel/cards/ (with an index.json) or contribute it to the catalog by pull request. Format, catalog and AI prompt: Card packages · PROMPT.md.

Choose a package when the card can be rebuilt from existing cards; choose native support (below) when it needs its own drawing or behaviour.

Three ways

Way You do Then
1. Request Open a card request with the card YAML, a screenshot from Home Assistant and a link to the card's source. A maintainer may label it ai-build; a GitHub Action then lets Claude implement it and opens a pull request.
2. Build with your AI Copy the prompt below into Claude Code, Codex, Cursor … in a fork of chochb/HA-Panel. Open a pull request (path below).
3. Build by hand Follow the checklist. Open a pull request.

Pull request path

  1. Fork chochb/HA-Panel, branch card/<card-type> from main.
  2. Implement the card (prompt or checklist below).
  3. ./gradlew testDebugUnitTest assembleDebug must pass (CI runs the same on every PR).
  4. Open the PR against main using the PR template: card type, card version you rebuilt, screenshots HA vs. HA Panel side by side, tested display model(s) if you have one.
  5. A maintainer reviews, merges and releases. Contributors do not bump versionName / versionCode.

Checklist for a card pull request

  • New file app/src/main/java/io/github/chochb/hapanel/karten/<Name>Card.kt (custom cards from HACS: karten/hacs/), package io.github.chochb.hapanel.
  • object <Name>Card : CardType with
    • types – the Lovelace type(s), e.g. setOf("custom:my-card")
    • specs – JSON per type: keys (all options the card understands), optional values (allowed values), superfluous (options without effect). The app reports these to the integration, which checks dashboards against them – an option missing in keys shows up as a repair.
    • defaultSize / minSize like the card's getGridOptions() in HA (sections view, 12 columns).
    • create(card, p) – returns the native View, or null if the config cannot be rendered.
  • Register the object in CardRegistry.ALL (raster/CardRegistry.kt).
  • Reuse helpers instead of new code: theme colours/sizes from theme/, entity state and actions from verbindung/ and ui/, more-info dialogs from moreinfo/, tile features from features/.
  • Sizes in CSS px = dp, measured on the original card in HA. Document the measurements and the source version in the KDoc of the object (see karten/hacs/VacuumCard.kt as an example).
  • Texts: use the card's own translations (asset JSON) or HA's; no hard-coded language.
  • Entry at the top of changes.json (kind: "card", type, text; use the current versionName, the maintainer adjusts it).
  • Unit tests in app/src/test/… for non-trivial logic (templates, parsing, maths). JVM tests, org.json available.
  • Files under ~800 lines; split into <Name>Card.kt + <Name>Views.kt if needed.
  • No new dependencies without discussing them in the issue first (APK size matters on the X2).

Prompt for AI assistants

Copy everything in the block (also in docs/ai-card-prompt.md) into your assistant, replace the two placeholders, and run it in a clone of your fork of chochb/HA-Panel.

You are adding native support for a Home Assistant Lovelace card to HA Panel, an Android app (Kotlin, no WebView,
no Compose; classic Android Views) that renders Lovelace dashboards natively on Shelly Wall Displays
(X2: Android 8.1, 32 bit; X2i/XL: Android 11). Repository: this working copy of github.com/chochb/HA-Panel.

Card to add: <CARD TYPE, e.g. custom:my-card>
Reference: <URL of the card's source code and version, plus example YAML>

Goal: the card must look and behave like the original in the HA frontend (same layout, sizes, colours from the
active HA theme, tap/hold/double-tap actions, more-info), for every option the original supports.

Rules
1. Read first: raster/CardRegistry.kt (CardType interface), karten/hacs/VacuumCard.kt and one similar existing
   card, app/Capabilities.kt, changes.json (top entries). Follow their structure and naming. Code comments may be
   German like the rest of the code base.
2. Study the original card's source (render code, config/defaults, styles, getGridOptions, translations). Rebuild
   it; do not invent options. Sizes: CSS px map 1:1 to dp.
3. Create app/src/main/java/io/github/chochb/hapanel/karten/hacs/<Name>Card.kt (built-in HA cards: karten/)
   with `object <Name>Card : CardType`: `types`, `specs` (JSON with "keys" = every config option of the
   original, "values" for enums, "superfluous" for options without effect), `defaultSize`/`minSize` as in
   getGridOptions, `create()` returning a View or null for an unusable config.
   KDoc on the object: card name, source repo + version you rebuilt, measured sizes.
4. Register it in CardRegistry.ALL. Never register a type twice.
5. Reuse existing helpers (theme/, ui/, verbindung/, moreinfo/, features/) for theme values, entity state,
   formatting, icons, actions and dialogs. Search before writing new helpers.
6. Translations: ship the card's own strings as an asset JSON if it has them; otherwise use HA translations
   already available in the app. No hard-coded user-facing language.
7. No new Gradle dependencies. Keep each file under ~800 lines.
8. Add unit tests in app/src/test/java/io/github/chochb/hapanel/ for parsing, templates or maths you added.
9. Add a new entry at the TOP of changes.json:
   {"version": "<current versionName>", "date": "<today>", "kind": "card", "type": "<card type>", "text": "<one sentence>"}
   Do not change versionName/versionCode in app/build.gradle.kts.
10. Run `./gradlew testDebugUnitTest assembleDebug` and fix everything until it passes.
11. Commit on branch card/<card-type-without-custom:> with message "Card: <card type>" and open a pull request
    against chochb/HA-Panel main using .github/PULL_REQUEST_TEMPLATE.md. List any options you could not
    rebuild and why. If you cannot open the PR yourself, print the PR title and body.

Integration side

Usually nothing is needed: the app reports its cards and options, and the integration's dashboard check uses that. Only new style rules (card_mod, Bubble styles) touch style-standard.json in the app or analyzer.py / stylecheck.py in HA-Panel-Integration.

Clone this wiki locally