Compare commits

..

2 Commits

Author SHA1 Message Date
Joakim Sørensen
d60639f99d Update .devcontainer.json 2023-01-29 10:14:40 +01:00
ludeeus
693b621dd5 Restructure devcontainer 2023-01-29 09:12:41 +00:00
570 changed files with 7408 additions and 11979 deletions

View File

@@ -1,13 +1,20 @@
{ {
"name": "Home Assistant Frontend", "name": "Home Assistant Frontend",
"build": { "image": "mcr.microsoft.com/devcontainers/python:0-3.10",
"dockerfile": "Dockerfile",
"context": ".."
},
"appPort": "8124:8123", "appPort": "8124:8123",
"postCreateCommand": "script/bootstrap", "postCreateCommand": "script/bootstrap",
"containerEnv": { "containerEnv": {
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}",
"DEVCONTAINER": "true"
},
"remoteUser": "vscode",
"remoteEnv": {
"PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/node_modules/.bin:/home/vscode/.local/bin"
},
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "16"
}
}, },
"customizations": { "customizations": {
"vscode": { "vscode": {

View File

@@ -1,13 +0,0 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.148.1/containers/python-3/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.10
ENV \
DEBIAN_FRONTEND=noninteractive \
DEVCONTAINER=true \
PATH=$PATH:./node_modules/.bin
# Install nvm
COPY .nvmrc /tmp/.nvmrc
RUN \
su vscode -c \
"source /usr/local/share/nvm/nvm.sh && nvm install $(cat /tmp/.nvmrc) 2>&1"

View File

@@ -5,7 +5,6 @@
"plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended",
"plugin:wc/recommended", "plugin:wc/recommended",
"plugin:lit/all", "plugin:lit/all",
"plugin:lit-a11y/recommended",
"prettier" "prettier"
], ],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
@@ -66,10 +65,7 @@
"import/extensions": [ "import/extensions": [
"error", "error",
"ignorePackages", "ignorePackages",
{ { "ts": "never", "js": "never" }
"ts": "never",
"js": "never"
}
], ],
"no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"], "no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"],
"object-curly-newline": "off", "object-curly-newline": "off",
@@ -116,14 +112,7 @@
], ],
"unused-imports/no-unused-imports": "error", "unused-imports/no-unused-imports": "error",
"lit/attribute-value-entities": "off", "lit/attribute-value-entities": "off",
"lit/no-template-map": "off", "lit/no-template-map": "off"
"lit/no-native-attributes": "warn",
"lit/no-this-assign-in-render": "warn",
"lit-a11y/click-events-have-key-events": ["off"],
"lit-a11y/no-autofocus": "off",
"lit-a11y/alt-text": "warn",
"lit-a11y/anchor-is-valid": "warn",
"lit-a11y/role-has-required-aria-attrs": "warn"
}, },
"plugins": ["disable", "unused-imports"], "plugins": ["disable", "unused-imports"],
"processor": "disable/disable" "processor": "disable/disable"

View File

@@ -10,10 +10,8 @@ updates:
directory: "/" directory: "/"
schedule: schedule:
interval: "daily" interval: "daily"
time: "03:00" time: "06:00"
open-pull-requests-limit: 10 open-pull-requests-limit: 5
labels:
- "dependencies"
ignore: ignore:
# Ignore rollup and plugins until everything else is updated # Ignore rollup and plugins until everything else is updated
- dependency-name: "*rollup*" - dependency-name: "*rollup*"

View File

@@ -33,7 +33,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Cast - name: Build Cast
run: ./node_modules/.bin/gulp build-cast run: ./node_modules/.bin/gulp build-cast
@@ -69,7 +71,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Cast - name: Build Cast
run: ./node_modules/.bin/gulp build-cast run: ./node_modules/.bin/gulp build-cast
@@ -83,4 +87,4 @@ jobs:
args: deploy --dir=cast/dist --prod args: deploy --dir=cast/dist --prod
env: env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_CAST_SITE_ID }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_CAST_SITE_ID }}

View File

@@ -15,13 +15,8 @@ env:
NODE_OPTIONS: --max_old_space_size=6144 NODE_OPTIONS: --max_old_space_size=6144
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs: jobs:
lint: lint:
name: Lint and check format
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
@@ -32,19 +27,20 @@ jobs:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
- name: Check for duplicate dependencies env:
run: yarn dedupe --check CI: true
- name: Build resources - name: Build resources
run: ./node_modules/.bin/gulp gen-icons-json build-translations build-locale-data gather-gallery-pages run: ./node_modules/.bin/gulp gen-icons-json build-translations build-locale-data gather-gallery-pages
- name: Run eslint - name: Run eslint
run: yarn run lint:eslint --quiet run: yarn run lint:eslint
- name: Run tsc - name: Run tsc
run: yarn run lint:types run: yarn run lint:types
- name: Run prettier - name: Run prettier
run: yarn run lint:prettier run: yarn run lint:prettier
- name: Check for duplicate dependencies
run: yarn dedupe --check
test: test:
name: Run tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
@@ -55,15 +51,16 @@ jobs:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build resources - name: Build resources
run: ./node_modules/.bin/gulp build-translations build-locale-data run: ./node_modules/.bin/gulp build-translations build-locale-data
- name: Run Tests - name: Run Tests
run: yarn run test run: yarn run test
build: build:
name: Build frontend
needs: [lint, test]
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, test]
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.3.0
@@ -73,15 +70,16 @@ jobs:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Application - name: Build Application
run: ./node_modules/.bin/gulp build-app run: ./node_modules/.bin/gulp build-app
env: env:
IS_TEST: "true" IS_TEST: "true"
supervisor: supervisor:
name: Build supervisor
needs: [lint, test]
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, test]
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.3.0
@@ -91,7 +89,9 @@ jobs:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Application - name: Build Application
run: ./node_modules/.bin/gulp build-hassio run: ./node_modules/.bin/gulp build-hassio
env: env:

View File

@@ -34,7 +34,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Demo - name: Build Demo
run: ./node_modules/.bin/gulp build-demo run: ./node_modules/.bin/gulp build-demo
@@ -70,7 +72,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Demo - name: Build Demo
run: ./node_modules/.bin/gulp build-demo run: ./node_modules/.bin/gulp build-demo
@@ -84,4 +88,4 @@ jobs:
args: deploy --dir=demo/dist --prod args: deploy --dir=demo/dist --prod
env: env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }}

View File

@@ -26,7 +26,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Gallery - name: Build Gallery
run: ./node_modules/.bin/gulp build-gallery run: ./node_modules/.bin/gulp build-gallery

View File

@@ -31,7 +31,9 @@ jobs:
cache: yarn cache: yarn
- name: Install dependencies - name: Install dependencies
run: yarn install --immutable run: yarn install
env:
CI: true
- name: Build Gallery - name: Build Gallery
run: ./node_modules/.bin/gulp build-gallery run: ./node_modules/.bin/gulp build-gallery

View File

