mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
20230222.0 (#15551)Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Steve Repsher <steverep@users.noreply.github.com> Co-authored-by: Bram Kragten <mail@bramkragten.nl> Co-authored-by: Paul Bottein <paul.bottein@gmail.com> Co-authored-by: Flavien Charlon <Flavien@users.noreply.github.com> Co-authored-by: Raman Gupta <7243222+raman325@users.noreply.github.com> Co-authored-by: karwosts <32912880+karwosts@users.noreply.github.com> Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Yosi Levy <37745463+yosilevy@users.noreply.github.com> Co-authored-by: lunmay <28674102+lunmay@users.noreply.github.com> Co-authored-by: Jc2k <john.carr@unrouted.co.uk> Co-authored-by: chiahsing <chiahsing@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Fix a coloring issue with climate states (#15325) resolver-webpack from 0.13.1 to 0.13.2 (#15355) resolver-webpack](https://github.com/import-js/eslint-plugin-import) from 0.13.1 to 0.13.2. fix some errors (#15334) Fix stats data being fetched for all entities when there are no energy/water stat ids (#15428) Fix custom card documentation url (#15439) fixes (#15446) fix dedupe precommit (#15399) Fix typo from restart dialog (whitch -> which) (#15458) Fix typo in water consumption description (#15464) Fix initial scroll inside more info dialog (#15473) Fix alert padding inside more info dialog (#15477) Fix area name in target picker (#15511) fix history crash) (#15509) Fix promise constructors with returns (#15486) fixes feb23 (#15487) Fix errors in duration data processing in Automation UI Editor (#15422) Fix map sizing in grids and h-stacks (#15290) Fix a typo: Add OpenTread Border Router (#15528) Fix tile card typings (#15529) fix more info history tooltips (#15533) Fix double defined cloud-account (#15537) Fix more info control assumed state color (#15548) Fix a bug in cast launcher that hassURL and path are incorrectly passed (#15546)
This commit is contained in:
commit
971d2ff1c2
@ -5,6 +5,7 @@
|
|||||||
"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",
|
||||||
@ -58,6 +59,8 @@
|
|||||||
"prefer-destructuring": "off",
|
"prefer-destructuring": "off",
|
||||||
"no-restricted-globals": [2, "event"],
|
"no-restricted-globals": [2, "event"],
|
||||||
"prefer-promise-reject-errors": "off",
|
"prefer-promise-reject-errors": "off",
|
||||||
|
"no-unsafe-optional-chaining": "warn",
|
||||||
|
"prefer-regex-literals": ["warn"],
|
||||||
"import/prefer-default-export": "off",
|
"import/prefer-default-export": "off",
|
||||||
"import/no-default-export": "off",
|
"import/no-default-export": "off",
|
||||||
"import/no-unresolved": "off",
|
"import/no-unresolved": "off",
|
||||||
@ -65,7 +68,10 @@
|
|||||||
"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",
|
||||||
@ -112,7 +118,15 @@
|
|||||||
],
|
],
|
||||||
"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/prefer-nothing": "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"
|
||||||
|
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@ -19,7 +19,3 @@ updates:
|
|||||||
- dependency-name: "*rollup*"
|
- dependency-name: "*rollup*"
|
||||||
- dependency-name: "@rollup/*"
|
- dependency-name: "@rollup/*"
|
||||||
- dependency-name: "serve"
|
- dependency-name: "serve"
|
||||||
# Wait for fullcalendar v6+ to fix shadow DOM issue
|
|
||||||
- dependency-name: "@fullcalendar/*"
|
|
||||||
versions:
|
|
||||||
- ">=6"
|
|
||||||
|
10
.github/workflows/cast_deployment.yaml
vendored
10
.github/workflows/cast_deployment.yaml
vendored
@ -33,9 +33,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Cast
|
- name: Build Cast
|
||||||
run: ./node_modules/.bin/gulp build-cast
|
run: ./node_modules/.bin/gulp build-cast
|
||||||
@ -71,9 +69,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Cast
|
- name: Build Cast
|
||||||
run: ./node_modules/.bin/gulp build-cast
|
run: ./node_modules/.bin/gulp build-cast
|
||||||
@ -87,4 +83,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 }}
|
||||||
|
34
.github/workflows/ci.yaml
vendored
34
.github/workflows/ci.yaml
vendored
@ -15,8 +15,13 @@ 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
|
||||||
@ -27,20 +32,19 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
- name: Check for duplicate dependencies
|
||||||
CI: true
|
run: yarn dedupe --check
|
||||||
- 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
|
run: yarn run lint:eslint --quiet
|
||||||
- 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
|
||||||
@ -51,16 +55,15 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
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:
|
||||||
runs-on: ubuntu-latest
|
name: Build frontend
|
||||||
needs: [lint, test]
|
needs: [lint, test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
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
|
||||||
@ -70,16 +73,15 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
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:
|
||||||
runs-on: ubuntu-latest
|
name: Build supervisor
|
||||||
needs: [lint, test]
|
needs: [lint, test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
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
|
||||||
@ -89,9 +91,7 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
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:
|
||||||
|
10
.github/workflows/demo_deployment.yaml
vendored
10
.github/workflows/demo_deployment.yaml
vendored
@ -34,9 +34,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Demo
|
- name: Build Demo
|
||||||
run: ./node_modules/.bin/gulp build-demo
|
run: ./node_modules/.bin/gulp build-demo
|
||||||
@ -72,9 +70,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Demo
|
- name: Build Demo
|
||||||
run: ./node_modules/.bin/gulp build-demo
|
run: ./node_modules/.bin/gulp build-demo
|
||||||
@ -88,4 +84,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 }}
|
||||||
|
4
.github/workflows/design_deployment.yaml
vendored
4
.github/workflows/design_deployment.yaml
vendored
@ -26,9 +26,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Gallery
|
- name: Build Gallery
|
||||||
run: ./node_modules/.bin/gulp build-gallery
|
run: ./node_modules/.bin/gulp build-gallery
|
||||||
|
4
.github/workflows/design_preview.yaml
vendored
4
.github/workflows/design_preview.yaml
vendored
@ -31,9 +31,7 @@ jobs:
|
|||||||
cache: yarn
|
cache: yarn
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --immutable
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
- name: Build Gallery
|
- name: Build Gallery
|
||||||
run: ./node_modules/.bin/gulp build-gallery
|
run: ./node_modules/.bin/gulp build-gallery
|
||||||
|
@ -67,7 +67,7 @@ module.exports.babelOptions = ({ latestBuild }) => ({
|
|||||||
"@babel/preset-env",
|
"@babel/preset-env",
|
||||||
{
|
{
|
||||||
useBuiltIns: "entry",
|
useBuiltIns: "entry",
|
||||||
corejs: { version: "3.27", proposals: true },
|
corejs: { version: "3.28", proposals: true },
|
||||||
bugfixes: true,
|
bugfixes: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -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, path, this.auth.data.hassUrl);
|
castSendShowLovelaceView(this.castManager, this.auth.data.hassUrl, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _handleLogout() {
|
private async _handleLogout() {
|
||||||
|
@ -6,6 +6,9 @@ set -e
|
|||||||
|
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
STATS=1 NODE_ENV=production ../node_modules/.bin/webpack --profile --json > compilation-stats.json
|
export STATS=1
|
||||||
npx webpack-bundle-analyzer compilation-stats.json dist/frontend_latest
|
statsfile="compilation-stats-demo.json"
|
||||||
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
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { customElement, 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,6 +14,7 @@ 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;
|
||||||
|
|
||||||
@ -154,5 +155,3 @@ declare global {
|
|||||||
"ha-demo-card": HADemoCard;
|
"ha-demo-card": HADemoCard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-demo-card", HADemoCard);
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// Compat needs to be first import
|
// Compat needs to be first import
|
||||||
import "../../src/resources/compatibility";
|
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 {
|
||||||
@ -26,7 +27,8 @@ 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";
|
||||||
|
|
||||||
class HaDemo extends HomeAssistantAppEl {
|
@customElement("ha-demo")
|
||||||
|
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,
|
||||||
@ -71,6 +73,7 @@ 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",
|
||||||
@ -86,6 +89,7 @@ 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,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -121,8 +125,6 @@ class HaDemo extends HomeAssistantAppEl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-demo", HaDemo);
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-demo": HaDemo;
|
"ha-demo": HaDemo;
|
||||||
|
@ -15,6 +15,7 @@ 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
|
||||||
@ -51,6 +52,7 @@ 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
|
||||||
@ -86,6 +88,7 @@ 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,
|
||||||
|
@ -156,18 +156,6 @@ 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**
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
title: Bar Slider
|
|
||||||
---
|
|
@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
title: Bar Switch
|
|
||||||
---
|
|
3
gallery/src/pages/components/ha-control-button.markdown
Normal file
3
gallery/src/pages/components/ha-control-button.markdown
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
title: Control Button
|
||||||
|
---
|
192
gallery/src/pages/components/ha-control-button.ts
Normal file
192
gallery/src/pages/components/ha-control-button.ts
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
3
gallery/src/pages/components/ha-control-slider.markdown
Normal file
3
gallery/src/pages/components/ha-control-slider.markdown
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
title: Control Slider
|
||||||
|
---
|
@ -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-bar-slider";
|
import "../../../../src/components/ha-control-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-bar-slider")
|
@customElement("demo-components-ha-control-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-bar-slider
|
<ha-control-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-bar-slider>
|
</ha-control-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-bar-slider
|
<ha-control-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-bar-slider>
|
</ha-control-slider>
|
||||||
`;
|
`;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
@ -141,11 +141,11 @@ export class DemoHaBarSlider extends LitElement {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
.custom {
|
.custom {
|
||||||
--slider-bar-color: #ffcf4c;
|
--control-slider-color: #ffcf4c;
|
||||||
--slider-bar-background: #ffcf4c;
|
--control-slider-background: #ffcf4c;
|
||||||
--slider-bar-background-opacity: 0.2;
|
--control-slider-background-opacity: 0.2;
|
||||||
--slider-bar-thickness: 100px;
|
--control-slider-thickness: 100px;
|
||||||
--slider-bar-border-radius: 24px;
|
--control-slider-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-bar-slider": DemoHaBarSlider;
|
"demo-components-ha-control-slider": DemoHaBarSlider;
|
||||||
}
|
}
|
||||||
}
|
}
|
3
gallery/src/pages/components/ha-control-switch.markdown
Normal file
3
gallery/src/pages/components/ha-control-switch.markdown
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
title: Control Switch
|
||||||
|
---
|
@ -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-bar-switch";
|
import "../../../../src/components/ha-control-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-bar-switch")
|
@customElement("demo-components-ha-control-switch")
|
||||||
export class DemoHaBarSwitch extends LitElement {
|
export class DemoHaControlSwitch extends LitElement {
|
||||||
@state() private checked = false;
|
@state() private checked = false;
|
||||||
|
|
||||||
handleValueChanged(e: any) {
|
handleValueChanged(e: any) {
|
||||||
@ -56,7 +56,7 @@ export class DemoHaBarSwitch 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-bar-switch
|
<ha-control-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 DemoHaBarSwitch extends LitElement {
|
|||||||
disabled=${ifDefined(config.disabled)}
|
disabled=${ifDefined(config.disabled)}
|
||||||
reversed=${ifDefined(config.reversed)}
|
reversed=${ifDefined(config.reversed)}
|
||||||
>
|
>
|
||||||
</ha-bar-switch>
|
</ha-control-switch>
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`;
|
||||||
@ -78,7 +78,7 @@ export class DemoHaBarSwitch extends LitElement {
|
|||||||
${repeat(switches, (sw) => {
|
${repeat(switches, (sw) => {
|
||||||
const { id, label, ...config } = sw;
|
const { id, label, ...config } = sw;
|
||||||
return html`
|
return html`
|
||||||
<ha-bar-switch
|
<ha-control-switch
|
||||||
.checked=${this.checked}
|
.checked=${this.checked}
|
||||||
vertical
|
vertical
|
||||||
class=${ifDefined(config.class)}
|
class=${ifDefined(config.class)}
|
||||||
@ -89,7 +89,7 @@ export class DemoHaBarSwitch extends LitElement {
|
|||||||
disabled=${ifDefined(config.disabled)}
|
disabled=${ifDefined(config.disabled)}
|
||||||
reversed=${ifDefined(config.reversed)}
|
reversed=${ifDefined(config.reversed)}
|
||||||
>
|
>
|
||||||
</ha-bar-switch>
|
</ha-control-switch>
|
||||||
`;
|
`;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
@ -115,11 +115,11 @@ export class DemoHaBarSwitch extends LitElement {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
.custom {
|
.custom {
|
||||||
--switch-bar-on-color: var(--green-color);
|
--control-switch-on-color: var(--green-color);
|
||||||
--switch-bar-off-color: var(--red-color);
|
--control-switch-off-color: var(--red-color);
|
||||||
--switch-bar-thickness: 100px;
|
--control-switch-thickness: 100px;
|
||||||
--switch-bar-border-radius: 24px;
|
--control-switch-border-radius: 24px;
|
||||||
--switch-bar-padding: 6px;
|
--control-switch-padding: 6px;
|
||||||
--mdc-icon-size: 24px;
|
--mdc-icon-size: 24px;
|
||||||
}
|
}
|
||||||
.vertical-switches {
|
.vertical-switches {
|
||||||
@ -140,6 +140,6 @@ export class DemoHaBarSwitch extends LitElement {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"demo-components-ha-bar-switch": DemoHaBarSwitch;
|
"demo-components-ha-control-switch": DemoHaControlSwitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ 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",
|
||||||
@ -18,7 +19,11 @@ 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((tip) => html`<ha-tip>${tip}</ha-tip>`)}
|
${tips.map(
|
||||||
|
(tip) => html`<ha-tip .hass=${provideHass(this)}
|
||||||
|
>${tip}</ha-tip
|
||||||
|
>`
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
</div>
|
</div>
|
||||||
|
3
gallery/src/pages/lovelace/tile-card.markdown
Normal file
3
gallery/src/pages/lovelace/tile-card.markdown
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
title: Tile Card
|
||||||
|
---
|
173
gallery/src/pages/lovelace/tile-card.ts
Normal file
173
gallery/src/pages/lovelace/tile-card.ts
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -197,6 +197,7 @@ const createEntityRegistryEntries = (
|
|||||||
platform: "updater",
|
platform: "updater",
|
||||||
has_entity_name: false,
|
has_entity_name: false,
|
||||||
unique_id: "updater",
|
unique_id: "updater",
|
||||||
|
options: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -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 { property } from "lit/decorators";
|
import { customElement, 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,7 +14,8 @@ 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";
|
||||||
|
|
||||||
class HassioAddonRepositoryEl extends LitElement {
|
@customElement("hassio-addon-repository")
|
||||||
|
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;
|
||||||
@ -140,5 +141,3 @@ class HassioAddonRepositoryEl extends LitElement {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("hassio-addon-repository", HassioAddonRepositoryEl);
|
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { customElement, 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";
|
||||||
@ -49,7 +49,8 @@ const sortRepos = (a: HassioAddonRepository, b: HassioAddonRepository) => {
|
|||||||
return a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1;
|
return a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HassioAddonStore extends LitElement {
|
@customElement("hassio-addon-store")
|
||||||
|
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;
|
||||||
@ -250,5 +251,3 @@ class HassioAddonStore extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("hassio-addon-store", HassioAddonStore);
|
|
||||||
|
@ -17,7 +17,6 @@ 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,
|
||||||
|
@ -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",
|
||||||
};
|
};
|
||||||
|
135
package.json
135
package.json
@ -25,25 +25,25 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braintree/sanitize-url": "^6.0.2",
|
"@braintree/sanitize-url": "^6.0.2",
|
||||||
"@codemirror/autocomplete": "^6.4.0",
|
"@codemirror/autocomplete": "^6.4.2",
|
||||||
"@codemirror/commands": "^6.2.0",
|
"@codemirror/commands": "^6.2.1",
|
||||||
"@codemirror/language": "^6.4.0",
|
"@codemirror/language": "^6.6.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.7.1",
|
"@codemirror/view": "^6.9.1",
|
||||||
"@formatjs/intl-datetimeformat": "^6.4.3",
|
"@egjs/hammerjs": "^2.0.17",
|
||||||
"@formatjs/intl-getcanonicallocales": "^2.0.5",
|
"@formatjs/intl-datetimeformat": "^6.5.1",
|
||||||
"@formatjs/intl-locale": "^3.0.11",
|
"@formatjs/intl-getcanonicallocales": "^2.1.0",
|
||||||
"@formatjs/intl-numberformat": "^8.3.3",
|
"@formatjs/intl-locale": "^3.1.1",
|
||||||
"@formatjs/intl-pluralrules": "^5.1.8",
|
"@formatjs/intl-numberformat": "^8.3.5",
|
||||||
"@formatjs/intl-relativetimeformat": "^11.1.8",
|
"@formatjs/intl-pluralrules": "^5.1.10",
|
||||||
"@fullcalendar/common": "^5.11.4",
|
"@formatjs/intl-relativetimeformat": "^11.1.10",
|
||||||
"@fullcalendar/core": "^5.11.4",
|
"@fullcalendar/core": "^6.1.4",
|
||||||
"@fullcalendar/daygrid": "^5.11.4",
|
"@fullcalendar/daygrid": "^6.1.4",
|
||||||
"@fullcalendar/interaction": "^5.11.4",
|
"@fullcalendar/interaction": "^6.1.4",
|
||||||
"@fullcalendar/list": "^5.11.4",
|
"@fullcalendar/list": "^6.1.4",
|
||||||
"@fullcalendar/timegrid": "^5.11.4",
|
"@fullcalendar/timegrid": "^6.1.4",
|
||||||
"@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,6 +71,7 @@
|
|||||||
"@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.2",
|
||||||
"@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",
|
||||||
@ -88,35 +89,34 @@
|
|||||||
"@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.6",
|
"@vaadin/combo-box": "^23.3.7",
|
||||||
"@vaadin/vaadin-themable-mixin": "^23.3.6",
|
"@vaadin/vaadin-themable-mixin": "^23.3.7",
|
||||||
"@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.5",
|
"@webcomponents/scoped-custom-element-registry": "^0.0.8",
|
||||||
"@webcomponents/webcomponentsjs": "^2.2.10",
|
"@webcomponents/webcomponentsjs": "^2.7.0",
|
||||||
"app-datepicker": "^5.1.0",
|
"app-datepicker": "^5.1.0",
|
||||||
"chart.js": "^3.3.2",
|
"chart.js": "^3.3.2",
|
||||||
"comlink": "^4.3.1",
|
"comlink": "^4.4.1",
|
||||||
"core-js": "^3.27.2",
|
"core-js": "^3.28.0",
|
||||||
"cropperjs": "^1.5.13",
|
"cropperjs": "^1.5.13",
|
||||||
"date-fns": "^2.29.3",
|
"date-fns": "^2.29.3",
|
||||||
"date-fns-tz": "^1.3.7",
|
"date-fns-tz": "^2.0.0",
|
||||||
"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",
|
||||||
"hammerjs": "^2.0.8",
|
"hls.js": "^1.3.3",
|
||||||
"hls.js": "^1.3.1",
|
|
||||||
"home-assistant-js-websocket": "^8.0.1",
|
"home-assistant-js-websocket": "^8.0.1",
|
||||||
"idb-keyval": "^5.1.3",
|
"idb-keyval": "^6.2.0",
|
||||||
"intl-messageformat": "^10.3.0",
|
"intl-messageformat": "^10.3.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"leaflet": "^1.7.1",
|
"leaflet": "^1.9.3",
|
||||||
"leaflet-draw": "^1.0.4",
|
"leaflet-draw": "^1.0.4",
|
||||||
"lit": "^2.6.1",
|
"lit": "^2.6.1",
|
||||||
"marked": "^4.0.12",
|
"marked": "^4.2.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",
|
||||||
@ -126,16 +126,17 @@
|
|||||||
"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.1",
|
"rrule": "^2.7.2",
|
||||||
"sortablejs": "^1.14.0",
|
"sortablejs": "^1.15.0",
|
||||||
"superstruct": "^1.0.3",
|
"superstruct": "^1.0.3",
|
||||||
"tinykeys": "^1.1.3",
|
"tinykeys": "^1.4.0",
|
||||||
"tsparticles": "^1.34.0",
|
"tsparticles-engine": "^2.9.3",
|
||||||
"unfetch": "^4.1.0",
|
"tsparticles-preset-links": "^2.9.3",
|
||||||
"vis-data": "^7.1.2",
|
"unfetch": "^5.0.0",
|
||||||
"vis-network": "^8.5.4",
|
"vis-data": "^7.1.4",
|
||||||
"vue": "^2.6.12",
|
"vis-network": "^9.1.2",
|
||||||
"vue2-daterange-picker": "^0.5.1",
|
"vue": "^2.7.14",
|
||||||
|
"vue2-daterange-picker": "^0.6.8",
|
||||||
"weekstart": "^1.1.0",
|
"weekstart": "^1.1.0",
|
||||||
"workbox-cacheable-response": "^6.5.4",
|
"workbox-cacheable-response": "^6.5.4",
|
||||||
"workbox-core": "^6.5.4",
|
"workbox-core": "^6.5.4",
|
||||||
@ -146,18 +147,18 @@
|
|||||||
"xss": "^1.0.14"
|
"xss": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.2",
|
"@babel/core": "^7.21.0",
|
||||||
"@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.20.7",
|
"@babel/plugin-proposal-decorators": "^7.21.0",
|
||||||
"@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.2",
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
||||||
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
||||||
"@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.18.6",
|
"@babel/preset-typescript": "^7.21.0",
|
||||||
"@koa/cors": "^4.0.0",
|
"@koa/cors": "^4.0.0",
|
||||||
"@octokit/auth-oauth-device": "^4.0.4",
|
"@octokit/auth-oauth-device": "^4.0.4",
|
||||||
"@octokit/rest": "^19.0.7",
|
"@octokit/rest": "^19.0.7",
|
||||||
@ -169,58 +170,60 @@
|
|||||||
"@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.5",
|
||||||
|
"@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": "^8",
|
"@types/mocha": "^10",
|
||||||
"@types/qrcode": "^1.5.0",
|
"@types/qrcode": "^1.5.0",
|
||||||
"@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.46.1",
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
||||||
"@typescript-eslint/parser": "^5.49.0",
|
"@typescript-eslint/parser": "^5.53.0",
|
||||||
"@web/dev-server": "^0.0.24",
|
"@web/dev-server": "^0.1.35",
|
||||||
"@web/dev-server-rollup": "^0.2.11",
|
"@web/dev-server-rollup": "^0.2.11",
|
||||||
"babel-loader": "^9.1.2",
|
"babel-loader": "^9.1.2",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.7",
|
||||||
"del": "^7.0.0",
|
"del": "^7.0.0",
|
||||||
"eslint": "^7.32.0",
|
"eslint": "^8.34.0",
|
||||||
"eslint-config-airbnb-base": "^14.2.1",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-config-airbnb-typescript": "^14.0.0",
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
||||||
"eslint-config-prettier": "^8.6.0",
|
"eslint-config-prettier": "^8.6.0",
|
||||||
"eslint-import-resolver-webpack": "^0.13.1",
|
"eslint-import-resolver-webpack": "^0.13.2",
|
||||||
"eslint-plugin-disable": "^2.0.3",
|
"eslint-plugin-disable": "^2.0.3",
|
||||||
"eslint-plugin-import": "^2.24.2",
|
"eslint-plugin-import": "^2.27.5",
|
||||||
"eslint-plugin-lit": "^1.6.1",
|
"eslint-plugin-lit": "^1.8.2",
|
||||||
"eslint-plugin-unused-imports": "^1.1.5",
|
"eslint-plugin-lit-a11y": "^2.3.0",
|
||||||
|
"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.6",
|
"gulp-json-transform": "^0.4.8",
|
||||||
"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": "^3.0.1",
|
"gulp-zopfli-green": "^6.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.5.0",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"lint-staged": "^13.1.0",
|
"lint-staged": "^13.1.2",
|
||||||
"lit-analyzer": "^1.2.1",
|
"lit-analyzer": "^1.2.1",
|
||||||
"lodash.template": "^4.5.0",
|
"lodash.template": "^4.5.0",
|
||||||
"magic-string": "^0.25.7",
|
"magic-string": "^0.29.0",
|
||||||
"map-stream": "^0.0.7",
|
"map-stream": "^0.0.7",
|
||||||
"merge-stream": "^2.0.0",
|
"merge-stream": "^2.0.0",
|
||||||
"mocha": "^8.4.0",
|
"mocha": "^10.2.0",
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.1",
|
||||||
"pinst": "^3.0.0",
|
"pinst": "^3.0.0",
|
||||||
"prettier": "^2.8.3",
|
"prettier": "^2.8.4",
|
||||||
"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",
|
||||||
@ -230,13 +233,13 @@
|
|||||||
"sinon": "^15.0.1",
|
"sinon": "^15.0.1",
|
||||||
"source-map-url": "^0.4.1",
|
"source-map-url": "^0.4.1",
|
||||||
"systemjs": "^6.13.0",
|
"systemjs": "^6.13.0",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.13",
|
||||||
"terser-webpack-plugin": "^5.2.4",
|
"terser-webpack-plugin": "^5.3.6",
|
||||||
"ts-lit-plugin": "^1.2.1",
|
"ts-lit-plugin": "^1.2.1",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"vinyl-buffer": "^1.0.1",
|
"vinyl-buffer": "^1.0.1",
|
||||||
"vinyl-source-stream": "^2.0.0",
|
"vinyl-source-stream": "^2.0.0",
|
||||||
"webpack": "^5.55.1",
|
"webpack": "=5.72.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": "^5.0.0",
|
||||||
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20230202.0"
|
version = "20230222.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"
|
||||||
|
@ -6,6 +6,9 @@ set -e
|
|||||||
|
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
STATS=1 NODE_ENV=production ./node_modules/.bin/webpack --profile --json > compilation-stats.json
|
export STATS=1
|
||||||
npx webpack-bundle-analyzer compilation-stats.json hass_frontend/frontend_latest
|
statsfile="compilation-stats.json"
|
||||||
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
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { customElement, 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,7 +25,8 @@ import "./ha-password-manager-polyfill";
|
|||||||
|
|
||||||
type State = "loading" | "error" | "step";
|
type State = "loading" | "error" | "step";
|
||||||
|
|
||||||
class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
@customElement("ha-auth-flow")
|
||||||
|
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;
|
||||||
@ -407,7 +408,6 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("ha-auth-flow", HaAuthFlow);
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { customElement, 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,7 +14,8 @@ import "./ha-auth-flow";
|
|||||||
|
|
||||||
import("./ha-pick-auth-provider");
|
import("./ha-pick-auth-provider");
|
||||||
|
|
||||||
class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
@customElement("ha-authorize")
|
||||||
|
export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||||
@property() public clientId?: string;
|
@property() public clientId?: string;
|
||||||
|
|
||||||
@property() public redirectUri?: string;
|
@property() public redirectUri?: string;
|
||||||
@ -183,4 +184,3 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("ha-authorize", HaAuthorize);
|
|
||||||
|
@ -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 { 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 "../components/ha-icon-next";
|
import "../components/ha-icon-next";
|
||||||
import { AuthProvider } from "../data/auth";
|
import { AuthProvider } from "../data/auth";
|
||||||
@ -13,7 +13,8 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
|
@customElement("ha-pick-auth-provider")
|
||||||
|
export class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
|
||||||
@property() public authProviders: AuthProvider[] = [];
|
@property() public authProviders: AuthProvider[] = [];
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -47,4 +48,3 @@ class HaPickAuthProvider extends litLocalizeLiteMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
customElements.define("ha-pick-auth-provider", HaPickAuthProvider);
|
|
||||||
|
@ -2,6 +2,7 @@ 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;
|
||||||
|
@ -10,11 +10,19 @@ 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: Number(parts[2]) || 0,
|
seconds: seconds_whole,
|
||||||
milliseconds: Number(parts[3]) || 0,
|
milliseconds: Math.floor((seconds - seconds_whole) * 1000),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return { seconds: duration };
|
return { seconds: duration };
|
||||||
|
@ -11,8 +11,7 @@ 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")) as any)
|
const Leaflet = (await import("leaflet")).default as LeafletModuleType;
|
||||||
.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);
|
||||||
|
@ -49,6 +49,8 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
return localize(`state.default.${state}`);
|
return localize(`state.default.${state}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const entity = entities[entityId] as EntityRegistryEntry | 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
|
||||||
@ -82,7 +84,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
return `${formatNumber(
|
return `${formatNumber(
|
||||||
state,
|
state,
|
||||||
locale,
|
locale,
|
||||||
getNumberFormatOptions({ state, attributes } as HassEntity)
|
getNumberFormatOptions({ state, attributes } as HassEntity, entity)
|
||||||
)}${unit}`;
|
)}${unit}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
return formatNumber(
|
return formatNumber(
|
||||||
state,
|
state,
|
||||||
locale,
|
locale,
|
||||||
getNumberFormatOptions({ state, attributes } as HassEntity)
|
getNumberFormatOptions({ state, attributes } as HassEntity, entity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,8 +201,6 @@ 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(
|
||||||
|
@ -4,12 +4,15 @@ 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,
|
||||||
@ -113,5 +116,43 @@ 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ import {
|
|||||||
HassEntity,
|
HassEntity,
|
||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
|
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||||
import { FrontendLocaleData, NumberFormat } from "../../data/translation";
|
import { FrontendLocaleData, NumberFormat } from "../../data/translation";
|
||||||
import { round } from "./round";
|
import { round } from "./round";
|
||||||
|
|
||||||
@ -90,8 +91,18 @@ 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?: EntityRegistryEntry
|
||||||
): Intl.NumberFormatOptions | undefined => {
|
): Intl.NumberFormatOptions | undefined => {
|
||||||
|
const precision =
|
||||||
|
entity?.options?.sensor?.display_precision ??
|
||||||
|
entity?.options?.sensor?.suggested_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))
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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);
|
||||||
|
@ -19,6 +19,7 @@ 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> = {}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { property, query } from "lit/decorators";
|
import { customElement, 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;
|
||||||
|
|
||||||
@ -69,8 +70,6 @@ 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;
|
||||||
|
@ -233,7 +233,11 @@ export default class HaChartBase extends LitElement {
|
|||||||
{
|
{
|
||||||
id: "afterRenderHook",
|
id: "afterRenderHook",
|
||||||
afterRender: (chart) => {
|
afterRender: (chart) => {
|
||||||
this._chartHeight = chart.height;
|
const change = chart.height - (this._chartHeight ?? 0);
|
||||||
|
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,
|
||||||
|
@ -59,7 +59,7 @@ 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,
|
||||||
@ -99,7 +99,11 @@ class StatisticsChart extends LitElement {
|
|||||||
if (!this.hasUpdated || changedProps.has("unit")) {
|
if (!this.hasUpdated || changedProps.has("unit")) {
|
||||||
this._createOptions();
|
this._createOptions();
|
||||||
}
|
}
|
||||||
if (changedProps.has("statisticsData") || changedProps.has("statTypes")) {
|
if (
|
||||||
|
changedProps.has("statisticsData") ||
|
||||||
|
changedProps.has("statTypes") ||
|
||||||
|
changedProps.has("hideLegend")
|
||||||
|
) {
|
||||||
this._generateData();
|
this._generateData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
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 {
|
||||||
@ -21,16 +22,15 @@ 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
|
||||||
@ -461,7 +461,9 @@ export class HaDataTable extends LitElement {
|
|||||||
const elapsed = curTime - startTime;
|
const elapsed = curTime - startTime;
|
||||||
|
|
||||||
if (elapsed < 100) {
|
if (elapsed < 100) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100 - elapsed));
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 100 - elapsed);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (this.curRequest !== curRequest) {
|
if (this.curRequest !== curRequest) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { HassEntity, 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,6 +37,8 @@ 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}
|
||||||
>
|
>
|
||||||
@ -94,6 +96,8 @@ 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;
|
||||||
@ -113,6 +117,7 @@ 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) {
|
||||||
@ -127,7 +132,12 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
const deviceEntityLookup: DeviceEntityLookup = {};
|
const deviceEntityLookup: DeviceEntityLookup = {};
|
||||||
|
|
||||||
if (includeDomains || excludeDomains || includeDeviceClasses) {
|
if (
|
||||||
|
includeDomains ||
|
||||||
|
excludeDomains ||
|
||||||
|
includeDeviceClasses ||
|
||||||
|
entityFilter
|
||||||
|
) {
|
||||||
for (const entity of entities) {
|
for (const entity of entities) {
|
||||||
if (!entity.device_id) {
|
if (!entity.device_id) {
|
||||||
continue;
|
continue;
|
||||||
@ -198,6 +208,22 @@ 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) =>
|
||||||
@ -274,6 +300,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
this.excludeDomains,
|
this.excludeDomains,
|
||||||
this.includeDeviceClasses,
|
this.includeDeviceClasses,
|
||||||
this.deviceFilter,
|
this.deviceFilter,
|
||||||
|
this.entityFilter,
|
||||||
this.excludeDevices
|
this.excludeDevices
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ 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 { HaDevicePickerDeviceFilterFunc } from "./ha-device-picker";
|
import type {
|
||||||
|
HaDevicePickerDeviceFilterFunc,
|
||||||
|
HaDevicePickerEntityFilterFunc,
|
||||||
|
} from "./ha-device-picker";
|
||||||
|
|
||||||
@customElement("ha-devices-picker")
|
@customElement("ha-devices-picker")
|
||||||
class HaDevicesPicker extends LitElement {
|
class HaDevicesPicker extends LitElement {
|
||||||
@ -44,6 +47,8 @@ class HaDevicesPicker extends LitElement {
|
|||||||
|
|
||||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||||
|
|
||||||
|
@property() public entityFilter?: HaDevicePickerEntityFilterFunc;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -59,6 +64,7 @@ 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}
|
||||||
@ -76,8 +82,10 @@ 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}
|
||||||
|
@ -186,7 +186,7 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
? formatNumber(
|
? formatNumber(
|
||||||
entityState.state,
|
entityState.state,
|
||||||
this.hass!.locale,
|
this.hass!.locale,
|
||||||
getNumberFormatOptions(entityState)
|
getNumberFormatOptions(entityState, entry)
|
||||||
)
|
)
|
||||||
: computeStateDisplay(
|
: computeStateDisplay(
|
||||||
this.hass!.localize,
|
this.hass!.localize,
|
||||||
|
@ -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 (["heating", "cooling", "drying", "fan"].includes(hvacAction)) {
|
if (hvacAction in HVAC_ACTION_TO_MODE) {
|
||||||
iconStyle.color = stateColorCss(
|
iconStyle.color = stateColorCss(
|
||||||
stateObj,
|
stateObj,
|
||||||
HVAC_ACTION_TO_MODE[hvacAction]
|
HVAC_ACTION_TO_MODE[hvacAction]
|
||||||
|
@ -37,13 +37,10 @@ class HaAlert extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public dismissable = false;
|
@property({ type: Boolean }) public dismissable = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public rtl = false;
|
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
class="issue-type ${classMap({
|
class="issue-type ${classMap({
|
||||||
rtl: this.rtl,
|
|
||||||
[this.alertType]: true,
|
[this.alertType]: true,
|
||||||
})}"
|
})}"
|
||||||
role="alert"
|
role="alert"
|
||||||
@ -84,9 +81,6 @@ class HaAlert extends LitElement {
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.issue-type.rtl {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
}
|
|
||||||
.issue-type::after {
|
.issue-type::after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -104,15 +98,12 @@ class HaAlert extends LitElement {
|
|||||||
.icon.no-title {
|
.icon.no-title {
|
||||||
align-self: center;
|
align-self: center;
|
||||||
}
|
}
|
||||||
.issue-type.rtl > .content {
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
.content {
|
.content {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
text-align: var(--float-start);
|
||||||
}
|
}
|
||||||
.action {
|
.action {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
@ -124,10 +115,9 @@ class HaAlert extends LitElement {
|
|||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
margin-inline-start: 8px;
|
||||||
.issue-type.rtl > .content > .main-content {
|
margin-inline-end: 0;
|
||||||
margin-left: 0;
|
direction: var(--direction);
|
||||||
margin-right: 8px;
|
|
||||||
}
|
}
|
||||||
.title {
|
.title {
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, TemplateResult } 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";
|
||||||
@ -83,7 +85,7 @@ export class HaAreaPicker extends LitElement {
|
|||||||
|
|
||||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||||
|
|
||||||
@property() public entityFilter?: (entity: EntityRegistryEntry) => boolean;
|
@property() public entityFilter?: (entity: HassEntity) => boolean;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled?: boolean;
|
@property({ type: Boolean }) public disabled?: boolean;
|
||||||
|
|
||||||
@ -135,7 +137,12 @@ export class HaAreaPicker extends LitElement {
|
|||||||
let inputDevices: DeviceRegistryEntry[] | undefined;
|
let inputDevices: DeviceRegistryEntry[] | undefined;
|
||||||
let inputEntities: EntityRegistryEntry[] | undefined;
|
let inputEntities: EntityRegistryEntry[] | undefined;
|
||||||
|
|
||||||
if (includeDomains || excludeDomains || includeDeviceClasses) {
|
if (
|
||||||
|
includeDomains ||
|
||||||
|
excludeDomains ||
|
||||||
|
includeDeviceClasses ||
|
||||||
|
entityFilter
|
||||||
|
) {
|
||||||
for (const entity of entities) {
|
for (const entity of entities) {
|
||||||
if (!entity.device_id) {
|
if (!entity.device_id) {
|
||||||
continue;
|
continue;
|
||||||
@ -145,16 +152,9 @@ export class HaAreaPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
deviceEntityLookup[entity.device_id].push(entity);
|
deviceEntityLookup[entity.device_id].push(entity);
|
||||||
}
|
}
|
||||||
inputDevices = devices;
|
|
||||||
inputEntities = entities.filter((entity) => entity.area_id);
|
|
||||||
} else {
|
|
||||||
if (deviceFilter) {
|
|
||||||
inputDevices = devices;
|
|
||||||
}
|
|
||||||
if (entityFilter) {
|
|
||||||
inputEntities = entities.filter((entity) => entity.area_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
inputDevices = devices;
|
||||||
|
inputEntities = entities.filter((entity) => entity.area_id);
|
||||||
|
|
||||||
if (includeDomains) {
|
if (includeDomains) {
|
||||||
inputDevices = inputDevices!.filter((device) => {
|
inputDevices = inputDevices!.filter((device) => {
|
||||||
@ -218,9 +218,26 @@ export class HaAreaPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (entityFilter) {
|
if (entityFilter) {
|
||||||
inputEntities = inputEntities!.filter((entity) =>
|
inputDevices = inputDevices!.filter((device) => {
|
||||||
entityFilter!(entity)
|
const devEntities = deviceEntityLookup[device.id];
|
||||||
);
|
if (!devEntities || !devEntities.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return deviceEntityLookup[device.id].some((entity) => {
|
||||||
|
const stateObj = this.hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return entityFilter(stateObj);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
inputEntities = inputEntities!.filter((entity) => {
|
||||||
|
const stateObj = this.hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return entityFilter!(stateObj);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let outputAreas = areas;
|
let outputAreas = areas;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, html, LitElement, TemplateResult } 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 type { EntityRegistryEntry } from "../data/entity_registry";
|
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||||
@ -48,7 +48,7 @@ export class HaAreasPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||||
|
|
||||||
@property() public entityFilter?: (entity: EntityRegistryEntry) => boolean;
|
@property() public entityFilter?: (entity: HassEntity) => boolean;
|
||||||
|
|
||||||
@property({ attribute: "picked-area-label" })
|
@property({ attribute: "picked-area-label" })
|
||||||
public pickedAreaLabel?: string;
|
public pickedAreaLabel?: string;
|
||||||
|
@ -41,9 +41,9 @@ class HaBluePrintPicker extends LitElement {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const result = Object.entries(blueprints)
|
const result = Object.entries(blueprints)
|
||||||
.filter(([_path, blueprint]) => !("error" in blueprint))
|
.filter((entry): entry is [string, Blueprint] => !("error" in entry[1]))
|
||||||
.map(([path, blueprint]) => ({
|
.map(([path, blueprint]) => ({
|
||||||
...(blueprint as Blueprint).metadata,
|
...blueprint.metadata,
|
||||||
path,
|
path,
|
||||||
}));
|
}));
|
||||||
return result.sort((a, b) =>
|
return result.sort((a, b) =>
|
||||||
|
@ -17,11 +17,8 @@ export class HaClickableListItem extends HaListItem {
|
|||||||
const href = this.href || "";
|
const href = this.href || "";
|
||||||
|
|
||||||
return html`${this.disableHref
|
return html`${this.disableHref
|
||||||
? html`<a aria-role="option">${r}</a>`
|
? html`<a>${r}</a>`
|
||||||
: html`<a
|
: html`<a target=${this.openNewTab ? "_blank" : ""} href=${href}
|
||||||
aria-role="option"
|
|
||||||
target=${this.openNewTab ? "_blank" : ""}
|
|
||||||
href=${href}
|
|
||||||
>${r}</a
|
>${r}</a
|
||||||
>`}`;
|
>`}`;
|
||||||
}
|
}
|
||||||
|
63
src/components/ha-control-button-group.ts
Normal file
63
src/components/ha-control-button-group.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
|
||||||
|
@customElement("ha-control-button-group")
|
||||||
|
export class HaControlButtonGroup extends LitElement {
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public vertical = false;
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
<div class="container">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return css`
|
||||||
|
:host {
|
||||||
|
--control-button-group-spacing: 12px;
|
||||||
|
--control-button-group-thickness: 40px;
|
||||||
|
height: var(--control-button-group-thickness);
|
||||||
|
width: auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
::slotted(*) {
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
::slotted(*:not(:last-child)) {
|
||||||
|
margin-right: var(--control-button-group-spacing);
|
||||||
|
margin-inline-end: var(--control-button-group-spacing);
|
||||||
|
margin-inline-start: initial;
|
||||||
|
direction: var(--direction);
|
||||||
|
}
|
||||||
|
:host([vertical]) {
|
||||||
|
width: var(--control-button-group-thickness);
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
:host([vertical]) .container {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
:host([vertical]) ::slotted(ha-control-button:not(:last-child)) {
|
||||||
|
margin-right: initial;
|
||||||
|
margin-inline-end: initial;
|
||||||
|
margin-bottom: var(--control-button-group-spacing);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-control-button-group": HaControlButtonGroup;
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,9 @@ import {
|
|||||||
state,
|
state,
|
||||||
} from "lit/decorators";
|
} from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import "../ha-icon";
|
|
||||||
import "../ha-svg-icon";
|
|
||||||
|
|
||||||
@customElement("ha-tile-button")
|
@customElement("ha-control-button")
|
||||||
export class HaTileButton extends LitElement {
|
export class HaControlButton extends LitElement {
|
||||||
@property({ type: Boolean, reflect: true }) disabled = false;
|
@property({ type: Boolean, reflect: true }) disabled = false;
|
||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
@ -28,7 +26,7 @@ export class HaTileButton extends LitElement {
|
|||||||
type="button"
|
type="button"
|
||||||
class="button"
|
class="button"
|
||||||
aria-label=${ifDefined(this.label)}
|
aria-label=${ifDefined(this.label)}
|
||||||
.title=${this.label}
|
title=${ifDefined(this.label)}
|
||||||
.disabled=${Boolean(this.disabled)}
|
.disabled=${Boolean(this.disabled)}
|
||||||
@focus=${this.handleRippleFocus}
|
@focus=${this.handleRippleFocus}
|
||||||
@blur=${this.handleRippleBlur}
|
@blur=${this.handleRippleBlur}
|
||||||
@ -81,9 +79,12 @@ export class HaTileButton extends LitElement {
|
|||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
--tile-button-icon-color: var(--primary-text-color);
|
display: block;
|
||||||
--tile-button-background-color: var(--disabled-color);
|
--control-button-icon-color: var(--primary-text-color);
|
||||||
--tile-button-background-opacity: 0.2;
|
--control-button-background-color: var(--disabled-color);
|
||||||
|
--control-button-background-opacity: 0.2;
|
||||||
|
--control-button-border-radius: 10px;
|
||||||
|
--mdc-icon-size: 20px;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
@ -97,7 +98,7 @@ export class HaTileButton extends LitElement {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border-radius: 10px;
|
border-radius: var(--control-button-border-radius);
|
||||||
border: none;
|
border: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@ -106,7 +107,8 @@ export class HaTileButton extends LitElement {
|
|||||||
outline: none;
|
outline: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: none;
|
background: none;
|
||||||
--mdc-ripple-color: var(--tile-button-background-color);
|
z-index: 1;
|
||||||
|
--mdc-ripple-color: var(--control-button-background-color);
|
||||||
}
|
}
|
||||||
.button::before {
|
.button::before {
|
||||||
content: "";
|
content: "";
|
||||||
@ -115,22 +117,21 @@ export class HaTileButton extends LitElement {
|
|||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--tile-button-background-color);
|
background-color: var(--control-button-background-color);
|
||||||
transition: background-color 180ms ease-in-out,
|
transition: background-color 180ms ease-in-out,
|
||||||
opacity 180ms ease-in-out;
|
opacity 180ms ease-in-out;
|
||||||
opacity: var(--tile-button-background-opacity);
|
opacity: var(--control-button-background-opacity);
|
||||||
}
|
}
|
||||||
.button ::slotted(*) {
|
.button ::slotted(*) {
|
||||||
--mdc-icon-size: 20px;
|
|
||||||
transition: color 180ms ease-in-out;
|
transition: color 180ms ease-in-out;
|
||||||
color: var(--tile-button-icon-color);
|
color: var(--control-button-icon-color);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
.button:disabled {
|
.button:disabled {
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
--tile-button-background-color: var(--disabled-color);
|
--control-button-background-color: var(--disabled-color);
|
||||||
--tile-button-icon-color: var(--disabled-text-color);
|
--control-button-icon-color: var(--disabled-text-color);
|
||||||
--tile-button-background-opacity: 0.2;
|
--control-button-background-opacity: 0.2;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -138,6 +139,6 @@ export class HaTileButton extends LitElement {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-tile-button": HaTileButton;
|
"ha-control-button": HaControlButton;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import "hammerjs";
|
import { DIRECTION_ALL, Manager, Pan, Tap } from "@egjs/hammerjs";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -42,9 +42,9 @@ const getPercentageFromEvent = (e: HammerInput, vertical: boolean) => {
|
|||||||
return Math.max(Math.min(1, (x - offset) / total), 0);
|
return Math.max(Math.min(1, (x - offset) / total), 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@customElement("ha-bar-slider")
|
@customElement("ha-control-slider")
|
||||||
export class HaBarSlider extends LitElement {
|
export class HaControlSlider extends LitElement {
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean, reflect: true })
|
||||||
public disabled = false;
|
public disabled = false;
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
@ -131,18 +131,18 @@ export class HaBarSlider extends LitElement {
|
|||||||
|
|
||||||
setupListeners() {
|
setupListeners() {
|
||||||
if (this.slider && !this._mc) {
|
if (this.slider && !this._mc) {
|
||||||
this._mc = new Hammer.Manager(this.slider, {
|
this._mc = new Manager(this.slider, {
|
||||||
touchAction: this.vertical ? "pan-x" : "pan-y",
|
touchAction: this.vertical ? "pan-x" : "pan-y",
|
||||||
});
|
});
|
||||||
this._mc.add(
|
this._mc.add(
|
||||||
new Hammer.Pan({
|
new Pan({
|
||||||
threshold: 10,
|
threshold: 10,
|
||||||
direction: Hammer.DIRECTION_ALL,
|
direction: DIRECTION_ALL,
|
||||||
enable: true,
|
enable: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._mc.add(new Hammer.Tap({ event: "singletap" }));
|
this._mc.add(new Tap({ event: "singletap" }));
|
||||||
|
|
||||||
let savedValue;
|
let savedValue;
|
||||||
this._mc.on("panstart", () => {
|
this._mc.on("panstart", () => {
|
||||||
@ -245,14 +245,16 @@ export class HaBarSlider extends LitElement {
|
|||||||
>
|
>
|
||||||
<div class="slider-track-background"></div>
|
<div class="slider-track-background"></div>
|
||||||
${this.mode === "cursor"
|
${this.mode === "cursor"
|
||||||
? html`
|
? this.value != null
|
||||||
<div
|
? html`
|
||||||
class=${classMap({
|
<div
|
||||||
"slider-track-cursor": true,
|
class=${classMap({
|
||||||
vertical: this.vertical,
|
"slider-track-cursor": true,
|
||||||
})}
|
vertical: this.vertical,
|
||||||
></div>
|
})}
|
||||||
`
|
></div>
|
||||||
|
`
|
||||||
|
: null
|
||||||
: html`
|
: html`
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@ -271,28 +273,29 @@ export class HaBarSlider extends LitElement {
|
|||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
--slider-bar-color: var(--primary-color);
|
--control-slider-color: var(--primary-color);
|
||||||
--slider-bar-background: var(--disabled-color);
|
--control-slider-background: var(--disabled-color);
|
||||||
--slider-bar-background-opacity: 0.2;
|
--control-slider-background-opacity: 0.2;
|
||||||
--slider-bar-thickness: 40px;
|
--control-slider-thickness: 40px;
|
||||||
--slider-bar-border-radius: 10px;
|
--control-slider-border-radius: 10px;
|
||||||
height: var(--slider-bar-thickness);
|
height: var(--control-slider-thickness);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: var(--slider-bar-border-radius);
|
border-radius: var(--control-slider-border-radius);
|
||||||
outline: none;
|
outline: none;
|
||||||
|
transition: box-shadow 180ms ease-in-out;
|
||||||
}
|
}
|
||||||
:host(:focus-visible) {
|
:host(:focus-visible) {
|
||||||
box-shadow: 0 0 0 2px var(--slider-bar-color);
|
box-shadow: 0 0 0 2px var(--control-slider-color);
|
||||||
}
|
}
|
||||||
:host([vertical]) {
|
:host([vertical]) {
|
||||||
width: var(--slider-bar-thickness);
|
width: var(--control-slider-thickness);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
.slider {
|
.slider {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: var(--slider-bar-border-radius);
|
border-radius: var(--control-slider-border-radius);
|
||||||
transform: translateZ(0);
|
transform: translateZ(0);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@ -306,19 +309,20 @@ export class HaBarSlider extends LitElement {
|
|||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: var(--slider-bar-background);
|
background: var(--control-slider-background);
|
||||||
opacity: var(--slider-bar-background-opacity);
|
opacity: var(--control-slider-background-opacity);
|
||||||
}
|
}
|
||||||
.slider .slider-track-bar {
|
.slider .slider-track-bar {
|
||||||
--border-radius: var(--slider-bar-border-radius);
|
--border-radius: var(--control-slider-border-radius);
|
||||||
--handle-size: 4px;
|
--handle-size: 4px;
|
||||||
--handle-margin: calc(var(--slider-bar-thickness) / 8);
|
--handle-margin: calc(var(--control-slider-thickness) / 8);
|
||||||
--slider-size: 100%;
|
--slider-size: 100%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--slider-bar-color);
|
background-color: var(--control-slider-color);
|
||||||
transition: transform 180ms ease-in-out;
|
transition: transform 180ms ease-in-out,
|
||||||
|
background-color 180ms ease-in-out;
|
||||||
}
|
}
|
||||||
.slider .slider-track-bar.show-handle {
|
.slider .slider-track-bar.show-handle {
|
||||||
--slider-size: calc(
|
--slider-size: calc(
|
||||||
@ -412,7 +416,7 @@ export class HaBarSlider extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.slider .slider-track-cursor {
|
.slider .slider-track-cursor {
|
||||||
--cursor-size: calc(var(--slider-bar-thickness) / 4);
|
--cursor-size: calc(var(--control-slider-thickness) / 4);
|
||||||
--handle-size: 4px;
|
--handle-size: 4px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
@ -445,12 +449,15 @@ export class HaBarSlider extends LitElement {
|
|||||||
:host([pressed]) .slider-track-cursor {
|
:host([pressed]) .slider-track-cursor {
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
|
:host(:disabled) .slider {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-bar-slider": HaBarSlider;
|
"ha-control-slider": HaControlSlider;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ import { customElement, property } from "lit/decorators";
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
@customElement("ha-bar-switch")
|
@customElement("ha-control-switch")
|
||||||
export class HaBarSwitch extends LitElement {
|
export class HaControlSwitch extends LitElement {
|
||||||
@property({ type: Boolean, attribute: "disabled" })
|
@property({ type: Boolean, reflect: true })
|
||||||
public disabled = false;
|
public disabled = false;
|
||||||
|
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean })
|
||||||
@ -40,7 +40,7 @@ export class HaBarSwitch extends LitElement {
|
|||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
if (changedProps.has("value")) {
|
if (changedProps.has("checked")) {
|
||||||
this.setAttribute("aria-checked", this.checked ? "true" : "false");
|
this.setAttribute("aria-checked", this.checked ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,35 +92,37 @@ export class HaBarSwitch extends LitElement {
|
|||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
--switch-bar-on-color: var(--primary-color);
|
--control-switch-on-color: var(--primary-color);
|
||||||
--switch-bar-off-color: var(--disabled-color);
|
--control-switch-off-color: var(--disabled-color);
|
||||||
--switch-bar-background-opacity: 0.2;
|
--control-switch-background-opacity: 0.2;
|
||||||
--switch-bar-thickness: 40px;
|
--control-switch-thickness: 40px;
|
||||||
--switch-bar-border-radius: 12px;
|
--control-switch-border-radius: 12px;
|
||||||
--switch-bar-padding: 4px;
|
--control-switch-padding: 4px;
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
height: var(--switch-bar-thickness);
|
height: var(--control-switch-thickness);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: var(--switch-bar-border-radius);
|
border-radius: var(--control-switch-border-radius);
|
||||||
outline: none;
|
outline: none;
|
||||||
|
transition: box-shadow 180ms ease-in-out;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
}
|
}
|
||||||
:host(:focus-visible) {
|
:host(:focus-visible) {
|
||||||
box-shadow: 0 0 0 2px var(--switch-bar-off-color);
|
box-shadow: 0 0 0 2px var(--control-switch-off-color);
|
||||||
}
|
}
|
||||||
:host([checked]:focus-visible) {
|
:host([checked]:focus-visible) {
|
||||||
box-shadow: 0 0 0 2px var(--switch-bar-on-color);
|
box-shadow: 0 0 0 2px var(--control-switch-on-color);
|
||||||
}
|
}
|
||||||
.switch {
|
.switch {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: var(--switch-bar-border-radius);
|
border-radius: var(--control-switch-border-radius);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: var(--switch-bar-padding);
|
padding: var(--control-switch-padding);
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.switch .background {
|
.switch .background {
|
||||||
@ -129,31 +131,31 @@ export class HaBarSwitch extends LitElement {
|
|||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--switch-bar-off-color);
|
background-color: var(--control-switch-off-color);
|
||||||
transition: background-color 180ms ease-in-out;
|
transition: background-color 180ms ease-in-out;
|
||||||
opacity: var(--switch-bar-background-opacity);
|
opacity: var(--control-switch-background-opacity);
|
||||||
}
|
}
|
||||||
.switch .button {
|
.switch .button {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: lightgrey;
|
background: lightgrey;
|
||||||
border-radius: calc(
|
border-radius: calc(
|
||||||
var(--switch-bar-border-radius) - var(--switch-bar-padding)
|
var(--control-switch-border-radius) - var(--control-switch-padding)
|
||||||
);
|
);
|
||||||
transition: transform 180ms ease-in-out,
|
transition: transform 180ms ease-in-out,
|
||||||
background-color 180ms ease-in-out;
|
background-color 180ms ease-in-out;
|
||||||
background-color: var(--switch-bar-off-color);
|
background-color: var(--control-switch-off-color);
|
||||||
color: white;
|
color: white;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
:host([checked]) .switch .background {
|
:host([checked]) .switch .background {
|
||||||
background-color: var(--switch-bar-on-color);
|
background-color: var(--control-switch-on-color);
|
||||||
}
|
}
|
||||||
:host([checked]) .switch .button {
|
:host([checked]) .switch .button {
|
||||||
transform: translateX(100%);
|
transform: translateX(100%);
|
||||||
background-color: var(--switch-bar-on-color);
|
background-color: var(--control-switch-on-color);
|
||||||
}
|
}
|
||||||
:host([reversed]) .switch {
|
:host([reversed]) .switch {
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
@ -162,7 +164,7 @@ export class HaBarSwitch extends LitElement {
|
|||||||
transform: translateX(-100%);
|
transform: translateX(-100%);
|
||||||
}
|
}
|
||||||
:host([vertical]) {
|
:host([vertical]) {
|
||||||
width: var(--switch-bar-thickness);
|
width: var(--control-switch-thickness);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
:host([vertical][checked]) .switch .button {
|
:host([vertical][checked]) .switch .button {
|
||||||
@ -188,6 +190,6 @@ export class HaBarSwitch extends LitElement {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-bar-switch": HaBarSwitch;
|
"ha-control-switch": HaControlSwitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,13 +40,31 @@ export class HaDialog extends DialogBase {
|
|||||||
this.suppressDefaultPressSelector,
|
this.suppressDefaultPressSelector,
|
||||||
SUPPRESS_DEFAULT_PRESS_SELECTOR,
|
SUPPRESS_DEFAULT_PRESS_SELECTOR,
|
||||||
].join(", ");
|
].join(", ");
|
||||||
|
this._updateScrolledAttribute();
|
||||||
|
this.contentElement?.addEventListener("scroll", this._onScroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback(): void {
|
||||||
|
this.contentElement.removeEventListener("scroll", this._onScroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _onScroll = () => {
|
||||||
|
this._updateScrolledAttribute();
|
||||||
|
};
|
||||||
|
|
||||||
|
private _updateScrolledAttribute() {
|
||||||
|
if (!this.contentElement) return;
|
||||||
|
this.toggleAttribute("scrolled", this.contentElement.scrollTop !== 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static override styles = [
|
static override styles = [
|
||||||
styles,
|
styles,
|
||||||
css`
|
css`
|
||||||
.mdc-dialog {
|
.mdc-dialog {
|
||||||
--mdc-dialog-scroll-divider-color: var(--divider-color);
|
--mdc-dialog-scroll-divider-color: var(
|
||||||
|
--dialog-scroll-divider-color,
|
||||||
|
var(--divider-color)
|
||||||
|
);
|
||||||
z-index: var(--dialog-z-index, 7);
|
z-index: var(--dialog-z-index, 7);
|
||||||
-webkit-backdrop-filter: var(--dialog-backdrop-filter, none);
|
-webkit-backdrop-filter: var(--dialog-backdrop-filter, none);
|
||||||
backdrop-filter: var(--dialog-backdrop-filter, none);
|
backdrop-filter: var(--dialog-backdrop-filter, none);
|
||||||
|
@ -75,7 +75,6 @@ export class HaFileUpload extends LitElement {
|
|||||||
${this.icon
|
${this.icon
|
||||||
? html`<span
|
? html`<span
|
||||||
class="mdc-text-field__icon mdc-text-field__icon--leading"
|
class="mdc-text-field__icon mdc-text-field__icon--leading"
|
||||||
tabindex="-1"
|
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@click=${this._openFilePicker}
|
@click=${this._openFilePicker}
|
||||||
@ -95,7 +94,6 @@ export class HaFileUpload extends LitElement {
|
|||||||
${this.value
|
${this.value
|
||||||
? html`<span
|
? html`<span
|
||||||
class="mdc-text-field__icon mdc-text-field__icon--trailing"
|
class="mdc-text-field__icon mdc-text-field__icon--trailing"
|
||||||
tabindex="1"
|
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="suffix"
|
slot="suffix"
|
||||||
|
@ -36,6 +36,12 @@ export class HaHeaderBar extends LitElement {
|
|||||||
position: static;
|
position: static;
|
||||||
color: var(--mdc-theme-on-primary, #fff);
|
color: var(--mdc-theme-on-primary, #fff);
|
||||||
}
|
}
|
||||||
|
.mdc-top-app-bar__section.mdc-top-app-bar__section--align-start {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.mdc-top-app-bar__section.mdc-top-app-bar__section--align-end {
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { mdiChevronLeft, mdiChevronRight } from "@mdi/js";
|
import { mdiChevronLeft, mdiChevronRight } from "@mdi/js";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
import { HaSvgIcon } from "./ha-svg-icon";
|
import { HaSvgIcon } from "./ha-svg-icon";
|
||||||
|
|
||||||
|
@customElement("ha-icon-next")
|
||||||
export class HaIconNext extends HaSvgIcon {
|
export class HaIconNext extends HaSvgIcon {
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
@ -20,5 +22,3 @@ declare global {
|
|||||||
"ha-icon-next": HaIconNext;
|
"ha-icon-next": HaIconNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-icon-next", HaIconNext);
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { mdiChevronLeft, mdiChevronRight } from "@mdi/js";
|
import { mdiChevronLeft, mdiChevronRight } from "@mdi/js";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
import { HaSvgIcon } from "./ha-svg-icon";
|
import { HaSvgIcon } from "./ha-svg-icon";
|
||||||
|
|
||||||
|
@customElement("ha-icon-prev")
|
||||||
export class HaIconPrev extends HaSvgIcon {
|
export class HaIconPrev extends HaSvgIcon {
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
@ -20,5 +22,3 @@ declare global {
|
|||||||
"ha-icon-prev": HaIconPrev;
|
"ha-icon-prev": HaIconPrev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-icon-prev", HaIconPrev);
|
|
||||||
|
@ -6,9 +6,10 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
|
||||||
|
@customElement("ha-label-badge")
|
||||||
class HaLabelBadge extends LitElement {
|
class HaLabelBadge extends LitElement {
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
@ -132,5 +133,3 @@ declare global {
|
|||||||
"ha-label-badge": HaLabelBadge;
|
"ha-label-badge": HaLabelBadge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-label-badge", HaLabelBadge);
|
|
||||||
|
@ -282,7 +282,9 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private async _navigateAwayClose() {
|
private async _navigateAwayClose() {
|
||||||
// allow new page to open before closing dialog
|
// allow new page to open before closing dialog
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 0);
|
||||||
|
});
|
||||||
fireEvent(this, "close-dialog");
|
fireEvent(this, "close-dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
|||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, PropertyValues, 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 { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
||||||
import {
|
import {
|
||||||
@ -52,11 +53,21 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _hasIntegration(selector: AreaSelector) {
|
||||||
|
return (
|
||||||
|
(selector.area?.entity &&
|
||||||
|
ensureArray(selector.area.entity).some(
|
||||||
|
(filter) => filter.integration
|
||||||
|
)) ||
|
||||||
|
(selector.area?.device &&
|
||||||
|
ensureArray(selector.area.device).some((device) => device.integration))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
if (
|
if (
|
||||||
changedProperties.has("selector") &&
|
changedProperties.has("selector") &&
|
||||||
(this.selector.area?.device?.integration ||
|
this._hasIntegration(this.selector) &&
|
||||||
this.selector.area?.entity?.integration) &&
|
|
||||||
!this._entitySources
|
!this._entitySources
|
||||||
) {
|
) {
|
||||||
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
||||||
@ -66,11 +77,7 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (
|
if (this._hasIntegration(this.selector) && !this._entitySources) {
|
||||||
(this.selector.area?.device?.integration ||
|
|
||||||
this.selector.area?.entity?.integration) &&
|
|
||||||
!this._entitySources
|
|
||||||
) {
|
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,10 +117,8 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterSelectorEntities(
|
return ensureArray(this.selector.area.entity).some((filter) =>
|
||||||
this.selector.area.entity,
|
filterSelectorEntities(filter, entity, this._entitySources)
|
||||||
entity,
|
|
||||||
this._entitySources
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,10 +132,8 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
|
|||||||
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return filterSelectorDevices(
|
return ensureArray(this.selector.area.device).some((filter) =>
|
||||||
this.selector.area.device,
|
filterSelectorDevices(filter, device, deviceIntegrations)
|
||||||
device,
|
|
||||||
deviceIntegrations
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } 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 { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
||||||
import {
|
import {
|
||||||
@ -13,7 +14,10 @@ import {
|
|||||||
fetchEntitySourcesWithCache,
|
fetchEntitySourcesWithCache,
|
||||||
} from "../../data/entity_sources";
|
} from "../../data/entity_sources";
|
||||||
import type { DeviceSelector } from "../../data/selector";
|
import type { DeviceSelector } from "../../data/selector";
|
||||||
import { filterSelectorDevices } from "../../data/selector";
|
import {
|
||||||
|
filterSelectorDevices,
|
||||||
|
filterSelectorEntities,
|
||||||
|
} from "../../data/selector";
|
||||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../device/ha-device-picker";
|
import "../device/ha-device-picker";
|
||||||
@ -49,11 +53,24 @@ export class HaDeviceSelector extends SubscribeMixin(LitElement) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _hasIntegration(selector: DeviceSelector) {
|
||||||
|
return (
|
||||||
|
(selector.device?.filter &&
|
||||||
|
ensureArray(selector.device.filter).some(
|
||||||
|
(filter) => filter.integration
|
||||||
|
)) ||
|
||||||
|
(selector.device?.entity &&
|
||||||
|
ensureArray(selector.device.entity).some(
|
||||||
|
(device) => device.integration
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProperties): void {
|
protected updated(changedProperties): void {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
if (
|
if (
|
||||||
changedProperties.has("selector") &&
|
changedProperties.has("selector") &&
|
||||||
this.selector.device?.integration &&
|
this._hasIntegration(this.selector) &&
|
||||||
!this._entitySources
|
!this._entitySources
|
||||||
) {
|
) {
|
||||||
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
||||||
@ -63,7 +80,7 @@ export class HaDeviceSelector extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this.selector.device?.integration && !this._entitySources) {
|
if (this._hasIntegration(this.selector) && !this._entitySources) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +92,7 @@ export class HaDeviceSelector extends SubscribeMixin(LitElement) {
|
|||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.deviceFilter=${this._filterDevices}
|
.deviceFilter=${this._filterDevices}
|
||||||
.includeDeviceClasses=${this.selector.device?.entity?.device_class
|
.entityFilter=${this._filterEntities}
|
||||||
? [this.selector.device.entity.device_class]
|
|
||||||
: undefined}
|
|
||||||
.includeDomains=${this.selector.device?.entity?.domain
|
|
||||||
? [this.selector.device.entity.domain]
|
|
||||||
: undefined}
|
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
@ -95,12 +107,7 @@ export class HaDeviceSelector extends SubscribeMixin(LitElement) {
|
|||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.deviceFilter=${this._filterDevices}
|
.deviceFilter=${this._filterDevices}
|
||||||
.includeDeviceClasses=${this.selector.device.entity?.device_class
|
.entityFilter=${this._filterEntities}
|
||||||
? [this.selector.device.entity.device_class]
|
|
||||||
: undefined}
|
|
||||||
.includeDomains=${this.selector.device.entity?.domain
|
|
||||||
? [this.selector.device.entity.domain]
|
|
||||||
: undefined}
|
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
></ha-devices-picker>
|
></ha-devices-picker>
|
||||||
@ -108,18 +115,25 @@ export class HaDeviceSelector extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
||||||
|
if (!this.selector.device?.filter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const deviceIntegrations =
|
const deviceIntegrations =
|
||||||
this._entitySources && this._entities
|
this._entitySources && this._entities
|
||||||
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (!this.selector.device) {
|
return ensureArray(this.selector.device.filter).some((filter) =>
|
||||||
|
filterSelectorDevices(filter, device, deviceIntegrations)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
private _filterEntities = (entity: HassEntity): boolean => {
|
||||||
|
if (!this.selector.device?.entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return filterSelectorDevices(
|
return ensureArray(this.selector.device.entity).some((filter) =>
|
||||||
this.selector.device,
|
filterSelectorEntities(filter, entity, this._entitySources)
|
||||||
device,
|
|
||||||
deviceIntegrations
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { html, LitElement, PropertyValues } from "lit";
|
import { html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import {
|
import {
|
||||||
EntitySources,
|
EntitySources,
|
||||||
fetchEntitySourcesWithCache,
|
fetchEntitySourcesWithCache,
|
||||||
@ -29,7 +30,18 @@ export class HaEntitySelector extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
|
private _hasIntegration(selector: EntitySelector) {
|
||||||
|
return (
|
||||||
|
selector.entity?.filter &&
|
||||||
|
ensureArray(selector.entity.filter).some((filter) => filter.integration)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
if (this._hasIntegration(this.selector) && !this._entitySources) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.selector.entity?.multiple) {
|
if (!this.selector.entity?.multiple) {
|
||||||
return html`<ha-entity-picker
|
return html`<ha-entity-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -64,7 +76,7 @@ export class HaEntitySelector extends LitElement {
|
|||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
if (
|
if (
|
||||||
changedProps.has("selector") &&
|
changedProps.has("selector") &&
|
||||||
this.selector.entity?.integration &&
|
this._hasIntegration(this.selector) &&
|
||||||
!this._entitySources
|
!this._entitySources
|
||||||
) {
|
) {
|
||||||
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
||||||
@ -74,13 +86,11 @@ export class HaEntitySelector extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _filterEntities = (entity: HassEntity): boolean => {
|
private _filterEntities = (entity: HassEntity): boolean => {
|
||||||
if (!this.selector?.entity) {
|
if (!this.selector?.entity?.filter) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return filterSelectorEntities(
|
return ensureArray(this.selector.entity.filter).some((filter) =>
|
||||||
this.selector.entity,
|
filterSelectorEntities(filter, entity, this._entitySources)
|
||||||
entity,
|
|
||||||
this._entitySources
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import { getSignedPath } from "../../data/auth";
|
|||||||
import {
|
import {
|
||||||
MediaClassBrowserSettings,
|
MediaClassBrowserSettings,
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
SUPPORT_BROWSE_MEDIA,
|
MediaPlayerEntityFeature,
|
||||||
} from "../../data/media-player";
|
} from "../../data/media-player";
|
||||||
import type { MediaSelector, MediaSelectorValue } from "../../data/selector";
|
import type { MediaSelector, MediaSelectorValue } from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
@ -80,7 +80,8 @@ export class HaMediaSelector extends LitElement {
|
|||||||
|
|
||||||
const supportsBrowse =
|
const supportsBrowse =
|
||||||
!this.value?.entity_id ||
|
!this.value?.entity_id ||
|
||||||
(stateObj && supportsFeature(stateObj, SUPPORT_BROWSE_MEDIA));
|
(stateObj &&
|
||||||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.BROWSE_MEDIA));
|
||||||
|
|
||||||
return html`<ha-entity-picker
|
return html`<ha-entity-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -14,7 +14,6 @@ import {
|
|||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
getDeviceIntegrationLookup,
|
getDeviceIntegrationLookup,
|
||||||
} from "../../data/device_registry";
|
} from "../../data/device_registry";
|
||||||
import { EntityRegistryEntry } from "../../data/entity_registry";
|
|
||||||
import {
|
import {
|
||||||
EntitySources,
|
EntitySources,
|
||||||
fetchEntitySourcesWithCache,
|
fetchEntitySourcesWithCache,
|
||||||
@ -45,12 +44,24 @@ export class HaTargetSelector extends LitElement {
|
|||||||
|
|
||||||
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
||||||
|
|
||||||
|
private _hasIntegration(selector: TargetSelector) {
|
||||||
|
return (
|
||||||
|
(selector.target?.entity &&
|
||||||
|
ensureArray(selector.target.entity).some(
|
||||||
|
(filter) => filter.integration
|
||||||
|
)) ||
|
||||||
|
(selector.target?.device &&
|
||||||
|
ensureArray(selector.target.device).some(
|
||||||
|
(device) => device.integration
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
if (
|
if (
|
||||||
changedProperties.has("selector") &&
|
changedProperties.has("selector") &&
|
||||||
(this.selector.target?.device?.integration ||
|
this._hasIntegration(this.selector) &&
|
||||||
this.selector.target?.entity?.integration) &&
|
|
||||||
!this._entitySources
|
!this._entitySources
|
||||||
) {
|
) {
|
||||||
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
fetchEntitySourcesWithCache(this.hass).then((sources) => {
|
||||||
@ -60,11 +71,7 @@ export class HaTargetSelector extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (
|
if (this._hasIntegration(this.selector) && !this._entitySources) {
|
||||||
(this.selector.target?.device?.integration ||
|
|
||||||
this.selector.target?.entity?.integration) &&
|
|
||||||
!this._entitySources
|
|
||||||
) {
|
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,39 +80,21 @@ export class HaTargetSelector extends LitElement {
|
|||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.deviceFilter=${this._filterDevices}
|
.deviceFilter=${this._filterDevices}
|
||||||
.entityFilter=${this._filterStates}
|
.entityFilter=${this._filterEntities}
|
||||||
.entityRegFilter=${this._filterRegEntities}
|
|
||||||
.includeDeviceClasses=${this.selector.target?.entity?.device_class
|
|
||||||
? [this.selector.target?.entity.device_class]
|
|
||||||
: undefined}
|
|
||||||
.includeDomains=${this.selector.target?.entity?.domain
|
|
||||||
? ensureArray(this.selector.target.entity.domain as string | string[])
|
|
||||||
: undefined}
|
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
></ha-target-picker>`;
|
></ha-target-picker>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filterStates = (entity: HassEntity): boolean => {
|
private _filterEntities = (entity: HassEntity): boolean => {
|
||||||
if (!this.selector.target?.entity) {
|
if (!this.selector.target?.entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterSelectorEntities(
|
return ensureArray(this.selector.target.entity).some((filter) =>
|
||||||
this.selector.target.entity,
|
filterSelectorEntities(filter, entity, this._entitySources)
|
||||||
entity,
|
|
||||||
this._entitySources
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private _filterRegEntities = (entity: EntityRegistryEntry): boolean => {
|
|
||||||
if (this.selector.target?.entity?.integration) {
|
|
||||||
if (entity.platform !== this.selector.target.entity.integration) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
||||||
if (!this.selector.target?.device) {
|
if (!this.selector.target?.device) {
|
||||||
return true;
|
return true;
|
||||||
@ -118,10 +107,8 @@ export class HaTargetSelector extends LitElement {
|
|||||||
)
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return filterSelectorDevices(
|
return ensureArray(this.selector.target.device).some((filter) =>
|
||||||
this.selector.target.device,
|
filterSelectorDevices(filter, device, deviceIntegrations)
|
||||||
device,
|
|
||||||
deviceIntegrations
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { html, LitElement, PropertyValues } from "lit";
|
import { html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
|
||||||
import type { Selector } from "../../data/selector";
|
import {
|
||||||
|
Selector,
|
||||||
|
handleLegacyEntitySelector,
|
||||||
|
handleLegacyDeviceSelector,
|
||||||
|
} from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
const LOAD_ELEMENTS = {
|
const LOAD_ELEMENTS = {
|
||||||
@ -75,12 +80,22 @@ export class HaSelector extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleLegacySelector = memoizeOne((selector: Selector) => {
|
||||||
|
if ("entity" in selector) {
|
||||||
|
return handleLegacyEntitySelector(selector);
|
||||||
|
}
|
||||||
|
if ("device" in selector) {
|
||||||
|
return handleLegacyDeviceSelector(selector);
|
||||||
|
}
|
||||||
|
return selector;
|
||||||
|
});
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${dynamicElement(`ha-selector-${this._type}`, {
|
${dynamicElement(`ha-selector-${this._type}`, {
|
||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
selector: this.selector,
|
selector: this._handleLegacySelector(this.selector),
|
||||||
value: this.value,
|
value: this.value,
|
||||||
label: this.label,
|
label: this.label,
|
||||||
placeholder: this.placeholder,
|
placeholder: this.placeholder,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { 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";
|
||||||
import { LocalizeFunc } from "../common/translations/localize";
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
@ -17,6 +17,7 @@ const rowRenderer: ComboBoxLitRenderer<{ service: string; name: string }> = (
|
|||||||
>
|
>
|
||||||
</mwc-list-item>`;
|
</mwc-list-item>`;
|
||||||
|
|
||||||
|
@customElement("ha-service-picker")
|
||||||
class HaServicePicker extends LitElement {
|
class HaServicePicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@ -113,8 +114,6 @@ class HaServicePicker extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-service-picker", HaServicePicker);
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-service-picker": HaServicePicker;
|
"ha-service-picker": HaServicePicker;
|
||||||
|
@ -9,32 +9,21 @@ import {
|
|||||||
mdiUnfoldMoreVertical,
|
mdiUnfoldMoreVertical,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import "@polymer/paper-tooltip/paper-tooltip";
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import {
|
import { HassEntity, HassServiceTarget } from "home-assistant-js-websocket";
|
||||||
HassEntity,
|
|
||||||
HassServiceTarget,
|
|
||||||
UnsubscribeFunc,
|
|
||||||
} from "home-assistant-js-websocket";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, unsafeCSS } from "lit";
|
import { css, CSSResultGroup, html, LitElement, unsafeCSS } 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";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { ComboBoxLightOpenedChangedEvent } from "@vaadin/combo-box/vaadin-combo-box-light";
|
||||||
import { ensureArray } from "../common/array/ensure-array";
|
import { ensureArray } from "../common/array/ensure-array";
|
||||||
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import {
|
import { isValidEntityId } from "../common/entity/valid_entity_id";
|
||||||
AreaRegistryEntry,
|
|
||||||
subscribeAreaRegistry,
|
|
||||||
} from "../data/area_registry";
|
|
||||||
import {
|
import {
|
||||||
computeDeviceName,
|
computeDeviceName,
|
||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
subscribeDeviceRegistry,
|
|
||||||
} from "../data/device_registry";
|
} from "../data/device_registry";
|
||||||
import {
|
import { EntityRegistryEntry } from "../data/entity_registry";
|
||||||
EntityRegistryEntry,
|
|
||||||
subscribeEntityRegistry,
|
|
||||||
} from "../data/entity_registry";
|
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./device/ha-device-picker";
|
import "./device/ha-device-picker";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||||
@ -44,9 +33,11 @@ import "./ha-area-picker";
|
|||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
import "./ha-input-helper-text";
|
import "./ha-input-helper-text";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
|
import { stopPropagation } from "../common/dom/stop_propagation";
|
||||||
|
import "@material/mwc-menu/mwc-menu-surface";
|
||||||
|
|
||||||
@customElement("ha-target-picker")
|
@customElement("ha-target-picker")
|
||||||
export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
export class HaTargetPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public value?: HassServiceTarget;
|
@property({ attribute: false }) public value?: HassServiceTarget;
|
||||||
@ -73,67 +64,25 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
||||||
|
|
||||||
@property() public entityRegFilter?: (entity: EntityRegistryEntry) => boolean;
|
|
||||||
|
|
||||||
@property() public entityFilter?: HaEntityPickerEntityFilterFunc;
|
@property() public entityFilter?: HaEntityPickerEntityFilterFunc;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public disabled = false;
|
@property({ type: Boolean, reflect: true }) public disabled = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public horizontal = false;
|
@property({ type: Boolean }) public addOnTop = false;
|
||||||
|
|
||||||
@state() private _areas?: { [areaId: string]: AreaRegistryEntry };
|
|
||||||
|
|
||||||
@state() private _devices?: {
|
|
||||||
[deviceId: string]: DeviceRegistryEntry;
|
|
||||||
};
|
|
||||||
|
|
||||||
@state() private _entities?: EntityRegistryEntry[];
|
|
||||||
|
|
||||||
@state() private _addMode?: "area_id" | "entity_id" | "device_id";
|
@state() private _addMode?: "area_id" | "entity_id" | "device_id";
|
||||||
|
|
||||||
@query("#input") private _inputElement?;
|
@query("#input") private _inputElement?;
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
@query(".add-container", true) private _addContainer?: HTMLDivElement;
|
||||||
return [
|
|
||||||
subscribeAreaRegistry(this.hass.connection!, (areas) => {
|
private _opened = false;
|
||||||
const areaLookup: { [areaId: string]: AreaRegistryEntry } = {};
|
|
||||||
for (const area of areas) {
|
|
||||||
areaLookup[area.area_id] = area;
|
|
||||||
}
|
|
||||||
this._areas = areaLookup;
|
|
||||||
}),
|
|
||||||
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
|
|
||||||
const deviceLookup: { [deviceId: string]: DeviceRegistryEntry } = {};
|
|
||||||
for (const device of devices) {
|
|
||||||
deviceLookup[device.id] = device;
|
|
||||||
}
|
|
||||||
this._devices = deviceLookup;
|
|
||||||
}),
|
|
||||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
|
||||||
this._entities = entities;
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this._areas || !this._devices || !this._entities) {
|
if (this.addOnTop) {
|
||||||
return html``;
|
return html` ${this._renderChips()} ${this._renderItems()} `;
|
||||||
}
|
}
|
||||||
return html`
|
return html` ${this._renderItems()} ${this._renderChips()} `;
|
||||||
${this.horizontal
|
|
||||||
? html`
|
|
||||||
<div class="horizontal-container">
|
|
||||||
${this._renderChips()} ${this._renderPicker()}
|
|
||||||
</div>
|
|
||||||
${this._renderItems()}
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<div>
|
|
||||||
${this._renderItems()} ${this._renderPicker()}
|
|
||||||
${this._renderChips()}
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderItems() {
|
private _renderItems() {
|
||||||
@ -141,7 +90,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
<div class="mdc-chip-set items">
|
<div class="mdc-chip-set items">
|
||||||
${this.value?.area_id
|
${this.value?.area_id
|
||||||
? ensureArray(this.value.area_id).map((area_id) => {
|
? ensureArray(this.value.area_id).map((area_id) => {
|
||||||
const area = this._areas![area_id];
|
const area = this.hass.areas![area_id];
|
||||||
return this._renderChip(
|
return this._renderChip(
|
||||||
"area_id",
|
"area_id",
|
||||||
area_id,
|
area_id,
|
||||||
@ -153,7 +102,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
: ""}
|
: ""}
|
||||||
${this.value?.device_id
|
${this.value?.device_id
|
||||||
? ensureArray(this.value.device_id).map((device_id) => {
|
? ensureArray(this.value.device_id).map((device_id) => {
|
||||||
const device = this._devices![device_id];
|
const device = this.hass.devices![device_id];
|
||||||
return this._renderChip(
|
return this._renderChip(
|
||||||
"device_id",
|
"device_id",
|
||||||
device_id,
|
device_id,
|
||||||
@ -180,7 +129,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _renderChips() {
|
private _renderChips() {
|
||||||
return html`
|
return html`
|
||||||
<div class="mdc-chip-set">
|
<div class="mdc-chip-set add-container">
|
||||||
<div
|
<div
|
||||||
class="mdc-chip area_id add"
|
class="mdc-chip area_id add"
|
||||||
.type=${"area_id"}
|
.type=${"area_id"}
|
||||||
@ -241,6 +190,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
${this._renderPicker()}
|
||||||
</div>
|
</div>
|
||||||
${this.helper
|
${this.helper
|
||||||
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||||
@ -248,11 +198,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _showPicker(ev) {
|
private _showPicker(ev) {
|
||||||
this._addMode = ev.currentTarget.type;
|
this._addMode = ev.currentTarget.type;
|
||||||
await this.updateComplete;
|
|
||||||
await this._inputElement?.focus();
|
|
||||||
await this._inputElement?.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderChip(
|
private _renderChip(
|
||||||
@ -287,7 +234,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
</span>
|
</span>
|
||||||
${type === "entity_id"
|
${type === "entity_id"
|
||||||
? ""
|
? ""
|
||||||
: html` <span role="gridcell">
|
: html`<span role="gridcell">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
class="expand-btn mdc-chip__icon mdc-chip__icon--trailing"
|
class="expand-btn mdc-chip__icon mdc-chip__icon--trailing"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
@ -330,60 +277,72 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _renderPicker() {
|
private _renderPicker() {
|
||||||
switch (this._addMode) {
|
if (!this._addMode) {
|
||||||
case "area_id":
|
return html``;
|
||||||
return html`
|
|
||||||
<ha-area-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
id="input"
|
|
||||||
.type=${"area_id"}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.components.target-picker.add_area_id"
|
|
||||||
)}
|
|
||||||
no-add
|
|
||||||
.deviceFilter=${this.deviceFilter}
|
|
||||||
.entityFilter=${this.entityRegFilter}
|
|
||||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
|
||||||
.includeDomains=${this.includeDomains}
|
|
||||||
.excludeAreas=${ensureArray(this.value?.area_id)}
|
|
||||||
@value-changed=${this._targetPicked}
|
|
||||||
></ha-area-picker>
|
|
||||||
`;
|
|
||||||
case "device_id":
|
|
||||||
return html`
|
|
||||||
<ha-device-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
id="input"
|
|
||||||
.type=${"device_id"}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.components.target-picker.add_device_id"
|
|
||||||
)}
|
|
||||||
.deviceFilter=${this.deviceFilter}
|
|
||||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
|
||||||
.includeDomains=${this.includeDomains}
|
|
||||||
.excludeDevices=${ensureArray(this.value?.device_id)}
|
|
||||||
@value-changed=${this._targetPicked}
|
|
||||||
></ha-device-picker>
|
|
||||||
`;
|
|
||||||
case "entity_id":
|
|
||||||
return html`
|
|
||||||
<ha-entity-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
id="input"
|
|
||||||
.type=${"entity_id"}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.components.target-picker.add_entity_id"
|
|
||||||
)}
|
|
||||||
.entityFilter=${this.entityFilter}
|
|
||||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
|
||||||
.includeDomains=${this.includeDomains}
|
|
||||||
.excludeEntities=${ensureArray(this.value?.entity_id)}
|
|
||||||
@value-changed=${this._targetPicked}
|
|
||||||
allow-custom-entity
|
|
||||||
></ha-entity-picker>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
return html``;
|
return html`<mwc-menu-surface
|
||||||
|
open
|
||||||
|
.anchor=${this._addContainer}
|
||||||
|
.corner=${"BOTTOM_START"}
|
||||||
|
@closed=${this._onClosed}
|
||||||
|
@opened=${this._onOpened}
|
||||||
|
@opened-changed=${this._openedChanged}
|
||||||
|
@input=${stopPropagation}
|
||||||
|
>${this._addMode === "area_id"
|
||||||
|
? html`
|
||||||
|
<ha-area-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
id="input"
|
||||||
|
.type=${"area_id"}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.components.target-picker.add_area_id"
|
||||||
|
)}
|
||||||
|
no-add
|
||||||
|
.deviceFilter=${this.deviceFilter}
|
||||||
|
.entityFilter=${this.entityFilter}
|
||||||
|
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||||
|
.includeDomains=${this.includeDomains}
|
||||||
|
.excludeAreas=${ensureArray(this.value?.area_id)}
|
||||||
|
@value-changed=${this._targetPicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
|
></ha-area-picker>
|
||||||
|
`
|
||||||
|
: this._addMode === "device_id"
|
||||||
|
? html`
|
||||||
|
<ha-device-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
id="input"
|
||||||
|
.type=${"device_id"}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.components.target-picker.add_device_id"
|
||||||
|
)}
|
||||||
|
.deviceFilter=${this.deviceFilter}
|
||||||
|
.entityFilter=${this.entityFilter}
|
||||||
|
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||||
|
.includeDomains=${this.includeDomains}
|
||||||
|
.excludeDevices=${ensureArray(this.value?.device_id)}
|
||||||
|
@value-changed=${this._targetPicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
|
></ha-device-picker>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<ha-entity-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
id="input"
|
||||||
|
.type=${"entity_id"}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.components.target-picker.add_entity_id"
|
||||||
|
)}
|
||||||
|
.entityFilter=${this.entityFilter}
|
||||||
|
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||||
|
.includeDomains=${this.includeDomains}
|
||||||
|
.excludeEntities=${ensureArray(this.value?.entity_id)}
|
||||||
|
@value-changed=${this._targetPicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
|
allow-custom-entity
|
||||||
|
></ha-entity-picker>
|
||||||
|
`}</mwc-menu-surface
|
||||||
|
>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _targetPicked(ev) {
|
private _targetPicked(ev) {
|
||||||
@ -393,8 +352,12 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
const value = ev.detail.value;
|
const value = ev.detail.value;
|
||||||
const target = ev.currentTarget;
|
const target = ev.currentTarget;
|
||||||
|
|
||||||
|
if (target.type === "entity_id" && !isValidEntityId(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
target.value = "";
|
target.value = "";
|
||||||
this._addMode = undefined;
|
|
||||||
if (
|
if (
|
||||||
this.value &&
|
this.value &&
|
||||||
this.value[target.type] &&
|
this.value[target.type] &&
|
||||||
@ -419,7 +382,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
const newDevices: string[] = [];
|
const newDevices: string[] = [];
|
||||||
const newEntities: string[] = [];
|
const newEntities: string[] = [];
|
||||||
if (target.type === "area_id") {
|
if (target.type === "area_id") {
|
||||||
Object.values(this._devices!).forEach((device) => {
|
Object.values(this.hass.devices).forEach((device) => {
|
||||||
if (
|
if (
|
||||||
device.area_id === target.id &&
|
device.area_id === target.id &&
|
||||||
!this.value!.device_id?.includes(device.id) &&
|
!this.value!.device_id?.includes(device.id) &&
|
||||||
@ -428,7 +391,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
newDevices.push(device.id);
|
newDevices.push(device.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._entities!.forEach((entity) => {
|
Object.values(this.hass.entities).forEach((entity) => {
|
||||||
if (
|
if (
|
||||||
entity.area_id === target.id &&
|
entity.area_id === target.id &&
|
||||||
!this.value!.entity_id?.includes(entity.entity_id) &&
|
!this.value!.entity_id?.includes(entity.entity_id) &&
|
||||||
@ -438,7 +401,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (target.type === "device_id") {
|
} else if (target.type === "device_id") {
|
||||||
this._entities!.forEach((entity) => {
|
Object.values(this.hass.entities).forEach((entity) => {
|
||||||
if (
|
if (
|
||||||
entity.device_id === target.id &&
|
entity.device_id === target.id &&
|
||||||
!this.value!.entity_id?.includes(entity.entity_id) &&
|
!this.value!.entity_id?.includes(entity.entity_id) &&
|
||||||
@ -501,10 +464,36 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _onClosed(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
ev.target.open = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _onOpened() {
|
||||||
|
if (!this._addMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this._inputElement?.focus();
|
||||||
|
await this._inputElement?.open();
|
||||||
|
this._opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _openedChanged(ev: ComboBoxLightOpenedChangedEvent) {
|
||||||
|
if (this._opened && !ev.detail.value) {
|
||||||
|
this._opened = false;
|
||||||
|
this._addMode = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _preventDefault(ev: Event) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
private _deviceMeetsFilter(device: DeviceRegistryEntry): boolean {
|
private _deviceMeetsFilter(device: DeviceRegistryEntry): boolean {
|
||||||
const devEntities = this._entities?.filter(
|
const devEntities = Object.values(this.hass.entities).filter(
|
||||||
(entity) => entity.device_id === device.id
|
(entity) => entity.device_id === device.id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.includeDomains) {
|
if (this.includeDomains) {
|
||||||
if (!devEntities || !devEntities.length) {
|
if (!devEntities || !devEntities.length) {
|
||||||
return false;
|
return false;
|
||||||
@ -541,7 +530,23 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.deviceFilter) {
|
if (this.deviceFilter) {
|
||||||
return this.deviceFilter(device);
|
if (!this.deviceFilter(device)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.entityFilter) {
|
||||||
|
if (
|
||||||
|
!devEntities.some((entity) => {
|
||||||
|
const stateObj = this.hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.entityFilter!(stateObj);
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -550,6 +555,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
if (entity.entity_category) {
|
if (entity.entity_category) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.includeDomains &&
|
this.includeDomains &&
|
||||||
!this.includeDomains.includes(computeDomain(entity.entity_id))
|
!this.includeDomains.includes(computeDomain(entity.entity_id))
|
||||||
@ -568,8 +574,15 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.entityRegFilter) {
|
|
||||||
return this.entityRegFilter(entity);
|
if (this.entityFilter) {
|
||||||
|
const stateObj = this.hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!this.entityFilter!(stateObj)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -577,12 +590,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
${unsafeCSS(chipStyles)}
|
${unsafeCSS(chipStyles)}
|
||||||
.horizontal-container {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
min-height: 56px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.mdc-chip {
|
.mdc-chip {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
}
|
}
|
||||||
@ -595,6 +602,10 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
.mdc-chip.add {
|
.mdc-chip.add {
|
||||||
color: rgba(0, 0, 0, 0.87);
|
color: rgba(0, 0, 0, 0.87);
|
||||||
}
|
}
|
||||||
|
.add-container {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
.mdc-chip:not(.add) {
|
.mdc-chip:not(.add) {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
@ -666,6 +677,15 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
opacity: var(--light-disabled-opacity);
|
opacity: var(--light-disabled-opacity);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
mwc-menu-surface {
|
||||||
|
--mdc-menu-min-width: 100%;
|
||||||
|
}
|
||||||
|
ha-entity-picker,
|
||||||
|
ha-device-picker,
|
||||||
|
ha-area-picker {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,12 @@ import { customElement, property } from "lit/decorators";
|
|||||||
export class HaTextArea extends TextAreaBase {
|
export class HaTextArea extends TextAreaBase {
|
||||||
@property({ type: Boolean, reflect: true }) autogrow = false;
|
@property({ type: Boolean, reflect: true }) autogrow = false;
|
||||||
|
|
||||||
|
firstUpdated() {
|
||||||
|
super.firstUpdated();
|
||||||
|
|
||||||
|
this.setAttribute("dir", document.dir);
|
||||||
|
}
|
||||||
|
|
||||||
updated(changedProperties: PropertyValues) {
|
updated(changedProperties: PropertyValues) {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
if (this.autogrow && changedProperties.has("value")) {
|
if (this.autogrow && changedProperties.has("value")) {
|
||||||
@ -47,6 +53,10 @@ export class HaTextArea extends TextAreaBase {
|
|||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
:host([dir="rtl"]) .mdc-floating-label {
|
||||||
|
right: 16px;
|
||||||
|
left: initial;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,24 @@
|
|||||||
import { mdiLightbulbOutline } from "@mdi/js";
|
import { mdiLightbulbOutline } from "@mdi/js";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { property, customElement } from "lit/decorators";
|
||||||
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
@customElement("ha-tip")
|
@customElement("ha-tip")
|
||||||
class HaTip extends LitElement {
|
class HaTip extends LitElement {
|
||||||
public render() {
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
public render(): TemplateResult {
|
||||||
|
if (!this.hass) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-svg-icon .path=${mdiLightbulbOutline}></ha-svg-icon>
|
<ha-svg-icon .path=${mdiLightbulbOutline}></ha-svg-icon>
|
||||||
<span class="prefix">Tip!</span>
|
<span class="prefix"
|
||||||
|
>${this.hass.localize("ui.panel.config.tips.tip")}</span
|
||||||
|
>
|
||||||
<span class="text"><slot></slot></span>
|
<span class="text"><slot></slot></span>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -21,7 +30,10 @@ class HaTip extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
|
direction: var(--direction);
|
||||||
margin-left: 2px;
|
margin-left: 2px;
|
||||||
|
margin-inline-start: 2px;
|
||||||
|
margin-inline-end: initial;
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import "@polymer/paper-toast/paper-toast";
|
import "@polymer/paper-toast/paper-toast";
|
||||||
import type { PaperToastElement } from "@polymer/paper-toast/paper-toast";
|
import type { PaperToastElement } from "@polymer/paper-toast/paper-toast";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
import type { Constructor } from "../types";
|
import type { Constructor } from "../types";
|
||||||
|
|
||||||
const PaperToast = customElements.get(
|
const PaperToast = customElements.get(
|
||||||
"paper-toast"
|
"paper-toast"
|
||||||
) as Constructor<PaperToastElement>;
|
) as Constructor<PaperToastElement>;
|
||||||
|
|
||||||
|
@customElement("ha-toast")
|
||||||
export class HaToast extends PaperToast {
|
export class HaToast extends PaperToast {
|
||||||
private _resizeListener?: (obj: { matches: boolean }) => unknown;
|
private _resizeListener?: (obj: { matches: boolean }) => unknown;
|
||||||
|
|
||||||
@ -34,5 +36,3 @@ declare global {
|
|||||||
"ha-toast": HaToast;
|
"ha-toast": HaToast;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("ha-toast", HaToast);
|
|
||||||
|
@ -25,6 +25,8 @@ export class HaTileInfo extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 40px;
|
||||||
}
|
}
|
||||||
span {
|
span {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import "../ha-bar-slider";
|
import "../ha-control-slider";
|
||||||
|
|
||||||
@customElement("ha-tile-slider")
|
@customElement("ha-tile-slider")
|
||||||
export class HaTileSlider extends LitElement {
|
export class HaTileSlider extends LitElement {
|
||||||
@ -30,7 +30,7 @@ export class HaTileSlider extends LitElement {
|
|||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ha-bar-slider
|
<ha-control-slider
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.mode=${this.mode}
|
.mode=${this.mode}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@ -40,24 +40,24 @@ export class HaTileSlider extends LitElement {
|
|||||||
aria-label=${ifDefined(this.label)}
|
aria-label=${ifDefined(this.label)}
|
||||||
.showHandle=${this.showHandle}
|
.showHandle=${this.showHandle}
|
||||||
>
|
>
|
||||||
</ha-bar-slider>
|
</ha-control-slider>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
ha-bar-slider {
|
ha-control-slider {
|
||||||
--slider-bar-color: var(--tile-slider-color, var(--primary-color));
|
--control-slider-color: var(--tile-slider-color, var(--primary-color));
|
||||||
--slider-bar-background: var(
|
--control-slider-background: var(
|
||||||
--tile-slider-background,
|
--tile-slider-background,
|
||||||
var(--disabled-color)
|
var(--disabled-color)
|
||||||
);
|
);
|
||||||
--slider-bar-background-opacity: var(
|
--control-slider-background-opacity: var(
|
||||||
--tile-slider-background-opacity,
|
--tile-slider-background-opacity,
|
||||||
0.2
|
0.2
|
||||||
);
|
);
|
||||||
--slider-bar-thickness: 40px;
|
--control-slider-thickness: 40px;
|
||||||
--slider-bar-border-radius: 10px;
|
--control-slider-border-radius: 10px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,15 @@ import { HomeAssistant } from "../types";
|
|||||||
export const FORMAT_TEXT = "text";
|
export const FORMAT_TEXT = "text";
|
||||||
export const FORMAT_NUMBER = "number";
|
export const FORMAT_NUMBER = "number";
|
||||||
|
|
||||||
|
export const enum AlarmControlPanelEntityFeature {
|
||||||
|
ARM_HOME = 1,
|
||||||
|
ARM_AWAY = 2,
|
||||||
|
ARM_NIGHT = 4,
|
||||||
|
TRIGGER = 8,
|
||||||
|
ARM_CUSTOM_BYPASS = 16,
|
||||||
|
ARM_VACATION = 32,
|
||||||
|
}
|
||||||
|
|
||||||
export const callAlarmAction = (
|
export const callAlarmAction = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: string,
|
entity: string,
|
||||||
|
@ -146,6 +146,7 @@ export interface TimeTrigger extends BaseTrigger {
|
|||||||
export interface TemplateTrigger extends BaseTrigger {
|
export interface TemplateTrigger extends BaseTrigger {
|
||||||
platform: "template";
|
platform: "template";
|
||||||
value_template: string;
|
value_template: string;
|
||||||
|
for?: string | number | ForDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EventTrigger extends BaseTrigger {
|
export interface EventTrigger extends BaseTrigger {
|
||||||
|
@ -3,7 +3,7 @@ import secondsToDuration from "../common/datetime/seconds_to_duration";
|
|||||||
import { ensureArray } from "../common/array/ensure-array";
|
import { ensureArray } from "../common/array/ensure-array";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { Condition, Trigger } from "./automation";
|
import { Condition, Trigger, ForDict } from "./automation";
|
||||||
import {
|
import {
|
||||||
DeviceCondition,
|
DeviceCondition,
|
||||||
DeviceTrigger,
|
DeviceTrigger,
|
||||||
@ -12,6 +12,18 @@ import {
|
|||||||
} from "./device_automation";
|
} from "./device_automation";
|
||||||
import { formatAttributeName } from "./entity_attributes";
|
import { formatAttributeName } from "./entity_attributes";
|
||||||
|
|
||||||
|
const describeDuration = (forTime: number | string | ForDict) => {
|
||||||
|
let duration: string | null;
|
||||||
|
if (typeof forTime === "number") {
|
||||||
|
duration = secondsToDuration(forTime);
|
||||||
|
} else if (typeof forTime === "string") {
|
||||||
|
duration = forTime;
|
||||||
|
} else {
|
||||||
|
duration = formatDuration(forTime);
|
||||||
|
}
|
||||||
|
return duration;
|
||||||
|
};
|
||||||
|
|
||||||
export const describeTrigger = (
|
export const describeTrigger = (
|
||||||
trigger: Trigger,
|
trigger: Trigger,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -73,14 +85,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.for) {
|
if (trigger.for) {
|
||||||
let duration: string | null;
|
const duration = describeDuration(trigger.for);
|
||||||
if (typeof trigger.for === "number") {
|
|
||||||
duration = secondsToDuration(trigger.for);
|
|
||||||
} else if (typeof trigger.for === "string") {
|
|
||||||
duration = trigger.for;
|
|
||||||
} else {
|
|
||||||
duration = formatDuration(trigger.for);
|
|
||||||
}
|
|
||||||
if (duration) {
|
if (duration) {
|
||||||
base += ` for ${duration}`;
|
base += ` for ${duration}`;
|
||||||
}
|
}
|
||||||
@ -156,15 +161,7 @@ export const describeTrigger = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.for) {
|
if (trigger.for) {
|
||||||
let duration: string | null;
|
const duration = describeDuration(trigger.for);
|
||||||
if (typeof trigger.for === "number") {
|
|
||||||
duration = secondsToDuration(trigger.for);
|
|
||||||
} else if (typeof trigger.for === "string") {
|
|
||||||
duration = trigger.for;
|
|
||||||
} else {
|
|
||||||
duration = formatDuration(trigger.for);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (duration) {
|
if (duration) {
|
||||||
base += ` for ${duration}`;
|
base += ` for ${duration}`;
|
||||||
}
|
}
|
||||||
@ -319,7 +316,14 @@ export const describeTrigger = (
|
|||||||
|
|
||||||
// Template Trigger
|
// Template Trigger
|
||||||
if (trigger.platform === "template") {
|
if (trigger.platform === "template") {
|
||||||
return "When a template triggers";
|
let base = "When a template triggers";
|
||||||
|
if (trigger.for) {
|
||||||
|
const duration = describeDuration(trigger.for);
|
||||||
|
if (duration) {
|
||||||
|
base += ` for ${duration}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webhook Trigger
|
// Webhook Trigger
|
||||||
@ -440,14 +444,7 @@ export const describeCondition = (
|
|||||||
base += ` ${entity} is ${states}`;
|
base += ` ${entity} is ${states}`;
|
||||||
|
|
||||||
if (condition.for) {
|
if (condition.for) {
|
||||||
let duration: string | null;
|
const duration = describeDuration(condition.for);
|
||||||
if (typeof condition.for === "number") {
|
|
||||||
duration = secondsToDuration(condition.for);
|
|
||||||
} else if (typeof condition.for === "string") {
|
|
||||||
duration = condition.for;
|
|
||||||
} else {
|
|
||||||
duration = formatDuration(condition.for);
|
|
||||||
}
|
|
||||||
if (duration) {
|
if (duration) {
|
||||||
base += ` for ${duration}`;
|
base += ` for ${duration}`;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ export interface BlueprintMetaData {
|
|||||||
input?: Record<string, BlueprintInput | null>;
|
input?: Record<string, BlueprintInput | null>;
|
||||||
description?: string;
|
description?: string;
|
||||||
source_url?: string;
|
source_url?: string;
|
||||||
|
author?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BlueprintInput {
|
export interface BlueprintInput {
|
||||||
@ -63,3 +64,19 @@ export const deleteBlueprint = (
|
|||||||
domain,
|
domain,
|
||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type BlueprintSourceType = "local" | "community" | "homeassistant";
|
||||||
|
|
||||||
|
export const getBlueprintSourceType = (
|
||||||
|
blueprint: Blueprint
|
||||||
|
): BlueprintSourceType => {
|
||||||
|
const sourceUrl = blueprint.metadata.source_url;
|
||||||
|
|
||||||
|
if (!sourceUrl) {
|
||||||
|
return "local";
|
||||||
|
}
|
||||||
|
if (sourceUrl.includes("github.com/home-assistant")) {
|
||||||
|
return "homeassistant";
|
||||||
|
}
|
||||||
|
return "community";
|
||||||
|
};
|
||||||
|
@ -406,24 +406,28 @@ const getEnergyData = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
...(await fetchStatistics(
|
...(energyStatIds.length
|
||||||
hass!,
|
? await fetchStatistics(
|
||||||
startMinHour,
|
hass!,
|
||||||
end,
|
startMinHour,
|
||||||
energyStatIds,
|
end,
|
||||||
period,
|
energyStatIds,
|
||||||
energyUnits,
|
period,
|
||||||
["sum"]
|
energyUnits,
|
||||||
)),
|
["sum"]
|
||||||
...(await fetchStatistics(
|
)
|
||||||
hass!,
|
: {}),
|
||||||
startMinHour,
|
...(waterStatIds.length
|
||||||
end,
|
? await fetchStatistics(
|
||||||
waterStatIds,
|
hass!,
|
||||||
period,
|
startMinHour,
|
||||||
waterUnits,
|
end,
|
||||||
["sum"]
|
waterStatIds,
|
||||||
)),
|
period,
|
||||||
|
waterUnits,
|
||||||
|
["sum"]
|
||||||
|
)
|
||||||
|
: {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let statsCompare;
|
let statsCompare;
|
||||||
@ -441,24 +445,28 @@ const getEnergyData = async (
|
|||||||
endCompare = addMilliseconds(start, -1);
|
endCompare = addMilliseconds(start, -1);
|
||||||
|
|
||||||
statsCompare = {
|
statsCompare = {
|
||||||
...(await fetchStatistics(
|
...(energyStatIds.length
|
||||||
hass!,
|
? await fetchStatistics(
|
||||||
compareStartMinHour,
|
hass!,
|
||||||
endCompare,
|
compareStartMinHour,
|
||||||
energyStatIds,
|
endCompare,
|
||||||
period,
|
energyStatIds,
|
||||||
energyUnits,
|
period,
|
||||||
["sum"]
|
energyUnits,
|
||||||
)),
|
["sum"]
|
||||||
...(await fetchStatistics(
|
)
|
||||||
hass!,
|
: {}),
|
||||||
compareStartMinHour,
|
...(waterStatIds.length
|
||||||
endCompare,
|
? await fetchStatistics(
|
||||||
waterStatIds,
|
hass!,
|
||||||
period,
|
compareStartMinHour,
|
||||||
waterUnits,
|
endCompare,
|
||||||
["sum"]
|
waterStatIds,
|
||||||
)),
|
period,
|
||||||
|
waterUnits,
|
||||||
|
["sum"]
|
||||||
|
)
|
||||||
|
: {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ export interface EntityRegistryEntry {
|
|||||||
original_name?: string;
|
original_name?: string;
|
||||||
unique_id: string;
|
unique_id: string;
|
||||||
translation_key?: string;
|
translation_key?: string;
|
||||||
|
options: EntityRegistryOptions | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||||
@ -39,6 +40,8 @@ export interface UpdateEntityRegistryEntryResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SensorEntityOptions {
|
export interface SensorEntityOptions {
|
||||||
|
display_precision?: number | null;
|
||||||
|
suggested_display_precision?: number | null;
|
||||||
unit_of_measurement?: string | null;
|
unit_of_measurement?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +57,12 @@ export interface WeatherEntityOptions {
|
|||||||
wind_speed_unit?: string | null;
|
wind_speed_unit?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EntityRegistryOptions {
|
||||||
|
number?: NumberEntityOptions;
|
||||||
|
sensor?: SensorEntityOptions;
|
||||||
|
weather?: WeatherEntityOptions;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EntityRegistryEntryUpdateParams {
|
export interface EntityRegistryEntryUpdateParams {
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
icon?: string | null;
|
icon?: string | null;
|
||||||
|
@ -2,6 +2,7 @@ import {
|
|||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
|
|
||||||
interface GroupEntityAttributes extends HassEntityAttributeBase {
|
interface GroupEntityAttributes extends HassEntityAttributeBase {
|
||||||
entity_id: string[];
|
entity_id: string[];
|
||||||
@ -13,3 +14,13 @@ interface GroupEntityAttributes extends HassEntityAttributeBase {
|
|||||||
export interface GroupEntity extends HassEntityBase {
|
export interface GroupEntity extends HassEntityBase {
|
||||||
attributes: GroupEntityAttributes;
|
attributes: GroupEntityAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const computeGroupDomain = (
|
||||||
|
stateObj: GroupEntity
|
||||||
|
): string | undefined => {
|
||||||
|
const entityIds = stateObj.attributes.entity_id || [];
|
||||||
|
const uniqueDomains = [
|
||||||
|
...new Set(entityIds.map((entityId) => computeDomain(entityId))),
|
||||||
|
];
|
||||||
|
return uniqueDomains.length === 1 ? uniqueDomains[0] : undefined;
|
||||||
|
};
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
|
|
||||||
export interface CustomCardEntry {
|
export interface CustomCardEntry {
|
||||||
type: string;
|
type: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -6,8 +8,16 @@ export interface CustomCardEntry {
|
|||||||
documentationURL?: string;
|
documentationURL?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CustomTileFeatureEntry {
|
||||||
|
type: string;
|
||||||
|
name?: string;
|
||||||
|
supported?: (stateObj: HassEntity) => boolean;
|
||||||
|
configurable?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CustomCardsWindow {
|
export interface CustomCardsWindow {
|
||||||
customCards?: CustomCardEntry[];
|
customCards?: CustomCardEntry[];
|
||||||
|
customTileFeatures?: CustomTileFeatureEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CUSTOM_TYPE_PREFIX = "custom:";
|
export const CUSTOM_TYPE_PREFIX = "custom:";
|
||||||
@ -17,8 +27,18 @@ const customCardsWindow = window as CustomCardsWindow;
|
|||||||
if (!("customCards" in customCardsWindow)) {
|
if (!("customCards" in customCardsWindow)) {
|
||||||
customCardsWindow.customCards = [];
|
customCardsWindow.customCards = [];
|
||||||
}
|
}
|
||||||
|
if (!("customTileFeatures" in customCardsWindow)) {
|
||||||
|
customCardsWindow.customTileFeatures = [];
|
||||||
|
}
|
||||||
|
|
||||||
export const customCards = customCardsWindow.customCards!;
|
export const customCards = customCardsWindow.customCards!;
|
||||||
|
export const customTileFeatures = customCardsWindow.customTileFeatures!;
|
||||||
|
|
||||||
export const getCustomCardEntry = (type: string) =>
|
export const getCustomCardEntry = (type: string) =>
|
||||||
customCards.find((card) => card.type === type);
|
customCards.find((card) => card.type === type);
|
||||||
|
|
||||||
|
export const isCustomType = (type: string) =>
|
||||||
|
type.startsWith(CUSTOM_TYPE_PREFIX);
|
||||||
|
|
||||||
|
export const stripCustomPrefix = (type: string) =>
|
||||||
|
type.slice(CUSTOM_TYPE_PREFIX.length);
|
||||||
|
@ -1,4 +1,53 @@
|
|||||||
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
|
import { navigate } from "../common/navigate";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
import { subscribeDeviceRegistry } from "./device_registry";
|
||||||
|
|
||||||
|
export const canCommissionMatterExternal = (hass: HomeAssistant) =>
|
||||||
|
hass.auth.external?.config.canCommissionMatter;
|
||||||
|
|
||||||
|
export const startExternalCommissioning = (hass: HomeAssistant) =>
|
||||||
|
hass.auth.external!.fireMessage({
|
||||||
|
type: "matter/commission",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const redirectOnNewMatterDevice = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
callback?: () => void
|
||||||
|
): UnsubscribeFunc => {
|
||||||
|
let curMatterDevices: Set<string> | undefined;
|
||||||
|
const unsubDeviceReg = subscribeDeviceRegistry(hass.connection, (entries) => {
|
||||||
|
if (!curMatterDevices) {
|
||||||
|
curMatterDevices = new Set(
|
||||||
|
Object.values(entries)
|
||||||
|
.filter((device) =>
|
||||||
|
device.identifiers.find((identifier) => identifier[0] === "matter")
|
||||||
|
)
|
||||||
|
.map((device) => device.id)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newMatterDevices = Object.values(entries).filter(
|
||||||
|
(device) =>
|
||||||
|
device.identifiers.find((identifier) => identifier[0] === "matter") &&
|
||||||
|
!curMatterDevices!.has(device.id)
|
||||||
|
);
|
||||||
|
if (newMatterDevices.length) {
|
||||||
|
unsubDeviceReg();
|
||||||
|
curMatterDevices = undefined;
|
||||||
|
callback?.();
|
||||||
|
navigate(`/config/devices/device/${newMatterDevices[0].id}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
unsubDeviceReg();
|
||||||
|
curMatterDevices = undefined;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const addMatterDevice = (hass: HomeAssistant) => {
|
||||||
|
startExternalCommissioning(hass);
|
||||||
|
};
|
||||||
|
|
||||||
export const commissionMatterDevice = (
|
export const commissionMatterDevice = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -73,26 +73,33 @@ export interface MediaPlayerEntity extends HassEntityBase {
|
|||||||
| "off"
|
| "off"
|
||||||
| "on"
|
| "on"
|
||||||
| "unavailable"
|
| "unavailable"
|
||||||
| "unknown";
|
| "unknown"
|
||||||
|
| "standby"
|
||||||
|
| "buffering";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SUPPORT_PAUSE = 1;
|
export const enum MediaPlayerEntityFeature {
|
||||||
export const SUPPORT_SEEK = 2;
|
PAUSE = 1,
|
||||||
export const SUPPORT_VOLUME_SET = 4;
|
SEEK = 2,
|
||||||
export const SUPPORT_VOLUME_MUTE = 8;
|
VOLUME_SET = 4,
|
||||||
export const SUPPORT_PREVIOUS_TRACK = 16;
|
VOLUME_MUTE = 8,
|
||||||
export const SUPPORT_NEXT_TRACK = 32;
|
PREVIOUS_TRACK = 16,
|
||||||
export const SUPPORT_TURN_ON = 128;
|
NEXT_TRACK = 32,
|
||||||
export const SUPPORT_TURN_OFF = 256;
|
|
||||||
export const SUPPORT_PLAY_MEDIA = 512;
|
TURN_ON = 128,
|
||||||
export const SUPPORT_VOLUME_BUTTONS = 1024;
|
TURN_OFF = 256,
|
||||||
export const SUPPORT_SELECT_SOURCE = 2048;
|
PLAY_MEDIA = 512,
|
||||||
export const SUPPORT_STOP = 4096;
|
VOLUME_BUTTONS = 1024,
|
||||||
export const SUPPORT_PLAY = 16384;
|
SELECT_SOURCE = 2048,
|
||||||
export const SUPPORT_REPEAT_SET = 262144;
|
STOP = 4096,
|
||||||
export const SUPPORT_SELECT_SOUND_MODE = 65536;
|
CLEAR_PLAYLIST = 8192,
|
||||||
export const SUPPORT_SHUFFLE_SET = 32768;
|
PLAY = 16384,
|
||||||
export const SUPPORT_BROWSE_MEDIA = 131072;
|
SHUFFLE_SET = 32768,
|
||||||
|
SELECT_SOUND_MODE = 65536,
|
||||||
|
BROWSE_MEDIA = 131072,
|
||||||
|
REPEAT_SET = 262144,
|
||||||
|
GROUPING = 524288,
|
||||||
|
}
|
||||||
|
|
||||||
export type MediaPlayerBrowseAction = "pick" | "play";
|
export type MediaPlayerBrowseAction = "pick" | "play";
|
||||||
|
|
||||||
@ -264,7 +271,7 @@ export const computeMediaControls = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state === "off") {
|
if (state === "off") {
|
||||||
return supportsFeature(stateObj, SUPPORT_TURN_ON)
|
return supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON)
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
icon: mdiPower,
|
icon: mdiPower,
|
||||||
@ -276,7 +283,7 @@ export const computeMediaControls = (
|
|||||||
|
|
||||||
const buttons: ControlButton[] = [];
|
const buttons: ControlButton[] = [];
|
||||||
|
|
||||||
if (supportsFeature(stateObj, SUPPORT_TURN_OFF)) {
|
if (supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_OFF)) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiPower,
|
icon: mdiPower,
|
||||||
action: "turn_off",
|
action: "turn_off",
|
||||||
@ -288,7 +295,7 @@ export const computeMediaControls = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(state === "playing" || state === "paused" || assumedState) &&
|
(state === "playing" || state === "paused" || assumedState) &&
|
||||||
supportsFeature(stateObj, SUPPORT_SHUFFLE_SET) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.SHUFFLE_SET) &&
|
||||||
useExtendedControls
|
useExtendedControls
|
||||||
) {
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
@ -299,7 +306,7 @@ export const computeMediaControls = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(state === "playing" || state === "paused" || assumedState) &&
|
(state === "playing" || state === "paused" || assumedState) &&
|
||||||
supportsFeature(stateObj, SUPPORT_PREVIOUS_TRACK)
|
supportsFeature(stateObj, MediaPlayerEntityFeature.PREVIOUS_TRACK)
|
||||||
) {
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiSkipPrevious,
|
icon: mdiSkipPrevious,
|
||||||
@ -310,13 +317,13 @@ export const computeMediaControls = (
|
|||||||
if (
|
if (
|
||||||
!assumedState &&
|
!assumedState &&
|
||||||
((state === "playing" &&
|
((state === "playing" &&
|
||||||
(supportsFeature(stateObj, SUPPORT_PAUSE) ||
|
(supportsFeature(stateObj, MediaPlayerEntityFeature.PAUSE) ||
|
||||||
supportsFeature(stateObj, SUPPORT_STOP))) ||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.STOP))) ||
|
||||||
((state === "paused" || state === "idle") &&
|
((state === "paused" || state === "idle") &&
|
||||||
supportsFeature(stateObj, SUPPORT_PLAY)) ||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.PLAY)) ||
|
||||||
(state === "on" &&
|
(state === "on" &&
|
||||||
(supportsFeature(stateObj, SUPPORT_PLAY) ||
|
(supportsFeature(stateObj, MediaPlayerEntityFeature.PLAY) ||
|
||||||
supportsFeature(stateObj, SUPPORT_PAUSE))))
|
supportsFeature(stateObj, MediaPlayerEntityFeature.PAUSE))))
|
||||||
) {
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon:
|
icon:
|
||||||
@ -324,33 +331,42 @@ export const computeMediaControls = (
|
|||||||
? mdiPlayPause
|
? mdiPlayPause
|
||||||
: state !== "playing"
|
: state !== "playing"
|
||||||
? mdiPlay
|
? mdiPlay
|
||||||
: supportsFeature(stateObj, SUPPORT_PAUSE)
|
: supportsFeature(stateObj, MediaPlayerEntityFeature.PAUSE)
|
||||||
? mdiPause
|
? mdiPause
|
||||||
: mdiStop,
|
: mdiStop,
|
||||||
action:
|
action:
|
||||||
state !== "playing"
|
state !== "playing"
|
||||||
? "media_play"
|
? "media_play"
|
||||||
: supportsFeature(stateObj, SUPPORT_PAUSE)
|
: supportsFeature(stateObj, MediaPlayerEntityFeature.PAUSE)
|
||||||
? "media_pause"
|
? "media_pause"
|
||||||
: "media_stop",
|
: "media_stop",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assumedState && supportsFeature(stateObj, SUPPORT_PLAY)) {
|
if (
|
||||||
|
assumedState &&
|
||||||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.PLAY)
|
||||||
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiPlay,
|
icon: mdiPlay,
|
||||||
action: "media_play",
|
action: "media_play",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assumedState && supportsFeature(stateObj, SUPPORT_PAUSE)) {
|
if (
|
||||||
|
assumedState &&
|
||||||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.PAUSE)
|
||||||
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiPause,
|
icon: mdiPause,
|
||||||
action: "media_pause",
|
action: "media_pause",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assumedState && supportsFeature(stateObj, SUPPORT_STOP)) {
|
if (
|
||||||
|
assumedState &&
|
||||||
|
supportsFeature(stateObj, MediaPlayerEntityFeature.STOP)
|
||||||
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiStop,
|
icon: mdiStop,
|
||||||
action: "media_stop",
|
action: "media_stop",
|
||||||
@ -359,7 +375,7 @@ export const computeMediaControls = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(state === "playing" || state === "paused" || assumedState) &&
|
(state === "playing" || state === "paused" || assumedState) &&
|
||||||
supportsFeature(stateObj, SUPPORT_NEXT_TRACK)
|
supportsFeature(stateObj, MediaPlayerEntityFeature.NEXT_TRACK)
|
||||||
) {
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
icon: mdiSkipNext,
|
icon: mdiSkipNext,
|
||||||
@ -369,7 +385,7 @@ export const computeMediaControls = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(state === "playing" || state === "paused" || assumedState) &&
|
(state === "playing" || state === "paused" || assumedState) &&
|
||||||
supportsFeature(stateObj, SUPPORT_REPEAT_SET) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.REPEAT_SET) &&
|
||||||
useExtendedControls
|
useExtendedControls
|
||||||
) {
|
) {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
|
@ -16,8 +16,10 @@ export type Selector =
|
|||||||
| DateSelector
|
| DateSelector
|
||||||
| DateTimeSelector
|
| DateTimeSelector
|
||||||
| DeviceSelector
|
| DeviceSelector
|
||||||
|
| LegacyDeviceSelector
|
||||||
| DurationSelector
|
| DurationSelector
|
||||||
| EntitySelector
|
| EntitySelector
|
||||||
|
| LegacyEntitySelector
|
||||||
| FileSelector
|
| FileSelector
|
||||||
| IconSelector
|
| IconSelector
|
||||||
| LocationSelector
|
| LocationSelector
|
||||||
@ -48,22 +50,10 @@ export interface AddonSelector {
|
|||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectorDevice {
|
|
||||||
integration?: NonNullable<DeviceSelector["device"]>["integration"];
|
|
||||||
manufacturer?: NonNullable<DeviceSelector["device"]>["manufacturer"];
|
|
||||||
model?: NonNullable<DeviceSelector["device"]>["model"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelectorEntity {
|
|
||||||
integration?: NonNullable<EntitySelector["entity"]>["integration"];
|
|
||||||
domain?: NonNullable<EntitySelector["entity"]>["domain"];
|
|
||||||
device_class?: NonNullable<EntitySelector["entity"]>["device_class"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AreaSelector {
|
export interface AreaSelector {
|
||||||
area: {
|
area: {
|
||||||
entity?: SelectorEntity;
|
entity?: EntitySelectorFilter | readonly EntitySelectorFilter[];
|
||||||
device?: SelectorDevice;
|
device?: DeviceSelectorFilter | readonly DeviceSelectorFilter[];
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
@ -108,33 +98,77 @@ export interface DateTimeSelector {
|
|||||||
datetime: {} | null;
|
datetime: {} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DeviceSelectorFilter {
|
||||||
|
integration?: string;
|
||||||
|
manufacturer?: string;
|
||||||
|
model?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DeviceSelector {
|
export interface DeviceSelector {
|
||||||
device: {
|
device: {
|
||||||
integration?: string;
|
filter?: DeviceSelectorFilter | readonly DeviceSelectorFilter[];
|
||||||
manufacturer?: string;
|
entity?: EntitySelectorFilter | readonly EntitySelectorFilter[];
|
||||||
model?: string;
|
|
||||||
entity?: SelectorEntity;
|
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LegacyDeviceSelector {
|
||||||
|
device:
|
||||||
|
| DeviceSelector["device"] & {
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
integration?: DeviceSelectorFilter["integration"];
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
manufacturer?: DeviceSelectorFilter["manufacturer"];
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
model?: DeviceSelectorFilter["model"];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export interface DurationSelector {
|
export interface DurationSelector {
|
||||||
duration: {
|
duration: {
|
||||||
enable_day?: boolean;
|
enable_day?: boolean;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EntitySelectorFilter {
|
||||||
|
integration?: string;
|
||||||
|
domain?: string | readonly string[];
|
||||||
|
device_class?: string | readonly string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface EntitySelector {
|
export interface EntitySelector {
|
||||||
entity: {
|
entity: {
|
||||||
integration?: string;
|
|
||||||
domain?: string | readonly string[];
|
|
||||||
device_class?: string;
|
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
include_entities?: string[];
|
include_entities?: string[];
|
||||||
exclude_entities?: string[];
|
exclude_entities?: string[];
|
||||||
|
filter?: EntitySelectorFilter | readonly EntitySelectorFilter[];
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LegacyEntitySelector {
|
||||||
|
entity:
|
||||||
|
| EntitySelector["entity"] & {
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
integration?: EntitySelectorFilter["integration"];
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
domain?: EntitySelectorFilter["domain"];
|
||||||
|
/**
|
||||||
|
* @deprecated Use filter instead
|
||||||
|
*/
|
||||||
|
device_class?: EntitySelectorFilter["device_class"];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export interface StatisticSelector {
|
export interface StatisticSelector {
|
||||||
statistic: {
|
statistic: {
|
||||||
device_class?: string;
|
device_class?: string;
|
||||||
@ -250,8 +284,8 @@ export interface StringSelector {
|
|||||||
|
|
||||||
export interface TargetSelector {
|
export interface TargetSelector {
|
||||||
target: {
|
target: {
|
||||||
entity?: SelectorEntity;
|
entity?: EntitySelectorFilter | readonly EntitySelectorFilter[];
|
||||||
device?: SelectorDevice;
|
device?: DeviceSelectorFilter | readonly DeviceSelectorFilter[];
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +315,7 @@ export interface UiColorSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const filterSelectorDevices = (
|
export const filterSelectorDevices = (
|
||||||
filterDevice: SelectorDevice,
|
filterDevice: DeviceSelectorFilter,
|
||||||
device: DeviceRegistryEntry,
|
device: DeviceRegistryEntry,
|
||||||
deviceIntegrationLookup: Record<string, string[]> | undefined
|
deviceIntegrationLookup: Record<string, string[]> | undefined
|
||||||
): boolean => {
|
): boolean => {
|
||||||
@ -308,7 +342,7 @@ export const filterSelectorDevices = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const filterSelectorEntities = (
|
export const filterSelectorEntities = (
|
||||||
filterEntity: SelectorEntity,
|
filterEntity: EntitySelectorFilter,
|
||||||
entity: HassEntity,
|
entity: HassEntity,
|
||||||
entitySources?: EntitySources
|
entitySources?: EntitySources
|
||||||
): boolean => {
|
): boolean => {
|
||||||
@ -329,11 +363,15 @@ export const filterSelectorEntities = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (filterDeviceClass) {
|
||||||
filterDeviceClass &&
|
const entityDeviceClass = entity.attributes.device_class;
|
||||||
entity.attributes.device_class !== filterDeviceClass
|
if (
|
||||||
) {
|
entityDeviceClass && Array.isArray(filterDeviceClass)
|
||||||
return false;
|
? !filterDeviceClass.includes(entityDeviceClass)
|
||||||
|
: entityDeviceClass !== filterDeviceClass
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -345,3 +383,59 @@ export const filterSelectorEntities = (
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleLegacyEntitySelector = (
|
||||||
|
selector: LegacyEntitySelector | EntitySelector
|
||||||
|
): EntitySelector => {
|
||||||
|
if (!selector.entity) return { entity: null };
|
||||||
|
|
||||||
|
if ("filter" in selector.entity) return selector;
|
||||||
|
|
||||||
|
const { domain, integration, device_class, ...rest } = (
|
||||||
|
selector as LegacyEntitySelector
|
||||||
|
).entity!;
|
||||||
|
|
||||||
|
if (domain || integration || device_class) {
|
||||||
|
return {
|
||||||
|
entity: {
|
||||||
|
...rest,
|
||||||
|
filter: {
|
||||||
|
domain,
|
||||||
|
integration,
|
||||||
|
device_class,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
entity: rest,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleLegacyDeviceSelector = (
|
||||||
|
selector: LegacyDeviceSelector | DeviceSelector
|
||||||
|
): DeviceSelector => {
|
||||||
|
if (!selector.device) return { device: null };
|
||||||
|
|
||||||
|
if ("filter" in selector.device) return selector;
|
||||||
|
|
||||||
|
const { integration, manufacturer, model, ...rest } = (
|
||||||
|
selector as LegacyDeviceSelector
|
||||||
|
).device!;
|
||||||
|
|
||||||
|
if (integration || manufacturer || model) {
|
||||||
|
return {
|
||||||
|
device: {
|
||||||
|
...rest,
|
||||||
|
filter: {
|
||||||
|
integration,
|
||||||
|
manufacturer,
|
||||||
|
model,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
device: rest,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
66
src/data/thread.ts
Normal file
66
src/data/thread.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
|
export interface ThreadRouter {
|
||||||
|
brand: "google" | "apple" | "homeassistant";
|
||||||
|
server: string;
|
||||||
|
extended_pan_id: string;
|
||||||
|
model_name: string | null;
|
||||||
|
network_name: string;
|
||||||
|
vendor_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ThreadDataSet {
|
||||||
|
created;
|
||||||
|
dataset_id;
|
||||||
|
extended_pan_id;
|
||||||
|
network_name: string;
|
||||||
|
pan_id;
|
||||||
|
preferred: boolean;
|
||||||
|
source;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ThreadRouterDiscoveryEvent {
|
||||||
|
key: string;
|
||||||
|
type: "router_discovered" | "router_removed";
|
||||||
|
data: ThreadRouter;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DiscoveryStream {
|
||||||
|
hass: HomeAssistant;
|
||||||
|
|
||||||
|
routers: { [key: string]: ThreadRouter };
|
||||||
|
|
||||||
|
constructor(hass: HomeAssistant) {
|
||||||
|
this.hass = hass;
|
||||||
|
this.routers = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
processEvent(streamMessage: ThreadRouterDiscoveryEvent): ThreadRouter[] {
|
||||||
|
if (streamMessage.type === "router_discovered") {
|
||||||
|
this.routers[streamMessage.key] = streamMessage.data;
|
||||||
|
} else if (streamMessage.type === "router_removed") {
|
||||||
|
delete this.routers[streamMessage.key];
|
||||||
|
}
|
||||||
|
return Object.values(this.routers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const subscribeDiscoverThreadRouters = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
callbackFunction: (routers: ThreadRouter[]) => void
|
||||||
|
) => {
|
||||||
|
const stream = new DiscoveryStream(hass);
|
||||||
|
return hass.connection.subscribeMessage<ThreadRouterDiscoveryEvent>(
|
||||||
|
(message) => callbackFunction(stream.processEvent(message)),
|
||||||
|
{
|
||||||
|
type: "thread/discover_routers",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const listThreadDataSets = (
|
||||||
|
hass: HomeAssistant
|
||||||
|
): Promise<{ datasets: ThreadDataSet[] }> =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "thread/list_datasets",
|
||||||
|
});
|
@ -150,7 +150,9 @@ export const checkForEntityUpdates = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// there is no reliable way to know if all the updates are done updating, so we just wait a bit for now...
|
// there is no reliable way to know if all the updates are done updating, so we just wait a bit for now...
|
||||||
await new Promise((r) => setTimeout(r, 10000));
|
await new Promise((r) => {
|
||||||
|
setTimeout(r, 10000);
|
||||||
|
});
|
||||||
|
|
||||||
unsubscribeEvents();
|
unsubscribeEvents();
|
||||||
|
|
||||||
|
@ -92,7 +92,23 @@ enum NodeType {
|
|||||||
"End Node" = 1,
|
"End Node" = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum FirmwareUpdateStatus {
|
enum RFRegion {
|
||||||
|
"Europe" = 0x00,
|
||||||
|
"USA" = 0x01,
|
||||||
|
"Australia/New Zealand" = 0x02,
|
||||||
|
"Hong Kong" = 0x03,
|
||||||
|
"India" = 0x05,
|
||||||
|
"Israel" = 0x06,
|
||||||
|
"Russia" = 0x07,
|
||||||
|
"China" = 0x08,
|
||||||
|
"USA (Long Range)" = 0x09,
|
||||||
|
"Japan" = 0x20,
|
||||||
|
"Korea" = 0x21,
|
||||||
|
"Unknown" = 0xfe,
|
||||||
|
"Default (EU)" = 0xff,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum NodeFirmwareUpdateStatus {
|
||||||
Error_Timeout = -1,
|
Error_Timeout = -1,
|
||||||
Error_Checksum = 0,
|
Error_Checksum = 0,
|
||||||
Error_TransmissionFailed = 1,
|
Error_TransmissionFailed = 1,
|
||||||
@ -108,6 +124,19 @@ export enum FirmwareUpdateStatus {
|
|||||||
OK_RestartPending = 0xff,
|
OK_RestartPending = 0xff,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ControllerFirmwareUpdateStatus {
|
||||||
|
// An expected response was not received from the controller in time
|
||||||
|
Error_Timeout = 0,
|
||||||
|
/** The maximum number of retry attempts for a firmware fragments were reached */
|
||||||
|
Error_RetryLimitReached,
|
||||||
|
/** The update was aborted by the bootloader */
|
||||||
|
Error_Aborted,
|
||||||
|
/** This controller does not support firmware updates */
|
||||||
|
Error_NotSupported,
|
||||||
|
|
||||||
|
OK = 0xff,
|
||||||
|
}
|
||||||
|
|
||||||
export interface QRProvisioningInformation {
|
export interface QRProvisioningInformation {
|
||||||
version: QRCodeVersion;
|
version: QRCodeVersion;
|
||||||
securityClasses: SecurityClass[];
|
securityClasses: SecurityClass[];
|
||||||
@ -149,6 +178,7 @@ export interface ZWaveJSController {
|
|||||||
sdk_version: string;
|
sdk_version: string;
|
||||||
type: number;
|
type: number;
|
||||||
own_node_id: number;
|
own_node_id: number;
|
||||||
|
rf_region: RFRegion | null;
|
||||||
is_primary: boolean;
|
is_primary: boolean;
|
||||||
is_using_home_id_from_other_network: boolean;
|
is_using_home_id_from_other_network: boolean;
|
||||||
is_sis_present: boolean;
|
is_sis_present: boolean;
|
||||||
@ -176,6 +206,7 @@ export interface ZWaveJSNodeStatus {
|
|||||||
zwave_plus_version: number | null;
|
zwave_plus_version: number | null;
|
||||||
highest_security_class: SecurityClass | null;
|
highest_security_class: SecurityClass | null;
|
||||||
is_controller_node: boolean;
|
is_controller_node: boolean;
|
||||||
|
has_firmware_update_cc: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ZwaveJSNodeMetadata {
|
export interface ZwaveJSNodeMetadata {
|
||||||
@ -304,7 +335,7 @@ export interface ZWaveJSNodeStatusUpdatedMessage {
|
|||||||
status: NodeStatus;
|
status: NodeStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ZWaveJSNodeFirmwareUpdateProgressMessage {
|
export interface ZWaveJSFirmwareUpdateProgressMessage {
|
||||||
event: "firmware update progress";
|
event: "firmware update progress";
|
||||||
current_file: number;
|
current_file: number;
|
||||||
total_files: number;
|
total_files: number;
|
||||||
@ -315,12 +346,18 @@ export interface ZWaveJSNodeFirmwareUpdateProgressMessage {
|
|||||||
|
|
||||||
export interface ZWaveJSNodeFirmwareUpdateFinishedMessage {
|
export interface ZWaveJSNodeFirmwareUpdateFinishedMessage {
|
||||||
event: "firmware update finished";
|
event: "firmware update finished";
|
||||||
status: FirmwareUpdateStatus;
|
status: NodeFirmwareUpdateStatus;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
wait_time?: number;
|
wait_time?: number;
|
||||||
reinterview: boolean;
|
reinterview: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ZWaveJSControllerFirmwareUpdateFinishedMessage {
|
||||||
|
event: "firmware update finished";
|
||||||
|
status: ControllerFirmwareUpdateStatus;
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export type ZWaveJSNodeFirmwareUpdateCapabilities =
|
export type ZWaveJSNodeFirmwareUpdateCapabilities =
|
||||||
| { firmware_upgradable: false }
|
| { firmware_upgradable: false }
|
||||||
| {
|
| {
|
||||||
@ -422,7 +459,8 @@ export const subscribeAddZwaveNode = (
|
|||||||
inclusion_strategy: InclusionStrategy = InclusionStrategy.Default,
|
inclusion_strategy: InclusionStrategy = InclusionStrategy.Default,
|
||||||
qr_provisioning_information?: QRProvisioningInformation,
|
qr_provisioning_information?: QRProvisioningInformation,
|
||||||
qr_code_string?: string,
|
qr_code_string?: string,
|
||||||
planned_provisioning_entry?: PlannedProvisioningEntry
|
planned_provisioning_entry?: PlannedProvisioningEntry,
|
||||||
|
dsk?: string
|
||||||
): Promise<UnsubscribeFunc> =>
|
): Promise<UnsubscribeFunc> =>
|
||||||
hass.connection.subscribeMessage((message) => callbackFunction(message), {
|
hass.connection.subscribeMessage((message) => callbackFunction(message), {
|
||||||
type: "zwave_js/add_node",
|
type: "zwave_js/add_node",
|
||||||
@ -431,6 +469,7 @@ export const subscribeAddZwaveNode = (
|
|||||||
qr_code_string,
|
qr_code_string,
|
||||||
qr_provisioning_information,
|
qr_provisioning_information,
|
||||||
planned_provisioning_entry,
|
planned_provisioning_entry,
|
||||||
|
dsk,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const stopZwaveInclusion = (hass: HomeAssistant, entry_id: string) =>
|
export const stopZwaveInclusion = (hass: HomeAssistant, entry_id: string) =>
|
||||||
@ -458,6 +497,17 @@ export const zwaveGrantSecurityClasses = (
|
|||||||
client_side_auth,
|
client_side_auth,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const zwaveTryParseDskFromQrCode = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry_id: string,
|
||||||
|
qr_code_string: string
|
||||||
|
) =>
|
||||||
|
hass.callWS<string | null>({
|
||||||
|
type: "zwave_js/try_parse_dsk_from_qr_code_string",
|
||||||
|
entry_id,
|
||||||
|
qr_code_string,
|
||||||
|
});
|
||||||
|
|
||||||
export const zwaveValidateDskAndEnterPin = (
|
export const zwaveValidateDskAndEnterPin = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry_id: string,
|
entry_id: string,
|
||||||
@ -700,21 +750,17 @@ export const fetchZwaveNodeFirmwareUpdateCapabilities = (
|
|||||||
device_id: string
|
device_id: string
|
||||||
): Promise<ZWaveJSNodeFirmwareUpdateCapabilities> =>
|
): Promise<ZWaveJSNodeFirmwareUpdateCapabilities> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "zwave_js/get_firmware_update_capabilities",
|
type: "zwave_js/get_node_firmware_update_capabilities",
|
||||||
device_id,
|
device_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const uploadFirmwareAndBeginUpdate = async (
|
export const uploadFirmwareAndBeginUpdate = async (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_id: string,
|
device_id: string,
|
||||||
file: File,
|
file: File
|
||||||
target?: number
|
|
||||||
) => {
|
) => {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append("file", file);
|
fd.append("file", file);
|
||||||
if (target !== undefined) {
|
|
||||||
fd.append("target", target.toString());
|
|
||||||
}
|
|
||||||
const resp = await hass.fetchWithAuth(
|
const resp = await hass.fetchWithAuth(
|
||||||
`/api/zwave_js/firmware/upload/${device_id}`,
|
`/api/zwave_js/firmware/upload/${device_id}`,
|
||||||
{
|
{
|
||||||
@ -733,8 +779,9 @@ export const subscribeZwaveNodeFirmwareUpdate = (
|
|||||||
device_id: string,
|
device_id: string,
|
||||||
callbackFunction: (
|
callbackFunction: (
|
||||||
message:
|
message:
|
||||||
|
| ZWaveJSFirmwareUpdateProgressMessage
|
||||||
|
| ZWaveJSControllerFirmwareUpdateFinishedMessage
|
||||||
| ZWaveJSNodeFirmwareUpdateFinishedMessage
|
| ZWaveJSNodeFirmwareUpdateFinishedMessage
|
||||||
| ZWaveJSNodeFirmwareUpdateProgressMessage
|
|
||||||
) => void
|
) => void
|
||||||
): Promise<UnsubscribeFunc> =>
|
): Promise<UnsubscribeFunc> =>
|
||||||
hass.connection.subscribeMessage(
|
hass.connection.subscribeMessage(
|
||||||
|
@ -101,6 +101,19 @@ export const showConfigFlowDialog = (
|
|||||||
return hass.localize(`component.${step.handler}.selector.${key}`);
|
return hass.localize(`component.${step.handler}.selector.${key}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderShowFormStepSubmitButton(hass, step) {
|
||||||
|
return (
|
||||||
|
hass.localize(
|
||||||
|
`component.${step.handler}.config.step.${step.step_id}.submit`
|
||||||
|
) ||
|
||||||
|
hass.localize(
|
||||||
|
`ui.panel.config.integrations.config_flow.${
|
||||||
|
step.last_step === false ? "next" : "submit"
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
renderExternalStepHeader(hass, step) {
|
renderExternalStepHeader(hass, step) {
|
||||||
return (
|
return (
|
||||||
hass.localize(
|
hass.localize(
|
||||||
|
@ -67,6 +67,11 @@ export interface FlowConfig {
|
|||||||
key: string
|
key: string
|
||||||
): string;
|
): string;
|
||||||
|
|
||||||
|
renderShowFormStepSubmitButton(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
step: DataEntryFlowStepForm
|
||||||
|
): string;
|
||||||
|
|
||||||
renderExternalStepHeader(
|
renderExternalStepHeader(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
step: DataEntryFlowStepExternal
|
step: DataEntryFlowStepExternal
|
||||||
|
@ -115,6 +115,19 @@ export const showOptionsFlowDialog = (
|
|||||||
return hass.localize(`component.${configEntry.domain}.selector.${key}`);
|
return hass.localize(`component.${configEntry.domain}.selector.${key}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderShowFormStepSubmitButton(hass, step) {
|
||||||
|
return (
|
||||||
|
hass.localize(
|
||||||
|
`component.${configEntry.domain}.options.step.${step.step_id}.submit`
|
||||||
|
) ||
|
||||||
|
hass.localize(
|
||||||
|
`ui.panel.config.integrations.config_flow.${
|
||||||
|
step.last_step === false ? "next" : "submit"
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
renderExternalStepHeader(_hass, _step) {
|
renderExternalStepHeader(_hass, _step) {
|
||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
|
@ -70,10 +70,9 @@ class StepFlowForm extends LitElement {
|
|||||||
: html`
|
: html`
|
||||||
<div>
|
<div>
|
||||||
<mwc-button @click=${this._submitStep}>
|
<mwc-button @click=${this._submitStep}>
|
||||||
${this.hass.localize(
|
${this.flowConfig.renderShowFormStepSubmitButton(
|
||||||
`ui.panel.config.integrations.config_flow.${
|
this.hass,
|
||||||
this.step.last_step === false ? "next" : "submit"
|
this.step
|
||||||
}`
|
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
|
import { html, LitElement, TemplateResult, css, CSSResultGroup } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
|
import { isUnavailableState } from "../../../data/entity";
|
||||||
|
import { LightEntity } from "../../../data/light";
|
||||||
|
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
|
||||||
|
import "../../../panels/lovelace/components/hui-timestamp-display";
|
||||||
|
import { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
|
@customElement("ha-more-info-state-header")
|
||||||
|
export class HaMoreInfoStateHeader extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public stateObj!: LightEntity;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public stateOverride?: string;
|
||||||
|
|
||||||
|
private _computeStateDisplay(stateObj: HassEntity): TemplateResult | string {
|
||||||
|
if (
|
||||||
|
stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
|
||||||
|
!isUnavailableState(stateObj.state)
|
||||||
|
) {
|
||||||
|
return html`
|
||||||
|
<hui-timestamp-display
|
||||||
|
.hass=${this.hass}
|
||||||
|
.ts=${new Date(stateObj.state)}
|
||||||
|
format="relative"
|
||||||
|
capitalize
|
||||||
|
></hui-timestamp-display>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stateDisplay = computeStateDisplay(
|
||||||
|
this.hass!.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass!.locale,
|
||||||
|
this.hass!.entities
|
||||||
|
);
|
||||||
|
|
||||||
|
return stateDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
const name = this.stateObj.attributes.friendly_name;
|
||||||
|
|
||||||
|
const stateDisplay =
|
||||||
|
this.stateOverride ?? this._computeStateDisplay(this.stateObj);
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<p class="name">${name}</p>
|
||||||
|
<p class="state">${stateDisplay}</p>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return css`
|
||||||
|
p {
|
||||||
|
text-align: center;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.name {
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 36px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
.state {
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 24px;
|
||||||
|
letter-spacing: 0.1px;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-more-info-state-header": HaMoreInfoStateHeader;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user