-
-
Notifications
You must be signed in to change notification settings - Fork 28
Modernization #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iantrich
wants to merge
17
commits into
master
Choose a base branch
from
modernization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Modernization #178
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1963d22
feat: complete Lit 3 migration cleanup, typing fixes, and shouldUpdat…
iantrich 7044fef
Add visual editor and devcontainer updates
iantrich 7865907
Fix duration handling; update tests, docs, license
iantrich cbc133f
Improve helpers loading, timers, and touch handling
iantrich aca2e06
Use showConfirmationDialog for confirmations
iantrich 39ea364
dev dashboard config for testing
iantrich dd2261b
Allow empty-map restrictions; fix touchend handling
iantrich 65e76c7
Refactor release workflow to use environment variable for versioning
iantrich 8a7f2b3
Update label for unlocked icon in ha-icon-picker to clarify default b…
iantrich 6583f01
Add unit tests for action-handler-directive functionality
iantrich 7d5ddc5
Update src/restriction-card.ts
iantrich cb8b96b
Update src/restriction-card.ts
iantrich 46f939d
Update localization guidelines and enhance example section formatting…
iantrich d535c7f
Merge branch 'modernization' of https://github.com/iantrich/restricti…
iantrich cd0ebbb
Remove outdated YAML resources section from README
iantrich 9790381
Refactor devcontainer setup: remove Dockerfile and update to use cust…
iantrich 8fcbe1f
Update devcontainer base image to use latest version
iantrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM thomasloven/hass-custom-devcontainer:latest | ||
|
|
||
| # Install Node.js 24 (must run as root) | ||
| USER root | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \ | ||
| && apt-get install -y --no-install-recommends nodejs \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Fix CRLF line endings in the container script (base image ships with Windows line endings) | ||
| RUN sed -i 's/\r//' /usr/bin/container | ||
|
|
||
| # Enable corepack (yarn) | ||
| RUN corepack enable | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Home Assistant Custom Card - Dev Container Setup | ||
|
|
||
| This directory contains the development container configuration for building and testing the restriction-card custom card for Home Assistant. | ||
|
|
||
| ## Setup Instructions | ||
|
|
||
| 1. **Install VS Code Remote Containers** | ||
| - [VS Code Extension: Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) | ||
|
|
||
| 2. **Open in Dev Container** | ||
| - Open the project folder in VS Code | ||
| - Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on Mac) | ||
| - Type "Remote-Containers: Reopen in Container" | ||
| - Wait for the container to build (first time takes ~2-3 minutes) | ||
|
|
||
| 3. **Build the Card** | ||
| ```bash | ||
| yarn build # Lint and build | ||
| yarn start # Start dev server with hot reload (port 5000) | ||
| yarn lint # Check code quality | ||
| yarn rollup # Production build | ||
| ``` | ||
|
|
||
| 4. **Access Services** | ||
| - **Dev Container**: Terminal in VS Code (automatic) | ||
| - **Home Assistant**: http://localhost:8123 (user: dev/pass: dev) | ||
| - **Rollup Dev Server**: http://localhost:5000 | ||
|
|
||
| 5. **Configure Home Assistant to Use Your Card** | ||
| - In Home Assistant, go to Settings > Dashboards | ||
| - Create a new Dashboard | ||
| - Add the card from the GUI | ||
|
|
||
| ## File Structure | ||
|
|
||
| ``` | ||
| .devcontainer/ | ||
| ├── Dockerfile # Docker image definition | ||
| ├── devcontainer.json # VS Code dev container config | ||
| ├── .gitignore # Ignore HA data | ||
| └── README.md # This file | ||
| ``` | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| ### Building the Card | ||
|
|
||
| ```bash | ||
| # One-time setup (automatic on container creation) | ||
| yarn install | ||
|
|
||
| # Development with hot reload | ||
| yarn start # Runs Rollup in watch mode on port 5000 | ||
|
|
||
| # Quality checks | ||
| yarn lint # ESLint check | ||
| yarn build # Full build pipeline (lint + rollup) | ||
|
|
||
| # Production build | ||
| yarn rollup # Create optimized dist files | ||
| ``` | ||
|
|
||
| ### File Locations | ||
|
|
||
| - **Source Code**: `src/` | ||
| - **Built Output**: `dist/` (inside container) | ||
| - **Configuration**: Root directory (`tsconfig.json`, `rollup.config.js`, etc.) | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Container Won't Start | ||
| ```bash | ||
| # Rebuild the container | ||
| ctrl+shift+p → "Remote: Rebuild Container" | ||
| ``` | ||
|
|
||
| ### Port Already in Use | ||
| ```bash | ||
| # Find what's using port 5000 or 8123 | ||
| lsof -i :5000 | ||
| lsof -i :8123 | ||
| ``` | ||
|
|
||
| ### Node Modules Issues | ||
| ```bash | ||
| # Clear and reinstall dependencies | ||
| rm -rf node_modules | ||
| yarn install | ||
| ``` | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - [Home Assistant Custom Card Development](https://developers.home-assistant.io/docs/frontend/custom-ui/custom-card/) | ||
| - [VS Code Dev Containers Docs](https://code.visualstudio.com/docs/remote/containers) | ||
| - [Lit Documentation](https://lit.dev/) | ||
| - [Material Design Web Components](https://github.com/material-components/material-web) | ||
|
|
||
| ## Environment Details | ||
|
|
||
| - **Node.js**: 24 | ||
| - **TypeScript**: 5.9.3 | ||
| - **Build Tool**: Rollup 4.20 | ||
| - **Linter**: ESLint 9 + TypeScript Support | ||
| - **Code Formatter**: Prettier 3.8 | ||
| - **Web Framework**: Lit 3.3 | ||
| - **Home Assistant Image**: Latest (optional) | ||
|
|
||
| ## Notes | ||
|
|
||
| - All Yarn commands run inside the container automatically | ||
| - VS Code extensions are configured for TypeScript and YAML development |
4 changes: 2 additions & 2 deletions
4
.devcontainer/configuration.yaml → .devcontainer/config/configuration.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| default_config: | ||
| lovelace: | ||
| mode: yaml | ||
| homeassistant_alerts: | ||
| enabled: false | ||
| demo: | ||
| frontend: | ||
| themes: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,70 @@ | ||
| // See https://aka.ms/vscode-remote/devcontainer.json for format details. | ||
| // For format details, see https://aka.ms/devcontainer.json | ||
| // Uses thomasloven/hass-custom-devcontainer for Home Assistant + Dev environment | ||
| { | ||
| "name": "Restriction Card Development", | ||
| "image": "ludeeus/container:monster", | ||
| "context": "..", | ||
| "appPort": ["5000:5000", "9123:8123"], | ||
| "postCreateCommand": "npm install", | ||
| "runArgs": [ | ||
| "-v", | ||
| "${env:HOME}${env:USERPROFILE}/.ssh:/tmp/.ssh" // This is added so you can push from inside the container | ||
| "name": "Home Assistant Custom Card Dev", | ||
|
|
||
| // Build from Dockerfile based on thomasloven/hass-custom-devcontainer (provides the `container` CLI) | ||
| "build": { | ||
| "dockerfile": "Dockerfile" | ||
| }, | ||
|
|
||
| // Set working directory | ||
| "workspaceFolder": "/workspaces/test", | ||
|
|
||
| // Mount project to workspace, dist to Lovelace plugins, and config directory for Home Assistant | ||
| "mounts": [ | ||
| "source=${localWorkspaceFolder},target=/workspaces/test,type=bind", | ||
| "source=${localWorkspaceFolder}/dist,target=/config/www/workspace,type=bind", | ||
| "source=${localWorkspaceFolder}/.devcontainer/config,target=/config,type=bind" | ||
| ], | ||
| "extensions": [ | ||
| "github.vscode-pull-request-github", | ||
| "eamodio.gitlens", | ||
| "dbaeumer.vscode-eslint", | ||
| "esbenp.prettier-vscode", | ||
| "bierner.lit-html", | ||
| "runem.lit-plugin", | ||
| "auchenberg.vscode-browser-preview", | ||
| "davidanson.vscode-markdownlint", | ||
| "redhat.vscode-yaml" | ||
| ], | ||
| "settings": { | ||
| "files.eol": "\n", | ||
| "editor.tabSize": 4, | ||
| "terminal.integrated.shell.linux": "/bin/bash", | ||
| "editor.formatOnPaste": false, | ||
| "editor.formatOnSave": true, | ||
| "editor.formatOnType": true, | ||
| "files.trimTrailingWhitespace": true | ||
|
|
||
| // Forward Home Assistant port | ||
| "forwardPorts": [8123], | ||
| "portsAttributes": { | ||
| "8123": { | ||
| "label": "Home Assistant", | ||
| "onAutoForward": "notify" | ||
| } | ||
| }, | ||
|
|
||
| // Container environment variables for Home Assistant setup | ||
| "containerEnv": { | ||
| "COREPACK_ENABLE_DOWNLOAD_PROMPT": "0", | ||
| "DEVCONTAINER": "1", | ||
| "HASS_USERNAME": "dev", | ||
| "HASS_PASSWORD": "dev", | ||
| "LOVELACE_REMOTE_FILES": "http://localhost:5000/restriction-card.js" | ||
| }, | ||
|
|
||
| // Setup Home Assistant and install dependencies | ||
| "postCreateCommand": "container setup && corepack enable && yarn install", | ||
| "postStartCommand": "container launch & yarn start & wait", | ||
|
iantrich marked this conversation as resolved.
|
||
|
|
||
| // VS Code extensions for development | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "dbaeumer.vscode-eslint", | ||
| "esbenp.prettier-vscode", | ||
| "ms-vscode.vscode-typescript-next", | ||
| "redhat.vscode-yaml" | ||
| ], | ||
| "settings": { | ||
| "typescript.enablePromptUseWorkspaceTsdk": true, | ||
| "[typescript]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode", | ||
| "editor.formatOnSave": true, | ||
| "editor.codeActionsOnSave": { | ||
| "source.fixAll.eslint": "explicit" | ||
| } | ||
| }, | ||
| "typescript.tsdk": "node_modules/typescript/lib", | ||
| "typescript.tsserver.pluginPaths": [ | ||
| "node_modules/typescript/lib" | ||
| ], | ||
| "files.eol": "\n", | ||
| "task.allowAutomaticTasks": "on" | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Enforce LF line endings for all text files | ||
| * text=auto eol=lf | ||
|
|
||
| # Explicitly declare common source file types | ||
| *.ts text eol=lf | ||
| *.js text eol=lf | ||
| *.json text eol=lf | ||
| *.md text eol=lf | ||
| *.yml text eol=lf | ||
| *.yaml text eol=lf | ||
| *.css text eol=lf | ||
| *.html text eol=lf | ||
|
|
||
| # Binary files — no line ending conversion | ||
| *.png binary | ||
| *.jpg binary | ||
| *.gif binary | ||
| *.ico binary | ||
| *.zip binary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # GitHub Copilot Instructions | ||
|
|
||
| You are assisting with development of this Home Assistant Lovelace custom card project. | ||
| The codebase is TypeScript + Lit and builds with Rollup. | ||
|
|
||
| Use these instructions as project-specific guardrails when generating, editing, or reviewing code. | ||
|
|
||
| ## Quick reference | ||
|
|
||
| ### Core commands | ||
|
|
||
| ```bash | ||
| yarn install | ||
| yarn start | ||
| yarn build | ||
| yarn lint | ||
| ``` | ||
|
|
||
| ### Primary files | ||
|
|
||
| - `src/restriction-card.ts` — main card implementation | ||
| - `src/editor.ts` — visual editor (`LovelaceCardEditor`) | ||
| - `src/types.ts` — card config and type definitions | ||
| - `src/action-handler-directive.ts` — tap/hold/double-tap directive | ||
| - `src/localize/languages/en.json` and `src/localize/languages/nb.json` — translation files | ||
| - `rollup.config.js` and `rollup.config.dev.js` — production and dev build config | ||
|
iantrich marked this conversation as resolved.
|
||
|
|
||
| ## Architecture and patterns | ||
|
|
||
| - The custom element is `custom:restriction-card`. | ||
| - Prefer Lit 3 patterns and idiomatic web component structure. | ||
| - Keep configuration shape centralized in `src/types.ts`. | ||
| - Keep editor schema and defaults aligned with runtime card behavior. | ||
| - Keep feature logic in small, readable helpers instead of long monolithic methods. | ||
|
|
||
| ## TypeScript standards | ||
|
|
||
| - Use strict, explicit typing; avoid `any` unless there is no practical alternative. | ||
| - Use `import type` for type-only imports where appropriate. | ||
| - Validate and narrow optional config fields before use. | ||
| - Keep public API names stable unless explicitly requested to change them. | ||
|
|
||
| ## Lit and component guidance | ||
|
|
||
| - Use `@property` for public reactive inputs and `@state` for internal state. | ||
| - Avoid direct DOM mutation when Lit reactivity can handle updates. | ||
| - Preserve existing card/editor lifecycle behavior. | ||
| - For card config, validate early in `setConfig` and throw actionable errors. | ||
| - Keep `getCardSize` deterministic and aligned with rendered density. | ||
|
|
||
| ## Home Assistant integration | ||
|
|
||
| - Use Home Assistant helpers and conventions from `custom-card-helpers`. | ||
| - Ensure tap, hold, and double-tap actions are wired through existing action patterns. | ||
| - Support unavailable/loading/error states gracefully. | ||
| - Keep Lovelace config compatibility in mind when changing schema or defaults. | ||
|
|
||
| ## Localization and copy | ||
|
|
||
| - Do not hardcode user-facing strings when a localize key should be used. | ||
| - Add new translation keys to both language files currently in the repo (`en.json`, `nb.json`). | ||
| - Keep copy concise, sentence case, and user-facing. | ||
|
iantrich marked this conversation as resolved.
|
||
| - Favor consistent terminology across card UI and editor labels. | ||
|
|
||
| ## Styling and UX | ||
|
|
||
| - Respect Home Assistant theme variables and CSS custom properties. | ||
| - Avoid hardcoded colors when theme tokens can be used. | ||
| - Keep spacing and typography consistent with existing card styles. | ||
| - Ensure layouts work in both compact and wider dashboard widths. | ||
|
|
||
| ## Build and quality expectations | ||
|
|
||
| - Keep `yarn lint` clean for changed code. | ||
| - Ensure `yarn build` succeeds after non-trivial changes. | ||
| - Do not introduce unrelated refactors in focused changes. | ||
| - If updating build tooling, keep dev and prod Rollup configs consistent. | ||
|
|
||
| ## Safe change workflow | ||
|
|
||
| 1. Read adjacent code before editing. | ||
| 2. Implement the smallest viable change. | ||
| 3. Run relevant checks (`yarn lint`, `yarn build`, or targeted command). | ||
| 4. Update docs/README when behavior or config changes. | ||
| 5. Summarize what changed and why. | ||
|
|
||
| ## Pull request guidance | ||
|
|
||
| - Keep PRs focused to one logical change. | ||
| - Include screenshots or short clips for visible UI/editor changes. | ||
| - Document config changes and migration notes when applicable. | ||
| - Call out any follow-up work explicitly instead of bundling extra scope. | ||
|
|
||
| ## Avoid these common issues | ||
|
|
||
| - Breaking editor/card config parity | ||
| - Adding untyped dynamic config access | ||
| - Hardcoding text instead of localization keys | ||
| - Overriding theme behavior with fixed styles | ||
| - Changing output filenames or card tag without explicit request | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.