@@ -53,25 +53,13 @@ module.exports.definedVars = ({ isProdBuild, latestBuild, defineOverlay }) => ({
...defineOverlay, ...defineOverlay,
}); });
const htmlMinifierOptions = {
caseSensitive: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
removeComments: true,
removeRedundantAttributes: true,
minifyCSS: {
level: 0,
},
};
module.exports.terserOptions = (latestBuild) => ({ module.exports.terserOptions = (latestBuild) => ({
safari10: !latestBuild, safari10: !latestBuild,
ecma: latestBuild ? undefined : 5, ecma: latestBuild ? undefined : 5,
output: { comments: false }, output: { comments: false },
}); });
module.exports.babelOptions = ({ latestBuild, isProdBuild }) => ({ module.exports.babelOptions = ({ latestBuild }) => ({
babelrc: false, babelrc: false,
compact: false, compact: false,
presets: [ presets: [
@@ -79,7 +67,7 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild }) => ({
"@babel/preset-env", "@babel/preset-env",
{ {
useBuiltIns: "entry", useBuiltIns: "entry",
corejs: { version: "3.29", proposals: true }, corejs: "3.15",
bugfixes: true, bugfixes: true,
}, },
], ],
@@ -105,30 +93,12 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild }) => ({
"@babel/plugin-syntax-import-meta", "@babel/plugin-syntax-import-meta",
"@babel/plugin-syntax-dynamic-import", "@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-top-level-await", "@babel/plugin-syntax-top-level-await",
// Support various proposals
"@babel/plugin-proposal-optional-chaining", "@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator", "@babel/plugin-proposal-nullish-coalescing-operator",
["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: true }], ["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: true }],
["@babel/plugin-proposal-private-methods", { loose: true }], ["@babel/plugin-proposal-private-methods", { loose: true }],
["@babel/plugin-proposal-private-property-in-object", { loose: true }], ["@babel/plugin-proposal-private-property-in-object", { loose: true }],
["@babel/plugin-proposal-class-properties", { loose: true }], ["@babel/plugin-proposal-class-properties", { loose: true }],
// Minify template literals for production
isProdBuild && [
"template-html-minifier",
{
modules: {
lit: [
"html",
{ name: "svg", encapsulation: "svg" },
{ name: "css", encapsulation: "style" },
],
"@polymer/polymer/lib/utils/html-tag": ["html"],
},
strictCSS: true,
htmlMinifier: htmlMinifierOptions,
failOnError: true, // we can turn this off in case of false positives
},
],
].filter(Boolean), ].filter(Boolean),
exclude: [ exclude: [
// \\ for Windows, / for Mac OS and Linux // \\ for Windows, / for Mac OS and Linux

View File

@@ -43,14 +43,7 @@ const createRollupConfig = ({
preserveEntrySignatures: false, preserveEntrySignatures: false,
plugins: [ plugins: [
ignore({ ignore({
files: bundle files: bundle.emptyPackages({ latestBuild }),
.emptyPackages({ latestBuild })
// TEMP HACK: Makes Rollup build work again
.concat(
require.resolve(
"@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min"
)
),
}), }),
resolve({ resolve({
extensions, extensions,
@@ -61,7 +54,7 @@ const createRollupConfig = ({
commonjs(), commonjs(),
json(), json(),
babel({ babel({
...bundle.babelOptions({ latestBuild, isProdBuild }), ...bundle.babelOptions({ latestBuild }),
extensions, extensions,
babelHelpers: isWDS ? "inline" : "bundled", babelHelpers: isWDS ? "inline" : "bundled",
}), }),

View File

@@ -51,7 +51,7 @@ const createWebpackConfig = ({
use: { use: {
loader: "babel-loader", loader: "babel-loader",
options: { options: {
...bundle.babelOptions({ latestBuild, isProdBuild }), ...bundle.babelOptions({ latestBuild }),
cacheDirectory: !isProdBuild, cacheDirectory: !isProdBuild,
cacheCompression: false, cacheCompression: false,
}, },

View File

@@ -181,7 +181,7 @@ class HcCast extends LitElement {
private async _handlePickView(ev: Event) { private async _handlePickView(ev: Event) {
const path = (ev.currentTarget as any).getAttribute("data-path"); const path = (ev.currentTarget as any).getAttribute("data-path");
await ensureConnectedCastSession(this.castManager!, this.auth!); await ensureConnectedCastSession(this.castManager!, this.auth!);
castSendShowLovelaceView(this.castManager, this.auth.data.hassUrl, path); castSendShowLovelaceView(this.castManager, path, this.auth.data.hassUrl);
} }
private async _handleLogout() { private async _handleLogout() {

View File

@@ -1,4 +1,4 @@
import { html, nothing } from "lit"; import { html, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { mockHistory } from "../../../../demo/src/stubs/history"; import { mockHistory } from "../../../../demo/src/stubs/history";
import { LovelaceConfig } from "../../../../src/data/lovelace"; import { LovelaceConfig } from "../../../../src/data/lovelace";
@@ -18,9 +18,9 @@ class HcDemo extends HassElement {
@state() private _lovelaceConfig?: LovelaceConfig; @state() private _lovelaceConfig?: LovelaceConfig;
protected render() { protected render(): TemplateResult {
if (!this._lovelaceConfig) { if (!this._lovelaceConfig) {
return nothing; return html``;
} }
return html` return html`
<hc-lovelace <hc-lovelace

View File

@@ -252,22 +252,6 @@ export class HcMain extends HassElement {
msg.urlPath = null; msg.urlPath = null;
} }
this._lovelacePath = msg.viewPath; this._lovelacePath = msg.viewPath;
if (msg.urlPath === "energy") {
this._lovelaceConfig = {
views: [
{
strategy: {
type: "energy",
options: { show_date_selection: true },
},
},
],
};
this._urlPath = "energy";
this._lovelacePath = 0;
this._sendStatus();
return;
}
if (!this._unsubLovelace || this._urlPath !== msg.urlPath) { if (!this._unsubLovelace || this._urlPath !== msg.urlPath) {
this._urlPath = msg.urlPath; this._urlPath = msg.urlPath;
this._lovelaceConfig = undefined; this._lovelaceConfig = undefined;

View File

@@ -6,9 +6,6 @@ set -e
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
export STATS=1 STATS=1 NODE_ENV=production ../node_modules/.bin/webpack --profile --json > compilation-stats.json
statsfile="compilation-stats-demo.json" npx webpack-bundle-analyzer compilation-stats.json dist/frontend_latest
rm compilation-stats.json
./node_modules/.bin/webpack-cli --profile --node-env=production --json=$statsfile
npx webpack-bundle-analyzer $statsfile dist/frontend_latest
rm -f $statsfile

View File

@@ -1,5 +1,5 @@
import { mdiTelevision } from "@mdi/js"; import { mdiTelevision } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators"; import { customElement, state } from "lit/decorators";
import { CastManager } from "../../../src/cast/cast_manager"; import { CastManager } from "../../../src/cast/cast_manager";
import { castSendShowDemo } from "../../../src/cast/receiver_messages"; import { castSendShowDemo } from "../../../src/cast/receiver_messages";
@@ -20,12 +20,12 @@ class CastDemoRow extends LitElement implements LovelaceRow {
// No config possible. // No config possible.
} }
protected render() { protected render(): TemplateResult {
if ( if (
!this._castManager || !this._castManager ||
this._castManager.castState === "NO_DEVICES_AVAILABLE" this._castManager.castState === "NO_DEVICES_AVAILABLE"
) { ) {
return nothing; return html``;
} }
return html` return html`
<ha-svg-icon .path=${mdiTelevision}></ha-svg-icon> <ha-svg-icon .path=${mdiTelevision}></ha-svg-icon>

View File

@@ -1,6 +1,6 @@
import "@material/mwc-button"; import "@material/mwc-button";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import { until } from "lit/directives/until"; import { until } from "lit/directives/until";
import "../../../src/components/ha-card"; import "../../../src/components/ha-card";
import "../../../src/components/ha-circular-progress"; import "../../../src/components/ha-circular-progress";
@@ -14,7 +14,6 @@ import {
setDemoConfig, setDemoConfig,
} from "../configs/demo-configs"; } from "../configs/demo-configs";
@customElement("ha-demo-card")
export class HADemoCard extends LitElement implements LovelaceCard { export class HADemoCard extends LitElement implements LovelaceCard {
@property({ attribute: false }) public lovelace?: Lovelace; @property({ attribute: false }) public lovelace?: Lovelace;
@@ -30,9 +29,9 @@ export class HADemoCard extends LitElement implements LovelaceCard {
public setConfig(_config: LovelaceCardConfig) {} public setConfig(_config: LovelaceCardConfig) {}
protected render() { protected render(): TemplateResult {
if (this._hidden) { if (this._hidden) {
return nothing; return html``;
} }
return html` return html`
<ha-card> <ha-card>
@@ -155,3 +154,5 @@ declare global {
"ha-demo-card": HADemoCard; "ha-demo-card": HADemoCard;
} }
} }
customElements.define("ha-demo-card", HADemoCard);

View File

@@ -1,6 +1,4 @@
// Compat needs to be first import // Compat needs to be first import
import "../../src/resources/compatibility";
import { customElement } from "lit/decorators";
import { isNavigationClick } from "../../src/common/dom/is-navigation-click"; import { isNavigationClick } from "../../src/common/dom/is-navigation-click";
import { navigate } from "../../src/common/navigate"; import { navigate } from "../../src/common/navigate";
import { import {
@@ -8,6 +6,7 @@ import {
provideHass, provideHass,
} from "../../src/fake_data/provide_hass"; } from "../../src/fake_data/provide_hass";
import { HomeAssistantAppEl } from "../../src/layouts/home-assistant"; import { HomeAssistantAppEl } from "../../src/layouts/home-assistant";
import "../../src/resources/compatibility";
import { HomeAssistant } from "../../src/types"; import { HomeAssistant } from "../../src/types";
import { selectedDemoConfig } from "./configs/demo-configs"; import { selectedDemoConfig } from "./configs/demo-configs";
import { mockAuth } from "./stubs/auth"; import { mockAuth } from "./stubs/auth";
@@ -27,8 +26,7 @@ import { mockSystemLog } from "./stubs/system_log";
import { mockTemplate } from "./stubs/template"; import { mockTemplate } from "./stubs/template";
import { mockTranslations } from "./stubs/translations"; import { mockTranslations } from "./stubs/translations";
@customElement("ha-demo") class HaDemo extends HomeAssistantAppEl {
export class HaDemo extends HomeAssistantAppEl {
protected async _initializeHass() { protected async _initializeHass() {
const initial: Partial<MockHomeAssistant> = { const initial: Partial<MockHomeAssistant> = {
panelUrl: (this as any)._panelUrl, panelUrl: (this as any)._panelUrl,
@@ -73,7 +71,6 @@ export class HaDemo extends HomeAssistantAppEl {
entity_category: null, entity_category: null,
has_entity_name: false, has_entity_name: false,
unique_id: "co2_intensity", unique_id: "co2_intensity",
options: null,
}, },
{ {
config_entry_id: "co2signal", config_entry_id: "co2signal",
@@ -89,7 +86,6 @@ export class HaDemo extends HomeAssistantAppEl {
entity_category: null, entity_category: null,
has_entity_name: false, has_entity_name: false,
unique_id: "grid_fossil_fuel_percentage", unique_id: "grid_fossil_fuel_percentage",
options: null,
}, },
]); ]);
@@ -125,6 +121,8 @@ export class HaDemo extends HomeAssistantAppEl {
} }
} }
customElements.define("ha-demo", HaDemo);
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"ha-demo": HaDemo; "ha-demo": HaDemo;

View File

@@ -66,7 +66,7 @@ const incrementalUnits = ["clients", "queries", "ads"];
export const mockHistory = (mockHass: MockHomeAssistant) => { export const mockHistory = (mockHass: MockHomeAssistant) => {
mockHass.mockAPI( mockHass.mockAPI(
/history\/period\/.+/, new RegExp("history/period/.+"),
(hass, _method, path, _parameters) => { (hass, _method, path, _parameters) => {
const params = parseQuery<HistoryQueryParams>(path.split("?")[1]); const params = parseQuery<HistoryQueryParams>(path.split("?")[1]);
const entities = params.filter_entity_id.split(","); const entities = params.filter_entity_id.split(",");

View File

@@ -15,7 +15,6 @@ import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
const generateMeanStatistics = ( const generateMeanStatistics = (
start: Date, start: Date,
end: Date, end: Date,
// eslint-disable-next-line @typescript-eslint/default-param-last
period: "5minute" | "hour" | "day" | "month" = "hour", period: "5minute" | "hour" | "day" | "month" = "hour",
initValue: number, initValue: number,
maxDiff: number maxDiff: number
@@ -52,7 +51,6 @@ const generateMeanStatistics = (
const generateSumStatistics = ( const generateSumStatistics = (
start: Date, start: Date,
end: Date, end: Date,
// eslint-disable-next-line @typescript-eslint/default-param-last
period: "5minute" | "hour" | "day" | "month" = "hour", period: "5minute" | "hour" | "day" | "month" = "hour",
initValue: number, initValue: number,
maxDiff: number maxDiff: number
@@ -88,7 +86,6 @@ const generateSumStatistics = (
const generateCurvedStatistics = ( const generateCurvedStatistics = (
start: Date, start: Date,
end: Date, end: Date,
// eslint-disable-next-line @typescript-eslint/default-param-last
_period: "5minute" | "hour" | "day" | "month" = "hour", _period: "5minute" | "hour" | "day" | "month" = "hour",
initValue: number, initValue: number,
maxDiff: number, maxDiff: number,

View File

@@ -1,4 +1,4 @@
import { css, html, nothing } from "lit"; import { html, css } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { until } from "lit/directives/until"; import { until } from "lit/directives/until";
import { HaMarkdown } from "../../../src/components/ha-markdown"; import { HaMarkdown } from "../../../src/components/ha-markdown";
@@ -10,7 +10,7 @@ class PageDescription extends HaMarkdown {
render() { render() {
if (!PAGES[this.page].description) { if (!PAGES[this.page].description) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,5 +1,5 @@
import { dump } from "js-yaml"; import { dump } from "js-yaml";
import { css, html, LitElement, nothing } from "lit"; import { html, css, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import "../../../../src/components/ha-yaml-editor"; import "../../../../src/components/ha-yaml-editor";
@@ -127,16 +127,16 @@ export class DemoAutomationDescribeAction extends LitElement {
@state() _action = initialAction; @state() _action = initialAction;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`
<ha-card header="Actions"> <ha-card header="Actions">
<div class="action"> <div class="action">
<span> <span>
${this._action ${this._action
? describeAction(this.hass, [], this._action) ? describeAction(this.hass, this._action)
: "<invalid YAML>"} : "<invalid YAML>"}
</span> </span>
<ha-yaml-editor <ha-yaml-editor
@@ -149,7 +149,7 @@ export class DemoAutomationDescribeAction extends LitElement {
${ACTIONS.map( ${ACTIONS.map(
(conf) => html` (conf) => html`
<div class="action"> <div class="action">
<span>${describeAction(this.hass, [], conf as any)}</span> <span>${describeAction(this.hass, conf as any)}</span>
<pre>${dump(conf)}</pre> <pre>${dump(conf)}</pre>
</div> </div>
` `

View File

@@ -1,5 +1,5 @@
import { dump } from "js-yaml"; import { dump } from "js-yaml";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import "../../../../src/components/ha-yaml-editor"; import "../../../../src/components/ha-yaml-editor";
@@ -53,9 +53,9 @@ export class DemoAutomationDescribeCondition extends LitElement {
@state() _condition = initialCondition; @state() _condition = initialCondition;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,5 +1,5 @@
import { dump } from "js-yaml"; import { dump } from "js-yaml";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import "../../../../src/components/ha-yaml-editor"; import "../../../../src/components/ha-yaml-editor";
@@ -64,9 +64,9 @@ export class DemoAutomationDescribeTrigger extends LitElement {
@state() _trigger = initialTrigger; @state() _trigger = initialTrigger;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,6 +1,5 @@
/* eslint-disable lit/no-template-arrow */ /* eslint-disable lit/no-template-arrow */
import { html, css, LitElement, TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import "../../../../src/components/trace/hat-script-graph"; import "../../../../src/components/trace/hat-script-graph";
@@ -30,9 +29,9 @@ const traces: DemoTrace[] = [
export class DemoAutomationTraceTimeline extends LitElement { export class DemoAutomationTraceTimeline extends LitElement {
@property({ attribute: false }) hass?: HomeAssistant; @property({ attribute: false }) hass?: HomeAssistant;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`
${traces.map( ${traces.map(

View File

@@ -1,15 +1,14 @@
/* eslint-disable lit/no-template-arrow */ /* eslint-disable lit/no-template-arrow */
import { html, css, LitElement, TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import "../../../../src/components/trace/hat-script-graph"; import "../../../../src/components/trace/hat-script-graph";
import "../../../../src/components/trace/hat-trace-timeline"; import "../../../../src/components/trace/hat-trace-timeline";
import { customElement, property, state } from "lit/decorators";
import { provideHass } from "../../../../src/fake_data/provide_hass"; import { provideHass } from "../../../../src/fake_data/provide_hass";
import { HomeAssistant } from "../../../../src/types"; import { HomeAssistant } from "../../../../src/types";
import { DemoTrace } from "../../data/traces/types";
import { basicTrace } from "../../data/traces/basic_trace"; import { basicTrace } from "../../data/traces/basic_trace";
import { motionLightTrace } from "../../data/traces/motion-light-trace"; import { motionLightTrace } from "../../data/traces/motion-light-trace";
import { DemoTrace } from "../../data/traces/types";
const traces: DemoTrace[] = [basicTrace, motionLightTrace]; const traces: DemoTrace[] = [basicTrace, motionLightTrace];
@@ -19,9 +18,9 @@ export class DemoAutomationTrace extends LitElement {
@state() private _selected = {}; @state() private _selected = {};
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`
${traces.map( ${traces.map(

View File

@@ -156,6 +156,18 @@ The `title ` option should not be used without a description.
*Documentation coming soon* *Documentation coming soon*
**Right to left**
<ha-alert alert-type="success" rtl>
This is an info alert — check it out!
</ha-alert>
```html
<ha-alert alert-type="success" rtl>
This is an info alert — check it out!
</ha-alert>
```
### API ### API
**Properties/Attributes** **Properties/Attributes**

View File

@@ -0,0 +1,3 @@
---
title: Bar Slider
---

View File

@@ -2,7 +2,7 @@ import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators"; import { customElement, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { repeat } from "lit/directives/repeat"; import { repeat } from "lit/directives/repeat";
import "../../../../src/components/ha-control-slider"; import "../../../../src/components/ha-bar-slider";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
const sliders: { const sliders: {
@@ -46,7 +46,7 @@ const sliders: {
}, },
]; ];
@customElement("demo-components-ha-control-slider") @customElement("demo-components-ha-bar-slider")
export class DemoHaBarSlider extends LitElement { export class DemoHaBarSlider extends LitElement {
@state() private value = 50; @state() private value = 50;
@@ -86,7 +86,7 @@ export class DemoHaBarSlider extends LitElement {
<div class="card-content"> <div class="card-content">
<label id=${id}>${label}</label> <label id=${id}>${label}</label>
<pre>Config: ${JSON.stringify(config)}</pre> <pre>Config: ${JSON.stringify(config)}</pre>
<ha-control-slider <ha-bar-slider
.value=${this.value} .value=${this.value}
.mode=${config.mode} .mode=${config.mode}
class=${ifDefined(config.class)} class=${ifDefined(config.class)}
@@ -94,7 +94,7 @@ export class DemoHaBarSlider extends LitElement {
@slider-moved=${this.handleSliderMoved} @slider-moved=${this.handleSliderMoved}
aria-labelledby=${id} aria-labelledby=${id}
> >
</ha-control-slider> </ha-bar-slider>
</div> </div>
</ha-card> </ha-card>
`; `;
@@ -106,7 +106,7 @@ export class DemoHaBarSlider extends LitElement {
${repeat(sliders, (slider) => { ${repeat(sliders, (slider) => {
const { id, label, ...config } = slider; const { id, label, ...config } = slider;
return html` return html`
<ha-control-slider <ha-bar-slider
.value=${this.value} .value=${this.value}
.mode=${config.mode} .mode=${config.mode}
vertical vertical
@@ -115,7 +115,7 @@ export class DemoHaBarSlider extends LitElement {
@slider-moved=${this.handleSliderMoved} @slider-moved=${this.handleSliderMoved}
aria-label=${label} aria-label=${label}
> >
</ha-control-slider> </ha-bar-slider>
`; `;
})} })}
</div> </div>
@@ -141,11 +141,11 @@ export class DemoHaBarSlider extends LitElement {
font-weight: 600; font-weight: 600;
} }
.custom { .custom {
--control-slider-color: #ffcf4c; --slider-bar-color: #ffcf4c;
--control-slider-background: #ffcf4c; --slider-bar-background: #ffcf4c;
--control-slider-background-opacity: 0.2; --slider-bar-background-opacity: 0.2;
--control-slider-thickness: 100px; --slider-bar-thickness: 100px;
--control-slider-border-radius: 24px; --slider-bar-border-radius: 24px;
} }
.vertical-sliders { .vertical-sliders {
height: 300px; height: 300px;
@@ -165,6 +165,6 @@ export class DemoHaBarSlider extends LitElement {
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"demo-components-ha-control-slider": DemoHaBarSlider; "demo-components-ha-bar-slider": DemoHaBarSlider;
} }
} }

View File

@@ -0,0 +1,3 @@
---
title: Bar Switch
---

View File

@@ -8,7 +8,7 @@ import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators"; import { customElement, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { repeat } from "lit/directives/repeat"; import { repeat } from "lit/directives/repeat";
import "../../../../src/components/ha-control-switch"; import "../../../../src/components/ha-bar-switch";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
const switches: { const switches: {
@@ -39,8 +39,8 @@ const switches: {
}, },
]; ];
@customElement("demo-components-ha-control-switch") @customElement("demo-components-ha-bar-switch")
export class DemoHaControlSwitch extends LitElement { export class DemoHaBarSwitch extends LitElement {
@state() private checked = false; @state() private checked = false;
handleValueChanged(e: any) { handleValueChanged(e: any) {
@@ -56,7 +56,7 @@ export class DemoHaControlSwitch extends LitElement {
<div class="card-content"> <div class="card-content">
<label id=${id}>${label}</label> <label id=${id}>${label}</label>
<pre>Config: ${JSON.stringify(config)}</pre> <pre>Config: ${JSON.stringify(config)}</pre>
<ha-control-switch <ha-bar-switch
.checked=${this.checked} .checked=${this.checked}
class=${ifDefined(config.class)} class=${ifDefined(config.class)}
@change=${this.handleValueChanged} @change=${this.handleValueChanged}
@@ -66,7 +66,7 @@ export class DemoHaControlSwitch extends LitElement {
disabled=${ifDefined(config.disabled)} disabled=${ifDefined(config.disabled)}
reversed=${ifDefined(config.reversed)} reversed=${ifDefined(config.reversed)}
> >
</ha-control-switch> </ha-bar-switch>
</div> </div>
</ha-card> </ha-card>
`; `;
@@ -78,7 +78,7 @@ export class DemoHaControlSwitch extends LitElement {
${repeat(switches, (sw) => { ${repeat(switches, (sw) => {
const { id, label, ...config } = sw; const { id, label, ...config } = sw;
return html` return html`
<ha-control-switch <ha-bar-switch
.checked=${this.checked} .checked=${this.checked}
vertical vertical
class=${ifDefined(config.class)} class=${ifDefined(config.class)}
@@ -89,7 +89,7 @@ export class DemoHaControlSwitch extends LitElement {
disabled=${ifDefined(config.disabled)} disabled=${ifDefined(config.disabled)}
reversed=${ifDefined(config.reversed)} reversed=${ifDefined(config.reversed)}
> >
</ha-control-switch> </ha-bar-switch>
`; `;
})} })}
</div> </div>
@@ -115,11 +115,11 @@ export class DemoHaControlSwitch extends LitElement {
font-weight: 600; font-weight: 600;
} }
.custom { .custom {
--control-switch-on-color: var(--green-color); --switch-bar-on-color: var(--green-color);
--control-switch-off-color: var(--red-color); --switch-bar-off-color: var(--red-color);
--control-switch-thickness: 100px; --switch-bar-thickness: 100px;
--control-switch-border-radius: 24px; --switch-bar-border-radius: 24px;
--control-switch-padding: 6px; --switch-bar-padding: 6px;
--mdc-icon-size: 24px; --mdc-icon-size: 24px;
} }
.vertical-switches { .vertical-switches {
@@ -140,6 +140,6 @@ export class DemoHaControlSwitch extends LitElement {
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"demo-components-ha-control-switch": DemoHaControlSwitch; "demo-components-ha-bar-switch": DemoHaBarSwitch;
} }
} }

View File

@@ -1,3 +0,0 @@
---
title: Control Button
---

View File

@@ -1,192 +0,0 @@
import {
mdiFanSpeed1,
mdiFanSpeed2,
mdiFanSpeed3,
mdiLightbulb,
} from "@mdi/js";
import { css, html, LitElement, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { repeat } from "lit/directives/repeat";
import "../../../../src/components/ha-control-button";
import "../../../../src/components/ha-card";
import "../../../../src/components/ha-svg-icon";
import "../../../../src/components/ha-control-button-group";
type Button = {
label: string;
icon?: string;
class?: string;
disabled?: boolean;
};
const buttons: Button[] = [
{
label: "Button",
},
{
label: "Button and custom style",
class: "custom",
},
{
label: "Disabled Button",
disabled: true,
},
];
type ButtonGroup = {
vertical?: boolean;
class?: string;
};
const buttonGroups: ButtonGroup[] = [
{},
{
class: "custom-group",
},
];
@customElement("demo-components-ha-control-button")
export class DemoHaBarButton extends LitElement {
protected render(): TemplateResult {
return html`
<ha-card>
${repeat(
buttons,
(btn) => html`
<div class="card-content">
<pre>Config: ${JSON.stringify(btn)}</pre>
<ha-control-button
class=${ifDefined(btn.class)}
label=${ifDefined(btn.label)}
disabled=${ifDefined(btn.disabled)}
>
<ha-svg-icon .path=${btn.icon || mdiLightbulb}></ha-svg-icon>
</ha-control-button>
</div>
`
)}
</ha-card>
<ha-card>
${repeat(
buttonGroups,
(group) => html`
<div class="card-content">
<pre>Config: ${JSON.stringify(group)}</pre>
<ha-control-button-group class=${ifDefined(group.class)}>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed1}
label="Speed 1"
></ha-svg-icon>
</ha-control-button>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed2}
label="Speed 2"
></ha-svg-icon>
</ha-control-button>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed3}
label="Speed 3"
></ha-svg-icon>
</ha-control-button>
</ha-control-button-group>
</div>
`
)}
</ha-card>
<ha-card>
<div class="card-content">
<p class="title"><b>Vertical</b></p>
<div class="vertical-buttons">
${repeat(
buttonGroups,
(group) => html`
<ha-control-button-group
vertical
class=${ifDefined(group.class)}
>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed1}
label="Speed 1"
></ha-svg-icon>
</ha-control-button>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed2}
label="Speed 2"
></ha-svg-icon>
</ha-control-button>
<ha-control-button>
<ha-svg-icon
.path=${mdiFanSpeed3}
label="Speed 3"
></ha-svg-icon>
</ha-control-button>
</ha-control-button-group>
`
)}
</div>
</div>
</ha-card>
`;
}
static get styles() {
return css`
ha-card {
max-width: 600px;
margin: 24px auto;
}
pre {
margin-top: 0;
margin-bottom: 8px;
}
p {
margin: 0;
}
label {
font-weight: 600;
}
.custom {
--control-button-icon-color: var(--primary-color);
--control-button-background-color: var(--primary-color);
--control-button-background-opacity: 0.2;
--control-button-border-radius: 18px;
height: 100px;
width: 100px;
}
.custom-group {
--control-button-group-thickness: 100px;
--control-button-group-border-radius: 18px;
--control-button-group-spacing: 20px;
}
.custom-group ha-control-button {
--control-button-border-radius: 18px;
--mdc-icon-size: 32px;
}
.vertical-buttons {
height: 300px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
p.title {
margin-bottom: 12px;
}
.vertical-switches > *:not(:last-child) {
margin-right: 4px;
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"demo-components-ha-control-button": DemoHaBarButton;
}
}

View File

@@ -1,3 +0,0 @@
---
title: Control Slider
---

View File

@@ -1,3 +0,0 @@
---
title: Control Switch
---

View File

@@ -3,7 +3,6 @@ import { customElement } from "lit/decorators";
import "../../../../src/components/ha-tip"; import "../../../../src/components/ha-tip";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element";
import { provideHass } from "../../../../src/fake_data/provide_hass";
const tips: (string | TemplateResult)[] = [ const tips: (string | TemplateResult)[] = [
"Test tip", "Test tip",
@@ -19,11 +18,7 @@ export class DemoHaTip extends LitElement {
<div class=${mode}> <div class=${mode}>
<ha-card header="ha-tip ${mode} demo"> <ha-card header="ha-tip ${mode} demo">
<div class="card-content"> <div class="card-content">
${tips.map( ${tips.map((tip) => html`<ha-tip>${tip}</ha-tip>`)}
(tip) => html`<ha-tip .hass=${provideHass(this)}
>${tip}</ha-tip
>`
)}
</div> </div>
</ha-card> </ha-card>
</div> </div>

View File

@@ -1,3 +0,0 @@
---
title: Tile Card
---

View File

@@ -1,173 +0,0 @@
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, query } from "lit/decorators";
import { CoverEntityFeature } from "../../../../src/data/cover";
import { LightColorMode } from "../../../../src/data/light";
import { VacuumEntityFeature } from "../../../../src/data/vacuum";
import { getEntity } from "../../../../src/fake_data/entity";
import { provideHass } from "../../../../src/fake_data/provide_hass";
import "../../components/demo-cards";
const ENTITIES = [
getEntity("switch", "tv_outlet", "on", {
friendly_name: "TV outlet",
device_class: "outlet",
}),
getEntity("light", "bed_light", "on", {
friendly_name: "Bed Light",
supported_color_modes: [LightColorMode.HS],
}),
getEntity("light", "unavailable", "unavailable", {
friendly_name: "Unavailable entity",
}),
getEntity("climate", "thermostat", "heat", {
current_temperature: 73,
min_temp: 45,
max_temp: 95,
temperature: 80,
hvac_modes: ["heat", "cool", "auto", "off"],
friendly_name: "Thermostat",
hvac_action: "heating",
}),
getEntity("person", "paulus", "home", {
friendly_name: "Paulus",
}),
getEntity("vacuum", "first_floor_vacuum", "docked", {
friendly_name: "First floor vacuum",
supported_features:
VacuumEntityFeature.START +
VacuumEntityFeature.STOP +
VacuumEntityFeature.RETURN_HOME,
}),
getEntity("cover", "kitchen_shutter", "open", {
friendly_name: "Kitchen shutter",
device_class: "shutter",
supported_features:
CoverEntityFeature.CLOSE +
CoverEntityFeature.OPEN +
CoverEntityFeature.STOP,
}),
getEntity("cover", "pergola_roof", "open", {
friendly_name: "Pergola Roof",
supported_features:
CoverEntityFeature.CLOSE_TILT +
CoverEntityFeature.OPEN_TILT +
CoverEntityFeature.STOP_TILT,
}),
];
const CONFIGS = [
{
heading: "Basic example",
config: `
- type: tile
entity: switch.tv_outlet
`,
},
{
heading: "Vertical example",
config: `
- type: tile
entity: switch.tv_outlet
vertical: true
`,
},
{
heading: "Custom color",
config: `
- type: tile
entity: switch.tv_outlet
color: pink
`,
},
{
heading: "Unknown entity",
config: `
- type: tile
entity: light.unknown
`,
},
{
heading: "Unavailable entity",
config: `
- type: tile
entity: light.unavailable
`,
},
{
heading: "Climate",
config: `
- type: tile
entity: climate.thermostat
`,
},
{
heading: "Person",
config: `
- type: tile
entity: person.paulus
`,
},
{
heading: "Light brightness feature",
config: `
- type: tile
entity: light.bed_light
features:
- type: "light-brightness"
`,
},
{
heading: "Vacuum commands feature",
config: `
- type: tile
entity: vacuum.first_floor_vacuum
features:
- type: "vacuum-commands"
commands:
- start_pause
- stop
- return_home
`,
},
{
heading: "Cover open close feature",
config: `
- type: tile
entity: cover.kitchen_shutter
features:
- type: "cover-open-close"
`,
},
{
heading: "Cover tilt feature",
config: `
- type: tile
entity: cover.pergola_roof
features:
- type: "cover-tilt"
`,
},
];
@customElement("demo-lovelace-tile-card")
class DemoTile extends LitElement {
@query("#demos") private _demoRoot!: HTMLElement;
protected render(): TemplateResult {
return html`<demo-cards id="demos" .configs=${CONFIGS}></demo-cards>`;
}
protected firstUpdated(changedProperties: PropertyValues) {
super.firstUpdated(changedProperties);
const hass = provideHass(this._demoRoot);
hass.updateTranslations(null, "en");
hass.updateTranslations("lovelace", "en");
hass.addEntities(ENTITIES);
}
}
declare global {
interface HTMLElementTagNameMap {
"demo-lovelace-tile-card": DemoTile;
}
}

View File

@@ -2,7 +2,7 @@ import {
HassEntity, HassEntity,
HassEntityAttributeBase, HassEntityAttributeBase,
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { computeDomain } from "../../../../src/common/entity/compute_domain"; import { computeDomain } from "../../../../src/common/entity/compute_domain";
@@ -387,9 +387,9 @@ export class DemoEntityState extends LitElement {
hass.updateTranslations("config", "en"); hass.updateTranslations("config", "en");
} }
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,22 +1,22 @@
import { css, html, LitElement, nothing } from "lit"; import { html, css, LitElement, TemplateResult } from "lit";
import "../../../../src/components/ha-formfield"; import "../../../../src/components/ha-formfield";
import "../../../../src/components/ha-switch"; import "../../../../src/components/ha-switch";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import { customElement, property, state } from "lit/decorators";
import { IntegrationManifest } from "../../../../src/data/integration"; import { IntegrationManifest } from "../../../../src/data/integration";
import { DeviceRegistryEntry } from "../../../../src/data/device_registry";
import { EntityRegistryEntry } from "../../../../src/data/entity_registry";
import { provideHass } from "../../../../src/fake_data/provide_hass"; import { provideHass } from "../../../../src/fake_data/provide_hass";
import { HomeAssistant } from "../../../../src/types";
import "../../../../src/panels/config/integrations/ha-integration-card";
import "../../../../src/panels/config/integrations/ha-ignored-config-entry-card";
import "../../../../src/panels/config/integrations/ha-config-flow-card"; import "../../../../src/panels/config/integrations/ha-config-flow-card";
import type { import type {
ConfigEntryExtended, ConfigEntryExtended,
DataEntryFlowProgressExtended, DataEntryFlowProgressExtended,
} from "../../../../src/panels/config/integrations/ha-config-integrations"; } from "../../../../src/panels/config/integrations/ha-config-integrations";
import "../../../../src/panels/config/integrations/ha-ignored-config-entry-card"; import { DeviceRegistryEntry } from "../../../../src/data/device_registry";
import "../../../../src/panels/config/integrations/ha-integration-card"; import { EntityRegistryEntry } from "../../../../src/data/entity_registry";
import { HomeAssistant } from "../../../../src/types";
const createConfigEntry = ( const createConfigEntry = (
title: string, title: string,
@@ -197,7 +197,6 @@ const createEntityRegistryEntries = (
platform: "updater", platform: "updater",
has_entity_name: false, has_entity_name: false,
unique_id: "updater", unique_id: "updater",
options: null,
}, },
]; ];
@@ -231,9 +230,9 @@ export class DemoIntegrationCard extends LitElement {
@state() isCloud = false; @state() isCloud = false;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`
<div class="container"> <div class="container">

View File

@@ -1,6 +1,6 @@
import { mdiArrowUpBoldCircle, mdiPuzzle } from "@mdi/js"; import { mdiArrowUpBoldCircle, mdiPuzzle } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { atLeastVersion } from "../../../src/common/config/version"; import { atLeastVersion } from "../../../src/common/config/version";
import { navigate } from "../../../src/common/navigate"; import { navigate } from "../../../src/common/navigate";
@@ -14,8 +14,7 @@ import "../components/hassio-card-content";
import { filterAndSort } from "../components/hassio-filter-addons"; import { filterAndSort } from "../components/hassio-filter-addons";
import { hassioStyle } from "../resources/hassio-style"; import { hassioStyle } from "../resources/hassio-style";
@customElement("hassio-addon-repository") class HassioAddonRepositoryEl extends LitElement {
export class HassioAddonRepositoryEl extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public supervisor!: Supervisor; @property({ attribute: false }) public supervisor!: Supervisor;
@@ -141,3 +140,5 @@ export class HassioAddonRepositoryEl extends LitElement {
]; ];
} }
} }
customElements.define("hassio-addon-repository", HassioAddonRepositoryEl);

View File

@@ -6,11 +6,10 @@ import {
CSSResultGroup, CSSResultGroup,
html, html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { atLeastVersion } from "../../../src/common/config/version"; import { atLeastVersion } from "../../../src/common/config/version";
import { fireEvent } from "../../../src/common/dom/fire_event"; import { fireEvent } from "../../../src/common/dom/fire_event";
@@ -50,8 +49,7 @@ const sortRepos = (a: HassioAddonRepository, b: HassioAddonRepository) => {
return a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1; return a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1;
}; };
@customElement("hassio-addon-store") class HassioAddonStore extends LitElement {
export class HassioAddonStore extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public supervisor!: Supervisor; @property({ attribute: false }) public supervisor!: Supervisor;
@@ -74,8 +72,8 @@ export class HassioAddonStore extends LitElement {
} }
} }
protected render() { protected render(): TemplateResult {
let repos: (TemplateResult | typeof nothing)[] = []; let repos: TemplateResult[] = [];
if (this.supervisor.store.repositories) { if (this.supervisor.store.repositories) {
repos = this.addonRepositories( repos = this.addonRepositories(
@@ -174,7 +172,7 @@ export class HassioAddonStore extends LitElement {
.supervisor=${this.supervisor} .supervisor=${this.supervisor}
></hassio-addon-repository> ></hassio-addon-repository>
` `
: nothing; : html``;
}) })
); );
@@ -252,3 +250,5 @@ export class HassioAddonStore extends LitElement {
`; `;
} }
} }
customElements.define("hassio-addon-store", HassioAddonStore);

View File

@@ -4,7 +4,7 @@ import {
html, html,
LitElement, LitElement,
PropertyValues, PropertyValues,
nothing, TemplateResult,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
@@ -47,9 +47,9 @@ class HassioAddonNetwork extends LitElement {
this._setNetworkConfig(); this._setNetworkConfig();
} }
protected render() { protected render(): TemplateResult {
if (!this._config) { if (!this._config) {
return nothing; return html``;
} }
const hasHiddenOptions = Object.keys(this._config).find( const hasHiddenOptions = Object.keys(this._config).find(

View File

@@ -8,7 +8,7 @@ import {
html, html,
LitElement, LitElement,
PropertyValues, PropertyValues,
nothing, TemplateResult,
} from "lit"; } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
@@ -160,9 +160,9 @@ export class HassioBackups extends LitElement {
})) }))
); );
protected render() { protected render(): TemplateResult {
if (!this.supervisor) { if (!this.supervisor) {
return nothing; return html``;
} }
return html` return html`
<hass-tabs-subpage-data-table <hass-tabs-subpage-data-table

View File

@@ -1,13 +1,6 @@
import { mdiFolder, mdiHomeAssistant, mdiPuzzle } from "@mdi/js"; import { mdiFolder, mdiHomeAssistant, mdiPuzzle } from "@mdi/js";
import { PaperInputElement } from "@polymer/paper-input/paper-input"; import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
css,
CSSResultGroup,
html,
LitElement,
TemplateResult,
nothing,
} from "lit";
import { customElement, property, query } from "lit/decorators"; import { customElement, property, query } from "lit/decorators";
import { atLeastVersion } from "../../../src/common/config/version"; import { atLeastVersion } from "../../../src/common/config/version";
import { formatDate } from "../../../src/common/datetime/format_date"; import { formatDate } from "../../../src/common/datetime/format_date";
@@ -18,9 +11,9 @@ import "../../../src/components/ha-formfield";
import "../../../src/components/ha-radio"; import "../../../src/components/ha-radio";
import type { HaRadio } from "../../../src/components/ha-radio"; import type { HaRadio } from "../../../src/components/ha-radio";
import { import {
HassioBackupDetail,
HassioFullBackupCreateParams, HassioFullBackupCreateParams,
HassioPartialBackupCreateParams, HassioPartialBackupCreateParams,
HassioBackupDetail,
} from "../../../src/data/hassio/backup"; } from "../../../src/data/hassio/backup";
import { Supervisor } from "../../../src/data/supervisor/supervisor"; import { Supervisor } from "../../../src/data/supervisor/supervisor";
import { PolymerChangedEvent } from "../../../src/polymer-types"; import { PolymerChangedEvent } from "../../../src/polymer-types";
@@ -122,9 +115,9 @@ export class SupervisorBackupContent extends LitElement {
this.supervisor?.localize(`backup.${key}`) || this.supervisor?.localize(`backup.${key}`) ||
this.localize!(`ui.panel.page-onboarding.restore.${key}`); this.localize!(`ui.panel.page-onboarding.restore.${key}`);
protected render() { protected render(): TemplateResult {
if (!this.onboarding && !this.supervisor) { if (!this.onboarding && !this.supervisor) {
return nothing; return html``;
} }
const foldersSection = const foldersSection =
this.backupType === "partial" ? this._getSection("folders") : undefined; this.backupType === "partial" ? this._getSection("folders") : undefined;

View File

@@ -1,6 +1,6 @@
import "@material/mwc-button"; import "@material/mwc-button";
import { mdiHomeAssistant } from "@mdi/js"; import { mdiHomeAssistant } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import "../../../src/components/buttons/ha-progress-button"; import "../../../src/components/buttons/ha-progress-button";
@@ -33,14 +33,14 @@ export class HassioUpdate extends LitElement {
).length ).length
); );
protected render() { protected render(): TemplateResult {
if (!this.supervisor) { if (!this.supervisor) {
return nothing; return html``;
} }
const updatesAvailable = this._pendingUpdates(this.supervisor); const updatesAvailable = this._pendingUpdates(this.supervisor);
if (!updatesAvailable) { if (!updatesAvailable) {
return nothing; return html``;
} }
return html` return html`
@@ -80,9 +80,9 @@ export class HassioUpdate extends LitElement {
name: string, name: string,
key: string, key: string,
object: HassioHomeAssistantInfo | HassioSupervisorInfo | HassioHassOSInfo object: HassioHomeAssistantInfo | HassioSupervisorInfo | HassioHassOSInfo
) { ): TemplateResult {
if (!object.update_available) { if (!object.update_available) {
return nothing; return html``;
} }
return html` return html`
<ha-card outlined> <ha-card outlined>

View File

@@ -1,5 +1,5 @@
import { mdiClose } from "@mdi/js"; import { mdiClose } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
import "../../../../src/components/ha-header-bar"; import "../../../../src/components/ha-header-bar";
@@ -36,9 +36,9 @@ export class DialogHassioBackupUpload
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this._dialogParams) { if (!this._dialogParams) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,11 +1,9 @@
import { ActionDetail } from "@material/mwc-list"; import { ActionDetail } from "@material/mwc-list";
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { mdiClose, mdiDotsVertical } from "@mdi/js"; import { mdiClose, mdiDotsVertical } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { atLeastVersion } from "../../../../src/common/config/version";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
import { stopPropagation } from "../../../../src/common/dom/stop_propagation";
import { slugify } from "../../../../src/common/string/slugify"; import { slugify } from "../../../../src/common/string/slugify";
import "../../../../src/components/buttons/ha-progress-button"; import "../../../../src/components/buttons/ha-progress-button";
import "../../../../src/components/ha-alert"; import "../../../../src/components/ha-alert";
@@ -13,11 +11,11 @@ import "../../../../src/components/ha-button-menu";
import "../../../../src/components/ha-header-bar"; import "../../../../src/components/ha-header-bar";
import "../../../../src/components/ha-icon-button"; import "../../../../src/components/ha-icon-button";
import { getSignedPath } from "../../../../src/data/auth"; import { getSignedPath } from "../../../../src/data/auth";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { import {
fetchHassioBackupInfo, fetchHassioBackupInfo,
HassioBackupDetail, HassioBackupDetail,
} from "../../../../src/data/hassio/backup"; } from "../../../../src/data/hassio/backup";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { import {
showAlertDialog, showAlertDialog,
showConfirmationDialog, showConfirmationDialog,
@@ -29,6 +27,8 @@ import { fileDownload } from "../../../../src/util/file_download";
import "../../components/supervisor-backup-content"; import "../../components/supervisor-backup-content";
import type { SupervisorBackupContent } from "../../components/supervisor-backup-content"; import type { SupervisorBackupContent } from "../../components/supervisor-backup-content";
import { HassioBackupDialogParams } from "./show-dialog-hassio-backup"; import { HassioBackupDialogParams } from "./show-dialog-hassio-backup";
import { atLeastVersion } from "../../../../src/common/config/version";
import { stopPropagation } from "../../../../src/common/dom/stop_propagation";
@customElement("dialog-hassio-backup") @customElement("dialog-hassio-backup")
class HassioBackupDialog class HassioBackupDialog
@@ -62,9 +62,9 @@ class HassioBackupDialog
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this._dialogParams || !this._backup) { if (!this._dialogParams || !this._backup) {
return nothing; return html``;
} }
return html` return html`
<ha-dialog <ha-dialog

View File

@@ -1,15 +1,15 @@
import "@material/mwc-button"; import "@material/mwc-button";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
import "../../../../src/components/buttons/ha-progress-button";
import "../../../../src/components/ha-alert"; import "../../../../src/components/ha-alert";
import "../../../../src/components/buttons/ha-progress-button";
import { createCloseHeading } from "../../../../src/components/ha-dialog"; import { createCloseHeading } from "../../../../src/components/ha-dialog";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { import {
createHassioFullBackup, createHassioFullBackup,
createHassioPartialBackup, createHassioPartialBackup,
} from "../../../../src/data/hassio/backup"; } from "../../../../src/data/hassio/backup";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { showAlertDialog } from "../../../../src/dialogs/generic/show-dialog-box"; import { showAlertDialog } from "../../../../src/dialogs/generic/show-dialog-box";
import { haStyle, haStyleDialog } from "../../../../src/resources/styles"; import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
import { HomeAssistant } from "../../../../src/types"; import { HomeAssistant } from "../../../../src/types";
@@ -42,9 +42,9 @@ class HassioCreateBackupDialog extends LitElement {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this._dialogParams) { if (!this._dialogParams) {
return nothing; return html``;
} }
return html` return html`
<ha-dialog <ha-dialog

View File

@@ -1,5 +1,5 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
@@ -55,9 +55,9 @@ class HassioDatadiskDialog extends LitElement {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this.dialogParams) { if (!this.dialogParams) {
return nothing; return html``;
} }
return html` return html`
<ha-dialog <ha-dialog

8
hassio/src/dialogs/hardware/dialog-hassio-hardware.ts Normal file → Executable file
View File

@@ -1,13 +1,13 @@
import { mdiClose } from "@mdi/js"; import { mdiClose } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
import "../../../../src/components/search-input";
import { stringCompare } from "../../../../src/common/string/compare"; import { stringCompare } from "../../../../src/common/string/compare";
import "../../../../src/components/ha-dialog"; import "../../../../src/components/ha-dialog";
import "../../../../src/components/ha-expansion-panel"; import "../../../../src/components/ha-expansion-panel";
import "../../../../src/components/ha-icon-button"; import "../../../../src/components/ha-icon-button";
import "../../../../src/components/search-input";
import { HassioHardwareInfo } from "../../../../src/data/hassio/hardware"; import { HassioHardwareInfo } from "../../../../src/data/hassio/hardware";
import { dump } from "../../../../src/resources/js-yaml-dump"; import { dump } from "../../../../src/resources/js-yaml-dump";
import { haStyle, haStyleDialog } from "../../../../src/resources/styles"; import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
@@ -53,9 +53,9 @@ class HassioHardwareDialog extends LitElement {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this._dialogParams) { if (!this._dialogParams) {
return nothing; return html``;
} }
const devices = _filterDevices( const devices = _filterDevices(

View File

@@ -1,4 +1,4 @@
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { createCloseHeading } from "../../../../src/components/ha-dialog"; import { createCloseHeading } from "../../../../src/components/ha-dialog";
import "../../../../src/components/ha-markdown"; import "../../../../src/components/ha-markdown";
@@ -27,9 +27,9 @@ class HassioMarkdownDialog extends LitElement {
this._opened = false; this._opened = false;
} }
protected render() { protected render(): TemplateResult {
if (!this._opened) { if (!this._opened) {
return nothing; return html``;
} }
return html` return html`
<ha-dialog <ha-dialog

View File

@@ -5,7 +5,7 @@ import "@material/mwc-tab";
import "@material/mwc-tab-bar"; import "@material/mwc-tab-bar";
import { mdiClose } from "@mdi/js"; import { mdiClose } from "@mdi/js";
import { PaperInputElement } from "@polymer/paper-input/paper-input"; import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { cache } from "lit/directives/cache"; import { cache } from "lit/directives/cache";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
@@ -17,6 +17,7 @@ import "../../../../src/components/ha-formfield";
import "../../../../src/components/ha-header-bar"; import "../../../../src/components/ha-header-bar";
import "../../../../src/components/ha-icon-button"; import "../../../../src/components/ha-icon-button";
import "../../../../src/components/ha-radio"; import "../../../../src/components/ha-radio";
import "../../../../src/components/ha-related-items";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common"; import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { import {
AccessPoints, AccessPoints,
@@ -83,9 +84,9 @@ export class DialogHassioNetwork
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
protected render() { protected render(): TemplateResult {
if (!this._params || !this._interface) { if (!this._params || !this._interface) {
return nothing; return html``;
} }
return html` return html`
@@ -137,10 +138,7 @@ export class DialogHassioNetwork
)} )}
${this._interface?.type === "wireless" ${this._interface?.type === "wireless"
? html` ? html`
<ha-expansion-panel <ha-expansion-panel header="Wi-Fi" outlined>
.header=${this.supervisor.localize("dialog.network.wifi")}
outlined
>
${this._interface?.wifi?.ssid ${this._interface?.wifi?.ssid
? html`<p> ? html`<p>
${this.supervisor.localize( ${this.supervisor.localize(
@@ -179,11 +177,7 @@ export class DialogHassioNetwork
> >
<span>${ap.ssid}</span> <span>${ap.ssid}</span>
<span slot="secondary"> <span slot="secondary">
${ap.mac} - ${ap.mac} - Strength: ${ap.signal}
${this.supervisor.localize(
"dialog.network.signal_strength"
)}:
${ap.signal}
</span> </span>
</mwc-list-item> </mwc-list-item>
` `
@@ -247,9 +241,7 @@ export class DialogHassioNetwork
class="flex-auto" class="flex-auto"
type="password" type="password"
id="psk" id="psk"
.label=${this.supervisor.localize( label="Password"
"dialog.network.wifi_password"
)}
version="wifi" version="wifi"
@value-changed=${this @value-changed=${this
._handleInputValueChangedWifi} ._handleInputValueChangedWifi}

View File

@@ -1,11 +1,11 @@
import "@polymer/paper-tooltip/paper-tooltip";
import "@material/mwc-button/mwc-button"; import "@material/mwc-button/mwc-button";
import { mdiDelete, mdiDeleteOff } from "@mdi/js"; import { mdiDelete, mdiDeleteOff } from "@mdi/js";
import "@polymer/paper-input/paper-input"; import "@polymer/paper-input/paper-input";
import type { PaperInputElement } from "@polymer/paper-input/paper-input"; import type { PaperInputElement } from "@polymer/paper-input/paper-input";
import "@polymer/paper-item/paper-item"; import "@polymer/paper-item/paper-item";
import "@polymer/paper-item/paper-item-body"; import "@polymer/paper-item/paper-item-body";
import "@polymer/paper-tooltip/paper-tooltip"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
@@ -19,14 +19,14 @@ import {
HassioAddonRepository, HassioAddonRepository,
} from "../../../../src/data/hassio/addon"; } from "../../../../src/data/hassio/addon";
import { extractApiErrorMessage } from "../../../../src/data/hassio/common"; import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
import type { HomeAssistant } from "../../../../src/types";
import { HassioRepositoryDialogParams } from "./show-dialog-repositories";
import { import {
addStoreRepository, addStoreRepository,
fetchStoreRepositories, fetchStoreRepositories,
removeStoreRepository, removeStoreRepository,
} from "../../../../src/data/supervisor/store"; } from "../../../../src/data/supervisor/store";
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
import type { HomeAssistant } from "../../../../src/types";
import { HassioRepositoryDialogParams } from "./show-dialog-repositories";
@customElement("dialog-hassio-repositories") @customElement("dialog-hassio-repositories")
class HassioRepositoriesDialog extends LitElement { class HassioRepositoriesDialog extends LitElement {
@@ -82,9 +82,9 @@ class HassioRepositoriesDialog extends LitElement {
.map((repo) => repo.slug) .map((repo) => repo.slug)
); );
protected render() { protected render(): TemplateResult {
if (!this._dialogParams?.supervisor || this._repositories === undefined) { if (!this._dialogParams?.supervisor || this._repositories === undefined) {
return nothing; return html``;
} }
const repositories = this._filteredRepositories(this._repositories); const repositories = this._filteredRepositories(this._repositories);
const usedRepositories = this._filteredUsedRepositories( const usedRepositories = this._filteredUsedRepositories(

View File

@@ -1,5 +1,5 @@
import { sanitizeUrl } from "@braintree/sanitize-url"; import { sanitizeUrl } from "@braintree/sanitize-url";
import { html, LitElement, TemplateResult, nothing } from "lit"; import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { navigate } from "../../src/common/navigate"; import { navigate } from "../../src/common/navigate";
import { import {
@@ -101,13 +101,13 @@ class HassioMyRedirect extends LitElement {
navigate(url, { replace: true }); navigate(url, { replace: true });
} }
protected render() { protected render(): TemplateResult {
if (this._error) { if (this._error) {
return html`<hass-error-screen return html`<hass-error-screen
.error=${this._error} .error=${this._error}
></hass-error-screen>`; ></hass-error-screen>`;
} }
return nothing; return html``;
} }
private _createRedirectUrl(redirect: Redirect): string { private _createRedirectUrl(redirect: Redirect): string {

View File

@@ -5,7 +5,7 @@ import {
html, html,
LitElement, LitElement,
PropertyValues, PropertyValues,
nothing, TemplateResult,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
@@ -116,12 +116,12 @@ class UpdateAvailableCard extends LitElement {
storeAddons.find((addon) => addon.slug === slug) storeAddons.find((addon) => addon.slug === slug)
); );
protected render() { protected render(): TemplateResult {
if ( if (
!this._updateType || !this._updateType ||
(this._updateType === "addon" && !this._addonInfo) (this._updateType === "addon" && !this._addonInfo)
) { ) {
return nothing; return html``;
} }
const changelog = changelogUrl(this._updateType, this._version_latest); const changelog = changelogUrl(this._updateType, this._version_latest);

View File

@@ -5,5 +5,5 @@ module.exports = {
'printf "%s\n" "Translation files should not be added or modified here. Instead, make the necessary modifications in src/translations/en.json. Other languages are managed externally. Please see https://developers.home-assistant.io/docs/translations/ for details." ' + 'printf "%s\n" "Translation files should not be added or modified here. Instead, make the necessary modifications in src/translations/en.json. Other languages are managed externally. Please see https://developers.home-assistant.io/docs/translations/ for details." ' +
files.join(" ") + files.join(" ") +
" >&2 && exit 1", " >&2 && exit 1",
"yarn.lock": () => "yarn dedupe", "/yarn.lock": () => "yarn dedupe",
}; };

View File

@@ -24,26 +24,26 @@
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)", "author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@braintree/sanitize-url": "^6.0.2", "@braintree/sanitize-url": "^6.0.0",
"@codemirror/autocomplete": "^6.4.2", "@codemirror/autocomplete": "^6.4.0",
"@codemirror/commands": "^6.2.1", "@codemirror/commands": "^6.1.3",
"@codemirror/language": "^6.6.0", "@codemirror/language": "^6.4.0",
"@codemirror/legacy-modes": "^6.3.1", "@codemirror/legacy-modes": "^6.3.1",
"@codemirror/search": "^6.2.3", "@codemirror/search": "^6.2.3",
"@codemirror/state": "^6.2.0", "@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.1", "@codemirror/view": "^6.7.1",
"@egjs/hammerjs": "^2.0.17", "@formatjs/intl-datetimeformat": "^4.2.5",
"@formatjs/intl-datetimeformat": "^6.5.1", "@formatjs/intl-getcanonicallocales": "^2.0.5",
"@formatjs/intl-getcanonicallocales": "^2.1.0", "@formatjs/intl-locale": "^3.0.11",
"@formatjs/intl-locale": "^3.1.1", "@formatjs/intl-numberformat": "^7.2.5",
"@formatjs/intl-numberformat": "^8.3.5", "@formatjs/intl-pluralrules": "^4.1.5",
"@formatjs/intl-pluralrules": "^5.1.10", "@formatjs/intl-relativetimeformat": "^9.3.2",
"@formatjs/intl-relativetimeformat": "^11.1.10", "@fullcalendar/common": "5.9.0",
"@fullcalendar/core": "^6.1.4", "@fullcalendar/core": "5.9.0",
"@fullcalendar/daygrid": "^6.1.4", "@fullcalendar/daygrid": "5.9.0",
"@fullcalendar/interaction": "^6.1.4", "@fullcalendar/interaction": "5.9.0",
"@fullcalendar/list": "^6.1.4", "@fullcalendar/list": "5.9.0",
"@fullcalendar/timegrid": "^6.1.4", "@fullcalendar/timegrid": "5.9.0",
"@lezer/highlight": "^1.1.3", "@lezer/highlight": "^1.1.3",
"@lit-labs/motion": "^1.0.3", "@lit-labs/motion": "^1.0.3",
"@lit-labs/virtualizer": "^1.0.1", "@lit-labs/virtualizer": "^1.0.1",
@@ -71,7 +71,6 @@
"@material/mwc-textfield": "^0.27.0", "@material/mwc-textfield": "^0.27.0",
"@material/mwc-top-app-bar-fixed": "^0.27.0", "@material/mwc-top-app-bar-fixed": "^0.27.0",
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0", "@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
"@material/web": "=1.0.0-pre.3",
"@mdi/js": "7.1.96", "@mdi/js": "7.1.96",
"@mdi/svg": "7.1.96", "@mdi/svg": "7.1.96",
"@polymer/app-layout": "^3.1.0", "@polymer/app-layout": "^3.1.0",
@@ -89,55 +88,55 @@
"@polymer/paper-tooltip": "^3.0.1", "@polymer/paper-tooltip": "^3.0.1",
"@polymer/polymer": "3.4.1", "@polymer/polymer": "3.4.1",
"@thomasloven/round-slider": "0.6.0", "@thomasloven/round-slider": "0.6.0",
"@vaadin/combo-box": "^23.3.7", "@vaadin/combo-box": "^23.3.5",
"@vaadin/vaadin-themable-mixin": "^23.3.7", "@vaadin/vaadin-themable-mixin": "^23.3.5",
"@vibrant/color": "^3.2.1-alpha.1", "@vibrant/color": "^3.2.1-alpha.1",
"@vibrant/core": "^3.2.1-alpha.1", "@vibrant/core": "^3.2.1-alpha.1",
"@vibrant/quantizer-mmcq": "^3.2.1-alpha.1", "@vibrant/quantizer-mmcq": "^3.2.1-alpha.1",
"@vue/web-component-wrapper": "^1.3.0", "@vue/web-component-wrapper": "^1.3.0",
"@webcomponents/scoped-custom-element-registry": "^0.0.8", "@webcomponents/scoped-custom-element-registry": "^0.0.5",
"@webcomponents/webcomponentsjs": "^2.7.0", "@webcomponents/webcomponentsjs": "^2.2.10",
"app-datepicker": "^5.1.0", "app-datepicker": "^5.1.0",
"chart.js": "^3.3.2", "chart.js": "^3.3.2",
"comlink": "^4.4.1", "comlink": "^4.3.1",
"core-js": "^3.29.0", "core-js": "^3.15.2",
"cropperjs": "^1.5.13", "cropperjs": "^1.5.13",
"date-fns": "^2.29.3", "date-fns": "^2.29.3",
"date-fns-tz": "^2.0.0", "date-fns-tz": "^1.3.7",
"deep-clone-simple": "^1.1.1", "deep-clone-simple": "^1.1.1",
"deep-freeze": "^0.0.1", "deep-freeze": "^0.0.1",
"fuse.js": "^6.6.2", "fuse.js": "^6.6.2",
"google-timezones-json": "^1.0.2", "google-timezones-json": "^1.0.2",
"hls.js": "^1.3.4", "hammerjs": "^2.0.8",
"hls.js": "^1.3.1",
"home-assistant-js-websocket": "^8.0.1", "home-assistant-js-websocket": "^8.0.1",
"idb-keyval": "^6.2.0", "idb-keyval": "^5.1.3",
"intl-messageformat": "^10.3.1", "intl-messageformat": "^10.2.5",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"leaflet": "^1.9.3", "leaflet": "^1.7.1",
"leaflet-draw": "^1.0.4", "leaflet-draw": "^1.0.4",
"lit": "^2.6.1", "lit": "^2.6.1",
"marked": "^4.2.12", "marked": "^4.0.12",
"memoize-one": "^6.0.0", "memoize-one": "^6.0.0",
"node-vibrant": "3.2.1-alpha.1", "node-vibrant": "3.2.1-alpha.1",
"proxy-polyfill": "^0.3.2", "proxy-polyfill": "^0.3.2",
"punycode": "^2.3.0", "punycode": "^2.3.0",
"qr-scanner": "^1.4.2", "qr-scanner": "^1.3.0",
"qrcode": "^1.5.1", "qrcode": "^1.5.1",
"regenerator-runtime": "^0.13.11", "regenerator-runtime": "^0.13.11",
"resize-observer-polyfill": "^1.5.1", "resize-observer-polyfill": "^1.5.1",
"roboto-fontface": "^0.10.0", "roboto-fontface": "^0.10.0",
"rrule": "^2.7.2", "rrule": "^2.7.1",
"sortablejs": "^1.15.0", "sortablejs": "^1.14.0",
"superstruct": "^1.0.3", "superstruct": "^1.0.3",
"tinykeys": "^1.4.0", "tinykeys": "^1.1.3",
"tsparticles-engine": "^2.9.3", "tsparticles": "^1.34.0",
"tsparticles-preset-links": "^2.9.3", "unfetch": "^4.1.0",
"unfetch": "^5.0.0", "vis-data": "^7.1.2",
"vis-data": "^7.1.4", "vis-network": "^8.5.4",
"vis-network": "^9.1.4", "vue": "^2.6.12",
"vue": "^2.7.14", "vue2-daterange-picker": "^0.5.1",
"vue2-daterange-picker": "^0.6.8", "weekstart": "^1.1.0",
"weekstart": "^2.0.0",
"workbox-cacheable-response": "^6.5.4", "workbox-cacheable-response": "^6.5.4",
"workbox-core": "^6.5.4", "workbox-core": "^6.5.4",
"workbox-expiration": "^6.5.4", "workbox-expiration": "^6.5.4",
@@ -147,110 +146,107 @@
"xss": "^1.0.14" "xss": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.21.0", "@babel/core": "^7.20.2",
"@babel/plugin-external-helpers": "^7.18.6", "@babel/plugin-external-helpers": "^7.18.6",
"@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.21.0", "@babel/plugin-proposal-decorators": "^7.20.7",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7", "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
"@babel/plugin-proposal-optional-chaining": "^7.21.0", "@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-syntax-top-level-await": "^7.14.5", "@babel/plugin-syntax-top-level-await": "^7.14.5",
"@babel/preset-env": "^7.20.2", "@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0", "@babel/preset-typescript": "^7.18.6",
"@koa/cors": "^4.0.0", "@koa/cors": "^3.1.0",
"@octokit/auth-oauth-device": "^4.0.4", "@octokit/auth-oauth-device": "^4.0.2",
"@octokit/rest": "^19.0.7", "@octokit/rest": "^19.0.7",
"@open-wc/dev-server-hmr": "^0.1.3", "@open-wc/dev-server-hmr": "^0.0.2",
"@rollup/plugin-babel": "^5.2.1", "@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.0.3", "@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2", "@rollup/plugin-replace": "^2.3.2",
"@types/chromecast-caf-receiver": "5.0.12", "@types/chromecast-caf-receiver": "5.0.12",
"@types/chromecast-caf-sender": "^1.0.5", "@types/chromecast-caf-sender": "^1.0.3",
"@types/esprima": "^4",
"@types/glob": "^8", "@types/glob": "^8",
"@types/hammerjs": "^2.0.41",
"@types/js-yaml": "^4", "@types/js-yaml": "^4",
"@types/leaflet": "^1", "@types/leaflet": "^1",
"@types/leaflet-draw": "^1", "@types/leaflet-draw": "^1",
"@types/marked": "^4", "@types/marked": "^4",
"@types/mocha": "^10", "@types/mocha": "^8",
"@types/qrcode": "^1.5.0", "@types/qrcode": "^1.5.0",
"@types/serve-handler": "^6",
"@types/sortablejs": "^1", "@types/sortablejs": "^1",
"@types/tar": "^6", "@types/tar": "^6",
"@types/webspeechapi": "^0.0.29", "@types/webspeechapi": "^0.0.29",
"@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^5.49.0",
"@web/dev-server": "^0.1.35", "@web/dev-server": "^0.0.24",
"@web/dev-server-rollup": "^0.2.11", "@web/dev-server-rollup": "^0.2.11",
"babel-loader": "^9.1.2", "babel-loader": "^9.1.0",
"babel-plugin-template-html-minifier": "^4.1.0", "chai": "^4.3.4",
"chai": "^4.3.7",
"del": "^7.0.0", "del": "^7.0.0",
"eslint": "^8.35.0", "eslint": "^7.32.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-airbnb-typescript": "^14.0.0",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",
"eslint-import-resolver-webpack": "^0.13.2", "eslint-import-resolver-webpack": "^0.13.1",
"eslint-plugin-disable": "^2.0.3", "eslint-plugin-disable": "^2.0.1",
"eslint-plugin-import": "^2.27.5", "eslint-plugin-import": "^2.24.2",
"eslint-plugin-lit": "^1.8.2", "eslint-plugin-lit": "^1.6.1",
"eslint-plugin-lit-a11y": "^2.3.0", "eslint-plugin-unused-imports": "^1.1.5",
"eslint-plugin-unused-imports": "^2.0.0",
"eslint-plugin-wc": "^1.4.0", "eslint-plugin-wc": "^1.4.0",
"esprima": "^4.0.1",
"fancy-log": "^2.0.0", "fancy-log": "^2.0.0",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"glob": "^8.1.0", "glob": "^8.1.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-flatmap": "^1.0.2", "gulp-flatmap": "^1.0.2",
"gulp-json-transform": "^0.4.8", "gulp-json-transform": "^0.4.6",
"gulp-merge-json": "^2.1.2", "gulp-merge-json": "^2.1.2",
"gulp-rename": "^2.0.0", "gulp-rename": "^2.0.0",
"gulp-zopfli-green": "^6.0.1", "gulp-zopfli-green": "^3.0.1",
"html-minifier": "^4.0.0", "html-minifier": "^4.0.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"instant-mocha": "^1.5.0", "instant-mocha": "^1.3.1",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"lint-staged": "^13.1.2", "lint-staged": "^13.1.0",
"lit-analyzer": "^1.2.1", "lit-analyzer": "^1.2.1",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"magic-string": "^0.30.0", "magic-string": "^0.25.7",
"map-stream": "^0.0.7", "map-stream": "^0.0.7",
"merge-stream": "^2.0.0", "merge-stream": "^1.0.1",
"mocha": "^10.2.0", "mocha": "^8.4.0",
"object-hash": "^3.0.0", "object-hash": "^3.0.0",
"open": "^8.4.1", "open": "^8.4.0",
"pinst": "^3.0.0", "pinst": "^3.0.0",
"prettier": "^2.8.4", "prettier": "^2.8.3",
"require-dir": "^1.2.0", "require-dir": "^1.2.0",
"rollup": "^2.8.2", "rollup": "^2.8.2",
"rollup-plugin-string": "^3.0.0", "rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^5.3.0", "rollup-plugin-terser": "^5.3.0",
"rollup-plugin-visualizer": "^5.9.0", "rollup-plugin-visualizer": "^5.9.0",
"serve-handler": "^6.1.5", "serve": "^11.3.2",
"sinon": "^15.0.1", "sinon": "^15.0.1",
"source-map-url": "^0.4.1", "source-map-url": "^0.4.0",
"systemjs": "^6.14.0", "systemjs": "^6.3.2",
"tar": "^6.1.13", "tar": "^6.1.11",
"terser-webpack-plugin": "^5.3.6", "terser-webpack-plugin": "^5.2.4",
"ts-lit-plugin": "^1.2.1", "ts-lit-plugin": "^1.2.1",
"typescript": "^4.9.5", "typescript": "^4.9.4",
"vinyl-buffer": "^1.0.1", "vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0", "vinyl-source-stream": "^2.0.0",
"webpack": "=5.72.1", "webpack": "^5.55.1",
"webpack-cli": "^5.0.1", "webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1", "webpack-dev-server": "^4.11.1",
"webpack-manifest-plugin": "^5.0.0", "webpack-manifest-plugin": "^4.0.2",
"webpackbar": "^5.0.2", "webpackbar": "^5.0.2",
"workbox-build": "^6.5.4" "workbox-build": "^6.5.4"
}, },
"_comment": "Polymer 3.2 contained a bug, fixed in https://github.com/Polymer/polymer/pull/5569, add as patch", "_comment": "Polymer 3.2 contained a bug, fixed in https://github.com/Polymer/polymer/pull/5569, add as patch",
"resolutions": { "resolutions": {
"@polymer/polymer": "patch:@polymer/polymer@3.4.1#./.yarn/patches/@polymer/polymer/pr-5569.patch" "@polymer/polymer": "patch:@polymer/polymer@3.4.1#./.yarn/patches/@polymer/polymer/pr-5569.patch",
"@webcomponents/webcomponentsjs": "^2.2.10"
}, },
"main": "src/home-assistant.js", "main": "src/home-assistant.js",
"prettier": { "prettier": {

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "home-assistant-frontend" name = "home-assistant-frontend"
version = "20230302.0" version = "20230128.0"
license = {text = "Apache-2.0"} license = {text = "Apache-2.0"}
description = "The Home Assistant frontend" description = "The Home Assistant frontend"
readme = "README.md" readme = "README.md"

View File

@@ -6,9 +6,6 @@ set -e
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
export STATS=1 STATS=1 NODE_ENV=production ./node_modules/.bin/webpack --profile --json > compilation-stats.json
statsfile="compilation-stats.json" npx webpack-bundle-analyzer compilation-stats.json hass_frontend/frontend_latest
rm compilation-stats.json
./node_modules/.bin/webpack-cli --profile --node-env=production --json=$statsfile
npx webpack-bundle-analyzer $statsfile hass_frontend/frontend_latest
rm -f $statsfile

View File

@@ -5,10 +5,10 @@ import {
CSSResultGroup, CSSResultGroup,
html, html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
TemplateResult,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import "../components/ha-alert"; import "../components/ha-alert";
import "../components/ha-checkbox"; import "../components/ha-checkbox";
import { computeInitialHaFormData } from "../components/ha-form/compute-initial-ha-form-data"; import { computeInitialHaFormData } from "../components/ha-form/compute-initial-ha-form-data";
@@ -25,8 +25,7 @@ import "./ha-password-manager-polyfill";
type State = "loading" | "error" | "step"; type State = "loading" | "error" | "step";
@customElement("ha-auth-flow") class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
@property({ attribute: false }) public authProvider?: AuthProvider; @property({ attribute: false }) public authProvider?: AuthProvider;
@property() public clientId?: string; @property() public clientId?: string;
@@ -134,11 +133,11 @@ export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
}, 500); }, 500);
} }
private _renderForm() { private _renderForm(): TemplateResult {
switch (this._state) { switch (this._state) {
case "step": case "step":
if (this._step == null) { if (this._step == null) {
return nothing; return html``;
} }
return html` return html`
${this._renderStep(this._step)} ${this._renderStep(this._step)}
@@ -176,11 +175,11 @@ export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
</ha-alert> </ha-alert>
`; `;
default: default:
return nothing; return html``;
} }
} }
private _renderStep(step: DataEntryFlowStep) { private _renderStep(step: DataEntryFlowStep): TemplateResult {
switch (step.type) { switch (step.type) {
case "abort": case "abort":
return html` return html`
@@ -202,7 +201,7 @@ export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
.content=${this._computeStepDescription(step)} .content=${this._computeStepDescription(step)}
></ha-markdown> ></ha-markdown>
` `
: nothing} : html``}
<ha-form <ha-form
.data=${this._stepData} .data=${this._stepData}
.schema=${autocompleteLoginFields(step.data_schema)} .schema=${autocompleteLoginFields(step.data_schema)}
@@ -228,7 +227,7 @@ export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
: ""} : ""}
`; `;
default: default:
return nothing; return html``;
} }
} }
@@ -408,6 +407,7 @@ export class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
`; `;
} }
} }
customElements.define("ha-auth-flow", HaAuthFlow);
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {

View File

@@ -1,5 +1,5 @@
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit"; import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import punycode from "punycode"; import punycode from "punycode";
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element"; import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
import { extractSearchParamsObject } from "../common/url/search-params"; import { extractSearchParamsObject } from "../common/url/search-params";
@@ -14,8 +14,7 @@ import "./ha-auth-flow";
import("./ha-pick-auth-provider"); import("./ha-pick-auth-provider");
@customElement("ha-authorize") class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
@property() public clientId?: string; @property() public clientId?: string;
@property() public redirectUri?: string; @property() public redirectUri?: string;
@@ -184,3 +183,4 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
`; `;
} }
} }
customElements.define("ha-authorize", HaAuthorize);

View File

@@ -1,6 +1,6 @@
import { css, html, LitElement, nothing } from "lit"; /* eslint-disable lit/prefer-static-styles */
import { html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import type { HaFormSchema } from "../components/ha-form/types"; import type { HaFormSchema } from "../components/ha-form/types";
import { autocompleteLoginFields } from "../data/auth"; import { autocompleteLoginFields } from "../data/auth";
@@ -29,43 +29,35 @@ export class HaPasswordManagerPolyfill extends LitElement {
@property({ attribute: false }) public boundingRect?: DOMRect; @property({ attribute: false }) public boundingRect?: DOMRect;
private _styleElement?: HTMLStyleElement;
public connectedCallback() {
super.connectedCallback();
this._styleElement = document.createElement("style");
this._styleElement.textContent = css`
.password-manager-polyfill {
position: absolute;
opacity: 0;
z-index: -1;
}
.password-manager-polyfill input {
width: 100%;
height: 62px;
padding: 0;
border: 0;
}
.password-manager-polyfill input[type="submit"] {
width: 0;
height: 0;
}
`.toString();
document.head.append(this._styleElement);
}
public disconnectedCallback() {
super.disconnectedCallback();
this._styleElement?.remove();
delete this._styleElement;
}
protected createRenderRoot() { protected createRenderRoot() {
// Add under document body so the element isn't placed inside any shadow roots // Add under document body so the element isn't placed inside any shadow roots
return document.body; return document.body;
} }
protected render() { private get styles() {
return `
.password-manager-polyfill {
position: absolute;
top: ${this.boundingRect?.y || 148}px;
left: calc(50% - ${(this.boundingRect?.width || 360) / 2}px);
width: ${this.boundingRect?.width || 360}px;
opacity: 0;
z-index: -1;
}
.password-manager-polyfill input {
width: 100%;
height: 62px;
padding: 0;
border: 0;
}
.password-manager-polyfill input[type="submit"] {
width: 0;
height: 0;
}
`;
}
protected render(): TemplateResult {
if ( if (
this.step && this.step &&
this.step.type === "form" && this.step.type === "form" &&
@@ -75,11 +67,6 @@ export class HaPasswordManagerPolyfill extends LitElement {
return html` return html`
<form <form
class="password-manager-polyfill" class="password-manager-polyfill"
style=${styleMap({
top: `${this.boundingRect?.y || 148}px`,
left: `calc(50% - ${(this.boundingRect?.width || 360) / 2}px)`,
width: `${this.boundingRect?.width || 360}px`,
})}
aria-hidden="true" aria-hidden="true"
@submit=${this._handleSubmit} @submit=${this._handleSubmit}
> >
@@ -87,13 +74,16 @@ export class HaPasswordManagerPolyfill extends LitElement {
this.render_input(input) this.render_input(input)
)} )}
<input type="submit" /> <input type="submit" />
<style>
${this.styles}
</style>
</form> </form>
`; `;
} }
return nothing; return html``;
} }
private render_input(schema: HaFormSchema) { private render_input(schema: HaFormSchema): TemplateResult | string {
const inputType = schema.name.includes("password") ? "password" : "text"; const inputType = schema.name.includes("password") ? "password" : "text";
if (schema.type !== "string") { if (schema.type !== "string") {
return ""; return "";

View File

@@ -1,7 +1,7 @@
import "@polymer/paper-item/paper-item"; import "@polymer/paper-item/paper-item";
import "@polymer/paper-item/paper-item-body"; import "@polymer/paper-item/paper-item-body";
import { css, html, LitElement } from "lit"; import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators"; import { property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import "../components/ha-icon-next"; import "../components/ha-icon-next";
import { AuthProvider } from "../data/auth"; import { AuthProvider } from "../data/auth";
@@ -13,8 +13,7 @@ declare global {
} }
} }
@customElement("ha-pick-auth-provider") class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
export class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
@property() public authProviders: AuthProvider[] = []; @property() public authProviders: AuthProvider[] = [];
protected render() { protected render() {
@@ -48,3 +47,4 @@ export class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
} }
`; `;
} }
customElements.define("ha-pick-auth-provider", HaPickAuthProvider);

View File

@@ -2,7 +2,6 @@ type NonUndefined<T> = T extends undefined ? never : T;
export function ensureArray(value: undefined): undefined; export function ensureArray(value: undefined): undefined;
export function ensureArray<T>(value: T | T[]): NonUndefined<T>[]; export function ensureArray<T>(value: T | T[]): NonUndefined<T>[];
export function ensureArray<T>(value: T | readonly T[]): NonUndefined<T>[];
export function ensureArray(value) { export function ensureArray(value) {
if (value === undefined || Array.isArray(value)) { if (value === undefined || Array.isArray(value)) {
return value; return value;

View File

@@ -22,11 +22,3 @@ export const atLeastVersion = (
Number(haPatch) >= patch) Number(haPatch) >= patch)
); );
}; };
export const isDevVersion = (version: string): boolean => {
if (__DEMO__) {
return false;
}
return version.includes("dev");
};

View File

@@ -1,6 +1,7 @@
/** Constants to be used in the frontend. */ /** Constants to be used in the frontend. */
import { import {
mdiAccount,
mdiAirFilter, mdiAirFilter,
mdiAlert, mdiAlert,
mdiAngleAcute, mdiAngleAcute,
@@ -23,6 +24,7 @@ import {
mdiDatabase, mdiDatabase,
mdiEarHearing, mdiEarHearing,
mdiEye, mdiEye,
mdiFan,
mdiFlash, mdiFlash,
mdiFlower, mdiFlower,
mdiFormatListBulleted, mdiFormatListBulleted,
@@ -47,6 +49,7 @@ import {
mdiProgressClock, mdiProgressClock,
mdiRayVertex, mdiRayVertex,
mdiRemote, mdiRemote,
mdiRobot,
mdiRobotVacuum, mdiRobotVacuum,
mdiScriptText, mdiScriptText,
mdiSineWave, mdiSineWave,
@@ -57,12 +60,15 @@ import {
mdiThermostat, mdiThermostat,
mdiTimerOutline, mdiTimerOutline,
mdiTransmissionTower, mdiTransmissionTower,
mdiVideo,
mdiWater, mdiWater,
mdiWaterPercent, mdiWaterPercent,
mdiWeatherCloudy,
mdiWeatherPouring, mdiWeatherPouring,
mdiWeatherRainy, mdiWeatherRainy,
mdiWeatherWindy, mdiWeatherWindy,
mdiWeight, mdiWeight,
mdiWhiteBalanceSunny,
mdiWifi, mdiWifi,
} from "@mdi/js"; } from "@mdi/js";
@@ -77,12 +83,15 @@ export const DEFAULT_DOMAIN_ICON = mdiBookmark;
export const FIXED_DOMAIN_ICONS = { export const FIXED_DOMAIN_ICONS = {
alert: mdiAlert, alert: mdiAlert,
air_quality: mdiAirFilter, air_quality: mdiAirFilter,
automation: mdiRobot,
calendar: mdiCalendar, calendar: mdiCalendar,
camera: mdiVideo,
climate: mdiThermostat, climate: mdiThermostat,
configurator: mdiCog, configurator: mdiCog,
conversation: mdiMicrophoneMessage, conversation: mdiMicrophoneMessage,
counter: mdiCounter, counter: mdiCounter,
demo: mdiHomeAssistant, demo: mdiHomeAssistant,
fan: mdiFan,
google_assistant: mdiGoogleAssistant, google_assistant: mdiGoogleAssistant,
group: mdiGoogleCirclesCommunities, group: mdiGoogleCirclesCommunities,
homeassistant: mdiHomeAssistant, homeassistant: mdiHomeAssistant,
@@ -98,6 +107,7 @@ export const FIXED_DOMAIN_ICONS = {
notify: mdiCommentAlert, notify: mdiCommentAlert,
number: mdiRayVertex, number: mdiRayVertex,
persistent_notification: mdiBell, persistent_notification: mdiBell,
person: mdiAccount,
plant: mdiFlower, plant: mdiFlower,
proximity: mdiAppleSafari, proximity: mdiAppleSafari,
remote: mdiRemote, remote: mdiRemote,
@@ -108,10 +118,13 @@ export const FIXED_DOMAIN_ICONS = {
sensor: mdiEye, sensor: mdiEye,
siren: mdiBullhorn, siren: mdiBullhorn,
simple_alarm: mdiBell, simple_alarm: mdiBell,
sun: mdiWhiteBalanceSunny,
text: mdiFormTextbox, text: mdiFormTextbox,
timer: mdiTimerOutline, timer: mdiTimerOutline,
updater: mdiCloudUpload, updater: mdiCloudUpload,
vacuum: mdiRobotVacuum, vacuum: mdiRobotVacuum,
water_heater: mdiThermometer,
weather: mdiWeatherCloudy,
zone: mdiMapMarkerRadius, zone: mdiMapMarkerRadius,
}; };

View File

@@ -10,19 +10,11 @@ export const createDurationData = (
if (typeof duration !== "object") { if (typeof duration !== "object") {
if (typeof duration === "string" || isNaN(duration)) { if (typeof duration === "string" || isNaN(duration)) {
const parts = duration?.toString().split(":") || []; const parts = duration?.toString().split(":") || [];
if (parts.length === 1) {
return { seconds: Number(parts[0]) };
}
if (parts.length > 3) {
return undefined;
}
const seconds = Number(parts[2]) || 0;
const seconds_whole = Math.floor(seconds);
return { return {
hours: Number(parts[0]) || 0, hours: Number(parts[0]) || 0,
minutes: Number(parts[1]) || 0, minutes: Number(parts[1]) || 0,
seconds: seconds_whole, seconds: Number(parts[2]) || 0,
milliseconds: Math.floor((seconds - seconds_whole) * 1000), milliseconds: Number(parts[3]) || 0,
}; };
} }
return { seconds: duration }; return { seconds: duration };

View File

@@ -1,12 +1,6 @@
import { getWeekStartByLocale } from "weekstart"; import { getWeekStartByLocale } from "weekstart";
import { FrontendLocaleData, FirstWeekday } from "../../data/translation"; import { FrontendLocaleData, FirstWeekday } from "../../data/translation";
import { polyfillsLoaded } from "../translations/localize";
if (__BUILD__ === "latest" && polyfillsLoaded) {
await polyfillsLoaded;
}
export const weekdays = [ export const weekdays = [
"sunday", "sunday",
"monday", "monday",

View File

@@ -11,7 +11,8 @@ export const setupLeafletMap = async (
throw new Error("Cannot setup Leaflet map on disconnected element"); throw new Error("Cannot setup Leaflet map on disconnected element");
} }
// eslint-disable-next-line // eslint-disable-next-line
const Leaflet = (await import("leaflet")).default as LeafletModuleType; const Leaflet = ((await import("leaflet")) as any)
.default as LeafletModuleType;
Leaflet.Icon.Default.imagePath = "/static/images/leaflet/images/"; Leaflet.Icon.Default.imagePath = "/static/images/leaflet/images/";
const map = Leaflet.map(mapElement); const map = Leaflet.map(mapElement);

View File

@@ -1,5 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { EntityRegistryDisplayEntry } from "../../data/entity_registry"; import { EntityRegistryEntry } from "../../data/entity_registry";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import { LocalizeFunc } from "../translations/localize"; import { LocalizeFunc } from "../translations/localize";
import { computeDomain } from "./compute_domain"; import { computeDomain } from "./compute_domain";
@@ -15,7 +15,7 @@ export const computeAttributeValueDisplay = (
const attributeValue = const attributeValue =
value !== undefined ? value : stateObj.attributes[attribute]; value !== undefined ? value : stateObj.attributes[attribute];
const domain = computeDomain(entityId); const domain = computeDomain(entityId);
const entity = entities[entityId] as EntityRegistryDisplayEntry | undefined; const entity = entities[entityId] as EntityRegistryEntry | undefined;
const translationKey = entity?.translation_key; const translationKey = entity?.translation_key;
return ( return (
@@ -38,7 +38,7 @@ export const computeAttributeNameDisplay = (
): string => { ): string => {
const entityId = stateObj.entity_id; const entityId = stateObj.entity_id;
const domain = computeDomain(entityId); const domain = computeDomain(entityId);
const entity = entities[entityId] as EntityRegistryDisplayEntry | undefined; const entity = entities[entityId] as EntityRegistryEntry | undefined;
const translationKey = entity?.translation_key; const translationKey = entity?.translation_key;
return ( return (

View File

@@ -1,6 +1,6 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity"; import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { EntityRegistryDisplayEntry } from "../../data/entity_registry"; import { EntityRegistryEntry } from "../../data/entity_registry";
import { FrontendLocaleData } from "../../data/translation"; import { FrontendLocaleData } from "../../data/translation";
import { import {
updateIsInstallingFromAttributes, updateIsInstallingFromAttributes,
@@ -49,8 +49,6 @@ export const computeStateDisplayFromEntityAttributes = (
return localize(`state.default.${state}`); return localize(`state.default.${state}`);
} }
const entity = entities[entityId] as EntityRegistryDisplayEntry | undefined;
// Entities with a `unit_of_measurement` or `state_class` are numeric values and should use `formatNumber` // Entities with a `unit_of_measurement` or `state_class` are numeric values and should use `formatNumber`
if (isNumericFromAttributes(attributes)) { if (isNumericFromAttributes(attributes)) {
// state is duration // state is duration
@@ -84,7 +82,7 @@ export const computeStateDisplayFromEntityAttributes = (
return `${formatNumber( return `${formatNumber(
state, state,
locale, locale,
getNumberFormatOptions({ state, attributes } as HassEntity, entity) getNumberFormatOptions({ state, attributes } as HassEntity)
)}${unit}`; )}${unit}`;
} }
@@ -162,7 +160,7 @@ export const computeStateDisplayFromEntityAttributes = (
return formatNumber( return formatNumber(
state, state,
locale, locale,
getNumberFormatOptions({ state, attributes } as HassEntity, entity) getNumberFormatOptions({ state, attributes } as HassEntity)
); );
} }
@@ -201,6 +199,8 @@ export const computeStateDisplayFromEntityAttributes = (
: localize("ui.card.update.up_to_date"); : localize("ui.card.update.up_to_date");
} }
const entity = entities[entityId] as EntityRegistryEntry | undefined;
return ( return (
(entity?.translation_key && (entity?.translation_key &&
localize( localize(

View File

@@ -15,8 +15,6 @@ import {
mdiCheckCircleOutline, mdiCheckCircleOutline,
mdiClock, mdiClock,
mdiCloseCircleOutline, mdiCloseCircleOutline,
mdiFan,
mdiFanOff,
mdiGestureTapButton, mdiGestureTapButton,
mdiLanConnect, mdiLanConnect,
mdiLanDisconnect, mdiLanDisconnect,
@@ -30,8 +28,6 @@ import {
mdiPowerPlug, mdiPowerPlug,
mdiPowerPlugOff, mdiPowerPlugOff,
mdiRestart, mdiRestart,
mdiRobot,
mdiRobotOff,
mdiSpeaker, mdiSpeaker,
mdiSpeakerOff, mdiSpeakerOff,
mdiSpeakerPause, mdiSpeakerPause,
@@ -43,12 +39,7 @@ import {
mdiTelevisionPlay, mdiTelevisionPlay,
mdiToggleSwitchVariant, mdiToggleSwitchVariant,
mdiToggleSwitchVariantOff, mdiToggleSwitchVariantOff,
mdiVideo,
mdiVideoOff,
mdiWaterBoiler,
mdiWaterBoilerOff,
mdiWeatherNight, mdiWeatherNight,
mdiWhiteBalanceSunny,
} from "@mdi/js"; } from "@mdi/js";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { UpdateEntity, updateIsInstalling } from "../../data/update"; import { UpdateEntity, updateIsInstalling } from "../../data/update";
@@ -90,9 +81,6 @@ export const domainIconWithoutDefault = (
case "alarm_control_panel": case "alarm_control_panel":
return alarmPanelIcon(compareState); return alarmPanelIcon(compareState);
case "automation":
return compareState === "off" ? mdiRobotOff : mdiRobot;
case "binary_sensor": case "binary_sensor":
return binarySensorIcon(compareState, stateObj); return binarySensorIcon(compareState, stateObj);
@@ -106,9 +94,6 @@ export const domainIconWithoutDefault = (
return mdiGestureTapButton; return mdiGestureTapButton;
} }
case "camera":
return compareState === "off" ? mdiVideoOff : mdiVideo;
case "cover": case "cover":
return coverIcon(compareState, stateObj); return coverIcon(compareState, stateObj);
@@ -123,9 +108,6 @@ export const domainIconWithoutDefault = (
} }
return compareState === "not_home" ? mdiAccountArrowRight : mdiAccount; return compareState === "not_home" ? mdiAccountArrowRight : mdiAccount;
case "fan":
return compareState === "off" ? mdiFanOff : mdiFan;
case "humidifier": case "humidifier":
return compareState === "off" ? mdiAirHumidifierOff : mdiAirHumidifier; return compareState === "off" ? mdiAirHumidifierOff : mdiAirHumidifier;
@@ -234,7 +216,7 @@ export const domainIconWithoutDefault = (
case "sun": case "sun":
return stateObj?.state === "above_horizon" return stateObj?.state === "above_horizon"
? mdiWhiteBalanceSunny ? FIXED_DOMAIN_ICONS[domain]
: mdiWeatherNight; : mdiWeatherNight;
case "switch_as_x": case "switch_as_x":
@@ -250,9 +232,6 @@ export const domainIconWithoutDefault = (
: mdiPackageUp : mdiPackageUp
: mdiPackage; : mdiPackage;
case "water_heater":
return compareState === "off" ? mdiWaterBoilerOff : mdiWaterBoiler;
case "weather": case "weather":
return weatherIcon(stateObj?.state); return weatherIcon(stateObj?.state);
} }

View File

@@ -4,15 +4,12 @@ import { domainToName } from "../../data/integration";
import { getIntegrationDescriptions } from "../../data/integrations"; import { getIntegrationDescriptions } from "../../data/integrations";
import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow"; import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow";
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box"; import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import { showMatterAddDeviceDialog } from "../../panels/config/integrations/integration-panels/matter/show-dialog-add-matter-device";
import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node"; import { showZWaveJSAddNodeDialog } from "../../panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-add-node";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import { documentationUrl } from "../../util/documentation-url"; import { documentationUrl } from "../../util/documentation-url";
import { isComponentLoaded } from "../config/is_component_loaded"; import { isComponentLoaded } from "../config/is_component_loaded";
import { navigate } from "../navigate"; import { navigate } from "../navigate";
export const PROTOCOL_INTEGRATIONS = ["zha", "zwave_js", "matter"] as const;
export const protocolIntegrationPicked = async ( export const protocolIntegrationPicked = async (
element: HTMLElement, element: HTMLElement,
hass: HomeAssistant, hass: HomeAssistant,
@@ -116,43 +113,5 @@ export const protocolIntegrationPicked = async (
} }
navigate("/config/zha/add"); navigate("/config/zha/add");
} else if (domain === "matter") {
const entries = await getConfigEntries(hass, {
domain,
});
if (!isComponentLoaded(hass, domain) || !entries.length) {
// If the component isn't loaded, ask them to load the integration first
showConfirmationDialog(element, {
title: hass.localize(
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee_title",
{ integration: "Matter" }
),
text: hass.localize(
"ui.panel.config.integrations.config_flow.missing_matter",
{
integration: "Matter",
brand: options?.brand || options?.domain || "Matter",
supported_hardware_link: html`<a
href=${documentationUrl(hass, "/integrations/matter")}
target="_blank"
rel="noreferrer"
>${hass.localize(
"ui.panel.config.integrations.config_flow.supported_hardware"
)}</a
>`,
}
),
confirmText: hass.localize(
"ui.panel.config.integrations.config_flow.proceed"
),
confirm: () => {
showConfigFlowDialog(element, {
startFlowHandler: "matter",
});
},
});
return;
}
showMatterAddDeviceDialog(element);
} }
}; };

View File

@@ -2,7 +2,6 @@ import {
HassEntity, HassEntity,
HassEntityAttributeBase, HassEntityAttributeBase,
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { EntityRegistryDisplayEntry } from "../../data/entity_registry";
import { FrontendLocaleData, NumberFormat } from "../../data/translation"; import { FrontendLocaleData, NumberFormat } from "../../data/translation";
import { round } from "./round"; import { round } from "./round";
@@ -77,26 +76,6 @@ export const formatNumber = (
).format(Number(num)); ).format(Number(num));
} }
} }
if (
!Number.isNaN(Number(num)) &&
num !== "" &&
localeOptions?.number_format === NumberFormat.none &&
Intl &&
(options?.maximumFractionDigits != null ||
options?.minimumFractionDigits != null)
) {
// If NumberFormat is none, just set the digits options for precision and use en-US format without grouping.
return new Intl.NumberFormat(
"en-US",
getDefaultFormatOptions(num, {
useGrouping: false,
maximumFractionDigits: options?.maximumFractionDigits,
minimumFractionDigits: options?.minimumFractionDigits,
})
).format(Number(num));
}
if (typeof num === "string") { if (typeof num === "string") {
return num; return num;
} }
@@ -111,16 +90,8 @@ export const formatNumber = (
* @returns An `Intl.NumberFormatOptions` object with `maximumFractionDigits` set to 0, or `undefined` * @returns An `Intl.NumberFormatOptions` object with `maximumFractionDigits` set to 0, or `undefined`
*/ */
export const getNumberFormatOptions = ( export const getNumberFormatOptions = (
entityState: HassEntity, entityState: HassEntity
entity?: EntityRegistryDisplayEntry
): Intl.NumberFormatOptions | undefined => { ): Intl.NumberFormatOptions | undefined => {
const precision = entity?.display_precision;
if (precision != null) {
return {
maximumFractionDigits: precision,
minimumFractionDigits: precision,
};
}
if ( if (
Number.isInteger(Number(entityState.attributes?.step)) && Number.isInteger(Number(entityState.attributes?.step)) &&
Number.isInteger(Number(entityState.state)) Number.isInteger(Number(entityState.state))

View File

@@ -1,4 +1,4 @@
const isTemplateRegex = /{%|{{/; const isTemplateRegex = new RegExp("{%|{{");
export const isTemplate = (value: string): boolean => export const isTemplate = (value: string): boolean =>
isTemplateRegex.test(value); isTemplateRegex.test(value);

View File

@@ -1,5 +1,6 @@
import { refine, string } from "superstruct"; import { refine, string } from "superstruct";
import { isCustomType } from "../../data/lovelace_custom_cards";
export const isCustomType = (value: string) => value.startsWith("custom:");
export const customType = () => export const customType = () =>
refine(string(), "custom element type", isCustomType); refine(string(), "custom element type", isCustomType);

View File

@@ -65,21 +65,19 @@ export interface FormatsType {
const loadedPolyfillLocale = new Set(); const loadedPolyfillLocale = new Set();
const locale = getLocalLanguage();
const polyfills: Promise<any>[] = []; const polyfills: Promise<any>[] = [];
if (__BUILD__ === "latest") { if (__BUILD__ === "latest") {
if (shouldPolyfillLocale()) { if (shouldPolyfillLocale()) {
await import("@formatjs/intl-locale/polyfill"); polyfills.push(import("@formatjs/intl-locale/polyfill"));
} }
if (shouldPolyfillPluralRules(locale)) { if (shouldPolyfillPluralRules()) {
polyfills.push(import("@formatjs/intl-pluralrules/polyfill")); polyfills.push(import("@formatjs/intl-pluralrules/polyfill"));
polyfills.push(import("@formatjs/intl-pluralrules/locale-data/en")); polyfills.push(import("@formatjs/intl-pluralrules/locale-data/en"));
} }
if (shouldPolyfillRelativeTime(locale)) { if (shouldPolyfillRelativeTime()) {
polyfills.push(import("@formatjs/intl-relativetimeformat/polyfill")); polyfills.push(import("@formatjs/intl-relativetimeformat/polyfill"));
} }
if (shouldPolyfillDateTime(locale)) { if (shouldPolyfillDateTime()) {
polyfills.push(import("@formatjs/intl-datetimeformat/polyfill")); polyfills.push(import("@formatjs/intl-datetimeformat/polyfill"));
polyfills.push(import("@formatjs/intl-datetimeformat/add-all-tz")); polyfills.push(import("@formatjs/intl-datetimeformat/add-all-tz"));
} }
@@ -90,7 +88,7 @@ export const polyfillsLoaded =
? undefined ? undefined
: Promise.all(polyfills).then(() => : Promise.all(polyfills).then(() =>
// Load the default language // Load the default language
loadPolyfillLocales(locale) loadPolyfillLocales(getLocalLanguage())
); );
/** /**
@@ -216,7 +214,7 @@ export const loadPolyfillLocales = async (language: string) => {
// @ts-ignore // @ts-ignore
Intl.DateTimeFormat.__addLocaleData(await result.json()); Intl.DateTimeFormat.__addLocaleData(await result.json());
} }
} catch (e) { } catch (_e) {
// Ignore // Ignore
} }
}; };

View File

@@ -19,7 +19,6 @@ const SECS_PER_HOUR = SECS_PER_MIN * 60;
// Adapted from https://github.com/formatjs/formatjs/blob/186cef62f980ec66252ee232f438a42d0b51b9f9/packages/intl-utils/src/diff.ts // Adapted from https://github.com/formatjs/formatjs/blob/186cef62f980ec66252ee232f438a42d0b51b9f9/packages/intl-utils/src/diff.ts
export function selectUnit( export function selectUnit(
from: Date | number, from: Date | number,
// eslint-disable-next-line @typescript-eslint/default-param-last
to: Date | number = Date.now(), to: Date | number = Date.now(),
locale: FrontendLocaleData, locale: FrontendLocaleData,
thresholds: Partial<Thresholds> = {} thresholds: Partial<Thresholds> = {}

View File

@@ -1,10 +1,9 @@
import { css, CSSResultGroup, html, LitElement } from "lit"; import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property, query } from "lit/decorators"; import { property, query } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "./ha-progress-button"; import "./ha-progress-button";
@customElement("ha-call-api-button")
class HaCallApiButton extends LitElement { class HaCallApiButton extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@@ -70,6 +69,8 @@ class HaCallApiButton extends LitElement {
} }
} }
customElements.define("ha-call-api-button", HaCallApiButton);
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"ha-call-api-button": HaCallApiButton; "ha-call-api-button": HaCallApiButton;

View File

@@ -233,11 +233,7 @@ export default class HaChartBase extends LitElement {
{ {
id: "afterRenderHook", id: "afterRenderHook",
afterRender: (chart) => { afterRender: (chart) => {
const change = chart.height - (this._chartHeight ?? 0); this._chartHeight = chart.height;
if (!this._chartHeight || change > 0 || change < -12) {
// hysteresis to prevent infinite render loops
this._chartHeight = chart.height;
}
}, },
legend: { legend: {
...this.options?.plugins?.legend, ...this.options?.plugins?.legend,

View File

@@ -22,7 +22,7 @@ class StateHistoryChartLine extends LitElement {
@property({ attribute: false }) public data: LineChartEntity[] = []; @property({ attribute: false }) public data: LineChartEntity[] = [];
@property() public names?: Record<string, string>; @property() public names: boolean | Record<string, string> = false;
@property() public unit?: string; @property() public unit?: string;

View File

@@ -19,7 +19,7 @@ export class StateHistoryChartTimeline extends LitElement {
@property() public narrow!: boolean; @property() public narrow!: boolean;
@property() public names?: Record<string, string>; @property() public names: boolean | Record<string, string> = false;
@property() public unit?: string; @property() public unit?: string;
@@ -64,8 +64,6 @@ export class StateHistoryChartTimeline extends LitElement {
} }
if ( if (
changedProps.has("startTime") ||
changedProps.has("endTime") ||
changedProps.has("data") || changedProps.has("data") ||
this._chartTime < this._chartTime <
new Date(this.endTime.getTime() - MIN_TIME_BETWEEN_UPDATES) new Date(this.endTime.getTime() - MIN_TIME_BETWEEN_UPDATES)
@@ -143,10 +141,7 @@ export class StateHistoryChartTimeline extends LitElement {
} }
}, },
afterUpdate: (y) => { afterUpdate: (y) => {
if ( if (this._yWidth !== Math.floor(y.width)) {
this._yWidth !== Math.floor(y.width) &&
y.ticks.length === this.data.length
) {
this._yWidth = Math.floor(y.width); this._yWidth = Math.floor(y.width);
fireEvent(this, "y-width-changed", { fireEvent(this, "y-width-changed", {
value: this._yWidth, value: this._yWidth,

View File

@@ -4,12 +4,11 @@ import {
CSSResultGroup, CSSResultGroup,
html, html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
TemplateResult,
} from "lit"; } from "lit";
import { customElement, eventOptions, property, state } from "lit/decorators"; import { customElement, property, state, eventOptions } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { restoreScroll } from "../../common/decorators/restore-scroll";
import { import {
HistoryResult, HistoryResult,
LineChartUnit, LineChartUnit,
@@ -18,6 +17,7 @@ import {
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import "./state-history-chart-line"; import "./state-history-chart-line";
import "./state-history-chart-timeline"; import "./state-history-chart-timeline";
import { restoreScroll } from "../../common/decorators/restore-scroll";
const CANVAS_TIMELINE_ROWS_CHUNK = 10; // Split up the canvases to avoid hitting the render limit const CANVAS_TIMELINE_ROWS_CHUNK = 10; // Split up the canvases to avoid hitting the render limit
@@ -38,14 +38,14 @@ declare global {
} }
@customElement("state-history-charts") @customElement("state-history-charts")
export class StateHistoryCharts extends LitElement { class StateHistoryCharts extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public historyData!: HistoryResult; @property({ attribute: false }) public historyData!: HistoryResult;
@property() public narrow!: boolean; @property() public narrow!: boolean;
@property() public names?: Record<string, string>; @property({ type: Boolean }) public names = false;
@property({ type: Boolean, attribute: "virtualize", reflect: true }) @property({ type: Boolean, attribute: "virtualize", reflect: true })
public virtualize = false; public virtualize = false;
@@ -71,7 +71,8 @@ export class StateHistoryCharts extends LitElement {
// @ts-ignore // @ts-ignore
@restoreScroll(".container") private _savedScrollPos?: number; @restoreScroll(".container") private _savedScrollPos?: number;
protected render() { @eventOptions({ passive: true })
protected render(): TemplateResult {
if (!isComponentLoaded(this.hass, "history")) { if (!isComponentLoaded(this.hass, "history")) {
return html`<div class="info"> return html`<div class="info">
${this.hass.localize("ui.components.history_charts.history_disabled")} ${this.hass.localize("ui.components.history_charts.history_disabled")}
@@ -130,9 +131,9 @@ export class StateHistoryCharts extends LitElement {
private _renderHistoryItem = ( private _renderHistoryItem = (
item: TimelineEntity[] | LineChartUnit, item: TimelineEntity[] | LineChartUnit,
index: number index: number
) => { ): TemplateResult => {
if (!item || index === undefined) { if (!item || index === undefined) {
return nothing; return html``;
} }
if (!Array.isArray(item)) { if (!Array.isArray(item)) {
return html`<div class="entry-container"> return html`<div class="entry-container">

View File

@@ -59,14 +59,14 @@ export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
class StatisticsChart extends LitElement { class StatisticsChart extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public statisticsData?: Statistics; @property({ attribute: false }) public statisticsData!: Statistics;
@property({ attribute: false }) public metadata?: Record< @property({ attribute: false }) public metadata?: Record<
string, string,
StatisticsMetaData StatisticsMetaData
>; >;
@property() public names?: Record<string, string>; @property() public names: boolean | Record<string, string> = false;
@property() public unit?: string; @property() public unit?: string;
@@ -99,11 +99,7 @@ class StatisticsChart extends LitElement {
if (!this.hasUpdated || changedProps.has("unit")) { if (!this.hasUpdated || changedProps.has("unit")) {
this._createOptions(); this._createOptions();
} }
if ( if (changedProps.has("statisticsData") || changedProps.has("statTypes")) {
changedProps.has("statisticsData") ||
changedProps.has("statTypes") ||
changedProps.has("hideLegend")
) {
this._generateData(); this._generateData();
} }
} }
@@ -332,10 +328,7 @@ class StatisticsChart extends LitElement {
prevEndTime = end; prevEndTime = end;
}; };
const color = getGraphColorByIndex( const color = getGraphColorByIndex(colorIndex, this._computedStyle!);
colorIndex,
this._computedStyle || getComputedStyle(this)
);
colorIndex++; colorIndex++;
const statTypes: this["statTypes"] = []; const statTypes: this["statTypes"] = [];

View File

@@ -1,4 +1,3 @@
import "@lit-labs/virtualizer";
import { mdiArrowDown, mdiArrowUp } from "@mdi/js"; import { mdiArrowDown, mdiArrowUp } from "@mdi/js";
import deepClone from "deep-clone-simple"; import deepClone from "deep-clone-simple";
import { import {
@@ -6,7 +5,6 @@ import {
CSSResultGroup, CSSResultGroup,
html, html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
} from "lit"; } from "lit";
@@ -23,15 +21,16 @@ import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { restoreScroll } from "../../common/decorators/restore-scroll"; import { restoreScroll } from "../../common/decorators/restore-scroll";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import "../search-input";
import { debounce } from "../../common/util/debounce"; import { debounce } from "../../common/util/debounce";
import { nextRender } from "../../common/util/render-status"; import { nextRender } from "../../common/util/render-status";
import { haStyleScrollbar } from "../../resources/styles"; import { haStyleScrollbar } from "../../resources/styles";
import { HomeAssistant } from "../../types";
import "../ha-checkbox"; import "../ha-checkbox";
import type { HaCheckbox } from "../ha-checkbox"; import type { HaCheckbox } from "../ha-checkbox";
import "../ha-svg-icon"; import "../ha-svg-icon";
import "../search-input";
import { filterData, sortData } from "./sort-filter"; import { filterData, sortData } from "./sort-filter";
import { HomeAssistant } from "../../types";
import "@lit-labs/virtualizer";
declare global { declare global {
// for fire event // for fire event
@@ -74,7 +73,7 @@ export interface DataTableColumnData<T = any> extends DataTableSortColumnData {
title: TemplateResult | string; title: TemplateResult | string;
label?: TemplateResult | string; label?: TemplateResult | string;
type?: "numeric" | "icon" | "icon-button" | "overflow-menu"; type?: "numeric" | "icon" | "icon-button" | "overflow-menu";
template?: (data: any, row: T) => TemplateResult | string | typeof nothing; template?: (data: any, row: T) => TemplateResult | string;
width?: string; width?: string;
maxWidth?: string; maxWidth?: string;
grows?: boolean; grows?: boolean;
@@ -353,10 +352,13 @@ export class HaDataTable extends LitElement {
`; `;
} }
private _renderRow = (row: DataTableRowData, index: number) => { private _renderRow = (
row: DataTableRowData,
index: number
): TemplateResult => {
// not sure how this happens... // not sure how this happens...
if (!row) { if (!row) {
return nothing; return html``;
} }
if (row.append) { if (row.append) {
return html` <div class="mdc-data-table__row">${row.content}</div> `; return html` <div class="mdc-data-table__row">${row.content}</div> `;
@@ -459,9 +461,7 @@ export class HaDataTable extends LitElement {
const elapsed = curTime - startTime; const elapsed = curTime - startTime;
if (elapsed < 100) { if (elapsed < 100) {
await new Promise((resolve) => { await new Promise((resolve) => setTimeout(resolve, 100 - elapsed));
setTimeout(resolve, 100 - elapsed);
});
} }
if (this.curRequest !== curRequest) { if (this.curRequest !== curRequest) {
return; return;

View File

@@ -67,11 +67,11 @@ const sortData = (
} }
} }
// Ensure "undefined" and "null" are always sorted to the bottom // Ensure "undefined" is always sorted to the bottom
if (valA == null && valB != null) { if (valA === undefined && valB !== undefined) {
return 1; return 1;
} }
if (valB == null && valA != null) { if (valB === undefined && valA !== undefined) {
return -1; return -1;
} }

View File

@@ -1,7 +1,7 @@
import "@material/mwc-button/mwc-button"; import "@material/mwc-button/mwc-button";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, nothing } from "lit"; import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
@@ -230,9 +230,9 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
} }
} }
protected render() { protected render(): TemplateResult {
if (!this._devices || !this._areas || !this._entities) { if (!this._devices || !this._areas || !this._entities) {
return nothing; return html``;
} }
const areas = this._getAreasWithDevices( const areas = this._getAreasWithDevices(
this._devices, this._devices,

View File

@@ -1,5 +1,5 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { import {
@@ -85,9 +85,9 @@ export abstract class HaDeviceAutomationPicker<
return `${this._automations[idx].device_id}_${idx}`; return `${this._automations[idx].device_id}_${idx}`;
} }
protected render() { protected render(): TemplateResult {
if (this._renderEmpty) { if (this._renderEmpty) {
return nothing; return html``;
} }
const value = this._value; const value = this._value;
return html` return html`

View File

@@ -1,5 +1,5 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, TemplateResult } from "lit"; import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
@@ -37,8 +37,6 @@ export type HaDevicePickerDeviceFilterFunc = (
device: DeviceRegistryEntry device: DeviceRegistryEntry
) => boolean; ) => boolean;
export type HaDevicePickerEntityFilterFunc = (entity: HassEntity) => boolean;
const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item
.twoline=${!!item.area} .twoline=${!!item.area}
> >
@@ -96,8 +94,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc; @property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property() public entityFilter?: HaDevicePickerEntityFilterFunc;
@property({ type: Boolean }) public disabled?: boolean; @property({ type: Boolean }) public disabled?: boolean;
@property({ type: Boolean }) public required?: boolean; @property({ type: Boolean }) public required?: boolean;
@@ -117,7 +113,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
excludeDomains: this["excludeDomains"], excludeDomains: this["excludeDomains"],
includeDeviceClasses: this["includeDeviceClasses"], includeDeviceClasses: this["includeDeviceClasses"],
deviceFilter: this["deviceFilter"], deviceFilter: this["deviceFilter"],
entityFilter: this["entityFilter"],
excludeDevices: this["excludeDevices"] excludeDevices: this["excludeDevices"]
): Device[] => { ): Device[] => {
if (!devices.length) { if (!devices.length) {
@@ -132,12 +127,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
const deviceEntityLookup: DeviceEntityLookup = {}; const deviceEntityLookup: DeviceEntityLookup = {};
if ( if (includeDomains || excludeDomains || includeDeviceClasses) {
includeDomains ||
excludeDomains ||
includeDeviceClasses ||
entityFilter
) {
for (const entity of entities) { for (const entity of entities) {
if (!entity.device_id) { if (!entity.device_id) {
continue; continue;
@@ -208,22 +198,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
}); });
} }
if (entityFilter) {
inputDevices = inputDevices.filter((device) => {
const devEntities = deviceEntityLookup[device.id];
if (!devEntities || !devEntities.length) {
return false;
}
return devEntities.some((entity) => {
const stateObj = this.hass.states[entity.entity_id];
if (!stateObj) {
return false;
}
return entityFilter(stateObj);
});
});
}
if (deviceFilter) { if (deviceFilter) {
inputDevices = inputDevices.filter( inputDevices = inputDevices.filter(
(device) => (device) =>
@@ -300,7 +274,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
this.excludeDomains, this.excludeDomains,
this.includeDeviceClasses, this.includeDeviceClasses,
this.deviceFilter, this.deviceFilter,
this.entityFilter,
this.excludeDevices this.excludeDevices
); );
} }

View File

@@ -1,13 +1,10 @@
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { PolymerChangedEvent } from "../../polymer-types"; import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "./ha-device-picker"; import "./ha-device-picker";
import type { import type { HaDevicePickerDeviceFilterFunc } from "./ha-device-picker";
HaDevicePickerDeviceFilterFunc,
HaDevicePickerEntityFilterFunc,
} from "./ha-device-picker";
@customElement("ha-devices-picker") @customElement("ha-devices-picker")
class HaDevicesPicker extends LitElement { class HaDevicesPicker extends LitElement {
@@ -47,11 +44,9 @@ class HaDevicesPicker extends LitElement {
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc; @property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property() public entityFilter?: HaDevicePickerEntityFilterFunc; protected render(): TemplateResult {
protected render() {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
const currentDevices = this._currentDevices; const currentDevices = this._currentDevices;
@@ -64,7 +59,6 @@ class HaDevicesPicker extends LitElement {
.curValue=${entityId} .curValue=${entityId}
.hass=${this.hass} .hass=${this.hass}
.deviceFilter=${this.deviceFilter} .deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeDomains=${this.excludeDomains} .excludeDomains=${this.excludeDomains}
.includeDeviceClasses=${this.includeDeviceClasses} .includeDeviceClasses=${this.includeDeviceClasses}
@@ -82,10 +76,8 @@ class HaDevicesPicker extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.helper=${this.helper} .helper=${this.helper}
.deviceFilter=${this.deviceFilter} .deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeDomains=${this.excludeDomains} .excludeDomains=${this.excludeDomains}
.excludeDevices=${currentDevices}
.includeDeviceClasses=${this.includeDeviceClasses} .includeDeviceClasses=${this.includeDeviceClasses}
.label=${this.pickDeviceLabel} .label=${this.pickDeviceLabel}
.disabled=${this.disabled} .disabled=${this.disabled}

View File

@@ -1,5 +1,5 @@
import type { HassEntity } from "home-assistant-js-websocket"; import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
@@ -76,9 +76,9 @@ class HaEntitiesPickerLight extends LitElement {
@property() public entityFilter?: HaEntityPickerEntityFilterFunc; @property() public entityFilter?: HaEntityPickerEntityFilterFunc;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
const currentEntities = this._currentEntities; const currentEntities = this._currentEntities;

View File

@@ -1,5 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, nothing } from "lit"; import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, query } from "lit/decorators"; import { customElement, property, query } from "lit/decorators";
import { formatAttributeName } from "../../data/entity_attributes"; import { formatAttributeName } from "../../data/entity_attributes";
import { PolymerChangedEvent } from "../../polymer-types"; import { PolymerChangedEvent } from "../../polymer-types";
@@ -60,9 +60,9 @@ class HaEntityAttributePicker extends LitElement {
} }
} }
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -1,4 +1,4 @@
import "../ha-list-item"; import "@material/mwc-list/mwc-list-item";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, TemplateResult } from "lit"; import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
@@ -24,13 +24,13 @@ export type HaEntityPickerEntityFilterFunc = (entity: HassEntity) => boolean;
// eslint-disable-next-line lit/prefer-static-styles // eslint-disable-next-line lit/prefer-static-styles
const rowRenderer: ComboBoxLitRenderer<HassEntityWithCachedName> = (item) => const rowRenderer: ComboBoxLitRenderer<HassEntityWithCachedName> = (item) =>
html`<ha-list-item graphic="avatar" .twoline=${!!item.entity_id}> html`<mwc-list-item graphic="avatar" .twoline=${!!item.entity_id}>
${item.state ${item.state
? html`<state-badge slot="graphic" .stateObj=${item}></state-badge>` ? html`<state-badge slot="graphic" .stateObj=${item}></state-badge>`
: ""} : ""}
<span>${item.friendly_name}</span> <span>${item.friendly_name}</span>
<span slot="secondary">${item.entity_id}</span> <span slot="secondary">${item.entity_id}</span>
</ha-list-item>`; </mwc-list-item>`;
@customElement("ha-entity-picker") @customElement("ha-entity-picker")
export class HaEntityPicker extends LitElement { export class HaEntityPicker extends LitElement {

View File

@@ -1,14 +1,14 @@
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, nothing } from "lit"; import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, query } from "lit/decorators"; import { customElement, property, query } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
import { computeStateDisplay } from "../../common/entity/compute_state_display"; import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { getStates } from "../../common/entity/get_states";
import { formatAttributeValue } from "../../data/entity_attributes";
import { PolymerChangedEvent } from "../../polymer-types"; import { PolymerChangedEvent } from "../../polymer-types";
import { getStates } from "../../common/entity/get_states";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "../ha-combo-box"; import "../ha-combo-box";
import type { HaComboBox } from "../ha-combo-box"; import type { HaComboBox } from "../ha-combo-box";
import { formatAttributeValue } from "../../data/entity_attributes";
import { fireEvent } from "../../common/dom/fire_event";
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean; export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
@@ -64,9 +64,9 @@ class HaEntityStatePicker extends LitElement {
} }
} }
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
return html` return html`

View File

@@ -22,7 +22,7 @@ import {
isNumericState, isNumericState,
} from "../../common/number/format_number"; } from "../../common/number/format_number";
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity"; import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { EntityRegistryDisplayEntry } from "../../data/entity_registry"; import { EntityRegistryEntry } from "../../data/entity_registry";
import { timerTimeRemaining } from "../../data/timer"; import { timerTimeRemaining } from "../../data/timer";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "../ha-label-badge"; import "../ha-label-badge";
@@ -160,7 +160,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeValue( private _computeValue(
domain: string, domain: string,
entityState: HassEntity, entityState: HassEntity,
entry?: EntityRegistryDisplayEntry entry?: EntityRegistryEntry
) { ) {
switch (domain) { switch (domain) {
case "alarm_control_panel": case "alarm_control_panel":
@@ -186,7 +186,7 @@ export class HaStateLabelBadge extends LitElement {
? formatNumber( ? formatNumber(
entityState.state, entityState.state,
this.hass!.locale, this.hass!.locale,
getNumberFormatOptions(entityState, entry) getNumberFormatOptions(entityState)
) )
: computeStateDisplay( : computeStateDisplay(
this.hass!.localize, this.hass!.localize,
@@ -200,7 +200,7 @@ export class HaStateLabelBadge extends LitElement {
private _computeShowIcon( private _computeShowIcon(
domain: string, domain: string,
entityState: HassEntity, entityState: HassEntity,
entry?: EntityRegistryDisplayEntry entry?: EntityRegistryEntry
): boolean { ): boolean {
if (entityState.state === UNAVAILABLE) { if (entityState.state === UNAVAILABLE) {
return false; return false;

View File

@@ -1,4 +1,4 @@
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import type { PolymerChangedEvent } from "../../polymer-types"; import type { PolymerChangedEvent } from "../../polymer-types";
@@ -56,9 +56,9 @@ class HaStatisticsPicker extends LitElement {
}) })
public ignoreRestrictionsOnFirstStatistic = false; public ignoreRestrictionsOnFirstStatistic = false;
protected render() { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return nothing; return html``;
} }
const ignoreRestriction = const ignoreRestriction =

View File

@@ -6,7 +6,7 @@ import {
html, html,
LitElement, LitElement,
PropertyValues, PropertyValues,
nothing, TemplateResult,
} from "lit"; } from "lit";
import { property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
@@ -45,7 +45,7 @@ export class StateBadge extends LitElement {
return this.stateColor || (domain === "light" && this.stateColor !== false); return this.stateColor || (domain === "light" && this.stateColor !== false);
} }
protected render() { protected render(): TemplateResult {
const stateObj = this.stateObj; const stateObj = this.stateObj;
// We either need a `stateObj` or one override // We either need a `stateObj` or one override
@@ -56,7 +56,7 @@ export class StateBadge extends LitElement {
} }
if (!this._showIcon) { if (!this._showIcon) {
return nothing; return html``;
} }
const domain = stateObj ? computeStateDomain(stateObj) : undefined; const domain = stateObj ? computeStateDomain(stateObj) : undefined;
@@ -133,7 +133,7 @@ export class StateBadge extends LitElement {
} }
if (stateObj.attributes.hvac_action) { if (stateObj.attributes.hvac_action) {
const hvacAction = stateObj.attributes.hvac_action; const hvacAction = stateObj.attributes.hvac_action;
if (hvacAction in HVAC_ACTION_TO_MODE) { if (["heating", "cooling", "drying", "fan"].includes(hvacAction)) {
iconStyle.color = stateColorCss( iconStyle.color = stateColorCss(
stateObj, stateObj,
HVAC_ACTION_TO_MODE[hvacAction] HVAC_ACTION_TO_MODE[hvacAction]

View File

@@ -1,6 +1,6 @@
import "@polymer/paper-tooltip/paper-tooltip"; import "@polymer/paper-tooltip/paper-tooltip";
import type { HassEntity } from "home-assistant-js-websocket"; import type { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { computeStateName } from "../../common/entity/compute_state_name"; import { computeStateName } from "../../common/entity/compute_state_name";
import { computeRTL } from "../../common/util/compute_rtl"; import { computeRTL } from "../../common/util/compute_rtl";
@@ -21,9 +21,9 @@ class StateInfo extends LitElement {
@property() public color?: string; @property() public color?: string;
protected render() { protected render(): TemplateResult {
if (!this.hass || !this.stateObj) { if (!this.hass || !this.stateObj) {
return nothing; return html``;
} }
const name = computeStateName(this.stateObj); const name = computeStateName(this.stateObj);

Some files were not shown because too many files have changed in this diff Show More