mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-14 05:20:31 +00:00
Compare commits
219 Commits
copilot/al
...
save_panel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f70c03eac7 | ||
|
|
abb659ebc6 | ||
|
|
b3f966318e | ||
|
|
98e619fd2d | ||
|
|
58be5a5423 | ||
|
|
06b64369d8 | ||
|
|
c44ed0a831 | ||
|
|
e9a7c5f62b | ||
|
|
05394e42da | ||
|
|
e7480ef896 | ||
|
|
7a49cbf308 | ||
|
|
2044deefb8 | ||
|
|
13146575a0 | ||
|
|
97e49f751c | ||
|
|
e0d241a2db | ||
|
|
83e065ae98 | ||
|
|
a6ee670682 | ||
|
|
c457f92826 | ||
|
|
c73bd96a1f | ||
|
|
711f8e2fc3 | ||
|
|
91a0066544 | ||
|
|
aee7b8b8d4 | ||
|
|
d38d770e1a | ||
|
|
0036679553 | ||
|
|
2b85108242 | ||
|
|
c74320cb82 | ||
|
|
8ebe6e24d2 | ||
|
|
d3182da587 | ||
|
|
41fbc5e44b | ||
|
|
3fea41eb0e | ||
|
|
9a627bdea7 | ||
|
|
d9a67f603d | ||
|
|
5f37f8c0ab | ||
|
|
f222702abf | ||
|
|
2107b7c267 | ||
|
|
1c05afebd7 | ||
|
|
7179bb2d26 | ||
|
|
95cf1fdcf7 | ||
|
|
9617956cc6 | ||
|
|
65df464731 | ||
|
|
bd4e9a3d05 | ||
|
|
963fc13a99 | ||
|
|
ff614918d4 | ||
|
|
48aa5fb970 | ||
|
|
190af65756 | ||
|
|
76911e0e0d | ||
|
|
b8ec7c2e72 | ||
|
|
10e20c2272 | ||
|
|
2ec05aac2f | ||
|
|
61fbe5b53c | ||
|
|
5f3f1c7139 | ||
|
|
48f37b1b1e | ||
|
|
9091df9db5 | ||
|
|
1cd7a1cd78 | ||
|
|
ae5c7026b9 | ||
|
|
3900f3995a | ||
|
|
237f974ee8 | ||
|
|
b2ec4b7d2c | ||
|
|
b4c83d7877 | ||
|
|
22c53b6859 | ||
|
|
750b1e5e16 | ||
|
|
5801ce944c | ||
|
|
79ad9dbf44 | ||
|
|
9814533d47 | ||
|
|
bdb6c684c0 | ||
|
|
0046167f5c | ||
|
|
5266f0d761 | ||
|
|
cc5c0d04c4 | ||
|
|
7f3d5f557f | ||
|
|
9b48cd7737 | ||
|
|
11c6f6ec78 | ||
|
|
cb0f59b26d | ||
|
|
c89fc35578 | ||
|
|
f03cd9c239 | ||
|
|
19a4e37933 | ||
|
|
76514babd5 | ||
|
|
b6abbdafb8 | ||
|
|
d35e6c0092 | ||
|
|
5c2ee54dec | ||
|
|
1dfca76c81 | ||
|
|
fd7f028fbf | ||
|
|
3f7283b1af | ||
|
|
d35323ac52 | ||
|
|
06475382e8 | ||
|
|
b60dd7f15d | ||
|
|
b77e65fabd | ||
|
|
cea691a04e | ||
|
|
50df2a34cd | ||
|
|
e6c0a84994 | ||
|
|
b03fa4bdc5 | ||
|
|
058cecc124 | ||
|
|
a5f058a7eb | ||
|
|
655c2ff3c2 | ||
|
|
e1b0a3e737 | ||
|
|
d59d436080 | ||
|
|
0fe0bf12f2 | ||
|
|
f5a3877f47 | ||
|
|
31d04f5338 | ||
|
|
4f7d223aa7 | ||
|
|
484c60073d | ||
|
|
0e1ab1a60c | ||
|
|
cef11e0c18 | ||
|
|
55e75e80d2 | ||
|
|
126a78ec8a | ||
|
|
063af39f0f | ||
|
|
132c4c8201 | ||
|
|
4c08e960f1 | ||
|
|
a8020256de | ||
|
|
2ea57c33ae | ||
|
|
db1408666c | ||
|
|
260288a061 | ||
|
|
45fd685913 | ||
|
|
896d76b218 | ||
|
|
cec24117dc | ||
|
|
34006d268b | ||
|
|
54c03d91df | ||
|
|
52a56a1c4e | ||
|
|
e49feeb4aa | ||
|
|
a0c30e433a | ||
|
|
354ce027eb | ||
|
|
5c224a942d | ||
|
|
0efa4f81d4 | ||
|
|
3ad2f35f29 | ||
|
|
7a21d5f7bc | ||
|
|
33226587e6 | ||
|
|
bd2673f311 | ||
|
|
cecadde497 | ||
|
|
494b8811d0 | ||
|
|
4e0a49b3da | ||
|
|
3145fed5dc | ||
|
|
3dd040fdc7 | ||
|
|
e3abe9736c | ||
|
|
fe41e72774 | ||
|
|
7078ef52d4 | ||
|
|
f1c9802ee3 | ||
|
|
35697e3f94 | ||
|
|
8ea7ad3026 | ||
|
|
73747fbedc | ||
|
|
aaa92bd354 | ||
|
|
5f75fc5bcb | ||
|
|
5fa44548c3 | ||
|
|
1945c11621 | ||
|
|
930575d292 | ||
|
|
0147dbab00 | ||
|
|
13ace24b83 | ||
|
|
616333591a | ||
|
|
8f5875c30f | ||
|
|
517cd49f35 | ||
|
|
25d9fc94b2 | ||
|
|
7b188759e3 | ||
|
|
76772d1098 | ||
|
|
6052745ca0 | ||
|
|
89b9780345 | ||
|
|
a607edca96 | ||
|
|
52eb3d8063 | ||
|
|
3e749ec085 | ||
|
|
ee2ec00069 | ||
|
|
0aa2941868 | ||
|
|
46cd1d5156 | ||
|
|
07a5c41fd4 | ||
|
|
4ad3c553d5 | ||
|
|
d40cc448a5 | ||
|
|
e2f3f9d348 | ||
|
|
98d44950f8 | ||
|
|
8ae9edb1ef | ||
|
|
84c4396c13 | ||
|
|
2b937a30e3 | ||
|
|
b7815bfd86 | ||
|
|
d94fa03411 | ||
|
|
0a7007ef9e | ||
|
|
dd12136dee | ||
|
|
6e2f89fe3d | ||
|
|
092085b9af | ||
|
|
1c06eb8661 | ||
|
|
c7e87b06b5 | ||
|
|
38c738c199 | ||
|
|
e899587307 | ||
|
|
c9feb0b75f | ||
|
|
10718c35d1 | ||
|
|
4dc6a37bad | ||
|
|
ac49fc7aba | ||
|
|
e4f008800b | ||
|
|
0b0ffd7bab | ||
|
|
dfa77526a2 | ||
|
|
9a3bd6c613 | ||
|
|
1161de5746 | ||
|
|
9df8e20391 | ||
|
|
11047a9c95 | ||
|
|
18fa66f61c | ||
|
|
758a048f34 | ||
|
|
ee0fc360b0 | ||
|
|
4012f95ec1 | ||
|
|
0336ce4606 | ||
|
|
9ba36ab7e2 | ||
|
|
fe7a08a1b0 | ||
|
|
87a8f9cedc | ||
|
|
01df7e20ca | ||
|
|
d181219522 | ||
|
|
6ae24b8135 | ||
|
|
8e009f24f9 | ||
|
|
53031f44ac | ||
|
|
af5a988457 | ||
|
|
bab0391a19 | ||
|
|
444123c47e | ||
|
|
f123d34046 | ||
|
|
1b40f99f68 | ||
|
|
b314b3ed2b | ||
|
|
59b8932969 | ||
|
|
107af753ec | ||
|
|
1f0acb3046 | ||
|
|
431e533929 | ||
|
|
02c845cbc6 | ||
|
|
628111ed20 | ||
|
|
e825a9c02f | ||
|
|
7a35bddf36 | ||
|
|
ad69270af8 | ||
|
|
404edf9483 | ||
|
|
a166b4e9b6 | ||
|
|
7a285f11db |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -36,14 +36,14 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -57,4 +57,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||||
|
|||||||
2
.github/workflows/relative-ci.yaml
vendored
2
.github/workflows/relative-ci.yaml
vendored
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Send bundle stats and build information to RelativeCI
|
- name: Send bundle stats and build information to RelativeCI
|
||||||
uses: relative-ci/agent-action@8504826a02078b05756e4c07e380023cc2c4274a # v3.1.0
|
uses: relative-ci/agent-action@feb19ddc698445db27401f1490f6ac182da0816f # v3.2.0
|
||||||
with:
|
with:
|
||||||
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
||||||
token: ${{ github.token }}
|
token: ${{ github.token }}
|
||||||
|
|||||||
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
@@ -55,7 +55,7 @@ jobs:
|
|||||||
script/release
|
script/release
|
||||||
|
|
||||||
- name: Upload release assets
|
- name: Upload release assets
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
dist/*.whl
|
dist/*.whl
|
||||||
@@ -108,7 +108,7 @@ jobs:
|
|||||||
- name: Tar folder
|
- name: Tar folder
|
||||||
run: tar -czf landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz -C landing-page/dist .
|
run: tar -czf landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz -C landing-page/dist .
|
||||||
- name: Upload release asset
|
- name: Upload release asset
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz
|
files: landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz
|
||||||
|
|
||||||
@@ -137,6 +137,6 @@ jobs:
|
|||||||
- name: Tar folder
|
- name: Tar folder
|
||||||
run: tar -czf hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz -C hassio/build .
|
run: tar -czf hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz -C hassio/build .
|
||||||
- name: Upload release asset
|
- name: Upload release asset
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz
|
files: hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz
|
||||||
|
|||||||
@@ -18,16 +18,16 @@ module.exports.sourceMapURL = () => {
|
|||||||
module.exports.ignorePackages = () => [];
|
module.exports.ignorePackages = () => [];
|
||||||
|
|
||||||
// Files from NPM packages that we should replace with empty file
|
// Files from NPM packages that we should replace with empty file
|
||||||
module.exports.emptyPackages = ({ isHassioBuild }) =>
|
module.exports.emptyPackages = ({ isHassioBuild, isLandingPageBuild }) =>
|
||||||
[
|
[
|
||||||
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
|
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
|
||||||
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
|
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
|
||||||
// Icons in supervisor conflict with icons in HA so we don't load.
|
// Icons in supervisor conflict with icons in HA so we don't load.
|
||||||
isHassioBuild &&
|
(isHassioBuild || isLandingPageBuild) &&
|
||||||
require.resolve(
|
require.resolve(
|
||||||
path.resolve(paths.root_dir, "src/components/ha-icon.ts")
|
path.resolve(paths.root_dir, "src/components/ha-icon.ts")
|
||||||
),
|
),
|
||||||
isHassioBuild &&
|
(isHassioBuild || isLandingPageBuild) &&
|
||||||
require.resolve(
|
require.resolve(
|
||||||
path.resolve(paths.root_dir, "src/components/ha-icon-picker.ts")
|
path.resolve(paths.root_dir, "src/components/ha-icon-picker.ts")
|
||||||
),
|
),
|
||||||
@@ -337,6 +337,7 @@ module.exports.config = {
|
|||||||
publicPath: publicPath(latestBuild),
|
publicPath: publicPath(latestBuild),
|
||||||
isProdBuild,
|
isProdBuild,
|
||||||
latestBuild,
|
latestBuild,
|
||||||
|
isLandingPageBuild: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const createRspackConfig = ({
|
|||||||
isStatsBuild,
|
isStatsBuild,
|
||||||
isTestBuild,
|
isTestBuild,
|
||||||
isHassioBuild,
|
isHassioBuild,
|
||||||
|
isLandingPageBuild,
|
||||||
dontHash,
|
dontHash,
|
||||||
}) => {
|
}) => {
|
||||||
if (!dontHash) {
|
if (!dontHash) {
|
||||||
@@ -168,7 +169,9 @@ const createRspackConfig = ({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new rspack.NormalModuleReplacementPlugin(
|
new rspack.NormalModuleReplacementPlugin(
|
||||||
new RegExp(bundle.emptyPackages({ isHassioBuild }).join("|")),
|
new RegExp(
|
||||||
|
bundle.emptyPackages({ isHassioBuild, isLandingPageBuild }).join("|")
|
||||||
|
),
|
||||||
path.resolve(paths.root_dir, "src/util/empty.js")
|
path.resolve(paths.root_dir, "src/util/empty.js")
|
||||||
),
|
),
|
||||||
!isProdBuild && new LogStartCompilePlugin(),
|
!isProdBuild && new LogStartCompilePlugin(),
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
} from "../../../../src/common/auth/token_storage";
|
} from "../../../../src/common/auth/token_storage";
|
||||||
import { atLeastVersion } from "../../../../src/common/config/version";
|
import { atLeastVersion } from "../../../../src/common/config/version";
|
||||||
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
|
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
|
||||||
|
import "../../../../src/components/ha-button";
|
||||||
import "../../../../src/components/ha-icon";
|
import "../../../../src/components/ha-icon";
|
||||||
import "../../../../src/components/ha-list";
|
import "../../../../src/components/ha-list";
|
||||||
import "../../../../src/components/ha-button";
|
|
||||||
import "../../../../src/components/ha-list-item";
|
import "../../../../src/components/ha-list-item";
|
||||||
import "../../../../src/components/ha-svg-icon";
|
import "../../../../src/components/ha-svg-icon";
|
||||||
import {
|
import {
|
||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
import { isStrategyDashboard } from "../../../../src/data/lovelace/config/types";
|
import { isStrategyDashboard } from "../../../../src/data/lovelace/config/types";
|
||||||
import type { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
import type { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
||||||
import "../../../../src/layouts/hass-loading-screen";
|
import "../../../../src/layouts/hass-loading-screen";
|
||||||
import { generateDefaultViewConfig } from "../../../../src/panels/lovelace/common/generate-lovelace-config";
|
|
||||||
import "./hc-layout";
|
import "./hc-layout";
|
||||||
|
|
||||||
@customElement("hc-cast")
|
@customElement("hc-cast")
|
||||||
@@ -96,7 +95,9 @@ class HcCast extends LitElement {
|
|||||||
<ha-list @action=${this._handlePickView} activatable>
|
<ha-list @action=${this._handlePickView} activatable>
|
||||||
${(
|
${(
|
||||||
this.lovelaceViews ?? [
|
this.lovelaceViews ?? [
|
||||||
generateDefaultViewConfig({}, {}, {}, {}, () => ""),
|
{
|
||||||
|
title: "Home",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
).map(
|
).map(
|
||||||
(view, idx) => html`
|
(view, idx) => html`
|
||||||
|
|||||||
55
gallery/src/pages/components/ha-dropdown.markdown
Normal file
55
gallery/src/pages/components/ha-dropdown.markdown
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
title: Dropdown
|
||||||
|
---
|
||||||
|
|
||||||
|
# Dropdown `<ha-dropdown>`
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
A compact, accessible dropdown menu for choosing actions or settings. `ha-dropdown` supports composed menu items (`<ha-dropdown-item>`) for icons, submenus, checkboxes, disabled entries, and destructive variants. Use composition with `slot="trigger"` to control the trigger button and use `<ha-dropdown-item>` for rich item content.
|
||||||
|
|
||||||
|
### Example usage (composition)
|
||||||
|
|
||||||
|
```html
|
||||||
|
<ha-dropdown open>
|
||||||
|
<ha-button slot="trigger" with-caret>Dropdown</ha-button>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon .path="mdiContentCut" slot="icon"></ha-svg-icon>
|
||||||
|
Cut
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon .path="mdiContentCopy" slot="icon"></ha-svg-icon>
|
||||||
|
Copy
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item disabled>
|
||||||
|
<ha-svg-icon .path="mdiContentPaste" slot="icon"></ha-svg-icon>
|
||||||
|
Paste
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
Show images
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-all-images"
|
||||||
|
>Show all images</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-thumbnails"
|
||||||
|
>Show thumbnails</ha-dropdown-item
|
||||||
|
>
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item type="checkbox" checked>Emoji shortcuts</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item type="checkbox" checked>Word wrap</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item variant="danger">
|
||||||
|
<ha-svg-icon .path="mdiDelete" slot="icon"></ha-svg-icon>
|
||||||
|
Delete
|
||||||
|
</ha-dropdown-item>
|
||||||
|
</ha-dropdown>
|
||||||
|
```
|
||||||
|
|
||||||
|
### API
|
||||||
|
|
||||||
|
This component is based on the webawesome dropdown component.
|
||||||
|
Check the [webawesome documentation](https://webawesome.com/docs/components/dropdown/) for more details.
|
||||||
133
gallery/src/pages/components/ha-dropdown.ts
Normal file
133
gallery/src/pages/components/ha-dropdown.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import "@home-assistant/webawesome/dist/components/button/button";
|
||||||
|
import "@home-assistant/webawesome/dist/components/dropdown/dropdown";
|
||||||
|
import "@home-assistant/webawesome/dist/components/icon/icon";
|
||||||
|
import "@home-assistant/webawesome/dist/components/popup/popup";
|
||||||
|
import {
|
||||||
|
mdiContentCopy,
|
||||||
|
mdiContentCut,
|
||||||
|
mdiContentPaste,
|
||||||
|
mdiDelete,
|
||||||
|
} from "@mdi/js";
|
||||||
|
import type { TemplateResult } from "lit";
|
||||||
|
import { css, html, LitElement } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element";
|
||||||
|
import "../../../../src/components/ha-button";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-dropdown";
|
||||||
|
import "../../../../src/components/ha-dropdown-item";
|
||||||
|
import "../../../../src/components/ha-icon-button";
|
||||||
|
import "../../../../src/components/ha-svg-icon";
|
||||||
|
|
||||||
|
@customElement("demo-components-ha-dropdown")
|
||||||
|
export class DemoHaDropdown extends LitElement {
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
${["light", "dark"].map(
|
||||||
|
(mode) => html`
|
||||||
|
<div class=${mode}>
|
||||||
|
<ha-card header="ha-button in ${mode}">
|
||||||
|
<div class="card-content">
|
||||||
|
<ha-dropdown open>
|
||||||
|
<ha-button slot="trigger" with-caret>Dropdown</ha-button>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentCut}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Cut
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentCopy}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Copy
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item disabled>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentPaste}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Paste
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item>
|
||||||
|
Show images
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-all-images"
|
||||||
|
>Show All Images</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-thumbnails"
|
||||||
|
>Show Thumbnails</ha-dropdown-item
|
||||||
|
>
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item type="checkbox" checked
|
||||||
|
>Emoji Shortcuts</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item type="checkbox" checked
|
||||||
|
>Word Wrap</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item variant="danger">
|
||||||
|
<ha-svg-icon .path=${mdiDelete} slot="icon"></ha-svg-icon>
|
||||||
|
Delete
|
||||||
|
</ha-dropdown-item>
|
||||||
|
</ha-dropdown>
|
||||||
|
</div>
|
||||||
|
</ha-card>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
firstUpdated(changedProps) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
applyThemesOnElement(
|
||||||
|
this.shadowRoot!.querySelector(".dark"),
|
||||||
|
{
|
||||||
|
default_theme: "default",
|
||||||
|
default_dark_theme: "default",
|
||||||
|
themes: {},
|
||||||
|
darkMode: true,
|
||||||
|
theme: "default",
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.dark,
|
||||||
|
.light {
|
||||||
|
display: block;
|
||||||
|
background-color: var(--primary-background-color);
|
||||||
|
padding: 0 50px;
|
||||||
|
}
|
||||||
|
.button {
|
||||||
|
padding: unset;
|
||||||
|
}
|
||||||
|
ha-card {
|
||||||
|
margin: 24px auto;
|
||||||
|
}
|
||||||
|
.card-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
.card-content div {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-components-ha-dropdown": DemoHaDropdown;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ const SENSOR_DEVICE_CLASSES = [
|
|||||||
"pm1",
|
"pm1",
|
||||||
"pm10",
|
"pm10",
|
||||||
"pm25",
|
"pm25",
|
||||||
|
"pm4",
|
||||||
"power_factor",
|
"power_factor",
|
||||||
"power",
|
"power",
|
||||||
"precipitation",
|
"precipitation",
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
import "@material/mwc-linear-progress";
|
import "@material/mwc-linear-progress";
|
||||||
import { type PropertyValues, css, html, nothing } from "lit";
|
import { mdiOpenInNew } from "@mdi/js";
|
||||||
|
import { css, html, nothing, type PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { extractSearchParam } from "../../src/common/url/search-params";
|
||||||
import "../../src/components/ha-alert";
|
import "../../src/components/ha-alert";
|
||||||
|
import "../../src/components/ha-button";
|
||||||
import "../../src/components/ha-fade-in";
|
import "../../src/components/ha-fade-in";
|
||||||
import "../../src/components/ha-spinner";
|
import "../../src/components/ha-spinner";
|
||||||
import { haStyle } from "../../src/resources/styles";
|
import "../../src/components/ha-svg-icon";
|
||||||
import "../../src/onboarding/onboarding-welcome-links";
|
|
||||||
import "./components/landing-page-network";
|
|
||||||
import "./components/landing-page-logs";
|
|
||||||
import { extractSearchParam } from "../../src/common/url/search-params";
|
|
||||||
import { onBoardingStyles } from "../../src/onboarding/styles";
|
|
||||||
import { makeDialogManager } from "../../src/dialogs/make-dialog-manager";
|
import { makeDialogManager } from "../../src/dialogs/make-dialog-manager";
|
||||||
import { LandingPageBaseElement } from "./landing-page-base-element";
|
import "../../src/onboarding/onboarding-welcome-links";
|
||||||
|
import { onBoardingStyles } from "../../src/onboarding/styles";
|
||||||
|
import { haStyle } from "../../src/resources/styles";
|
||||||
|
import "./components/landing-page-logs";
|
||||||
|
import "./components/landing-page-network";
|
||||||
import {
|
import {
|
||||||
getSupervisorNetworkInfo,
|
getSupervisorNetworkInfo,
|
||||||
pingSupervisor,
|
pingSupervisor,
|
||||||
type NetworkInfo,
|
type NetworkInfo,
|
||||||
} from "./data/supervisor";
|
} from "./data/supervisor";
|
||||||
|
import { LandingPageBaseElement } from "./landing-page-base-element";
|
||||||
|
|
||||||
export const ASSUME_CORE_START_SECONDS = 60;
|
export const ASSUME_CORE_START_SECONDS = 60;
|
||||||
const SCHEDULE_CORE_CHECK_SECONDS = 1;
|
const SCHEDULE_CORE_CHECK_SECONDS = 1;
|
||||||
@@ -94,16 +97,21 @@ class HaLandingPage extends LandingPageBaseElement {
|
|||||||
<ha-language-picker
|
<ha-language-picker
|
||||||
.value=${this.language}
|
.value=${this.language}
|
||||||
.label=${""}
|
.label=${""}
|
||||||
|
button-style
|
||||||
native-name
|
native-name
|
||||||
@value-changed=${this._languageChanged}
|
@value-changed=${this._languageChanged}
|
||||||
inline-arrow
|
inline-arrow
|
||||||
></ha-language-picker>
|
></ha-language-picker>
|
||||||
<a
|
<ha-button
|
||||||
|
appearance="plain"
|
||||||
|
variant="neutral"
|
||||||
href="https://www.home-assistant.io/getting-started/onboarding/"
|
href="https://www.home-assistant.io/getting-started/onboarding/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
>${this.localize("ui.panel.page-onboarding.help")}</a
|
|
||||||
>
|
>
|
||||||
|
${this.localize("ui.panel.page-onboarding.help")}
|
||||||
|
<ha-svg-icon slot="end" .path=${mdiOpenInNew}></ha-svg-icon>
|
||||||
|
</ha-button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -218,26 +226,8 @@ class HaLandingPage extends LandingPageBaseElement {
|
|||||||
ha-alert p {
|
ha-alert p {
|
||||||
text-align: unset;
|
text-align: unset;
|
||||||
}
|
}
|
||||||
ha-language-picker {
|
.footer ha-svg-icon {
|
||||||
display: block;
|
--mdc-icon-size: var(--ha-space-5);
|
||||||
width: 200px;
|
|
||||||
border-radius: var(--ha-border-radius-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
--ha-select-height: 40px;
|
|
||||||
--mdc-select-fill-color: none;
|
|
||||||
--mdc-select-label-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-idle-line-color: transparent;
|
|
||||||
--mdc-select-hover-line-color: transparent;
|
|
||||||
--mdc-select-dropdown-icon-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-shape-small: 0;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
margin-right: 16px;
|
|
||||||
margin-inline-end: 16px;
|
|
||||||
margin-inline-start: initial;
|
|
||||||
}
|
}
|
||||||
ha-fade-in {
|
ha-fade-in {
|
||||||
min-height: calc(100vh - 64px - 88px);
|
min-height: calc(100vh - 64px - 88px);
|
||||||
|
|||||||
43
package.json
43
package.json
@@ -52,7 +52,7 @@
|
|||||||
"@fullcalendar/list": "6.1.19",
|
"@fullcalendar/list": "6.1.19",
|
||||||
"@fullcalendar/luxon3": "6.1.19",
|
"@fullcalendar/luxon3": "6.1.19",
|
||||||
"@fullcalendar/timegrid": "6.1.19",
|
"@fullcalendar/timegrid": "6.1.19",
|
||||||
"@home-assistant/webawesome": "3.0.0-beta.6.ha.6",
|
"@home-assistant/webawesome": "3.0.0",
|
||||||
"@lezer/highlight": "1.2.3",
|
"@lezer/highlight": "1.2.3",
|
||||||
"@lit-labs/motion": "1.0.9",
|
"@lit-labs/motion": "1.0.9",
|
||||||
"@lit-labs/observers": "2.0.6",
|
"@lit-labs/observers": "2.0.6",
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
"@material/mwc-top-app-bar": "0.27.0",
|
"@material/mwc-top-app-bar": "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": "2.4.0",
|
"@material/web": "2.4.1",
|
||||||
"@mdi/js": "7.4.47",
|
"@mdi/js": "7.4.47",
|
||||||
"@mdi/svg": "7.4.47",
|
"@mdi/svg": "7.4.47",
|
||||||
"@replit/codemirror-indentation-markers": "6.5.3",
|
"@replit/codemirror-indentation-markers": "6.5.3",
|
||||||
@@ -89,8 +89,8 @@
|
|||||||
"@thomasloven/round-slider": "0.6.0",
|
"@thomasloven/round-slider": "0.6.0",
|
||||||
"@tsparticles/engine": "3.9.1",
|
"@tsparticles/engine": "3.9.1",
|
||||||
"@tsparticles/preset-links": "3.2.0",
|
"@tsparticles/preset-links": "3.2.0",
|
||||||
"@vaadin/combo-box": "24.9.2",
|
"@vaadin/combo-box": "24.9.5",
|
||||||
"@vaadin/vaadin-themable-mixin": "24.9.2",
|
"@vaadin/vaadin-themable-mixin": "24.9.5",
|
||||||
"@vibrant/color": "4.0.0",
|
"@vibrant/color": "4.0.0",
|
||||||
"@vue/web-component-wrapper": "1.3.0",
|
"@vue/web-component-wrapper": "1.3.0",
|
||||||
"@webcomponents/scoped-custom-element-registry": "0.0.10",
|
"@webcomponents/scoped-custom-element-registry": "0.0.10",
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
"fuse.js": "7.1.0",
|
"fuse.js": "7.1.0",
|
||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"gulp-zopfli-green": "6.0.2",
|
"gulp-zopfli-green": "6.0.2",
|
||||||
"hls.js": "1.6.13",
|
"hls.js": "1.6.14",
|
||||||
"home-assistant-js-websocket": "9.5.0",
|
"home-assistant-js-websocket": "9.5.0",
|
||||||
"idb-keyval": "6.2.2",
|
"idb-keyval": "6.2.2",
|
||||||
"intl-messageformat": "10.7.18",
|
"intl-messageformat": "10.7.18",
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
"lit": "3.3.1",
|
"lit": "3.3.1",
|
||||||
"lit-html": "3.3.1",
|
"lit-html": "3.3.1",
|
||||||
"luxon": "3.7.2",
|
"luxon": "3.7.2",
|
||||||
"marked": "16.4.1",
|
"marked": "17.0.0",
|
||||||
"memoize-one": "6.0.0",
|
"memoize-one": "6.0.0",
|
||||||
"node-vibrant": "4.0.3",
|
"node-vibrant": "4.0.3",
|
||||||
"object-hash": "3.0.0",
|
"object-hash": "3.0.0",
|
||||||
@@ -152,13 +152,13 @@
|
|||||||
"@babel/helper-define-polyfill-provider": "0.6.5",
|
"@babel/helper-define-polyfill-provider": "0.6.5",
|
||||||
"@babel/plugin-transform-runtime": "7.28.5",
|
"@babel/plugin-transform-runtime": "7.28.5",
|
||||||
"@babel/preset-env": "7.28.5",
|
"@babel/preset-env": "7.28.5",
|
||||||
"@bundle-stats/plugin-webpack-filter": "4.21.5",
|
"@bundle-stats/plugin-webpack-filter": "4.21.6",
|
||||||
"@lokalise/node-api": "15.3.1",
|
"@lokalise/node-api": "15.3.1",
|
||||||
"@octokit/auth-oauth-device": "8.0.2",
|
"@octokit/auth-oauth-device": "8.0.3",
|
||||||
"@octokit/plugin-retry": "8.0.2",
|
"@octokit/plugin-retry": "8.0.3",
|
||||||
"@octokit/rest": "22.0.0",
|
"@octokit/rest": "22.0.1",
|
||||||
"@rsdoctor/rspack-plugin": "1.3.4",
|
"@rsdoctor/rspack-plugin": "1.3.8",
|
||||||
"@rspack/core": "1.5.8",
|
"@rspack/core": "1.6.1",
|
||||||
"@rspack/dev-server": "1.1.4",
|
"@rspack/dev-server": "1.1.4",
|
||||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||||
"@types/chromecast-caf-receiver": "6.0.22",
|
"@types/chromecast-caf-receiver": "6.0.22",
|
||||||
@@ -178,12 +178,12 @@
|
|||||||
"@types/tar": "6.1.13",
|
"@types/tar": "6.1.13",
|
||||||
"@types/ua-parser-js": "0.7.39",
|
"@types/ua-parser-js": "0.7.39",
|
||||||
"@types/webspeechapi": "0.0.29",
|
"@types/webspeechapi": "0.0.29",
|
||||||
"@vitest/coverage-v8": "4.0.3",
|
"@vitest/coverage-v8": "4.0.8",
|
||||||
"babel-loader": "10.0.0",
|
"babel-loader": "10.0.0",
|
||||||
"babel-plugin-template-html-minifier": "4.1.0",
|
"babel-plugin-template-html-minifier": "4.1.0",
|
||||||
"browserslist-useragent-regexp": "4.1.3",
|
"browserslist-useragent-regexp": "4.1.3",
|
||||||
"del": "8.0.1",
|
"del": "8.0.1",
|
||||||
"eslint": "9.38.0",
|
"eslint": "9.39.1",
|
||||||
"eslint-config-airbnb-base": "15.0.0",
|
"eslint-config-airbnb-base": "15.0.0",
|
||||||
"eslint-config-prettier": "10.1.8",
|
"eslint-config-prettier": "10.1.8",
|
||||||
"eslint-import-resolver-webpack": "0.13.10",
|
"eslint-import-resolver-webpack": "0.13.10",
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
"gulp-rename": "2.1.0",
|
"gulp-rename": "2.1.0",
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
"husky": "9.1.7",
|
"husky": "9.1.7",
|
||||||
"jsdom": "27.0.1",
|
"jsdom": "27.1.0",
|
||||||
"jszip": "3.10.1",
|
"jszip": "3.10.1",
|
||||||
"lint-staged": "16.2.6",
|
"lint-staged": "16.2.6",
|
||||||
"lit-analyzer": "2.0.3",
|
"lit-analyzer": "2.0.3",
|
||||||
@@ -213,13 +213,13 @@
|
|||||||
"rspack-manifest-plugin": "5.1.0",
|
"rspack-manifest-plugin": "5.1.0",
|
||||||
"serve": "14.2.5",
|
"serve": "14.2.5",
|
||||||
"sinon": "21.0.0",
|
"sinon": "21.0.0",
|
||||||
"tar": "7.5.1",
|
"tar": "7.5.2",
|
||||||
"terser-webpack-plugin": "5.3.14",
|
"terser-webpack-plugin": "5.3.14",
|
||||||
"ts-lit-plugin": "2.0.2",
|
"ts-lit-plugin": "2.0.2",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"typescript-eslint": "8.46.2",
|
"typescript-eslint": "8.46.3",
|
||||||
"vite-tsconfig-paths": "5.1.4",
|
"vite-tsconfig-paths": "5.1.4",
|
||||||
"vitest": "4.0.3",
|
"vitest": "4.0.8",
|
||||||
"webpack-stats-plugin": "1.1.3",
|
"webpack-stats-plugin": "1.1.3",
|
||||||
"webpackbar": "7.0.0",
|
"webpackbar": "7.0.0",
|
||||||
"workbox-build": "patch:workbox-build@npm%3A7.1.1#~/.yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch"
|
"workbox-build": "patch:workbox-build@npm%3A7.1.1#~/.yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch"
|
||||||
@@ -231,9 +231,12 @@
|
|||||||
"clean-css": "5.3.3",
|
"clean-css": "5.3.3",
|
||||||
"@lit/reactive-element": "2.1.1",
|
"@lit/reactive-element": "2.1.1",
|
||||||
"@fullcalendar/daygrid": "6.1.19",
|
"@fullcalendar/daygrid": "6.1.19",
|
||||||
"globals": "16.4.0",
|
"globals": "16.5.0",
|
||||||
"tslib": "2.8.1",
|
"tslib": "2.8.1",
|
||||||
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch"
|
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.10.3"
|
"packageManager": "yarn@4.10.3",
|
||||||
|
"volta": {
|
||||||
|
"node": "22.21.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20250924.0"
|
version = "20251029.0"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
license-files = ["LICENSE*"]
|
license-files = ["LICENSE*"]
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable lit/prefer-static-styles */
|
/* eslint-disable lit/prefer-static-styles */
|
||||||
|
import { mdiOpenInNew } from "@mdi/js";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@@ -6,6 +7,8 @@ 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";
|
||||||
import "../components/ha-alert";
|
import "../components/ha-alert";
|
||||||
|
import "../components/ha-button";
|
||||||
|
import "../components/ha-svg-icon";
|
||||||
import type { AuthProvider, AuthUrlSearchParams } from "../data/auth";
|
import type { AuthProvider, AuthUrlSearchParams } from "../data/auth";
|
||||||
import { fetchAuthProviders } from "../data/auth";
|
import { fetchAuthProviders } from "../data/auth";
|
||||||
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
||||||
@@ -133,25 +136,8 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
ha-language-picker {
|
.footer ha-svg-icon {
|
||||||
width: 200px;
|
--mdc-icon-size: var(--ha-space-5);
|
||||||
border-radius: var(--ha-border-radius-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
--ha-select-height: 40px;
|
|
||||||
--mdc-select-fill-color: none;
|
|
||||||
--mdc-select-label-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-idle-line-color: transparent;
|
|
||||||
--mdc-select-hover-line-color: transparent;
|
|
||||||
--mdc-select-dropdown-icon-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-shape-small: 0;
|
|
||||||
}
|
|
||||||
.footer a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
margin-right: 16px;
|
|
||||||
margin-inline-end: 16px;
|
|
||||||
margin-inline-start: initial;
|
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
font-size: var(--ha-font-size-3xl);
|
font-size: var(--ha-font-size-3xl);
|
||||||
@@ -205,16 +191,21 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
<ha-language-picker
|
<ha-language-picker
|
||||||
.value=${this.language}
|
.value=${this.language}
|
||||||
.label=${""}
|
.label=${""}
|
||||||
|
button-style
|
||||||
native-name
|
native-name
|
||||||
@value-changed=${this._languageChanged}
|
@value-changed=${this._languageChanged}
|
||||||
inline-arrow
|
inline-arrow
|
||||||
></ha-language-picker>
|
></ha-language-picker>
|
||||||
<a
|
<ha-button
|
||||||
|
appearance="plain"
|
||||||
|
variant="neutral"
|
||||||
href="https://www.home-assistant.io/docs/authentication/"
|
href="https://www.home-assistant.io/docs/authentication/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
>${this.localize("ui.panel.page-authorize.help")}</a
|
|
||||||
>
|
>
|
||||||
|
${this.localize("ui.panel.page-authorize.help")}
|
||||||
|
<ha-svg-icon slot="end" .path=${mdiOpenInNew}></ha-svg-icon>
|
||||||
|
</ha-button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/common/condition/extract.ts
Normal file
36
src/common/condition/extract.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import type {
|
||||||
|
Condition,
|
||||||
|
TimeCondition,
|
||||||
|
} from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract media queries from conditions recursively
|
||||||
|
*/
|
||||||
|
export function extractMediaQueries(conditions: Condition[]): string[] {
|
||||||
|
return conditions.reduce<string[]>((array, c) => {
|
||||||
|
if ("conditions" in c && c.conditions) {
|
||||||
|
array.push(...extractMediaQueries(c.conditions));
|
||||||
|
}
|
||||||
|
if (c.condition === "screen" && c.media_query) {
|
||||||
|
array.push(c.media_query);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract time conditions from conditions recursively
|
||||||
|
*/
|
||||||
|
export function extractTimeConditions(
|
||||||
|
conditions: Condition[]
|
||||||
|
): TimeCondition[] {
|
||||||
|
return conditions.reduce<TimeCondition[]>((array, c) => {
|
||||||
|
if ("conditions" in c && c.conditions) {
|
||||||
|
array.push(...extractTimeConditions(c.conditions));
|
||||||
|
}
|
||||||
|
if (c.condition === "time") {
|
||||||
|
array.push(c);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
89
src/common/condition/listeners.ts
Normal file
89
src/common/condition/listeners.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { listenMediaQuery } from "../dom/media_query";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { Condition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
import { checkConditionsMet } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
import { extractMediaQueries, extractTimeConditions } from "./extract";
|
||||||
|
import { calculateNextTimeUpdate } from "./time-calculator";
|
||||||
|
|
||||||
|
/** Maximum delay for setTimeout (2^31 - 1 milliseconds, ~24.8 days)
|
||||||
|
* Values exceeding this will overflow and execute immediately
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value
|
||||||
|
*/
|
||||||
|
const MAX_TIMEOUT_DELAY = 2147483647;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to setup media query listeners for conditional visibility
|
||||||
|
*/
|
||||||
|
export function setupMediaQueryListeners(
|
||||||
|
conditions: Condition[],
|
||||||
|
hass: HomeAssistant,
|
||||||
|
addListener: (unsub: () => void) => void,
|
||||||
|
onUpdate: (conditionsMet: boolean) => void
|
||||||
|
): void {
|
||||||
|
const mediaQueries = extractMediaQueries(conditions);
|
||||||
|
|
||||||
|
if (mediaQueries.length === 0) return;
|
||||||
|
|
||||||
|
// Optimization for single media query
|
||||||
|
const hasOnlyMediaQuery =
|
||||||
|
conditions.length === 1 &&
|
||||||
|
conditions[0].condition === "screen" &&
|
||||||
|
!!conditions[0].media_query;
|
||||||
|
|
||||||
|
mediaQueries.forEach((mediaQuery) => {
|
||||||
|
const unsub = listenMediaQuery(mediaQuery, (matches) => {
|
||||||
|
if (hasOnlyMediaQuery) {
|
||||||
|
onUpdate(matches);
|
||||||
|
} else {
|
||||||
|
const conditionsMet = checkConditionsMet(conditions, hass);
|
||||||
|
onUpdate(conditionsMet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addListener(unsub);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to setup time-based listeners for conditional visibility
|
||||||
|
*/
|
||||||
|
export function setupTimeListeners(
|
||||||
|
conditions: Condition[],
|
||||||
|
hass: HomeAssistant,
|
||||||
|
addListener: (unsub: () => void) => void,
|
||||||
|
onUpdate: (conditionsMet: boolean) => void
|
||||||
|
): void {
|
||||||
|
const timeConditions = extractTimeConditions(conditions);
|
||||||
|
|
||||||
|
if (timeConditions.length === 0) return;
|
||||||
|
|
||||||
|
timeConditions.forEach((timeCondition) => {
|
||||||
|
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
|
const scheduleUpdate = () => {
|
||||||
|
const delay = calculateNextTimeUpdate(hass, timeCondition);
|
||||||
|
|
||||||
|
if (delay === undefined) return;
|
||||||
|
|
||||||
|
// Cap delay to prevent setTimeout overflow
|
||||||
|
const cappedDelay = Math.min(delay, MAX_TIMEOUT_DELAY);
|
||||||
|
|
||||||
|
timeoutId = setTimeout(() => {
|
||||||
|
if (delay <= MAX_TIMEOUT_DELAY) {
|
||||||
|
const conditionsMet = checkConditionsMet(conditions, hass);
|
||||||
|
onUpdate(conditionsMet);
|
||||||
|
}
|
||||||
|
scheduleUpdate();
|
||||||
|
}, cappedDelay);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register cleanup function once, outside of scheduleUpdate
|
||||||
|
addListener(() => {
|
||||||
|
if (timeoutId !== undefined) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
scheduleUpdate();
|
||||||
|
});
|
||||||
|
}
|
||||||
73
src/common/condition/time-calculator.ts
Normal file
73
src/common/condition/time-calculator.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { TZDate } from "@date-fns/tz";
|
||||||
|
import {
|
||||||
|
startOfDay,
|
||||||
|
addDays,
|
||||||
|
addMinutes,
|
||||||
|
differenceInMilliseconds,
|
||||||
|
} from "date-fns";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { TimeZone } from "../../data/translation";
|
||||||
|
import { parseTimeString } from "../datetime/check_time";
|
||||||
|
import type { TimeCondition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate milliseconds until next time boundary for a time condition
|
||||||
|
* @param hass Home Assistant object
|
||||||
|
* @param timeCondition Time condition to calculate next update for
|
||||||
|
* @returns Milliseconds until next boundary, or undefined if no boundaries
|
||||||
|
*/
|
||||||
|
export function calculateNextTimeUpdate(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
{ after, before, weekdays }: Omit<TimeCondition, "condition">
|
||||||
|
): number | undefined {
|
||||||
|
const timezone =
|
||||||
|
hass.locale.time_zone === TimeZone.server
|
||||||
|
? hass.config.time_zone
|
||||||
|
: Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
const updates: Date[] = [];
|
||||||
|
|
||||||
|
// Calculate next occurrence of after time
|
||||||
|
if (after) {
|
||||||
|
let afterDate = parseTimeString(after, timezone);
|
||||||
|
if (afterDate <= now) {
|
||||||
|
// If time has passed today, schedule for tomorrow
|
||||||
|
afterDate = addDays(afterDate, 1);
|
||||||
|
}
|
||||||
|
updates.push(afterDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate next occurrence of before time
|
||||||
|
if (before) {
|
||||||
|
let beforeDate = parseTimeString(before, timezone);
|
||||||
|
if (beforeDate <= now) {
|
||||||
|
// If time has passed today, schedule for tomorrow
|
||||||
|
beforeDate = addDays(beforeDate, 1);
|
||||||
|
}
|
||||||
|
updates.push(beforeDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If weekdays are specified, check for midnight (weekday transition)
|
||||||
|
if (weekdays && weekdays.length > 0 && weekdays.length < 7) {
|
||||||
|
// Calculate next midnight using startOfDay + addDays
|
||||||
|
const tomorrow = addDays(now, 1);
|
||||||
|
const midnight = startOfDay(tomorrow);
|
||||||
|
updates.push(midnight);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the soonest update time
|
||||||
|
const nextUpdate = updates.reduce((soonest, current) =>
|
||||||
|
current < soonest ? current : soonest
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add 1 minute buffer to ensure we're past the boundary
|
||||||
|
const updateWithBuffer = addMinutes(nextUpdate, 1);
|
||||||
|
|
||||||
|
// Calculate difference in milliseconds
|
||||||
|
return differenceInMilliseconds(updateWithBuffer, now);
|
||||||
|
}
|
||||||
131
src/common/datetime/check_time.ts
Normal file
131
src/common/datetime/check_time.ts
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
import { TZDate } from "@date-fns/tz";
|
||||||
|
import { isBefore, isAfter, isWithinInterval } from "date-fns";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { TimeZone } from "../../data/translation";
|
||||||
|
import { WEEKDAY_MAP } from "./weekday";
|
||||||
|
import type { TimeCondition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a time string format and value ranges without creating Date objects
|
||||||
|
* @param timeString Time string to validate (HH:MM or HH:MM:SS)
|
||||||
|
* @returns true if valid, false otherwise
|
||||||
|
*/
|
||||||
|
export function isValidTimeString(timeString: string): boolean {
|
||||||
|
// Reject empty strings
|
||||||
|
if (!timeString || timeString.trim() === "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = timeString.split(":");
|
||||||
|
|
||||||
|
if (parts.length < 2 || parts.length > 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure each part contains only digits (and optional leading zeros)
|
||||||
|
// This prevents "8:00 AM" from passing validation
|
||||||
|
if (!parts.every((part) => /^\d+$/.test(part))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hours = parseInt(parts[0], 10);
|
||||||
|
const minutes = parseInt(parts[1], 10);
|
||||||
|
const seconds = parts.length === 3 ? parseInt(parts[2], 10) : 0;
|
||||||
|
|
||||||
|
if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
hours >= 0 &&
|
||||||
|
hours <= 23 &&
|
||||||
|
minutes >= 0 &&
|
||||||
|
minutes <= 59 &&
|
||||||
|
seconds >= 0 &&
|
||||||
|
seconds <= 59
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a time string (HH:MM or HH:MM:SS) and set it on today's date in the given timezone
|
||||||
|
*
|
||||||
|
* Note: This function assumes the time string has already been validated by
|
||||||
|
* isValidTimeString() at configuration time. It does not re-validate at runtime
|
||||||
|
* for consistency with other condition types (screen, user, location, etc.)
|
||||||
|
*
|
||||||
|
* @param timeString The time string to parse (must be pre-validated)
|
||||||
|
* @param timezone The timezone to use
|
||||||
|
* @returns The Date object
|
||||||
|
*/
|
||||||
|
export const parseTimeString = (timeString: string, timezone: string): Date => {
|
||||||
|
const parts = timeString.split(":");
|
||||||
|
const hours = parseInt(parts[0], 10);
|
||||||
|
const minutes = parseInt(parts[1], 10);
|
||||||
|
const seconds = parts.length === 3 ? parseInt(parts[2], 10) : 0;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
const dateWithTime = new TZDate(
|
||||||
|
now.getFullYear(),
|
||||||
|
now.getMonth(),
|
||||||
|
now.getDate(),
|
||||||
|
hours,
|
||||||
|
minutes,
|
||||||
|
seconds,
|
||||||
|
0,
|
||||||
|
timezone
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Date(dateWithTime.getTime());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current time matches the time condition (after/before/weekday)
|
||||||
|
* @param hass Home Assistant object
|
||||||
|
* @param timeCondition Time condition to check
|
||||||
|
* @returns true if current time matches the condition
|
||||||
|
*/
|
||||||
|
export const checkTimeInRange = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
{ after, before, weekdays }: Omit<TimeCondition, "condition">
|
||||||
|
): boolean => {
|
||||||
|
const timezone =
|
||||||
|
hass.locale.time_zone === TimeZone.server
|
||||||
|
? hass.config.time_zone
|
||||||
|
: Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
|
||||||
|
// Check weekday condition
|
||||||
|
if (weekdays && weekdays.length > 0) {
|
||||||
|
const currentWeekday = WEEKDAY_MAP[now.getDay()];
|
||||||
|
if (!weekdays.includes(currentWeekday)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check time conditions
|
||||||
|
if (!after && !before) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const afterDate = after ? parseTimeString(after, timezone) : undefined;
|
||||||
|
const beforeDate = before ? parseTimeString(before, timezone) : undefined;
|
||||||
|
|
||||||
|
if (afterDate && beforeDate) {
|
||||||
|
if (isBefore(beforeDate, afterDate)) {
|
||||||
|
// Crosses midnight (e.g., 22:00 to 06:00)
|
||||||
|
return !isBefore(now, afterDate) || !isAfter(now, beforeDate);
|
||||||
|
}
|
||||||
|
return isWithinInterval(now, { start: afterDate, end: beforeDate });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (afterDate) {
|
||||||
|
return !isBefore(now, afterDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (beforeDate) {
|
||||||
|
return !isAfter(now, beforeDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
@@ -1,18 +1,7 @@
|
|||||||
import { getWeekStartByLocale } from "weekstart";
|
import { getWeekStartByLocale } from "weekstart";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { FirstWeekday } from "../../data/translation";
|
import { FirstWeekday } from "../../data/translation";
|
||||||
|
import { WEEKDAYS_LONG, type WeekdayIndex } from "./weekday";
|
||||||
export const weekdays = [
|
|
||||||
"sunday",
|
|
||||||
"monday",
|
|
||||||
"tuesday",
|
|
||||||
"wednesday",
|
|
||||||
"thursday",
|
|
||||||
"friday",
|
|
||||||
"saturday",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
||||||
|
|
||||||
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
||||||
if (locale.first_weekday === FirstWeekday.language) {
|
if (locale.first_weekday === FirstWeekday.language) {
|
||||||
@@ -23,12 +12,12 @@ export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
|||||||
}
|
}
|
||||||
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
||||||
}
|
}
|
||||||
return weekdays.includes(locale.first_weekday)
|
return WEEKDAYS_LONG.includes(locale.first_weekday)
|
||||||
? (weekdays.indexOf(locale.first_weekday) as WeekdayIndex)
|
? (WEEKDAYS_LONG.indexOf(locale.first_weekday) as WeekdayIndex)
|
||||||
: 1;
|
: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const firstWeekday = (locale: FrontendLocaleData) => {
|
export const firstWeekday = (locale: FrontendLocaleData) => {
|
||||||
const index = firstWeekdayIndex(locale);
|
const index = firstWeekdayIndex(locale);
|
||||||
return weekdays[index];
|
return WEEKDAYS_LONG[index];
|
||||||
};
|
};
|
||||||
|
|||||||
59
src/common/datetime/weekday.ts
Normal file
59
src/common/datetime/weekday.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
export type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
|
|
||||||
|
export type WeekdayShort =
|
||||||
|
| "sun"
|
||||||
|
| "mon"
|
||||||
|
| "tue"
|
||||||
|
| "wed"
|
||||||
|
| "thu"
|
||||||
|
| "fri"
|
||||||
|
| "sat";
|
||||||
|
|
||||||
|
export type WeekdayLong =
|
||||||
|
| "sunday"
|
||||||
|
| "monday"
|
||||||
|
| "tuesday"
|
||||||
|
| "wednesday"
|
||||||
|
| "thursday"
|
||||||
|
| "friday"
|
||||||
|
| "saturday";
|
||||||
|
|
||||||
|
export const WEEKDAYS_SHORT = [
|
||||||
|
"sun",
|
||||||
|
"mon",
|
||||||
|
"tue",
|
||||||
|
"wed",
|
||||||
|
"thu",
|
||||||
|
"fri",
|
||||||
|
"sat",
|
||||||
|
] as const satisfies readonly WeekdayShort[];
|
||||||
|
|
||||||
|
export const WEEKDAYS_LONG = [
|
||||||
|
"sunday",
|
||||||
|
"monday",
|
||||||
|
"tuesday",
|
||||||
|
"wednesday",
|
||||||
|
"thursday",
|
||||||
|
"friday",
|
||||||
|
"saturday",
|
||||||
|
] as const satisfies readonly WeekdayLong[];
|
||||||
|
|
||||||
|
export const WEEKDAY_MAP = {
|
||||||
|
0: "sun",
|
||||||
|
1: "mon",
|
||||||
|
2: "tue",
|
||||||
|
3: "wed",
|
||||||
|
4: "thu",
|
||||||
|
5: "fri",
|
||||||
|
6: "sat",
|
||||||
|
} as const satisfies Record<WeekdayIndex, WeekdayShort>;
|
||||||
|
|
||||||
|
export const WEEKDAY_SHORT_TO_LONG = {
|
||||||
|
sun: "sunday",
|
||||||
|
mon: "monday",
|
||||||
|
tue: "tuesday",
|
||||||
|
wed: "wednesday",
|
||||||
|
thu: "thursday",
|
||||||
|
fri: "friday",
|
||||||
|
sat: "saturday",
|
||||||
|
} as const satisfies Record<WeekdayShort, WeekdayLong>;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ThemeVars } from "../../data/ws-themes";
|
import type { ThemeVars } from "../../data/ws-themes";
|
||||||
import { darkColorVariables } from "../../resources/theme/color";
|
import { darkColorVariables } from "../../resources/theme/color";
|
||||||
|
import { darkSemanticVariables } from "../../resources/theme/semantic.globals";
|
||||||
import { derivedStyles } from "../../resources/theme/theme";
|
import { derivedStyles } from "../../resources/theme/theme";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -52,7 +53,7 @@ export const applyThemesOnElement = (
|
|||||||
|
|
||||||
if (themeToApply && darkMode) {
|
if (themeToApply && darkMode) {
|
||||||
cacheKey = `${cacheKey}__dark`;
|
cacheKey = `${cacheKey}__dark`;
|
||||||
themeRules = { ...darkColorVariables };
|
themeRules = { ...darkSemanticVariables, ...darkColorVariables };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (themeToApply === "default") {
|
if (themeToApply === "default") {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ type EntityCategory = "none" | "config" | "diagnostic";
|
|||||||
export interface EntityFilter {
|
export interface EntityFilter {
|
||||||
domain?: string | string[];
|
domain?: string | string[];
|
||||||
device_class?: string | string[];
|
device_class?: string | string[];
|
||||||
device?: string | string[];
|
device?: string | null | (string | null)[];
|
||||||
area?: string | string[];
|
area?: string | null | (string | null)[];
|
||||||
floor?: string | string[];
|
floor?: string | null | (string | null)[];
|
||||||
label?: string | string[];
|
label?: string | string[];
|
||||||
entity_category?: EntityCategory | EntityCategory[];
|
entity_category?: EntityCategory | EntityCategory[];
|
||||||
hidden_platform?: string | string[];
|
hidden_platform?: string | string[];
|
||||||
@@ -19,6 +19,18 @@ export interface EntityFilter {
|
|||||||
|
|
||||||
export type EntityFilterFunc = (entityId: string) => boolean;
|
export type EntityFilterFunc = (entityId: string) => boolean;
|
||||||
|
|
||||||
|
const normalizeFilterArray = <T>(
|
||||||
|
value: T | null | T[] | (T | null)[] | undefined
|
||||||
|
): Set<T | null> | undefined => {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (value === null) {
|
||||||
|
return new Set([null]);
|
||||||
|
}
|
||||||
|
return new Set(ensureArray(value));
|
||||||
|
};
|
||||||
|
|
||||||
export const generateEntityFilter = (
|
export const generateEntityFilter = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
filter: EntityFilter
|
filter: EntityFilter
|
||||||
@@ -29,11 +41,9 @@ export const generateEntityFilter = (
|
|||||||
const deviceClasses = filter.device_class
|
const deviceClasses = filter.device_class
|
||||||
? new Set(ensureArray(filter.device_class))
|
? new Set(ensureArray(filter.device_class))
|
||||||
: undefined;
|
: undefined;
|
||||||
const floors = filter.floor ? new Set(ensureArray(filter.floor)) : undefined;
|
const floors = normalizeFilterArray(filter.floor);
|
||||||
const areas = filter.area ? new Set(ensureArray(filter.area)) : undefined;
|
const areas = normalizeFilterArray(filter.area);
|
||||||
const devices = filter.device
|
const devices = normalizeFilterArray(filter.device);
|
||||||
? new Set(ensureArray(filter.device))
|
|
||||||
: undefined;
|
|
||||||
const entityCategories = filter.entity_category
|
const entityCategories = filter.entity_category
|
||||||
? new Set(ensureArray(filter.entity_category))
|
? new Set(ensureArray(filter.entity_category))
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -73,23 +83,20 @@ export const generateEntityFilter = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (floors) {
|
if (floors) {
|
||||||
if (!floor || !floors.has(floor.floor_id)) {
|
const floorId = floor?.floor_id ?? null;
|
||||||
|
if (!floors.has(floorId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (areas) {
|
if (areas) {
|
||||||
if (!area) {
|
const areaId = area?.area_id ?? null;
|
||||||
return false;
|
if (!areas.has(areaId)) {
|
||||||
}
|
|
||||||
if (!areas.has(area.area_id)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (devices) {
|
if (devices) {
|
||||||
if (!device) {
|
const deviceId = device?.id ?? null;
|
||||||
return false;
|
if (!devices.has(deviceId)) {
|
||||||
}
|
|
||||||
if (!devices.has(device.id)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ const FIXED_DOMAIN_ATTRIBUTE_STATES = {
|
|||||||
"pm1",
|
"pm1",
|
||||||
"pm10",
|
"pm10",
|
||||||
"pm25",
|
"pm25",
|
||||||
|
"pm4",
|
||||||
"power_factor",
|
"power_factor",
|
||||||
"power",
|
"power",
|
||||||
"pressure",
|
"pressure",
|
||||||
|
|||||||
36
src/common/util/parse-animation-duration.ts
Normal file
36
src/common/util/parse-animation-duration.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Parses a CSS duration string (e.g., "300ms", "3s") and returns the duration in milliseconds.
|
||||||
|
*
|
||||||
|
* @param duration - A CSS duration string (e.g., "300ms", "3s", "0.5s")
|
||||||
|
* @returns The duration in milliseconds, or 0 if the input is invalid
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* parseAnimationDuration("300ms") // Returns 300
|
||||||
|
* parseAnimationDuration("3s") // Returns 3000
|
||||||
|
* parseAnimationDuration("0.5s") // Returns 500
|
||||||
|
* parseAnimationDuration("invalid") // Returns 0
|
||||||
|
*/
|
||||||
|
export const parseAnimationDuration = (duration: string): number => {
|
||||||
|
const trimmed = duration.trim();
|
||||||
|
|
||||||
|
let value: number;
|
||||||
|
let multiplier: number;
|
||||||
|
|
||||||
|
if (trimmed.endsWith("ms")) {
|
||||||
|
value = parseFloat(trimmed.slice(0, -2));
|
||||||
|
multiplier = 1;
|
||||||
|
} else if (trimmed.endsWith("s")) {
|
||||||
|
value = parseFloat(trimmed.slice(0, -1));
|
||||||
|
multiplier = 1000;
|
||||||
|
} else {
|
||||||
|
// No recognized unit, try parsing as number (assume ms)
|
||||||
|
value = parseFloat(trimmed);
|
||||||
|
multiplier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isFinite(value) || value < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value * multiplier;
|
||||||
|
};
|
||||||
@@ -119,8 +119,8 @@ type Thresholds = Record<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
export const DEFAULT_THRESHOLDS: Thresholds = {
|
export const DEFAULT_THRESHOLDS: Thresholds = {
|
||||||
second: 45, // seconds to minute
|
second: 59, // seconds to minute
|
||||||
minute: 45, // minutes to hour
|
minute: 59, // minutes to hour
|
||||||
hour: 22, // hour to day
|
hour: 22, // hour to day
|
||||||
day: 5, // day to week
|
day: 5, // day to week
|
||||||
week: 4, // week to months
|
week: 4, // week to months
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ export function downSampleLineData<
|
|||||||
data: T[] | undefined,
|
data: T[] | undefined,
|
||||||
maxDetails: number,
|
maxDetails: number,
|
||||||
minX?: number,
|
minX?: number,
|
||||||
maxX?: number
|
maxX?: number,
|
||||||
|
useMean = false
|
||||||
): T[] {
|
): T[] {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return [];
|
return [];
|
||||||
@@ -17,15 +18,13 @@ export function downSampleLineData<
|
|||||||
const min = minX ?? getPointData(data[0]!)[0];
|
const min = minX ?? getPointData(data[0]!)[0];
|
||||||
const max = maxX ?? getPointData(data[data.length - 1]!)[0];
|
const max = maxX ?? getPointData(data[data.length - 1]!)[0];
|
||||||
const step = Math.ceil((max - min) / Math.floor(maxDetails));
|
const step = Math.ceil((max - min) / Math.floor(maxDetails));
|
||||||
const frames = new Map<
|
|
||||||
number,
|
|
||||||
{
|
|
||||||
min: { point: (typeof data)[number]; x: number; y: number };
|
|
||||||
max: { point: (typeof data)[number]; x: number; y: number };
|
|
||||||
}
|
|
||||||
>();
|
|
||||||
|
|
||||||
// Group points into frames
|
// Group points into frames
|
||||||
|
const frames = new Map<
|
||||||
|
number,
|
||||||
|
{ point: (typeof data)[number]; x: number; y: number }[]
|
||||||
|
>();
|
||||||
|
|
||||||
for (const point of data) {
|
for (const point of data) {
|
||||||
const pointData = getPointData(point);
|
const pointData = getPointData(point);
|
||||||
if (!Array.isArray(pointData)) continue;
|
if (!Array.isArray(pointData)) continue;
|
||||||
@@ -36,28 +35,53 @@ export function downSampleLineData<
|
|||||||
const frameIndex = Math.floor((x - min) / step);
|
const frameIndex = Math.floor((x - min) / step);
|
||||||
const frame = frames.get(frameIndex);
|
const frame = frames.get(frameIndex);
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
frames.set(frameIndex, { min: { point, x, y }, max: { point, x, y } });
|
frames.set(frameIndex, [{ point, x, y }]);
|
||||||
} else {
|
} else {
|
||||||
if (frame.min.y > y) {
|
frame.push({ point, x, y });
|
||||||
frame.min = { point, x, y };
|
|
||||||
}
|
|
||||||
if (frame.max.y < y) {
|
|
||||||
frame.max = { point, x, y };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert frames back to points
|
// Convert frames back to points
|
||||||
const result: T[] = [];
|
const result: T[] = [];
|
||||||
for (const [_i, frame] of frames) {
|
|
||||||
// Use min/max points to preserve visual accuracy
|
if (useMean) {
|
||||||
// The order of the data must be preserved so max may be before min
|
// Use mean values for each frame
|
||||||
if (frame.min.x > frame.max.x) {
|
for (const [_i, framePoints] of frames) {
|
||||||
result.push(frame.max.point);
|
const sumY = framePoints.reduce((acc, p) => acc + p.y, 0);
|
||||||
|
const meanY = sumY / framePoints.length;
|
||||||
|
const sumX = framePoints.reduce((acc, p) => acc + p.x, 0);
|
||||||
|
const meanX = sumX / framePoints.length;
|
||||||
|
|
||||||
|
const firstPoint = framePoints[0].point;
|
||||||
|
const pointData = getPointData(firstPoint);
|
||||||
|
const meanPoint = (
|
||||||
|
Array.isArray(pointData) ? [meanX, meanY] : { value: [meanX, meanY] }
|
||||||
|
) as T;
|
||||||
|
result.push(meanPoint);
|
||||||
}
|
}
|
||||||
result.push(frame.min.point);
|
} else {
|
||||||
if (frame.min.x < frame.max.x) {
|
// Use min/max values for each frame
|
||||||
result.push(frame.max.point);
|
for (const [_i, framePoints] of frames) {
|
||||||
|
let minPoint = framePoints[0];
|
||||||
|
let maxPoint = framePoints[0];
|
||||||
|
|
||||||
|
for (const p of framePoints) {
|
||||||
|
if (p.y < minPoint.y) {
|
||||||
|
minPoint = p;
|
||||||
|
}
|
||||||
|
if (p.y > maxPoint.y) {
|
||||||
|
maxPoint = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The order of the data must be preserved so max may be before min
|
||||||
|
if (minPoint.x > maxPoint.x) {
|
||||||
|
result.push(maxPoint.point);
|
||||||
|
}
|
||||||
|
result.push(minPoint.point);
|
||||||
|
if (minPoint.x < maxPoint.x) {
|
||||||
|
result.push(maxPoint.point);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ export class HaChartBase extends LitElement {
|
|||||||
|
|
||||||
private _shouldResizeChart = false;
|
private _shouldResizeChart = false;
|
||||||
|
|
||||||
|
private _resizeAnimationDuration?: number;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
private _resizeController = new ResizeController(this, {
|
private _resizeController = new ResizeController(this, {
|
||||||
callback: () => {
|
callback: () => {
|
||||||
@@ -205,6 +207,16 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
if (changedProps.has("options")) {
|
if (changedProps.has("options")) {
|
||||||
chartOptions = { ...chartOptions, ...this._createOptions() };
|
chartOptions = { ...chartOptions, ...this._createOptions() };
|
||||||
|
if (
|
||||||
|
this._compareCustomLegendOptions(
|
||||||
|
changedProps.get("options"),
|
||||||
|
this.options
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
// custom legend changes may require a resize to layout properly
|
||||||
|
this._shouldResizeChart = true;
|
||||||
|
this._resizeAnimationDuration = 250;
|
||||||
|
}
|
||||||
} else if (this._isTouchDevice && changedProps.has("_isZoomed")) {
|
} else if (this._isTouchDevice && changedProps.has("_isZoomed")) {
|
||||||
chartOptions.dataZoom = this._getDataZoomConfig();
|
chartOptions.dataZoom = this._getDataZoomConfig();
|
||||||
}
|
}
|
||||||
@@ -296,7 +308,7 @@ export class HaChartBase extends LitElement {
|
|||||||
itemStyle = {
|
itemStyle = {
|
||||||
color: dataset?.color as string,
|
color: dataset?.color as string,
|
||||||
...(dataset?.itemStyle as { borderColor?: string }),
|
...(dataset?.itemStyle as { borderColor?: string }),
|
||||||
itemStyle,
|
...itemStyle,
|
||||||
};
|
};
|
||||||
const color = itemStyle?.color as string;
|
const color = itemStyle?.color as string;
|
||||||
const borderColor = itemStyle?.borderColor as string;
|
const borderColor = itemStyle?.borderColor as string;
|
||||||
@@ -415,6 +427,7 @@ export class HaChartBase extends LitElement {
|
|||||||
...axis.axisPointer?.handle,
|
...axis.axisPointer?.handle,
|
||||||
show: true,
|
show: true,
|
||||||
},
|
},
|
||||||
|
label: { show: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: axis
|
: axis
|
||||||
@@ -508,6 +521,7 @@ export class HaChartBase extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.requestUpdate("_hiddenDatasets");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getDataZoomConfig(): DataZoomComponentOption | undefined {
|
private _getDataZoomConfig(): DataZoomComponentOption | undefined {
|
||||||
@@ -614,6 +628,10 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createTheme(style: CSSStyleDeclaration) {
|
private _createTheme(style: CSSStyleDeclaration) {
|
||||||
|
const textBorderColor =
|
||||||
|
style.getPropertyValue("--ha-card-background") ||
|
||||||
|
style.getPropertyValue("--card-background-color");
|
||||||
|
const textBorderWidth = 2;
|
||||||
return {
|
return {
|
||||||
color: getAllGraphColors(style),
|
color: getAllGraphColors(style),
|
||||||
backgroundColor: "transparent",
|
backgroundColor: "transparent",
|
||||||
@@ -637,15 +655,22 @@ export class HaChartBase extends LitElement {
|
|||||||
graph: {
|
graph: {
|
||||||
label: {
|
label: {
|
||||||
color: style.getPropertyValue("--primary-text-color"),
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
textBorderColor,
|
||||||
textBorderWidth: 2,
|
textBorderWidth,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pie: {
|
||||||
|
label: {
|
||||||
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
|
textBorderColor,
|
||||||
|
textBorderWidth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sankey: {
|
sankey: {
|
||||||
label: {
|
label: {
|
||||||
color: style.getPropertyValue("--primary-text-color"),
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
textBorderColor,
|
||||||
textBorderWidth: 2,
|
textBorderWidth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
categoryAxis: {
|
categoryAxis: {
|
||||||
@@ -958,11 +983,34 @@ export class HaChartBase extends LitElement {
|
|||||||
|
|
||||||
private _handleChartRenderFinished = () => {
|
private _handleChartRenderFinished = () => {
|
||||||
if (this._shouldResizeChart) {
|
if (this._shouldResizeChart) {
|
||||||
this.chart?.resize();
|
this.chart?.resize({
|
||||||
|
animation:
|
||||||
|
this._reducedMotion ||
|
||||||
|
typeof this._resizeAnimationDuration !== "number"
|
||||||
|
? undefined
|
||||||
|
: { duration: this._resizeAnimationDuration },
|
||||||
|
});
|
||||||
this._shouldResizeChart = false;
|
this._shouldResizeChart = false;
|
||||||
|
this._resizeAnimationDuration = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _compareCustomLegendOptions(
|
||||||
|
oldOptions: ECOption | undefined,
|
||||||
|
newOptions: ECOption | undefined
|
||||||
|
): boolean {
|
||||||
|
const oldLegends = ensureArray(
|
||||||
|
oldOptions?.legend || []
|
||||||
|
) as LegendComponentOption[];
|
||||||
|
const newLegends = ensureArray(
|
||||||
|
newOptions?.legend || []
|
||||||
|
) as LegendComponentOption[];
|
||||||
|
return (
|
||||||
|
oldLegends.some((l) => l.show && l.type === "custom") !==
|
||||||
|
newLegends.some((l) => l.show && l.type === "custom")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import type { EChartsType } from "echarts/core";
|
|||||||
import type { GraphSeriesOption } from "echarts/charts";
|
import type { GraphSeriesOption } from "echarts/charts";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state, query } from "lit/decorators";
|
import { customElement, property, state, query } from "lit/decorators";
|
||||||
import type { TopLevelFormatterParams } from "echarts/types/dist/shared";
|
import type {
|
||||||
|
CallbackDataParams,
|
||||||
|
TopLevelFormatterParams,
|
||||||
|
} from "echarts/types/dist/shared";
|
||||||
import { mdiFormatTextVariant, mdiGoogleCirclesGroup } from "@mdi/js";
|
import { mdiFormatTextVariant, mdiGoogleCirclesGroup } from "@mdi/js";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { listenMediaQuery } from "../../common/dom/media_query";
|
import { listenMediaQuery } from "../../common/dom/media_query";
|
||||||
@@ -16,6 +19,7 @@ import { deepEqual } from "../../common/util/deep-equal";
|
|||||||
export interface NetworkNode {
|
export interface NetworkNode {
|
||||||
id: string;
|
id: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
context?: string;
|
||||||
category?: number;
|
category?: number;
|
||||||
value?: number;
|
value?: number;
|
||||||
symbolSize?: number;
|
symbolSize?: number;
|
||||||
@@ -188,6 +192,25 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
|||||||
label: {
|
label: {
|
||||||
show: showLabels,
|
show: showLabels,
|
||||||
position: "right",
|
position: "right",
|
||||||
|
formatter: (params: CallbackDataParams) => {
|
||||||
|
const node = params.data as NetworkNode;
|
||||||
|
if (node.context) {
|
||||||
|
return `{primary|${node.name ?? ""}}\n{secondary|${node.context}}`;
|
||||||
|
}
|
||||||
|
return node.name ?? "";
|
||||||
|
},
|
||||||
|
rich: {
|
||||||
|
primary: {
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
fontSize: 12,
|
||||||
|
color: getComputedStyle(document.body).getPropertyValue(
|
||||||
|
"--secondary-text-color"
|
||||||
|
),
|
||||||
|
lineHeight: 16,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emphasis: {
|
emphasis: {
|
||||||
focus: isMobile ? "none" : "adjacency",
|
focus: isMobile ? "none" : "adjacency",
|
||||||
@@ -225,6 +248,7 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
|||||||
({
|
({
|
||||||
id: node.id,
|
id: node.id,
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
context: node.context,
|
||||||
category: node.category,
|
category: node.category,
|
||||||
value: node.value,
|
value: node.value,
|
||||||
symbolSize: node.symbolSize || 30,
|
symbolSize: node.symbolSize || 30,
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
|
|
||||||
private _previousYAxisLabelValue = 0;
|
private _previousYAxisLabelValue = 0;
|
||||||
|
|
||||||
|
private _yAxisMaximumFractionDigits = 0;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-chart-base
|
<ha-chart-base
|
||||||
@@ -757,8 +759,12 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1))
|
Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
this._yAxisMaximumFractionDigits = Math.max(
|
||||||
|
this._yAxisMaximumFractionDigits,
|
||||||
|
maximumFractionDigits
|
||||||
|
);
|
||||||
const label = formatNumber(value, this.hass.locale, {
|
const label = formatNumber(value, this.hass.locale, {
|
||||||
maximumFractionDigits,
|
maximumFractionDigits: this._yAxisMaximumFractionDigits,
|
||||||
});
|
});
|
||||||
const width = measureTextWidth(label, 12) + 5;
|
const width = measureTextWidth(label, 12) + 5;
|
||||||
if (width > this._yWidth) {
|
if (width > this._yWidth) {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class HaDataTableLabels extends LitElement {
|
|||||||
@click=${clickAction ? this._labelClicked : undefined}
|
@click=${clickAction ? this._labelClicked : undefined}
|
||||||
@keydown=${clickAction ? this._labelClicked : undefined}
|
@keydown=${clickAction ? this._labelClicked : undefined}
|
||||||
style=${color ? `--color: ${color}` : ""}
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
>
|
>
|
||||||
${label?.icon
|
${label?.icon
|
||||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||||
|
|||||||
@@ -197,9 +197,6 @@ export class HaDevicePicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.device-picker.placeholder");
|
this.hass.localize("ui.components.device-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.device-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
const valueRenderer = this._valueRenderer(this._configEntryLookup);
|
const valueRenderer = this._valueRenderer(this._configEntryLookup);
|
||||||
|
|
||||||
@@ -209,7 +206,10 @@ export class HaDevicePicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.searchLabel=${this.searchLabel}
|
.searchLabel=${this.searchLabel}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.device-picker.no_devices"
|
||||||
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
@@ -233,6 +233,11 @@ export class HaDevicePicker extends LitElement {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.device-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class HaEntitiesPicker extends LitElement {
|
|||||||
.createDomains=${this.createDomains}
|
.createDomains=${this.createDomains}
|
||||||
.required=${this.required && !currentEntities.length}
|
.required=${this.required && !currentEntities.length}
|
||||||
@value-changed=${this._addEntity}
|
@value-changed=${this._addEntity}
|
||||||
add-button
|
.addButton=${currentEntities.length > 0}
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ export class HaEntityNamePicker extends LitElement {
|
|||||||
private _toValue = memoizeOne(
|
private _toValue = memoizeOne(
|
||||||
(items: EntityNameItem[]): typeof this.value => {
|
(items: EntityNameItem[]): typeof this.value => {
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return "";
|
return undefined;
|
||||||
}
|
}
|
||||||
if (items.length === 1) {
|
if (items.length === 1) {
|
||||||
const item = items[0];
|
const item = items[0];
|
||||||
|
|||||||
@@ -269,9 +269,6 @@ export class HaEntityPicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.entity.entity-picker.placeholder");
|
this.hass.localize("ui.components.entity.entity-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.entity.entity-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
@@ -282,7 +279,7 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.searchLabel=${this.searchLabel}
|
.searchLabel=${this.searchLabel}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.addButton ? undefined : this.value}
|
.value=${this.addButton ? undefined : this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
@@ -356,6 +353,11 @@ export class HaEntityPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.entity.entity-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import "../ha-combo-box-item";
|
|||||||
import "../ha-generic-picker";
|
import "../ha-generic-picker";
|
||||||
import type { HaGenericPicker } from "../ha-generic-picker";
|
import type { HaGenericPicker } from "../ha-generic-picker";
|
||||||
import "../ha-icon-button";
|
import "../ha-icon-button";
|
||||||
import "../ha-input-helper-text";
|
|
||||||
import type {
|
import type {
|
||||||
PickerComboBoxItem,
|
PickerComboBoxItem,
|
||||||
PickerComboBoxSearchFn,
|
PickerComboBoxSearchFn,
|
||||||
@@ -271,7 +270,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(isRTL ? " ◂ " : " ▸ ");
|
.join(isRTL ? " ◂ " : " ▸ ");
|
||||||
const a11yLabel = [deviceName, entityName].filter(Boolean).join(" - ");
|
|
||||||
|
|
||||||
const sortingPrefix = `${TYPE_ORDER.indexOf("entity")}`;
|
const sortingPrefix = `${TYPE_ORDER.indexOf("entity")}`;
|
||||||
output.push({
|
output.push({
|
||||||
@@ -279,7 +277,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
statistic_id: id,
|
statistic_id: id,
|
||||||
primary,
|
primary,
|
||||||
secondary,
|
secondary,
|
||||||
a11y_label: a11yLabel,
|
|
||||||
stateObj: stateObj,
|
stateObj: stateObj,
|
||||||
type: "entity",
|
type: "entity",
|
||||||
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
||||||
@@ -458,9 +455,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.statistic-picker.placeholder");
|
this.hass.localize("ui.components.statistic-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.statistic-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
@@ -468,7 +462,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.allowCustomValue=${this.allowCustomEntity}
|
.allowCustomValue=${this.allowCustomEntity}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.statistic-picker.no_statistics"
|
||||||
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
@@ -477,6 +474,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.hideClearIcon=${this.hideClearIcon}
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
.searchFn=${this._searchFn}
|
.searchFn=${this._searchFn}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
|
.helper=${this.helper}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -521,6 +519,11 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
await this._picker?.open();
|
await this._picker?.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.statistic-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export class HaAreaPicker extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
|
|
||||||
|
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||||
|
|
||||||
public async open() {
|
public async open() {
|
||||||
@@ -367,14 +369,16 @@ export class HaAreaPicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.area-picker.no_match"
|
.emptyLabel=${this.hass.localize("ui.components.area-picker.no_areas")}
|
||||||
)}
|
.disabled=${this.disabled}
|
||||||
|
.required=${this.required}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
|
.addButtonLabel=${this.addButtonLabel}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -422,6 +426,11 @@ export class HaAreaPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.area-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export class HaButton extends Button {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
|
||||||
transition: background-color 0.15s ease-in-out;
|
transition: background-color 0.15s ease-in-out;
|
||||||
|
text-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([size="small"]) .button {
|
:host([size="small"]) .button {
|
||||||
|
|||||||
41
src/components/ha-dropdown-item.ts
Normal file
41
src/components/ha-dropdown-item.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item";
|
||||||
|
import { css, type CSSResultGroup } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Home Assistant dropdown item component
|
||||||
|
*
|
||||||
|
* @element ha-dropdown-item
|
||||||
|
* @extends {DropdownItem}
|
||||||
|
*
|
||||||
|
* @summary
|
||||||
|
* A stylable dropdown item component supporting Home Assistant theming, variants, and appearances based on webawesome dropdown item.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@customElement("ha-dropdown-item")
|
||||||
|
export class HaDropdownItem extends DropdownItem {
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
DropdownItem.styles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
min-height: var(--ha-space-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#icon ::slotted(*) {
|
||||||
|
color: var(--ha-color-on-neutral-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([variant="danger"]) #icon ::slotted(*) {
|
||||||
|
color: var(--ha-color-on-danger-quiet);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dropdown-item": HaDropdownItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/components/ha-dropdown.ts
Normal file
45
src/components/ha-dropdown.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import Dropdown from "@home-assistant/webawesome/dist/components/dropdown/dropdown";
|
||||||
|
import { css, type CSSResultGroup } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Home Assistant dropdown component
|
||||||
|
*
|
||||||
|
* @element ha-dropdown
|
||||||
|
* @extends {Dropdown}
|
||||||
|
*
|
||||||
|
* @summary
|
||||||
|
* A stylable dropdown component supporting Home Assistant theming, variants, and appearances based on webawesome dropdown.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@customElement("ha-dropdown")
|
||||||
|
export class HaDropdown extends Dropdown {
|
||||||
|
@property({ attribute: false }) dropdownTag = "ha-dropdown";
|
||||||
|
|
||||||
|
@property({ attribute: false }) dropdownItemTag = "ha-dropdown-item";
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
Dropdown.styles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
font-size: var(--ha-dropdown-font-size, var(--ha-font-size-m));
|
||||||
|
--wa-color-surface-raised: var(
|
||||||
|
--card-background-color,
|
||||||
|
var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#menu {
|
||||||
|
padding: var(--ha-space-1);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dropdown": HaDropdown;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,7 +109,10 @@ export class HaFilterLabels extends SubscribeMixin(LitElement) {
|
|||||||
.selected=${(this.value || []).includes(label.label_id)}
|
.selected=${(this.value || []).includes(label.label_id)}
|
||||||
hasMeta
|
hasMeta
|
||||||
>
|
>
|
||||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
<ha-label
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
|
>
|
||||||
${label.icon
|
${label.icon
|
||||||
? html`<ha-icon
|
? html`<ha-icon
|
||||||
slot="icon"
|
slot="icon"
|
||||||
|
|||||||
@@ -383,8 +383,9 @@ export class HaFloorPicker extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.floor-picker.no_match"
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.floor-picker.no_floors"
|
||||||
)}
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@@ -444,6 +445,11 @@ export class HaFloorPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.floor-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
.value=${getValue(this.data, item)}
|
.value=${getValue(this.data, item)}
|
||||||
.label=${this._computeLabel(item, this.data)}
|
.label=${this._computeLabel(item, this.data)}
|
||||||
.disabled=${item.disabled || this.disabled || false}
|
.disabled=${item.disabled || this.disabled || false}
|
||||||
.placeholder=${item.required ? "" : item.default}
|
.placeholder=${item.required ? undefined : item.default}
|
||||||
.helper=${this._computeHelper(item)}
|
.helper=${this._computeHelper(item)}
|
||||||
.localizeValue=${this.localizeValue}
|
.localizeValue=${this.localizeValue}
|
||||||
.required=${item.required || false}
|
.required=${item.required || false}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type { HomeAssistant } from "../types";
|
|||||||
import "./ha-bottom-sheet";
|
import "./ha-bottom-sheet";
|
||||||
import "./ha-button";
|
import "./ha-button";
|
||||||
import "./ha-combo-box-item";
|
import "./ha-combo-box-item";
|
||||||
import "./ha-icon-button";
|
|
||||||
import "./ha-input-helper-text";
|
import "./ha-input-helper-text";
|
||||||
import "./ha-picker-combo-box";
|
import "./ha-picker-combo-box";
|
||||||
import type {
|
import type {
|
||||||
@@ -26,9 +25,6 @@ import "./ha-svg-icon";
|
|||||||
export class HaGenericPicker extends LitElement {
|
export class HaGenericPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
// eslint-disable-next-line lit/no-native-attributes
|
|
||||||
@property({ type: Boolean }) public autofocus = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
@@ -50,8 +46,11 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false })
|
||||||
public getItems?: () => PickerComboBoxItem[];
|
public getItems?: (
|
||||||
|
searchString?: string,
|
||||||
|
section?: string
|
||||||
|
) => (PickerComboBoxItem | string)[];
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false, type: Array })
|
||||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||||
@@ -65,8 +64,11 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ attribute: "not-found-label", type: String })
|
@property({ attribute: false })
|
||||||
public notFoundLabel?: string;
|
public notFoundLabel?: string | ((search: string) => string);
|
||||||
|
|
||||||
|
@property({ attribute: "empty-label" })
|
||||||
|
public emptyLabel?: string;
|
||||||
|
|
||||||
@property({ attribute: "popover-placement" })
|
@property({ attribute: "popover-placement" })
|
||||||
public popoverPlacement:
|
public popoverPlacement:
|
||||||
@@ -86,6 +88,25 @@ export class HaGenericPicker extends LitElement {
|
|||||||
/** If set picker shows an add button instead of textbox when value isn't set */
|
/** If set picker shows an add button instead of textbox when value isn't set */
|
||||||
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||||
|
|
||||||
|
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||||
|
@property({ attribute: false }) public sections?: (
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
| "separator"
|
||||||
|
)[];
|
||||||
|
|
||||||
|
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||||
|
firstIndex: number;
|
||||||
|
lastIndex: number;
|
||||||
|
firstItem: PickerComboBoxItem | string;
|
||||||
|
secondItem: PickerComboBoxItem | string;
|
||||||
|
itemsCount: number;
|
||||||
|
}) => string | undefined;
|
||||||
|
|
||||||
|
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||||
|
|
||||||
@query(".container") private _containerElement?: HTMLDivElement;
|
@query(".container") private _containerElement?: HTMLDivElement;
|
||||||
|
|
||||||
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
||||||
@@ -98,6 +119,11 @@ export class HaGenericPicker extends LitElement {
|
|||||||
|
|
||||||
@state() private _openedNarrow = false;
|
@state() private _openedNarrow = false;
|
||||||
|
|
||||||
|
static shadowRootOptions = {
|
||||||
|
...LitElement.shadowRootOptions,
|
||||||
|
delegatesFocus: true,
|
||||||
|
};
|
||||||
|
|
||||||
private _narrow = false;
|
private _narrow = false;
|
||||||
|
|
||||||
// helper to set new value after closing picker, to avoid flicker
|
// helper to set new value after closing picker, to avoid flicker
|
||||||
@@ -190,16 +216,19 @@ export class HaGenericPicker extends LitElement {
|
|||||||
<ha-picker-combo-box
|
<ha-picker-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.allowCustomValue=${this.allowCustomValue}
|
.allowCustomValue=${this.allowCustomValue}
|
||||||
.label=${this.searchLabel ??
|
.label=${this.searchLabel}
|
||||||
(this.hass?.localize("ui.common.search") || "Search")}
|
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
.rowRenderer=${this.rowRenderer}
|
.rowRenderer=${this.rowRenderer}
|
||||||
.notFoundLabel=${this.notFoundLabel}
|
.notFoundLabel=${this.notFoundLabel}
|
||||||
|
.emptyLabel=${this.emptyLabel}
|
||||||
.getItems=${this.getItems}
|
.getItems=${this.getItems}
|
||||||
.getAdditionalItems=${this.getAdditionalItems}
|
.getAdditionalItems=${this.getAdditionalItems}
|
||||||
.searchFn=${this.searchFn}
|
.searchFn=${this.searchFn}
|
||||||
.mode=${dialogMode ? "dialog" : "popover"}
|
.mode=${dialogMode ? "dialog" : "popover"}
|
||||||
|
.sections=${this.sections}
|
||||||
|
.sectionTitleFunction=${this.sectionTitleFunction}
|
||||||
|
.selectedSection=${this.selectedSection}
|
||||||
></ha-picker-combo-box>
|
></ha-picker-combo-box>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,8 +224,9 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.label-picker.no_match"
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.label-picker.no_labels"
|
||||||
)}
|
)}
|
||||||
.addButtonLabel=${this.hass.localize("ui.components.label-picker.add")}
|
.addButtonLabel=${this.hass.localize("ui.components.label-picker.add")}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
@@ -288,6 +289,11 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.label-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { uid } from "../common/util/uid";
|
||||||
|
import "./ha-tooltip";
|
||||||
|
|
||||||
@customElement("ha-label")
|
@customElement("ha-label")
|
||||||
class HaLabel extends LitElement {
|
class HaLabel extends LitElement {
|
||||||
@property({ type: Boolean, reflect: true }) dense = false;
|
@property({ type: Boolean, reflect: true }) dense = false;
|
||||||
|
|
||||||
|
@property({ attribute: "description" })
|
||||||
|
public description?: string;
|
||||||
|
|
||||||
|
private _elementId = "label-" + uid();
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<span class="content">
|
<ha-tooltip
|
||||||
<slot name="icon"></slot>
|
.for=${this._elementId}
|
||||||
<slot></slot>
|
.disabled=${!this.description?.trim()}
|
||||||
</span>
|
>
|
||||||
|
${this.description}
|
||||||
|
</ha-tooltip>
|
||||||
|
<div class="container" .id=${this._elementId}>
|
||||||
|
<span class="content">
|
||||||
|
<slot name="icon"></slot>
|
||||||
|
<slot></slot>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,9 +51,7 @@ class HaLabel extends LitElement {
|
|||||||
font-weight: var(--ha-font-weight-medium);
|
font-weight: var(--ha-font-weight-medium);
|
||||||
line-height: var(--ha-line-height-condensed);
|
line-height: var(--ha-line-height-condensed);
|
||||||
letter-spacing: 0.1px;
|
letter-spacing: 0.1px;
|
||||||
vertical-align: middle;
|
|
||||||
height: 32px;
|
height: 32px;
|
||||||
padding: 0 16px;
|
|
||||||
border-radius: var(--ha-border-radius-xl);
|
border-radius: var(--ha-border-radius-xl);
|
||||||
color: var(--ha-label-text-color);
|
color: var(--ha-label-text-color);
|
||||||
--mdc-icon-size: 12px;
|
--mdc-icon-size: 12px;
|
||||||
@@ -66,15 +79,24 @@ class HaLabel extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([dense]) {
|
:host([dense]) {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
padding: 0 12px;
|
|
||||||
border-radius: var(--ha-border-radius-md);
|
border-radius: var(--ha-border-radius-md);
|
||||||
}
|
}
|
||||||
|
:host([dense]) .container {
|
||||||
|
padding: 0 12px;
|
||||||
|
}
|
||||||
:host([dense]) ::slotted([slot="icon"]) {
|
:host([dense]) ::slotted([slot="icon"]) {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
margin-left: -4px;
|
margin-left: -4px;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import "./chips/ha-input-chip";
|
|||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||||
import "./ha-label-picker";
|
import "./ha-label-picker";
|
||||||
import type { HaLabelPicker } from "./ha-label-picker";
|
import type { HaLabelPicker } from "./ha-label-picker";
|
||||||
|
import "./ha-tooltip";
|
||||||
|
|
||||||
@customElement("ha-labels-picker")
|
@customElement("ha-labels-picker")
|
||||||
export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
||||||
@@ -142,9 +143,17 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
const color = label?.color
|
const color = label?.color
|
||||||
? computeCssColor(label.color)
|
? computeCssColor(label.color)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
const elementId = "label-" + label.label_id;
|
||||||
return html`
|
return html`
|
||||||
|
<ha-tooltip
|
||||||
|
.for=${elementId}
|
||||||
|
.disabled=${!label?.description?.trim()}
|
||||||
|
>
|
||||||
|
${label?.description}
|
||||||
|
</ha-tooltip>
|
||||||
<ha-input-chip
|
<ha-input-chip
|
||||||
.item=${label}
|
.item=${label}
|
||||||
|
.id=${elementId}
|
||||||
@remove=${this._removeItem}
|
@remove=${this._removeItem}
|
||||||
@click=${this._openDetail}
|
@click=${this._openDetail}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { mdiMenuDown } from "@mdi/js";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { formatLanguageCode } from "../common/language/format_language";
|
import { formatLanguageCode } from "../common/language/format_language";
|
||||||
@@ -8,10 +9,10 @@ import { caseInsensitiveStringCompare } from "../common/string/compare";
|
|||||||
import type { FrontendLocaleData } from "../data/translation";
|
import type { FrontendLocaleData } from "../data/translation";
|
||||||
import { translationMetadata } from "../resources/translations-metadata";
|
import { translationMetadata } from "../resources/translations-metadata";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
||||||
|
import "./ha-button";
|
||||||
import "./ha-generic-picker";
|
import "./ha-generic-picker";
|
||||||
import "./ha-list-item";
|
import type { HaGenericPicker } from "./ha-generic-picker";
|
||||||
import type { PickerComboBoxItem } from "./ha-picker-combo-box";
|
import type { PickerComboBoxItem } from "./ha-picker-combo-box";
|
||||||
import "./ha-select";
|
|
||||||
|
|
||||||
export const getLanguageOptions = (
|
export const getLanguageOptions = (
|
||||||
languages: string[],
|
languages: string[],
|
||||||
@@ -75,6 +76,9 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
@property({ attribute: "native-name", type: Boolean })
|
@property({ attribute: "native-name", type: Boolean })
|
||||||
public nativeName = false;
|
public nativeName = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "button-style" })
|
||||||
|
public buttonStyle = false;
|
||||||
|
|
||||||
@property({ attribute: "no-sort", type: Boolean }) public noSort = false;
|
@property({ attribute: "no-sort", type: Boolean }) public noSort = false;
|
||||||
|
|
||||||
@property({ attribute: "inline-arrow", type: Boolean })
|
@property({ attribute: "inline-arrow", type: Boolean })
|
||||||
@@ -82,6 +86,8 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
|
|
||||||
@state() _defaultLanguages: string[] = [];
|
@state() _defaultLanguages: string[] = [];
|
||||||
|
|
||||||
|
@query("ha-generic-picker", true) public genericPicker!: HaGenericPicker;
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this._computeDefaultLanguageOptions();
|
this._computeDefaultLanguageOptions();
|
||||||
@@ -101,12 +107,13 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
this.hass?.locale
|
this.hass?.locale
|
||||||
);
|
);
|
||||||
|
|
||||||
private _valueRenderer = (value) => {
|
private _getLanguageName = (lang?: string) =>
|
||||||
const language = this._getItems().find(
|
this._getItems().find((language) => language.id === lang)?.primary;
|
||||||
(lang) => lang.id === value
|
|
||||||
)?.primary;
|
private _valueRenderer = (value) =>
|
||||||
return html`<span slot="headline">${language ?? value}</span> `;
|
html`<span slot="headline"
|
||||||
};
|
>${this._getLanguageName(value) ?? value}</span
|
||||||
|
> `;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const value =
|
const value =
|
||||||
@@ -118,9 +125,10 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
popover-placement="bottom-end"
|
popover-placement="bottom-end"
|
||||||
.notFoundLabel=${this.hass?.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.language-picker.no_match"
|
.emptyLabel=${this.hass?.localize(
|
||||||
)}
|
"ui.components.language-picker.no_languages"
|
||||||
|
) || "No languages available"}
|
||||||
.placeholder=${this.label ??
|
.placeholder=${this.label ??
|
||||||
(this.hass?.localize("ui.components.language-picker.language") ||
|
(this.hass?.localize("ui.components.language-picker.language") ||
|
||||||
"Language")}
|
"Language")}
|
||||||
@@ -130,10 +138,28 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
@value-changed=${this._changed}
|
@value-changed=${this._changed}
|
||||||
hide-clear-icon
|
hide-clear-icon
|
||||||
></ha-generic-picker>
|
>
|
||||||
|
${this.buttonStyle
|
||||||
|
? html`<ha-button
|
||||||
|
slot="field"
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
@click=${this._openPicker}
|
||||||
|
appearance="plain"
|
||||||
|
variant="neutral"
|
||||||
|
>
|
||||||
|
${this._getLanguageName(value)}
|
||||||
|
<ha-svg-icon slot="end" .path=${mdiMenuDown}></ha-svg-icon>
|
||||||
|
</ha-button>`
|
||||||
|
: nothing}
|
||||||
|
</ha-generic-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _openPicker(ev: Event) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.genericPicker.open();
|
||||||
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
ha-generic-picker {
|
ha-generic-picker {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -147,6 +173,15 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
this.value = ev.detail.value;
|
this.value = ev.detail.value;
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
fireEvent(this, "value-changed", { value: this.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) => {
|
||||||
|
const term = html`<b>‘${search}’</b>`;
|
||||||
|
return this.hass
|
||||||
|
? this.hass.localize("ui.components.language-picker.no_match", {
|
||||||
|
term,
|
||||||
|
})
|
||||||
|
: html`No languages found for ${term}`;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ListItemEl } from "@material/web/list/internal/listitem/list-item";
|
import { ListItemEl } from "@material/web/list/internal/listitem/list-item";
|
||||||
import { styles } from "@material/web/list/internal/listitem/list-item-styles";
|
import { styles } from "@material/web/list/internal/listitem/list-item-styles";
|
||||||
import { css } from "lit";
|
import { css, html, nothing, type TemplateResult } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
import "./ha-ripple";
|
||||||
|
|
||||||
export const haMdListStyles = [
|
export const haMdListStyles = [
|
||||||
styles,
|
styles,
|
||||||
@@ -25,6 +26,18 @@ export const haMdListStyles = [
|
|||||||
@customElement("ha-md-list-item")
|
@customElement("ha-md-list-item")
|
||||||
export class HaMdListItem extends ListItemEl {
|
export class HaMdListItem extends ListItemEl {
|
||||||
static override styles = haMdListStyles;
|
static override styles = haMdListStyles;
|
||||||
|
|
||||||
|
protected renderRipple(): TemplateResult | typeof nothing {
|
||||||
|
if (this.type === "text") {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`<ha-ripple
|
||||||
|
part="ripple"
|
||||||
|
for="item"
|
||||||
|
?disabled=${this.disabled && this.type !== "link"}
|
||||||
|
></ha-ripple>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { fireEvent } from "../common/dom/fire_event";
|
|||||||
import { titleCase } from "../common/string/title-case";
|
import { titleCase } from "../common/string/title-case";
|
||||||
import { fetchConfig } from "../data/lovelace/config/types";
|
import { fetchConfig } from "../data/lovelace/config/types";
|
||||||
import type { LovelaceViewRawConfig } from "../data/lovelace/config/view";
|
import type { LovelaceViewRawConfig } from "../data/lovelace/config/view";
|
||||||
|
import { getDefaultPanelUrlPath } from "../data/panel";
|
||||||
import type { HomeAssistant, PanelInfo, ValueChangedEvent } from "../types";
|
import type { HomeAssistant, PanelInfo, ValueChangedEvent } from "../types";
|
||||||
import "./ha-combo-box";
|
import "./ha-combo-box";
|
||||||
import type { HaComboBox } from "./ha-combo-box";
|
import type { HaComboBox } from "./ha-combo-box";
|
||||||
@@ -44,7 +45,7 @@ const createPanelNavigationItem = (hass: HomeAssistant, panel: PanelInfo) => ({
|
|||||||
path: `/${panel.url_path}`,
|
path: `/${panel.url_path}`,
|
||||||
icon: panel.icon ?? "mdi:view-dashboard",
|
icon: panel.icon ?? "mdi:view-dashboard",
|
||||||
title:
|
title:
|
||||||
panel.url_path === hass.defaultPanel
|
panel.url_path === getDefaultPanelUrlPath(hass)
|
||||||
? hass.localize("panel.states")
|
? hass.localize("panel.states")
|
||||||
: hass.localize(`panel.${panel.title}`) ||
|
: hass.localize(`panel.${panel.title}`) ||
|
||||||
panel.title ||
|
panel.title ||
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { LitVirtualizer } from "@lit-labs/virtualizer";
|
import type { LitVirtualizer } from "@lit-labs/virtualizer";
|
||||||
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||||
import { mdiMagnify } from "@mdi/js";
|
import { mdiMagnify, mdiMinusBoxOutline } from "@mdi/js";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import {
|
import {
|
||||||
@@ -14,11 +14,12 @@ import memoizeOne from "memoize-one";
|
|||||||
import { tinykeys } from "tinykeys";
|
import { tinykeys } from "tinykeys";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
|
||||||
import { HaFuse } from "../resources/fuse";
|
import { HaFuse } from "../resources/fuse";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import { loadVirtualizer } from "../resources/virtualizer";
|
import { loadVirtualizer } from "../resources/virtualizer";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./chips/ha-chip-set";
|
||||||
|
import "./chips/ha-filter-chip";
|
||||||
import "./ha-combo-box-item";
|
import "./ha-combo-box-item";
|
||||||
import "./ha-icon";
|
import "./ha-icon";
|
||||||
import "./ha-textfield";
|
import "./ha-textfield";
|
||||||
@@ -27,28 +28,18 @@ import type { HaTextField } from "./ha-textfield";
|
|||||||
export interface PickerComboBoxItem {
|
export interface PickerComboBoxItem {
|
||||||
id: string;
|
id: string;
|
||||||
primary: string;
|
primary: string;
|
||||||
a11y_label?: string;
|
|
||||||
secondary?: string;
|
secondary?: string;
|
||||||
search_labels?: string[];
|
search_labels?: string[];
|
||||||
sorting_label?: string;
|
sorting_label?: string;
|
||||||
icon_path?: string;
|
icon_path?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
}
|
}
|
||||||
|
const NO_ITEMS_AVAILABLE_ID = "___no_items_available___";
|
||||||
// Hack to force empty label to always display empty value by default in the search field
|
|
||||||
export interface PickerComboBoxItemWithLabel extends PickerComboBoxItem {
|
|
||||||
a11y_label: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NO_MATCHING_ITEMS_FOUND_ID = "___no_matching_items_found___";
|
|
||||||
|
|
||||||
const DEFAULT_ROW_RENDERER: RenderItemFunction<PickerComboBoxItem> = (
|
const DEFAULT_ROW_RENDERER: RenderItemFunction<PickerComboBoxItem> = (
|
||||||
item
|
item
|
||||||
) => html`
|
) => html`
|
||||||
<ha-combo-box-item
|
<ha-combo-box-item type="button" compact>
|
||||||
.type=${item.id === NO_MATCHING_ITEMS_FOUND_ID ? "text" : "button"}
|
|
||||||
compact
|
|
||||||
>
|
|
||||||
${item.icon
|
${item.icon
|
||||||
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
||||||
: item.icon_path
|
: item.icon_path
|
||||||
@@ -87,8 +78,11 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
|
|
||||||
@state() private _listScrolled = false;
|
@state() private _listScrolled = false;
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false })
|
||||||
public getItems?: () => PickerComboBoxItem[];
|
public getItems?: (
|
||||||
|
searchString?: string,
|
||||||
|
section?: string
|
||||||
|
) => (PickerComboBoxItem | string)[];
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false, type: Array })
|
||||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||||
@@ -96,21 +90,45 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public rowRenderer?: RenderItemFunction<PickerComboBoxItem>;
|
public rowRenderer?: RenderItemFunction<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ attribute: "not-found-label", type: String })
|
@property({ attribute: false })
|
||||||
public notFoundLabel?: string;
|
public notFoundLabel?: string | ((search: string) => string);
|
||||||
|
|
||||||
|
@property({ attribute: "empty-label" })
|
||||||
|
public emptyLabel?: string;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ reflect: true }) public mode: "popover" | "dialog" = "popover";
|
@property({ reflect: true }) public mode: "popover" | "dialog" = "popover";
|
||||||
|
|
||||||
|
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||||
|
@property({ attribute: false }) public sections?: (
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
| "separator"
|
||||||
|
)[];
|
||||||
|
|
||||||
|
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||||
|
firstIndex: number;
|
||||||
|
lastIndex: number;
|
||||||
|
firstItem: PickerComboBoxItem | string;
|
||||||
|
secondItem: PickerComboBoxItem | string;
|
||||||
|
itemsCount: number;
|
||||||
|
}) => string | undefined;
|
||||||
|
|
||||||
|
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||||
|
|
||||||
@query("lit-virtualizer") private _virtualizerElement?: LitVirtualizer;
|
@query("lit-virtualizer") private _virtualizerElement?: LitVirtualizer;
|
||||||
|
|
||||||
@query("ha-textfield") private _searchFieldElement?: HaTextField;
|
@query("ha-textfield") private _searchFieldElement?: HaTextField;
|
||||||
|
|
||||||
@state() private _items: PickerComboBoxItemWithLabel[] = [];
|
@state() private _items: (PickerComboBoxItem | string)[] = [];
|
||||||
|
|
||||||
private _allItems: PickerComboBoxItemWithLabel[] = [];
|
@state() private _sectionTitle?: string;
|
||||||
|
|
||||||
|
private _allItems: (PickerComboBoxItem | string)[] = [];
|
||||||
|
|
||||||
private _selectedItemIndex = -1;
|
private _selectedItemIndex = -1;
|
||||||
|
|
||||||
@@ -121,6 +139,8 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
|
|
||||||
private _removeKeyboardShortcuts?: () => void;
|
private _removeKeyboardShortcuts?: () => void;
|
||||||
|
|
||||||
|
private _search = "";
|
||||||
|
|
||||||
protected firstUpdated() {
|
protected firstUpdated() {
|
||||||
this._registerKeyboardShortcuts();
|
this._registerKeyboardShortcuts();
|
||||||
}
|
}
|
||||||
@@ -145,74 +165,142 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
"Search"}
|
"Search"}
|
||||||
@input=${this._filterChanged}
|
@input=${this._filterChanged}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
|
${this._renderSectionButtons()}
|
||||||
|
${this.sections?.length
|
||||||
|
? html`
|
||||||
|
<div class="section-title-wrapper">
|
||||||
|
<div
|
||||||
|
class="section-title ${!this.selectedSection &&
|
||||||
|
this._sectionTitle
|
||||||
|
? "show"
|
||||||
|
: ""}"
|
||||||
|
>
|
||||||
|
${this._sectionTitle}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
<lit-virtualizer
|
<lit-virtualizer
|
||||||
@scroll=${this._onScrollList}
|
.keyFunction=${this._keyFunction}
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
scroller
|
scroller
|
||||||
.items=${this._items}
|
.items=${this._items}
|
||||||
.renderItem=${this._renderItem}
|
.renderItem=${this._renderItem}
|
||||||
style="min-height: 36px;"
|
style="min-height: 36px;"
|
||||||
class=${this._listScrolled ? "scrolled" : ""}
|
class=${this._listScrolled ? "scrolled" : ""}
|
||||||
|
@scroll=${this._onScrollList}
|
||||||
@focus=${this._focusList}
|
@focus=${this._focusList}
|
||||||
|
@visibilityChanged=${this._visibilityChanged}
|
||||||
>
|
>
|
||||||
</lit-virtualizer> `;
|
</lit-virtualizer> `;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _defaultNotFoundItem = memoizeOne(
|
private _renderSectionButtons() {
|
||||||
(
|
if (!this.sections || this.sections.length === 0) {
|
||||||
label: this["notFoundLabel"],
|
return nothing;
|
||||||
localize?: LocalizeFunc
|
}
|
||||||
): PickerComboBoxItemWithLabel => ({
|
|
||||||
id: NO_MATCHING_ITEMS_FOUND_ID,
|
|
||||||
primary:
|
|
||||||
label ||
|
|
||||||
(localize && localize("ui.components.combo-box.no_match")) ||
|
|
||||||
"No matching items found",
|
|
||||||
icon_path: mdiMagnify,
|
|
||||||
a11y_label:
|
|
||||||
label ||
|
|
||||||
(localize && localize("ui.components.combo-box.no_match")) ||
|
|
||||||
"No matching items found",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
private _getAdditionalItems = (searchString?: string) => {
|
return html`
|
||||||
const items = this.getAdditionalItems?.(searchString) || [];
|
<ha-chip-set class="sections">
|
||||||
|
${this.sections.map((section) =>
|
||||||
|
section === "separator"
|
||||||
|
? html`<div class="separator"></div>`
|
||||||
|
: html`<ha-filter-chip
|
||||||
|
@click=${this._toggleSection}
|
||||||
|
.section-id=${section.id}
|
||||||
|
.selected=${this.selectedSection === section.id}
|
||||||
|
.label=${section.label}
|
||||||
|
>
|
||||||
|
</ha-filter-chip>`
|
||||||
|
)}
|
||||||
|
</ha-chip-set>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
return items.map<PickerComboBoxItemWithLabel>((item) => ({
|
@eventOptions({ passive: true })
|
||||||
...item,
|
private _visibilityChanged(ev) {
|
||||||
a11y_label: item.a11y_label || item.primary,
|
if (
|
||||||
}));
|
this._virtualizerElement &&
|
||||||
};
|
this.sectionTitleFunction &&
|
||||||
|
this.sections?.length
|
||||||
|
) {
|
||||||
|
const firstItem = this._virtualizerElement.items[ev.first];
|
||||||
|
const secondItem = this._virtualizerElement.items[ev.first + 1];
|
||||||
|
this._sectionTitle = this.sectionTitleFunction({
|
||||||
|
firstIndex: ev.first,
|
||||||
|
lastIndex: ev.last,
|
||||||
|
firstItem: firstItem as PickerComboBoxItem | string,
|
||||||
|
secondItem: secondItem as PickerComboBoxItem | string,
|
||||||
|
itemsCount: this._virtualizerElement.items.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _getItems = (): PickerComboBoxItemWithLabel[] => {
|
private _getAdditionalItems = (searchString?: string) =>
|
||||||
const items = this.getItems ? this.getItems() : [];
|
this.getAdditionalItems?.(searchString) || [];
|
||||||
|
|
||||||
const sortedItems = items
|
private _getItems = () => {
|
||||||
.map<PickerComboBoxItemWithLabel>((item) => ({
|
let items = [
|
||||||
...item,
|
...(this.getItems
|
||||||
a11y_label: item.a11y_label || item.primary,
|
? this.getItems(this._search, this.selectedSection)
|
||||||
}))
|
: []),
|
||||||
.sort((entityA, entityB) =>
|
];
|
||||||
|
|
||||||
|
if (!this.sections?.length) {
|
||||||
|
items = items.sort((entityA, entityB) =>
|
||||||
caseInsensitiveStringCompare(
|
caseInsensitiveStringCompare(
|
||||||
entityA.sorting_label!,
|
(entityA as PickerComboBoxItem).sorting_label!,
|
||||||
entityB.sorting_label!,
|
(entityB as PickerComboBoxItem).sorting_label!,
|
||||||
this.hass?.locale.language ?? navigator.language
|
this.hass?.locale.language ?? navigator.language
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!sortedItems.length) {
|
if (!items.length) {
|
||||||
sortedItems.push(
|
items.push(NO_ITEMS_AVAILABLE_ID);
|
||||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass?.localize)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const additionalItems = this._getAdditionalItems();
|
const additionalItems = this._getAdditionalItems();
|
||||||
sortedItems.push(...additionalItems);
|
items.push(...additionalItems);
|
||||||
return sortedItems;
|
|
||||||
|
if (this.mode === "dialog") {
|
||||||
|
items.push("padding"); // padding for safe area inset
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
private _renderItem = (item: PickerComboBoxItem, index: number) => {
|
private _renderItem = (item: PickerComboBoxItem | string, index: number) => {
|
||||||
|
if (item === "padding") {
|
||||||
|
return html`<div class="bottom-padding"></div>`;
|
||||||
|
}
|
||||||
|
if (item === NO_ITEMS_AVAILABLE_ID) {
|
||||||
|
return html`
|
||||||
|
<div class="combo-box-row">
|
||||||
|
<ha-combo-box-item type="text" compact>
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="start"
|
||||||
|
.path=${this._search ? mdiMagnify : mdiMinusBoxOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
<span slot="headline"
|
||||||
|
>${this._search
|
||||||
|
? typeof this.notFoundLabel === "function"
|
||||||
|
? this.notFoundLabel(this._search)
|
||||||
|
: this.notFoundLabel ||
|
||||||
|
this.hass?.localize("ui.components.combo-box.no_match") ||
|
||||||
|
"No matching items found"
|
||||||
|
: this.emptyLabel ||
|
||||||
|
this.hass?.localize("ui.components.combo-box.no_items") ||
|
||||||
|
"No items available"}</span
|
||||||
|
>
|
||||||
|
</ha-combo-box-item>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
if (typeof item === "string") {
|
||||||
|
return html`<div class="title">${item}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
const renderer = this.rowRenderer || DEFAULT_ROW_RENDERER;
|
const renderer = this.rowRenderer || DEFAULT_ROW_RENDERER;
|
||||||
return html`<div
|
return html`<div
|
||||||
id=${`list-item-${index}`}
|
id=${`list-item-${index}`}
|
||||||
@@ -221,9 +309,7 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
.index=${index}
|
.index=${index}
|
||||||
@click=${this._valueSelected}
|
@click=${this._valueSelected}
|
||||||
>
|
>
|
||||||
${item.id === NO_MATCHING_ITEMS_FOUND_ID
|
${renderer(item, index)}
|
||||||
? DEFAULT_ROW_RENDERER(item, index)
|
|
||||||
: renderer(item, index)}
|
|
||||||
</div>`;
|
</div>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,10 +328,6 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
const value = (ev.currentTarget as any).value as string;
|
const value = (ev.currentTarget as any).value as string;
|
||||||
const newValue = value?.trim();
|
const newValue = value?.trim();
|
||||||
|
|
||||||
if (newValue === NO_MATCHING_ITEMS_FOUND_ID) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", { value: newValue });
|
fireEvent(this, "value-changed", { value: newValue });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -256,51 +338,83 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
private _filterChanged = (ev: Event) => {
|
private _filterChanged = (ev: Event) => {
|
||||||
const textfield = ev.target as HaTextField;
|
const textfield = ev.target as HaTextField;
|
||||||
const searchString = textfield.value.trim();
|
const searchString = textfield.value.trim();
|
||||||
|
this._search = searchString;
|
||||||
|
|
||||||
if (!searchString) {
|
if (this.sections?.length) {
|
||||||
this._items = this._allItems;
|
this._items = this._getItems();
|
||||||
return;
|
} else {
|
||||||
}
|
if (!searchString) {
|
||||||
|
this._items = this._allItems;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const index = this._fuseIndex(this._allItems);
|
const index = this._fuseIndex(this._allItems as PickerComboBoxItem[]);
|
||||||
const fuse = new HaFuse(
|
const fuse = new HaFuse(
|
||||||
this._allItems,
|
this._allItems as PickerComboBoxItem[],
|
||||||
{
|
{
|
||||||
shouldSort: false,
|
shouldSort: false,
|
||||||
minMatchCharLength: Math.min(searchString.length, 2),
|
minMatchCharLength: Math.min(searchString.length, 2),
|
||||||
},
|
},
|
||||||
index
|
index
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = fuse.multiTermsSearch(searchString);
|
const results = fuse.multiTermsSearch(searchString);
|
||||||
let filteredItems = this._allItems as PickerComboBoxItem[];
|
let filteredItems = [...this._allItems];
|
||||||
if (results) {
|
|
||||||
const items = results.map((result) => result.item);
|
if (results) {
|
||||||
if (items.length === 0) {
|
const items: (PickerComboBoxItem | string)[] = results.map(
|
||||||
items.push(
|
(result) => result.item
|
||||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass?.localize)
|
);
|
||||||
|
|
||||||
|
if (!items.length) {
|
||||||
|
filteredItems.push(NO_ITEMS_AVAILABLE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
const additionalItems = this._getAdditionalItems();
|
||||||
|
items.push(...additionalItems);
|
||||||
|
|
||||||
|
filteredItems = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.searchFn) {
|
||||||
|
filteredItems = this.searchFn(
|
||||||
|
searchString,
|
||||||
|
filteredItems as PickerComboBoxItem[],
|
||||||
|
this._allItems as PickerComboBoxItem[]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const additionalItems = this._getAdditionalItems(searchString);
|
|
||||||
items.push(...additionalItems);
|
this._items = filteredItems as PickerComboBoxItem[];
|
||||||
filteredItems = items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.searchFn) {
|
|
||||||
filteredItems = this.searchFn(
|
|
||||||
searchString,
|
|
||||||
filteredItems,
|
|
||||||
this._allItems
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._items = filteredItems as PickerComboBoxItemWithLabel[];
|
|
||||||
this._selectedItemIndex = -1;
|
this._selectedItemIndex = -1;
|
||||||
if (this._virtualizerElement) {
|
if (this._virtualizerElement) {
|
||||||
this._virtualizerElement.scrollTo(0, 0);
|
this._virtualizerElement.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _toggleSection(ev: Event) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this._resetSelectedItem();
|
||||||
|
this._sectionTitle = undefined;
|
||||||
|
const section = (ev.target as HTMLElement)["section-id"] as string;
|
||||||
|
if (!section) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.selectedSection === section) {
|
||||||
|
this.selectedSection = undefined;
|
||||||
|
} else {
|
||||||
|
this.selectedSection = section;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._items = this._getItems();
|
||||||
|
|
||||||
|
// Reset scroll position when filter changes
|
||||||
|
if (this._virtualizerElement) {
|
||||||
|
this._virtualizerElement.scrollToIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _registerKeyboardShortcuts() {
|
private _registerKeyboardShortcuts() {
|
||||||
this._removeKeyboardShortcuts = tinykeys(this, {
|
this._removeKeyboardShortcuts = tinykeys(this, {
|
||||||
ArrowUp: this._selectPreviousItem,
|
ArrowUp: this._selectPreviousItem,
|
||||||
@@ -344,7 +458,7 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[nextIndex].id === NO_MATCHING_ITEMS_FOUND_ID) {
|
if (typeof items[nextIndex] === "string") {
|
||||||
// Skip titles, padding and empty search
|
// Skip titles, padding and empty search
|
||||||
if (nextIndex === maxItems) {
|
if (nextIndex === maxItems) {
|
||||||
return;
|
return;
|
||||||
@@ -373,7 +487,7 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[nextIndex]?.id === NO_MATCHING_ITEMS_FOUND_ID) {
|
if (typeof items[nextIndex] === "string") {
|
||||||
// Skip titles, padding and empty search
|
// Skip titles, padding and empty search
|
||||||
if (nextIndex === 0) {
|
if (nextIndex === 0) {
|
||||||
return;
|
return;
|
||||||
@@ -395,13 +509,6 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
|
|
||||||
const nextIndex = 0;
|
const nextIndex = 0;
|
||||||
|
|
||||||
if (
|
|
||||||
(this._virtualizerElement.items[nextIndex] as PickerComboBoxItem)?.id ===
|
|
||||||
NO_MATCHING_ITEMS_FOUND_ID
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||||
this._selectedItemIndex = nextIndex + 1;
|
this._selectedItemIndex = nextIndex + 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -419,13 +526,6 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
|
|
||||||
const nextIndex = this._virtualizerElement.items.length - 1;
|
const nextIndex = this._virtualizerElement.items.length - 1;
|
||||||
|
|
||||||
if (
|
|
||||||
(this._virtualizerElement.items[nextIndex] as PickerComboBoxItem)?.id ===
|
|
||||||
NO_MATCHING_ITEMS_FOUND_ID
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||||
this._selectedItemIndex = nextIndex - 1;
|
this._selectedItemIndex = nextIndex - 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -453,10 +553,7 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const firstItem = this._virtualizerElement?.items[0] as PickerComboBoxItem;
|
const firstItem = this._virtualizerElement?.items[0] as PickerComboBoxItem;
|
||||||
|
|
||||||
if (
|
if (this._virtualizerElement?.items.length === 1) {
|
||||||
this._virtualizerElement?.items.length === 1 &&
|
|
||||||
firstItem.id !== NO_MATCHING_ITEMS_FOUND_ID
|
|
||||||
) {
|
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: firstItem.id,
|
value: firstItem.id,
|
||||||
});
|
});
|
||||||
@@ -472,7 +569,7 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
const item = this._virtualizerElement?.items[
|
const item = this._virtualizerElement?.items[
|
||||||
this._selectedItemIndex
|
this._selectedItemIndex
|
||||||
] as PickerComboBoxItem;
|
] as PickerComboBoxItem;
|
||||||
if (item && item.id !== NO_MATCHING_ITEMS_FOUND_ID) {
|
if (item) {
|
||||||
fireEvent(this, "value-changed", { value: item.id });
|
fireEvent(this, "value-changed", { value: item.id });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -484,6 +581,9 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
this._selectedItemIndex = -1;
|
this._selectedItemIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _keyFunction = (item: PickerComboBoxItem | string) =>
|
||||||
|
typeof item === "string" ? item : item.id;
|
||||||
|
|
||||||
static styles = [
|
static styles = [
|
||||||
haStyleScrollbar,
|
haStyleScrollbar,
|
||||||
css`
|
css`
|
||||||
@@ -558,6 +658,80 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
background-color: var(--ha-color-fill-neutral-normal-hover);
|
background-color: var(--ha-color-fill-neutral-normal-hover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sections {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
gap: var(--ha-space-2);
|
||||||
|
padding: var(--ha-space-3) var(--ha-space-3);
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) .sections {
|
||||||
|
padding: var(--ha-space-3) var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sections ha-filter-chip {
|
||||||
|
flex-shrink: 0;
|
||||||
|
--md-filter-chip-selected-container-color: var(
|
||||||
|
--ha-color-fill-primary-normal-hover
|
||||||
|
);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sections .separator {
|
||||||
|
height: var(--ha-space-8);
|
||||||
|
width: 0;
|
||||||
|
border: 1px solid var(--ha-color-border-neutral-quiet);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title,
|
||||||
|
.title {
|
||||||
|
background-color: var(--ha-color-fill-neutral-quiet-resting);
|
||||||
|
padding: var(--ha-space-1) var(--ha-space-2);
|
||||||
|
font-weight: var(--ha-font-weight-bold);
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
min-height: var(--ha-space-6);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) .title {
|
||||||
|
padding: var(--ha-space-1) var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) ha-textfield {
|
||||||
|
padding: 0 var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title-wrapper {
|
||||||
|
height: 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 1px;
|
||||||
|
width: calc(100% - var(--ha-space-8));
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title.show {
|
||||||
|
opacity: 1;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-search {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: var(--ha-space-3);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { computeRTL } from "../common/util/compute_rtl";
|
|||||||
import { throttle } from "../common/util/throttle";
|
import { throttle } from "../common/util/throttle";
|
||||||
import { subscribeFrontendUserData } from "../data/frontend";
|
import { subscribeFrontendUserData } from "../data/frontend";
|
||||||
import type { ActionHandlerDetail } from "../data/lovelace/action_handler";
|
import type { ActionHandlerDetail } from "../data/lovelace/action_handler";
|
||||||
|
import { getDefaultPanelUrlPath } from "../data/panel";
|
||||||
import type { PersistentNotification } from "../data/persistent_notification";
|
import type { PersistentNotification } from "../data/persistent_notification";
|
||||||
import { subscribeNotifications } from "../data/persistent_notification";
|
import { subscribeNotifications } from "../data/persistent_notification";
|
||||||
import { subscribeRepairsIssueRegistry } from "../data/repairs";
|
import { subscribeRepairsIssueRegistry } from "../data/repairs";
|
||||||
@@ -142,7 +143,7 @@ const defaultPanelSorter = (
|
|||||||
export const computePanels = memoizeOne(
|
export const computePanels = memoizeOne(
|
||||||
(
|
(
|
||||||
panels: HomeAssistant["panels"],
|
panels: HomeAssistant["panels"],
|
||||||
defaultPanel: HomeAssistant["defaultPanel"],
|
defaultPanel: string,
|
||||||
panelsOrder: string[],
|
panelsOrder: string[],
|
||||||
hiddenPanels: string[],
|
hiddenPanels: string[],
|
||||||
locale: HomeAssistant["locale"]
|
locale: HomeAssistant["locale"]
|
||||||
@@ -157,7 +158,9 @@ export const computePanels = memoizeOne(
|
|||||||
Object.values(panels).forEach((panel) => {
|
Object.values(panels).forEach((panel) => {
|
||||||
if (
|
if (
|
||||||
hiddenPanels.includes(panel.url_path) ||
|
hiddenPanels.includes(panel.url_path) ||
|
||||||
(!panel.title && panel.url_path !== defaultPanel)
|
(!panel.title && panel.url_path !== defaultPanel) ||
|
||||||
|
(panel.default_visible === false &&
|
||||||
|
!panelsOrder.includes(panel.url_path))
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -296,7 +299,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
hass.localize !== oldHass.localize ||
|
hass.localize !== oldHass.localize ||
|
||||||
hass.locale !== oldHass.locale ||
|
hass.locale !== oldHass.locale ||
|
||||||
hass.states !== oldHass.states ||
|
hass.states !== oldHass.states ||
|
||||||
hass.defaultPanel !== oldHass.defaultPanel ||
|
hass.userData !== oldHass.userData ||
|
||||||
|
hass.systemData !== oldHass.systemData ||
|
||||||
hass.connected !== oldHass.connected
|
hass.connected !== oldHass.connected
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -399,9 +403,11 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||||
|
|
||||||
const [beforeSpacer, afterSpacer] = computePanels(
|
const [beforeSpacer, afterSpacer] = computePanels(
|
||||||
this.hass.panels,
|
this.hass.panels,
|
||||||
this.hass.defaultPanel,
|
defaultPanel,
|
||||||
this._panelOrder,
|
this._panelOrder,
|
||||||
this._hiddenPanels,
|
this._hiddenPanels,
|
||||||
this.hass.locale
|
this.hass.locale
|
||||||
@@ -416,23 +422,27 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
@scroll=${this._listboxScroll}
|
@scroll=${this._listboxScroll}
|
||||||
@keydown=${this._listboxKeydown}
|
@keydown=${this._listboxKeydown}
|
||||||
>
|
>
|
||||||
${this._renderPanels(beforeSpacer, selectedPanel)}
|
${this._renderPanels(beforeSpacer, selectedPanel, defaultPanel)}
|
||||||
${this._renderSpacer()}
|
${this._renderSpacer()}
|
||||||
${this._renderPanels(afterSpacer, selectedPanel)}
|
${this._renderPanels(afterSpacer, selectedPanel, defaultPanel)}
|
||||||
${this._renderExternalConfiguration()}
|
${this._renderExternalConfiguration()}
|
||||||
</ha-md-list>
|
</ha-md-list>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderPanels(panels: PanelInfo[], selectedPanel: string) {
|
private _renderPanels(
|
||||||
|
panels: PanelInfo[],
|
||||||
|
selectedPanel: string,
|
||||||
|
defaultPanel: string
|
||||||
|
) {
|
||||||
return panels.map((panel) =>
|
return panels.map((panel) =>
|
||||||
this._renderPanel(
|
this._renderPanel(
|
||||||
panel.url_path,
|
panel.url_path,
|
||||||
panel.url_path === this.hass.defaultPanel
|
panel.url_path === defaultPanel
|
||||||
? panel.title || this.hass.localize("panel.states")
|
? panel.title || this.hass.localize("panel.states")
|
||||||
: this.hass.localize(`panel.${panel.title}`) || panel.title,
|
: this.hass.localize(`panel.${panel.title}`) || panel.title,
|
||||||
panel.icon,
|
panel.icon,
|
||||||
panel.url_path === this.hass.defaultPanel && !panel.icon
|
panel.url_path === defaultPanel && !panel.icon
|
||||||
? PANEL_ICONS.lovelace
|
? PANEL_ICONS.lovelace
|
||||||
: panel.url_path in PANEL_ICONS
|
: panel.url_path in PANEL_ICONS
|
||||||
? PANEL_ICONS[panel.url_path]
|
? PANEL_ICONS[panel.url_path]
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ export class HaTooltip extends Tooltip {
|
|||||||
@property({ attribute: "show-delay", type: Number }) showDelay = 150;
|
@property({ attribute: "show-delay", type: Number }) showDelay = 150;
|
||||||
|
|
||||||
/** The amount of time to wait before hiding the tooltip when the user mouses out.. */
|
/** The amount of time to wait before hiding the tooltip when the user mouses out.. */
|
||||||
@property({ attribute: "hide-delay", type: Number }) hideDelay = 400;
|
@property({ attribute: "hide-delay", type: Number }) hideDelay = 150;
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
import { css, html, LitElement } from "lit";
|
||||||
import { mdiClose } from "@mdi/js";
|
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
|
||||||
import {
|
import {
|
||||||
customElement,
|
customElement,
|
||||||
eventOptions,
|
eventOptions,
|
||||||
@@ -8,6 +6,9 @@ import {
|
|||||||
query,
|
query,
|
||||||
state,
|
state,
|
||||||
} from "lit/decorators";
|
} from "lit/decorators";
|
||||||
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import { mdiClose } from "@mdi/js";
|
||||||
|
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
@@ -31,6 +32,8 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
*
|
*
|
||||||
* @slot header - Replace the entire header area.
|
* @slot header - Replace the entire header area.
|
||||||
* @slot headerNavigationIcon - Leading header action (e.g. close/back button).
|
* @slot headerNavigationIcon - Leading header action (e.g. close/back button).
|
||||||
|
* @slot headerTitle - Custom title content (used when header-title is not set).
|
||||||
|
* @slot headerSubtitle - Custom subtitle content (used when header-subtitle is not set).
|
||||||
* @slot headerActionItems - Trailing header actions (e.g. buttons, menus).
|
* @slot headerActionItems - Trailing header actions (e.g. buttons, menus).
|
||||||
* @slot - Dialog content body.
|
* @slot - Dialog content body.
|
||||||
* @slot footer - Dialog footer content.
|
* @slot footer - Dialog footer content.
|
||||||
@@ -52,8 +55,8 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
* @attr {boolean} open - Controls the dialog open state.
|
* @attr {boolean} open - Controls the dialog open state.
|
||||||
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
|
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
|
||||||
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
|
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
|
||||||
* @attr {string} header-title - Header title text when no custom title slot is provided.
|
* @attr {string} header-title - Header title text. If not set, the headerTitle slot is used.
|
||||||
* @attr {string} header-subtitle - Header subtitle text when no custom subtitle slot is provided.
|
* @attr {string} header-subtitle - Header subtitle text. If not set, the headerSubtitle slot is used.
|
||||||
* @attr {("above"|"below")} header-subtitle-position - Position of the subtitle relative to the title. Defaults to "below".
|
* @attr {("above"|"below")} header-subtitle-position - Position of the subtitle relative to the title. Defaults to "below".
|
||||||
* @attr {boolean} flexcontent - Makes the dialog body a flex container for flexible layouts.
|
* @attr {boolean} flexcontent - Makes the dialog body a flex container for flexible layouts.
|
||||||
*
|
*
|
||||||
@@ -72,6 +75,12 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
export class HaWaDialog extends LitElement {
|
export class HaWaDialog extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: "aria-labelledby" })
|
||||||
|
public ariaLabelledBy?: string;
|
||||||
|
|
||||||
|
@property({ attribute: "aria-describedby" })
|
||||||
|
public ariaDescribedBy?: string;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ type: Boolean, reflect: true })
|
||||||
public open = false;
|
public open = false;
|
||||||
|
|
||||||
@@ -81,11 +90,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
@property({ type: Boolean, reflect: true, attribute: "prevent-scrim-close" })
|
@property({ type: Boolean, reflect: true, attribute: "prevent-scrim-close" })
|
||||||
public preventScrimClose = false;
|
public preventScrimClose = false;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-title" })
|
@property({ attribute: "header-title" })
|
||||||
public headerTitle = "";
|
public headerTitle?: string;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-subtitle" })
|
@property({ attribute: "header-subtitle" })
|
||||||
public headerSubtitle = "";
|
public headerSubtitle?: string;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-subtitle-position" })
|
@property({ type: String, attribute: "header-subtitle-position" })
|
||||||
public headerSubtitlePosition: "above" | "below" = "below";
|
public headerSubtitlePosition: "above" | "below" = "below";
|
||||||
@@ -117,6 +126,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
.open=${this._open}
|
.open=${this._open}
|
||||||
.lightDismiss=${!this.preventScrimClose}
|
.lightDismiss=${!this.preventScrimClose}
|
||||||
without-header
|
without-header
|
||||||
|
aria-labelledby=${ifDefined(
|
||||||
|
this.ariaLabelledBy ||
|
||||||
|
(this.headerTitle !== undefined ? "ha-wa-dialog-title" : undefined)
|
||||||
|
)}
|
||||||
|
aria-describedby=${ifDefined(this.ariaDescribedBy)}
|
||||||
@wa-show=${this._handleShow}
|
@wa-show=${this._handleShow}
|
||||||
@wa-after-show=${this._handleAfterShow}
|
@wa-after-show=${this._handleAfterShow}
|
||||||
@wa-after-hide=${this._handleAfterHide}
|
@wa-after-hide=${this._handleAfterHide}
|
||||||
@@ -133,14 +147,14 @@ export class HaWaDialog extends LitElement {
|
|||||||
.path=${mdiClose}
|
.path=${mdiClose}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</slot>
|
</slot>
|
||||||
${this.headerTitle
|
${this.headerTitle !== undefined
|
||||||
? html`<span slot="title" class="title">
|
? html`<span slot="title" class="title" id="ha-wa-dialog-title">
|
||||||
${this.headerTitle}
|
${this.headerTitle}
|
||||||
</span>`
|
</span>`
|
||||||
: nothing}
|
: html`<slot name="headerTitle" slot="title"></slot>`}
|
||||||
${this.headerSubtitle
|
${this.headerSubtitle !== undefined
|
||||||
? html`<span slot="subtitle">${this.headerSubtitle}</span>`
|
? html`<span slot="subtitle">${this.headerSubtitle}</span>`
|
||||||
: nothing}
|
: html`<slot name="headerSubtitle" slot="subtitle"></slot>`}
|
||||||
<slot name="headerActionItems" slot="actionItems"></slot>
|
<slot name="headerActionItems" slot="actionItems"></slot>
|
||||||
</ha-dialog-header>
|
</ha-dialog-header>
|
||||||
</slot>
|
</slot>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
mdiLabel,
|
mdiLabel,
|
||||||
mdiTextureBox,
|
mdiTextureBox,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
|
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
@@ -19,9 +20,12 @@ import { computeDomain } from "../../common/entity/compute_domain";
|
|||||||
import { computeEntityName } from "../../common/entity/compute_entity_name";
|
import { computeEntityName } from "../../common/entity/compute_entity_name";
|
||||||
import { getEntityContext } from "../../common/entity/context/get_entity_context";
|
import { getEntityContext } from "../../common/entity/context/get_entity_context";
|
||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
|
import type { AreaRegistryEntry } from "../../data/area_registry";
|
||||||
import { getConfigEntry } from "../../data/config_entries";
|
import { getConfigEntry } from "../../data/config_entries";
|
||||||
import { labelsContext } from "../../data/context";
|
import { labelsContext } from "../../data/context";
|
||||||
|
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
||||||
|
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
import type { LabelRegistryEntry } from "../../data/label_registry";
|
||||||
import {
|
import {
|
||||||
@@ -111,10 +115,10 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const { name, context, iconPath, fallbackIconPath, stateObject } =
|
const { name, context, iconPath, fallbackIconPath, stateObject, notFound } =
|
||||||
this._itemData(this.type, this.itemId);
|
this._itemData(this.type, this.itemId);
|
||||||
|
|
||||||
const showEntities = this.type !== "entity";
|
const showEntities = this.type !== "entity" && !notFound;
|
||||||
|
|
||||||
const entries = this.parentEntries || this._entries;
|
const entries = this.parentEntries || this._entries;
|
||||||
|
|
||||||
@@ -128,7 +132,7 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-md-list-item type="text">
|
<ha-md-list-item type="text" class=${notFound ? "error" : ""}>
|
||||||
<div class="icon" slot="start">
|
<div class="icon" slot="start">
|
||||||
${this.subEntry
|
${this.subEntry
|
||||||
? html`
|
? html`
|
||||||
@@ -148,11 +152,15 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
/>`
|
/>`
|
||||||
: fallbackIconPath
|
: fallbackIconPath
|
||||||
? html`<ha-svg-icon .path=${fallbackIconPath}></ha-svg-icon>`
|
? html`<ha-svg-icon .path=${fallbackIconPath}></ha-svg-icon>`
|
||||||
: stateObject
|
: this.type === "entity"
|
||||||
? html`
|
? html`
|
||||||
<ha-state-icon
|
<ha-state-icon
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${stateObject}
|
.stateObj=${stateObject ||
|
||||||
|
({
|
||||||
|
entity_id: this.itemId,
|
||||||
|
attributes: {},
|
||||||
|
} as HassEntity)}
|
||||||
>
|
>
|
||||||
</ha-state-icon>
|
</ha-state-icon>
|
||||||
`
|
`
|
||||||
@@ -160,8 +168,14 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div slot="headline">${name}</div>
|
<div slot="headline">${name}</div>
|
||||||
${context && !this.hideContext
|
${notFound || (context && !this.hideContext)
|
||||||
? html`<span slot="supporting-text">${context}</span>`
|
? html`<span slot="supporting-text"
|
||||||
|
>${notFound
|
||||||
|
? this.hass.localize(
|
||||||
|
`ui.components.target-picker.${this.type}_not_found`
|
||||||
|
)
|
||||||
|
: context}</span
|
||||||
|
>`
|
||||||
: nothing}
|
: nothing}
|
||||||
${this._domainName && this.subEntry
|
${this._domainName && this.subEntry
|
||||||
? html`<span slot="supporting-text" class="domain"
|
? html`<span slot="supporting-text" class="domain"
|
||||||
@@ -474,26 +488,28 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
|
|
||||||
private _itemData = memoizeOne((type: TargetType, item: string) => {
|
private _itemData = memoizeOne((type: TargetType, item: string) => {
|
||||||
if (type === "floor") {
|
if (type === "floor") {
|
||||||
const floor = this.hass.floors?.[item];
|
const floor: FloorRegistryEntry | undefined = this.hass.floors?.[item];
|
||||||
return {
|
return {
|
||||||
name: floor?.name || item,
|
name: floor?.name || item,
|
||||||
iconPath: floor?.icon,
|
iconPath: floor?.icon,
|
||||||
fallbackIconPath: floor ? floorDefaultIconPath(floor) : mdiHome,
|
fallbackIconPath: floor ? floorDefaultIconPath(floor) : mdiHome,
|
||||||
|
notFound: !floor,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type === "area") {
|
if (type === "area") {
|
||||||
const area = this.hass.areas?.[item];
|
const area: AreaRegistryEntry | undefined = this.hass.areas?.[item];
|
||||||
return {
|
return {
|
||||||
name: area?.name || item,
|
name: area?.name || item,
|
||||||
context: area.floor_id && this.hass.floors?.[area.floor_id]?.name,
|
context: area?.floor_id && this.hass.floors?.[area.floor_id]?.name,
|
||||||
iconPath: area?.icon,
|
iconPath: area?.icon,
|
||||||
fallbackIconPath: mdiTextureBox,
|
fallbackIconPath: mdiTextureBox,
|
||||||
|
notFound: !area,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type === "device") {
|
if (type === "device") {
|
||||||
const device = this.hass.devices?.[item];
|
const device: DeviceRegistryEntry | undefined = this.hass.devices?.[item];
|
||||||
|
|
||||||
if (device.primary_config_entry) {
|
if (device?.primary_config_entry) {
|
||||||
this._getDeviceDomain(device.primary_config_entry);
|
this._getDeviceDomain(device.primary_config_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,24 +517,25 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
name: device ? computeDeviceNameDisplay(device, this.hass) : item,
|
name: device ? computeDeviceNameDisplay(device, this.hass) : item,
|
||||||
context: device?.area_id && this.hass.areas?.[device.area_id]?.name,
|
context: device?.area_id && this.hass.areas?.[device.area_id]?.name,
|
||||||
fallbackIconPath: mdiDevices,
|
fallbackIconPath: mdiDevices,
|
||||||
|
notFound: !device,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type === "entity") {
|
if (type === "entity") {
|
||||||
this._setDomainName(computeDomain(item));
|
this._setDomainName(computeDomain(item));
|
||||||
|
|
||||||
const stateObject = this.hass.states[item];
|
const stateObject: HassEntity | undefined = this.hass.states[item];
|
||||||
const entityName = computeEntityName(
|
const entityName = stateObject
|
||||||
stateObject,
|
? computeEntityName(stateObject, this.hass.entities, this.hass.devices)
|
||||||
this.hass.entities,
|
: item;
|
||||||
this.hass.devices
|
const { area, device } = stateObject
|
||||||
);
|
? getEntityContext(
|
||||||
const { area, device } = getEntityContext(
|
stateObject,
|
||||||
stateObject,
|
this.hass.entities,
|
||||||
this.hass.entities,
|
this.hass.devices,
|
||||||
this.hass.devices,
|
this.hass.areas,
|
||||||
this.hass.areas,
|
this.hass.floors
|
||||||
this.hass.floors
|
)
|
||||||
);
|
: { area: undefined, device: undefined };
|
||||||
const deviceName = device ? computeDeviceName(device) : undefined;
|
const deviceName = device ? computeDeviceName(device) : undefined;
|
||||||
const areaName = area ? computeAreaName(area) : undefined;
|
const areaName = area ? computeAreaName(area) : undefined;
|
||||||
const context = [areaName, entityName ? deviceName : undefined]
|
const context = [areaName, entityName ? deviceName : undefined]
|
||||||
@@ -528,15 +545,19 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
name: entityName || deviceName || item,
|
name: entityName || deviceName || item,
|
||||||
context,
|
context,
|
||||||
stateObject,
|
stateObject,
|
||||||
|
notFound: !stateObject && item !== "all" && item !== "none",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// type label
|
// type label
|
||||||
const label = this._labelRegistry.find((lab) => lab.label_id === item);
|
const label: LabelRegistryEntry | undefined = this._labelRegistry.find(
|
||||||
|
(lab) => lab.label_id === item
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
name: label?.name || item,
|
name: label?.name || item,
|
||||||
iconPath: label?.icon,
|
iconPath: label?.icon,
|
||||||
fallbackIconPath: mdiLabel,
|
fallbackIconPath: mdiLabel,
|
||||||
|
notFound: !label,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -597,17 +618,27 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
|
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background: var(--ha-color-fill-warning-quiet-resting);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error [slot="supporting-text"] {
|
||||||
|
color: var(--ha-color-on-warning-normal);
|
||||||
|
}
|
||||||
|
|
||||||
state-badge {
|
state-badge {
|
||||||
color: var(--ha-color-on-neutral-quiet);
|
color: var(--ha-color-on-neutral-quiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
|
width: 24px;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
--mdc-icon-button-size: 32px;
|
--mdc-icon-button-size: 32px;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -16,14 +16,10 @@ import memoizeOne from "memoize-one";
|
|||||||
import { computeCssColor } from "../../common/color/compute-color";
|
import { computeCssColor } from "../../common/color/compute-color";
|
||||||
import { hex2rgb } from "../../common/color/convert-color";
|
import { hex2rgb } from "../../common/color/convert-color";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { slugify } from "../../common/string/slugify";
|
import { computeDeviceNameDisplay } from "../../common/entity/compute_device_name";
|
||||||
import {
|
|
||||||
computeDeviceName,
|
|
||||||
computeDeviceNameDisplay,
|
|
||||||
} from "../../common/entity/compute_device_name";
|
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeEntityName } from "../../common/entity/compute_entity_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { getEntityContext } from "../../common/entity/context/get_entity_context";
|
import { slugify } from "../../common/string/slugify";
|
||||||
import { getConfigEntry } from "../../data/config_entries";
|
import { getConfigEntry } from "../../data/config_entries";
|
||||||
import { labelsContext } from "../../data/context";
|
import { labelsContext } from "../../data/context";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
@@ -172,23 +168,10 @@ export class HaTargetPickerValueChip extends LitElement {
|
|||||||
if (type === "entity") {
|
if (type === "entity") {
|
||||||
this._setDomainName(computeDomain(itemId));
|
this._setDomainName(computeDomain(itemId));
|
||||||
|
|
||||||
const stateObject = this.hass.states[itemId];
|
const stateObj = this.hass.states[itemId];
|
||||||
const entityName = computeEntityName(
|
|
||||||
stateObject,
|
|
||||||
this.hass.entities,
|
|
||||||
this.hass.devices
|
|
||||||
);
|
|
||||||
const { device } = getEntityContext(
|
|
||||||
stateObject,
|
|
||||||
this.hass.entities,
|
|
||||||
this.hass.devices,
|
|
||||||
this.hass.areas,
|
|
||||||
this.hass.floors
|
|
||||||
);
|
|
||||||
const deviceName = device ? computeDeviceName(device) : undefined;
|
|
||||||
return {
|
return {
|
||||||
name: entityName || deviceName || itemId,
|
name: computeStateName(stateObj) || itemId,
|
||||||
stateObject,
|
stateObject: stateObj,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,9 +128,7 @@ class HaUserPicker extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.user-picker.no_match"
|
|
||||||
)}
|
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
@@ -149,6 +147,11 @@ class HaUserPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.user-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { CONDITION_BUILDING_BLOCKS } from "./condition";
|
|||||||
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
|
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
|
||||||
import type { Action, Field, MODES } from "./script";
|
import type { Action, Field, MODES } from "./script";
|
||||||
import { migrateAutomationAction } from "./script";
|
import { migrateAutomationAction } from "./script";
|
||||||
|
import type { WeekdayShort } from "../common/datetime/weekday";
|
||||||
|
|
||||||
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
||||||
export const AUTOMATION_DEFAULT_MAX = 10;
|
export const AUTOMATION_DEFAULT_MAX = 10;
|
||||||
@@ -257,13 +258,11 @@ export interface ZoneCondition extends BaseCondition {
|
|||||||
zone: string;
|
zone: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Weekday = "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat";
|
|
||||||
|
|
||||||
export interface TimeCondition extends BaseCondition {
|
export interface TimeCondition extends BaseCondition {
|
||||||
condition: "time";
|
condition: "time";
|
||||||
after?: string;
|
after?: string;
|
||||||
before?: string;
|
before?: string;
|
||||||
weekday?: Weekday | Weekday[];
|
weekday?: WeekdayShort | WeekdayShort[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TemplateCondition extends BaseCondition {
|
export interface TemplateCondition extends BaseCondition {
|
||||||
|
|||||||
@@ -186,7 +186,8 @@ export const getDevices = (
|
|||||||
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
||||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||||
excludeDevices?: string[],
|
excludeDevices?: string[],
|
||||||
value?: string
|
value?: string,
|
||||||
|
idPrefix = ""
|
||||||
): DevicePickerItem[] => {
|
): DevicePickerItem[] => {
|
||||||
const devices = Object.values(hass.devices);
|
const devices = Object.values(hass.devices);
|
||||||
const entities = Object.values(hass.entities);
|
const entities = Object.values(hass.entities);
|
||||||
@@ -298,7 +299,7 @@ export const getDevices = (
|
|||||||
const domainName = domain ? domainToName(hass.localize, domain) : undefined;
|
const domainName = domain ? domainToName(hass.localize, domain) : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: device.id,
|
id: `${idPrefix}${device.id}`,
|
||||||
label: "",
|
label: "",
|
||||||
primary:
|
primary:
|
||||||
deviceName ||
|
deviceName ||
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ export type EnergySolarForecasts = Record<string, EnergySolarForecast>;
|
|||||||
export interface DeviceConsumptionEnergyPreference {
|
export interface DeviceConsumptionEnergyPreference {
|
||||||
// This is an ever increasing value
|
// This is an ever increasing value
|
||||||
stat_consumption: string;
|
stat_consumption: string;
|
||||||
|
stat_rate?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
included_in_stat?: string;
|
included_in_stat?: string;
|
||||||
}
|
}
|
||||||
@@ -130,11 +131,17 @@ export interface FlowToGridSourceEnergyPreference {
|
|||||||
number_energy_price: number | null;
|
number_energy_price: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GridPowerSourceEnergyPreference {
|
||||||
|
// W meter
|
||||||
|
stat_rate: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GridSourceTypeEnergyPreference {
|
export interface GridSourceTypeEnergyPreference {
|
||||||
type: "grid";
|
type: "grid";
|
||||||
|
|
||||||
flow_from: FlowFromGridSourceEnergyPreference[];
|
flow_from: FlowFromGridSourceEnergyPreference[];
|
||||||
flow_to: FlowToGridSourceEnergyPreference[];
|
flow_to: FlowToGridSourceEnergyPreference[];
|
||||||
|
power?: GridPowerSourceEnergyPreference[];
|
||||||
|
|
||||||
cost_adjustment_day: number;
|
cost_adjustment_day: number;
|
||||||
}
|
}
|
||||||
@@ -143,6 +150,7 @@ export interface SolarSourceTypeEnergyPreference {
|
|||||||
type: "solar";
|
type: "solar";
|
||||||
|
|
||||||
stat_energy_from: string;
|
stat_energy_from: string;
|
||||||
|
stat_rate?: string;
|
||||||
config_entry_solar_forecast: string[] | null;
|
config_entry_solar_forecast: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +158,7 @@ export interface BatterySourceTypeEnergyPreference {
|
|||||||
type: "battery";
|
type: "battery";
|
||||||
stat_energy_from: string;
|
stat_energy_from: string;
|
||||||
stat_energy_to: string;
|
stat_energy_to: string;
|
||||||
|
stat_rate?: string;
|
||||||
}
|
}
|
||||||
export interface GasSourceTypeEnergyPreference {
|
export interface GasSourceTypeEnergyPreference {
|
||||||
type: "gas";
|
type: "gas";
|
||||||
@@ -351,6 +360,35 @@ export const getReferencedStatisticIds = (
|
|||||||
return statIDs;
|
return statIDs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getReferencedStatisticIdsPower = (
|
||||||
|
prefs: EnergyPreferences
|
||||||
|
): string[] => {
|
||||||
|
const statIDs: (string | undefined)[] = [];
|
||||||
|
|
||||||
|
for (const source of prefs.energy_sources) {
|
||||||
|
if (source.type === "gas" || source.type === "water") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.type === "solar") {
|
||||||
|
statIDs.push(source.stat_rate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.type === "battery") {
|
||||||
|
statIDs.push(source.stat_rate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.power) {
|
||||||
|
statIDs.push(...source.power.map((p) => p.stat_rate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statIDs.push(...prefs.device_consumption.map((d) => d.stat_rate));
|
||||||
|
|
||||||
|
return statIDs.filter(Boolean) as string[];
|
||||||
|
};
|
||||||
|
|
||||||
export const enum CompareMode {
|
export const enum CompareMode {
|
||||||
NONE = "",
|
NONE = "",
|
||||||
PREVIOUS = "previous",
|
PREVIOUS = "previous",
|
||||||
@@ -398,9 +436,10 @@ const getEnergyData = async (
|
|||||||
"gas",
|
"gas",
|
||||||
"device",
|
"device",
|
||||||
]);
|
]);
|
||||||
|
const powerStatIds = getReferencedStatisticIdsPower(prefs);
|
||||||
const waterStatIds = getReferencedStatisticIds(prefs, info, ["water"]);
|
const waterStatIds = getReferencedStatisticIds(prefs, info, ["water"]);
|
||||||
|
|
||||||
const allStatIDs = [...energyStatIds, ...waterStatIds];
|
const allStatIDs = [...energyStatIds, ...waterStatIds, ...powerStatIds];
|
||||||
|
|
||||||
const dayDifference = differenceInDays(end || new Date(), start);
|
const dayDifference = differenceInDays(end || new Date(), start);
|
||||||
const period =
|
const period =
|
||||||
@@ -411,6 +450,8 @@ const getEnergyData = async (
|
|||||||
: dayDifference > 2
|
: dayDifference > 2
|
||||||
? "day"
|
? "day"
|
||||||
: "hour";
|
: "hour";
|
||||||
|
const finePeriod =
|
||||||
|
dayDifference > 64 ? "day" : dayDifference > 8 ? "hour" : "5minute";
|
||||||
|
|
||||||
const statsMetadata: Record<string, StatisticsMetaData> = {};
|
const statsMetadata: Record<string, StatisticsMetaData> = {};
|
||||||
const statsMetadataArray = allStatIDs.length
|
const statsMetadataArray = allStatIDs.length
|
||||||
@@ -432,6 +473,9 @@ const getEnergyData = async (
|
|||||||
? (gasUnit as (typeof VOLUME_UNITS)[number])
|
? (gasUnit as (typeof VOLUME_UNITS)[number])
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
|
const powerUnits: StatisticsUnitConfiguration = {
|
||||||
|
power: "kW",
|
||||||
|
};
|
||||||
const waterUnit = getEnergyWaterUnit(hass, prefs, statsMetadata);
|
const waterUnit = getEnergyWaterUnit(hass, prefs, statsMetadata);
|
||||||
const waterUnits: StatisticsUnitConfiguration = {
|
const waterUnits: StatisticsUnitConfiguration = {
|
||||||
volume: waterUnit,
|
volume: waterUnit,
|
||||||
@@ -442,6 +486,12 @@ const getEnergyData = async (
|
|||||||
"change",
|
"change",
|
||||||
])
|
])
|
||||||
: {};
|
: {};
|
||||||
|
const _powerStats: Statistics | Promise<Statistics> = powerStatIds.length
|
||||||
|
? fetchStatistics(hass!, start, end, powerStatIds, finePeriod, powerUnits, [
|
||||||
|
"mean",
|
||||||
|
])
|
||||||
|
: {};
|
||||||
|
|
||||||
const _waterStats: Statistics | Promise<Statistics> = waterStatIds.length
|
const _waterStats: Statistics | Promise<Statistics> = waterStatIds.length
|
||||||
? fetchStatistics(hass!, start, end, waterStatIds, period, waterUnits, [
|
? fetchStatistics(hass!, start, end, waterStatIds, period, waterUnits, [
|
||||||
"change",
|
"change",
|
||||||
@@ -548,6 +598,7 @@ const getEnergyData = async (
|
|||||||
|
|
||||||
const [
|
const [
|
||||||
energyStats,
|
energyStats,
|
||||||
|
powerStats,
|
||||||
waterStats,
|
waterStats,
|
||||||
energyStatsCompare,
|
energyStatsCompare,
|
||||||
waterStatsCompare,
|
waterStatsCompare,
|
||||||
@@ -555,13 +606,14 @@ const getEnergyData = async (
|
|||||||
fossilEnergyConsumptionCompare,
|
fossilEnergyConsumptionCompare,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
_energyStats,
|
_energyStats,
|
||||||
|
_powerStats,
|
||||||
_waterStats,
|
_waterStats,
|
||||||
_energyStatsCompare,
|
_energyStatsCompare,
|
||||||
_waterStatsCompare,
|
_waterStatsCompare,
|
||||||
_fossilEnergyConsumption,
|
_fossilEnergyConsumption,
|
||||||
_fossilEnergyConsumptionCompare,
|
_fossilEnergyConsumptionCompare,
|
||||||
]);
|
]);
|
||||||
const stats = { ...energyStats, ...waterStats };
|
const stats = { ...energyStats, ...waterStats, ...powerStats };
|
||||||
if (compare) {
|
if (compare) {
|
||||||
statsCompare = { ...energyStatsCompare, ...waterStatsCompare };
|
statsCompare = { ...energyStatsCompare, ...waterStatsCompare };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,7 +344,8 @@ export const getEntities = (
|
|||||||
includeUnitOfMeasurement?: string[],
|
includeUnitOfMeasurement?: string[],
|
||||||
includeEntities?: string[],
|
includeEntities?: string[],
|
||||||
excludeEntities?: string[],
|
excludeEntities?: string[],
|
||||||
value?: string
|
value?: string,
|
||||||
|
idPrefix = ""
|
||||||
): EntityComboBoxItem[] => {
|
): EntityComboBoxItem[] => {
|
||||||
let items: EntityComboBoxItem[] = [];
|
let items: EntityComboBoxItem[] = [];
|
||||||
|
|
||||||
@@ -395,10 +396,9 @@ export const getEntities = (
|
|||||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(isRTL ? " ◂ " : " ▸ ");
|
.join(isRTL ? " ◂ " : " ▸ ");
|
||||||
const a11yLabel = [deviceName, entityName].filter(Boolean).join(" - ");
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: entityId,
|
id: `${idPrefix}${entityId}`,
|
||||||
primary: primary,
|
primary: primary,
|
||||||
secondary: secondary,
|
secondary: secondary,
|
||||||
domain_name: domainName,
|
domain_name: domainName,
|
||||||
@@ -411,7 +411,6 @@ export const getEntities = (
|
|||||||
friendlyName,
|
friendlyName,
|
||||||
entityId,
|
entityId,
|
||||||
].filter(Boolean) as string[],
|
].filter(Boolean) as string[],
|
||||||
a11y_label: a11yLabel,
|
|
||||||
stateObj: stateObj,
|
stateObj: stateObj,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||||
|
import { atLeastVersion } from "../common/config/version";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface LogProvider {
|
export interface LogProvider {
|
||||||
@@ -8,4 +10,8 @@ export interface LogProvider {
|
|||||||
export const fetchErrorLog = (hass: HomeAssistant) =>
|
export const fetchErrorLog = (hass: HomeAssistant) =>
|
||||||
hass.callApi<string>("GET", "error_log");
|
hass.callApi<string>("GET", "error_log");
|
||||||
|
|
||||||
export const getErrorLogDownloadUrl = "/api/error_log";
|
export const getErrorLogDownloadUrl = (hass: HomeAssistant) =>
|
||||||
|
isComponentLoaded(hass, "hassio") &&
|
||||||
|
atLeastVersion(hass.config.version, 2025, 10)
|
||||||
|
? "/api/hassio/core/logs/latest"
|
||||||
|
: "/api/error_log";
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { Connection } from "home-assistant-js-websocket";
|
|||||||
export interface CoreFrontendUserData {
|
export interface CoreFrontendUserData {
|
||||||
showAdvanced?: boolean;
|
showAdvanced?: boolean;
|
||||||
showEntityIdPicker?: boolean;
|
showEntityIdPicker?: boolean;
|
||||||
|
defaultPanel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SidebarFrontendUserData {
|
export interface SidebarFrontendUserData {
|
||||||
@@ -10,15 +11,24 @@ export interface SidebarFrontendUserData {
|
|||||||
hiddenPanels: string[];
|
hiddenPanels: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CoreFrontendSystemData {
|
||||||
|
defaultPanel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface FrontendUserData {
|
interface FrontendUserData {
|
||||||
core: CoreFrontendUserData;
|
core: CoreFrontendUserData;
|
||||||
sidebar: SidebarFrontendUserData;
|
sidebar: SidebarFrontendUserData;
|
||||||
}
|
}
|
||||||
|
interface FrontendSystemData {
|
||||||
|
core: CoreFrontendSystemData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ValidUserDataKey = keyof FrontendUserData;
|
export type ValidUserDataKey = keyof FrontendUserData;
|
||||||
|
|
||||||
|
export type ValidSystemDataKey = keyof FrontendSystemData;
|
||||||
|
|
||||||
export const fetchFrontendUserData = async <
|
export const fetchFrontendUserData = async <
|
||||||
UserDataKey extends ValidUserDataKey,
|
UserDataKey extends ValidUserDataKey,
|
||||||
>(
|
>(
|
||||||
@@ -59,3 +69,46 @@ export const subscribeFrontendUserData = <UserDataKey extends ValidUserDataKey>(
|
|||||||
key: userDataKey,
|
key: userDataKey,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const fetchFrontendSystemData = async <
|
||||||
|
SystemDataKey extends ValidSystemDataKey,
|
||||||
|
>(
|
||||||
|
conn: Connection,
|
||||||
|
key: SystemDataKey
|
||||||
|
): Promise<FrontendSystemData[SystemDataKey] | null> => {
|
||||||
|
const result = await conn.sendMessagePromise<{
|
||||||
|
value: FrontendSystemData[SystemDataKey] | null;
|
||||||
|
}>({
|
||||||
|
type: "frontend/get_system_data",
|
||||||
|
key,
|
||||||
|
});
|
||||||
|
return result.value;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveFrontendSystemData = async <
|
||||||
|
SystemDataKey extends ValidSystemDataKey,
|
||||||
|
>(
|
||||||
|
conn: Connection,
|
||||||
|
key: SystemDataKey,
|
||||||
|
value: FrontendSystemData[SystemDataKey]
|
||||||
|
): Promise<void> =>
|
||||||
|
conn.sendMessagePromise<undefined>({
|
||||||
|
type: "frontend/set_system_data",
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const subscribeFrontendSystemData = <
|
||||||
|
SystemDataKey extends ValidSystemDataKey,
|
||||||
|
>(
|
||||||
|
conn: Connection,
|
||||||
|
systemDataKey: SystemDataKey,
|
||||||
|
onChange: (data: { value: FrontendSystemData[SystemDataKey] | null }) => void
|
||||||
|
) =>
|
||||||
|
conn.subscribeMessage<{ value: FrontendSystemData[SystemDataKey] | null }>(
|
||||||
|
onChange,
|
||||||
|
{
|
||||||
|
type: "frontend/subscribe_system_data",
|
||||||
|
key: systemDataKey,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
mdiChatSleep,
|
mdiChatSleep,
|
||||||
mdiClipboardList,
|
mdiClipboardList,
|
||||||
mdiClock,
|
mdiClock,
|
||||||
|
mdiCodeBraces,
|
||||||
mdiCog,
|
mdiCog,
|
||||||
mdiCommentAlert,
|
mdiCommentAlert,
|
||||||
mdiCounter,
|
mdiCounter,
|
||||||
@@ -113,6 +114,7 @@ export const FALLBACK_DOMAIN_ICONS = {
|
|||||||
text: mdiFormTextbox,
|
text: mdiFormTextbox,
|
||||||
time: mdiClock,
|
time: mdiClock,
|
||||||
timer: mdiTimerOutline,
|
timer: mdiTimerOutline,
|
||||||
|
template: mdiCodeBraces,
|
||||||
todo: mdiClipboardList,
|
todo: mdiClipboardList,
|
||||||
tts: mdiSpeakerMessage,
|
tts: mdiSpeakerMessage,
|
||||||
vacuum: mdiRobotVacuum,
|
vacuum: mdiRobotVacuum,
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ export const getLabels = (
|
|||||||
includeDeviceClasses?: string[],
|
includeDeviceClasses?: string[],
|
||||||
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
||||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||||
excludeLabels?: string[]
|
excludeLabels?: string[],
|
||||||
|
idPrefix = ""
|
||||||
): PickerComboBoxItem[] => {
|
): PickerComboBoxItem[] => {
|
||||||
if (!labels || labels.length === 0) {
|
if (!labels || labels.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
@@ -262,7 +263,7 @@ export const getLabels = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = outputLabels.map<PickerComboBoxItem>((label) => ({
|
const items = outputLabels.map<PickerComboBoxItem>((label) => ({
|
||||||
id: label.label_id,
|
id: `${idPrefix}${label.label_id}`,
|
||||||
primary: label.name,
|
primary: label.name,
|
||||||
secondary: label.description ?? "",
|
secondary: label.description ?? "",
|
||||||
icon: label.icon || undefined,
|
icon: label.icon || undefined,
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
|
||||||
import type { HomeAssistant, PanelInfo } from "../types";
|
import type { HomeAssistant, PanelInfo } from "../types";
|
||||||
|
|
||||||
/** Panel to show when no panel is picked. */
|
/** Panel to show when no panel is picked. */
|
||||||
export const DEFAULT_PANEL = "lovelace";
|
export const DEFAULT_PANEL = "lovelace";
|
||||||
|
|
||||||
export const getStorageDefaultPanelUrlPath = (): string => {
|
export const getCachedDefaultPanelUrlPath = (): string | null => {
|
||||||
const defaultPanel = window.localStorage.getItem("defaultPanel");
|
const defaultPanel = window.localStorage.getItem("defaultPanel");
|
||||||
|
return defaultPanel ? JSON.parse(defaultPanel) : null;
|
||||||
return defaultPanel ? JSON.parse(defaultPanel) : DEFAULT_PANEL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setDefaultPanel = (
|
export const getLegacyDefaultPanelUrlPath = (): string | null => {
|
||||||
element: HTMLElement,
|
const defaultPanel = window.localStorage.getItem("defaultPanel");
|
||||||
urlPath: string
|
return defaultPanel ? JSON.parse(defaultPanel) : null;
|
||||||
): void => {
|
|
||||||
fireEvent(element, "hass-default-panel", { defaultPanel: urlPath });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDefaultPanel = (hass: HomeAssistant): PanelInfo =>
|
export const getDefaultPanelUrlPath = (hass: HomeAssistant): string =>
|
||||||
hass.panels[hass.defaultPanel]
|
hass.userData?.defaultPanel ||
|
||||||
? hass.panels[hass.defaultPanel]
|
hass.systemData?.defaultPanel ||
|
||||||
: hass.panels[DEFAULT_PANEL];
|
getLegacyDefaultPanelUrlPath() ||
|
||||||
|
DEFAULT_PANEL;
|
||||||
|
|
||||||
|
export const getDefaultPanel = (hass: HomeAssistant): PanelInfo => {
|
||||||
|
const panel = getDefaultPanelUrlPath(hass);
|
||||||
|
|
||||||
|
return (panel ? hass.panels[panel] : undefined) ?? hass.panels[DEFAULT_PANEL];
|
||||||
|
};
|
||||||
|
|
||||||
export const getPanelNameTranslationKey = (panel: PanelInfo) => {
|
export const getPanelNameTranslationKey = (panel: PanelInfo) => {
|
||||||
if (panel.url_path === "lovelace") {
|
if (panel.url_path === "lovelace") {
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ export interface StopAction extends BaseAction {
|
|||||||
|
|
||||||
export interface SequenceAction extends BaseAction {
|
export interface SequenceAction extends BaseAction {
|
||||||
sequence: (ManualScriptConfig | Action)[];
|
sequence: (ManualScriptConfig | Action)[];
|
||||||
|
metadata?: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParallelAction extends BaseAction {
|
export interface ParallelAction extends BaseAction {
|
||||||
@@ -479,6 +480,7 @@ export const migrateAutomationAction = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof action === "object" && action !== null && "sequence" in action) {
|
if (typeof action === "object" && action !== null && "sequence" in action) {
|
||||||
|
delete (action as SequenceAction).metadata;
|
||||||
for (const sequenceAction of (action as SequenceAction).sequence) {
|
for (const sequenceAction of (action as SequenceAction).sequence) {
|
||||||
migrateAutomationAction(sequenceAction);
|
migrateAutomationAction(sequenceAction);
|
||||||
}
|
}
|
||||||
|
|||||||
152
src/dialogs/more-info/ha-more-info-add-to.ts
Normal file
152
src/dialogs/more-info/ha-more-info-add-to.ts
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import "../../components/ha-alert";
|
||||||
|
import "../../components/ha-icon";
|
||||||
|
import "../../components/ha-list-item";
|
||||||
|
import "../../components/ha-spinner";
|
||||||
|
import type {
|
||||||
|
ExternalEntityAddToActions,
|
||||||
|
ExternalEntityAddToAction,
|
||||||
|
} from "../../external_app/external_messaging";
|
||||||
|
import { showToast } from "../../util/toast";
|
||||||
|
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
|
@customElement("ha-more-info-add-to")
|
||||||
|
export class HaMoreInfoAddTo extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public entityId!: string;
|
||||||
|
|
||||||
|
@state() private _externalActions?: ExternalEntityAddToActions = {
|
||||||
|
actions: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
@state() private _loading = true;
|
||||||
|
|
||||||
|
private async _loadExternalActions() {
|
||||||
|
if (this.hass.auth.external?.config.hasEntityAddTo) {
|
||||||
|
this._externalActions =
|
||||||
|
await this.hass.auth.external?.sendMessage<"entity/add_to/get_actions">(
|
||||||
|
{
|
||||||
|
type: "entity/add_to/get_actions",
|
||||||
|
payload: { entity_id: this.entityId },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _actionSelected(ev: CustomEvent) {
|
||||||
|
const action = (ev.currentTarget as any)
|
||||||
|
.action as ExternalEntityAddToAction;
|
||||||
|
if (!action.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.hass.auth.external!.fireMessage({
|
||||||
|
type: "entity/add_to",
|
||||||
|
payload: {
|
||||||
|
entity_id: this.entityId,
|
||||||
|
app_payload: action.app_payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (err: any) {
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize(
|
||||||
|
"ui.dialogs.more_info_control.add_to.action_failed",
|
||||||
|
{
|
||||||
|
error: err.message || err,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async firstUpdated() {
|
||||||
|
await this._loadExternalActions();
|
||||||
|
this._loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
if (this._loading) {
|
||||||
|
return html`
|
||||||
|
<div class="loading">
|
||||||
|
<ha-spinner></ha-spinner>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._externalActions?.actions.length) {
|
||||||
|
return html`
|
||||||
|
<ha-alert alert-type="info">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.dialogs.more_info_control.add_to.no_actions"
|
||||||
|
)}
|
||||||
|
</ha-alert>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="actions-list">
|
||||||
|
${this._externalActions.actions.map(
|
||||||
|
(action) => html`
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!action.enabled}
|
||||||
|
.action=${action}
|
||||||
|
.twoline=${!!action.details}
|
||||||
|
@click=${this._actionSelected}
|
||||||
|
>
|
||||||
|
<span>${action.name}</span>
|
||||||
|
${action.details
|
||||||
|
? html`<span slot="secondary">${action.details}</span>`
|
||||||
|
: nothing}
|
||||||
|
<ha-icon slot="graphic" .icon=${action.mdi_icon}></ha-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
padding: var(--ha-space-2) var(--ha-space-6) var(--ha-space-6)
|
||||||
|
var(--ha-space-6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: var(--ha-space-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-list-item {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-list-item[disabled] {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-icon {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-more-info-add-to": HaMoreInfoAddTo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
mdiPencil,
|
mdiPencil,
|
||||||
mdiPencilOff,
|
mdiPencilOff,
|
||||||
mdiPencilOutline,
|
mdiPencilOutline,
|
||||||
|
mdiPlusBoxMultipleOutline,
|
||||||
mdiTransitConnectionVariant,
|
mdiTransitConnectionVariant,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
@@ -60,6 +61,7 @@ import {
|
|||||||
computeShowLogBookComponent,
|
computeShowLogBookComponent,
|
||||||
} from "./const";
|
} from "./const";
|
||||||
import "./controls/more-info-default";
|
import "./controls/more-info-default";
|
||||||
|
import "./ha-more-info-add-to";
|
||||||
import "./ha-more-info-history-and-logbook";
|
import "./ha-more-info-history-and-logbook";
|
||||||
import "./ha-more-info-info";
|
import "./ha-more-info-info";
|
||||||
import "./ha-more-info-settings";
|
import "./ha-more-info-settings";
|
||||||
@@ -73,7 +75,7 @@ export interface MoreInfoDialogParams {
|
|||||||
data?: Record<string, any>;
|
data?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type View = "info" | "history" | "settings" | "related";
|
type View = "info" | "history" | "settings" | "related" | "add_to";
|
||||||
|
|
||||||
interface ChildView {
|
interface ChildView {
|
||||||
viewTag: string;
|
viewTag: string;
|
||||||
@@ -194,6 +196,10 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _shouldShowAddEntityTo(): boolean {
|
||||||
|
return !!this.hass.auth.external?.config.hasEntityAddTo;
|
||||||
|
}
|
||||||
|
|
||||||
private _getDeviceId(): string | null {
|
private _getDeviceId(): string | null {
|
||||||
const entity = this.hass.entities[this._entityId!] as
|
const entity = this.hass.entities[this._entityId!] as
|
||||||
| EntityRegistryEntry
|
| EntityRegistryEntry
|
||||||
@@ -295,6 +301,11 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
this._setView("related");
|
this._setView("related");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _goToAddEntityTo(ev) {
|
||||||
|
if (!shouldHandleRequestSelectedEvent(ev)) return;
|
||||||
|
this._setView("add_to");
|
||||||
|
}
|
||||||
|
|
||||||
private _breadcrumbClick(ev: Event) {
|
private _breadcrumbClick(ev: Event) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this._setView("related");
|
this._setView("related");
|
||||||
@@ -521,6 +532,22 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
.path=${mdiInformationOutline}
|
.path=${mdiInformationOutline}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
|
${this._shouldShowAddEntityTo()
|
||||||
|
? html`
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@request-selected=${this._goToAddEntityTo}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.dialogs.more_info_control.add_entity_to"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiPlusBoxMultipleOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
@@ -613,7 +640,14 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
: "entity"}
|
: "entity"}
|
||||||
></ha-related-items>
|
></ha-related-items>
|
||||||
`
|
`
|
||||||
: nothing
|
: this._currView === "add_to"
|
||||||
|
? html`
|
||||||
|
<ha-more-info-add-to
|
||||||
|
.hass=${this.hass}
|
||||||
|
.entityId=${entityId}
|
||||||
|
></ha-more-info-add-to>
|
||||||
|
`
|
||||||
|
: nothing
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -152,10 +152,18 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setRedrawTimer() {
|
private _setUpdateTimer() {
|
||||||
// redraw the graph every minute to update the time axis
|
|
||||||
clearInterval(this._interval);
|
clearInterval(this._interval);
|
||||||
this._interval = window.setInterval(() => this._redrawGraph(), 1000 * 60);
|
this._interval = window.setInterval(() => {
|
||||||
|
// If using statistics, refresh the data
|
||||||
|
if (this._statistics) {
|
||||||
|
this._fetchStatistics();
|
||||||
|
}
|
||||||
|
// If using history, redraw the graph to update the time axis
|
||||||
|
if (this._stateHistory) {
|
||||||
|
this._redrawGraph();
|
||||||
|
}
|
||||||
|
}, 1000 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getStatisticsMetaData(statisticIds: string[] | undefined) {
|
private async _getStatisticsMetaData(statisticIds: string[] | undefined) {
|
||||||
@@ -170,6 +178,30 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
return statisticsMetaData;
|
return statisticsMetaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _fetchStatistics(): Promise<boolean> {
|
||||||
|
// Fire off the metadata and fetch at the same time
|
||||||
|
// to avoid waiting in sequence so the UI responds
|
||||||
|
// faster.
|
||||||
|
const _metadata = this._getStatisticsMetaData([this.entityId]);
|
||||||
|
const _statistics = fetchStatistics(
|
||||||
|
this.hass!,
|
||||||
|
subHours(new Date(), 24),
|
||||||
|
undefined,
|
||||||
|
[this.entityId],
|
||||||
|
"5minute",
|
||||||
|
undefined,
|
||||||
|
statTypes
|
||||||
|
);
|
||||||
|
const [metadata, statistics] = await Promise.all([_metadata, _statistics]);
|
||||||
|
if (metadata && Object.keys(metadata).length) {
|
||||||
|
this._metadata = metadata;
|
||||||
|
this._statistics = statistics;
|
||||||
|
this._statNames = { [this.entityId]: "" };
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private async _getStateHistory(): Promise<void> {
|
private async _getStateHistory(): Promise<void> {
|
||||||
if (
|
if (
|
||||||
isComponentLoaded(this.hass, "recorder") &&
|
isComponentLoaded(this.hass, "recorder") &&
|
||||||
@@ -180,27 +212,10 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
// has not opted into statistics so there is no need to check as it
|
// has not opted into statistics so there is no need to check as it
|
||||||
// requires another round-trip to the server.
|
// requires another round-trip to the server.
|
||||||
if (stateObj && stateObj.attributes.state_class) {
|
if (stateObj && stateObj.attributes.state_class) {
|
||||||
// Fire off the metadata and fetch at the same time
|
const hasStatistics = await this._fetchStatistics();
|
||||||
// to avoid waiting in sequence so the UI responds
|
if (hasStatistics) {
|
||||||
// faster.
|
// Using statistics, set up refresh timer
|
||||||
const _metadata = this._getStatisticsMetaData([this.entityId]);
|
this._setUpdateTimer();
|
||||||
const _statistics = fetchStatistics(
|
|
||||||
this.hass!,
|
|
||||||
subHours(new Date(), 24),
|
|
||||||
undefined,
|
|
||||||
[this.entityId],
|
|
||||||
"5minute",
|
|
||||||
undefined,
|
|
||||||
statTypes
|
|
||||||
);
|
|
||||||
const [metadata, statistics] = await Promise.all([
|
|
||||||
_metadata,
|
|
||||||
_statistics,
|
|
||||||
]);
|
|
||||||
if (metadata && Object.keys(metadata).length) {
|
|
||||||
this._metadata = metadata;
|
|
||||||
this._statistics = statistics;
|
|
||||||
this._statNames = { [this.entityId]: "" };
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +253,7 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
this._error = err;
|
this._error = err;
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
this._setRedrawTimer();
|
this._setUpdateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = [
|
static styles = [
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
} from "../../data/frontend";
|
} from "../../data/frontend";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { showConfirmationDialog } from "../generic/show-dialog-box";
|
import { showConfirmationDialog } from "../generic/show-dialog-box";
|
||||||
|
import { getDefaultPanelUrlPath } from "../../data/panel";
|
||||||
|
|
||||||
@customElement("dialog-edit-sidebar")
|
@customElement("dialog-edit-sidebar")
|
||||||
class DialogEditSidebar extends LitElement {
|
class DialogEditSidebar extends LitElement {
|
||||||
@@ -94,14 +95,27 @@ class DialogEditSidebar extends LitElement {
|
|||||||
|
|
||||||
const panels = this._panels(this.hass.panels);
|
const panels = this._panels(this.hass.panels);
|
||||||
|
|
||||||
|
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||||
|
|
||||||
const [beforeSpacer, afterSpacer] = computePanels(
|
const [beforeSpacer, afterSpacer] = computePanels(
|
||||||
this.hass.panels,
|
this.hass.panels,
|
||||||
this.hass.defaultPanel,
|
defaultPanel,
|
||||||
this._order,
|
this._order,
|
||||||
this._hidden,
|
this._hidden,
|
||||||
this.hass.locale
|
this.hass.locale
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add default hidden panels that are missing in hidden
|
||||||
|
for (const panel of panels) {
|
||||||
|
if (
|
||||||
|
panel.default_visible === false &&
|
||||||
|
!this._order.includes(panel.url_path) &&
|
||||||
|
!this._hidden.includes(panel.url_path)
|
||||||
|
) {
|
||||||
|
this._hidden.push(panel.url_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
...beforeSpacer,
|
...beforeSpacer,
|
||||||
...panels.filter((panel) => this._hidden!.includes(panel.url_path)),
|
...panels.filter((panel) => this._hidden!.includes(panel.url_path)),
|
||||||
@@ -109,12 +123,12 @@ class DialogEditSidebar extends LitElement {
|
|||||||
].map((panel) => ({
|
].map((panel) => ({
|
||||||
value: panel.url_path,
|
value: panel.url_path,
|
||||||
label:
|
label:
|
||||||
panel.url_path === this.hass.defaultPanel
|
panel.url_path === defaultPanel
|
||||||
? panel.title || this.hass.localize("panel.states")
|
? panel.title || this.hass.localize("panel.states")
|
||||||
: this.hass.localize(`panel.${panel.title}`) || panel.title || "?",
|
: this.hass.localize(`panel.${panel.title}`) || panel.title || "?",
|
||||||
icon: panel.icon || undefined,
|
icon: panel.icon || undefined,
|
||||||
iconPath:
|
iconPath:
|
||||||
panel.url_path === this.hass.defaultPanel && !panel.icon
|
panel.url_path === defaultPanel && !panel.icon
|
||||||
? PANEL_ICONS.lovelace
|
? PANEL_ICONS.lovelace
|
||||||
: panel.url_path in PANEL_ICONS
|
: panel.url_path in PANEL_ICONS
|
||||||
? PANEL_ICONS[panel.url_path]
|
? PANEL_ICONS[panel.url_path]
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ interface EMOutgoingMessageConfigGet extends EMMessage {
|
|||||||
type: "config/get";
|
type: "config/get";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EMOutgoingMessageEntityAddToGetActions extends EMMessage {
|
||||||
|
type: "entity/add_to/get_actions";
|
||||||
|
payload: {
|
||||||
|
entity_id: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface EMOutgoingMessageBarCodeScan extends EMMessage {
|
interface EMOutgoingMessageBarCodeScan extends EMMessage {
|
||||||
type: "bar_code/scan";
|
type: "bar_code/scan";
|
||||||
payload: {
|
payload: {
|
||||||
@@ -75,6 +82,10 @@ interface EMOutgoingMessageWithAnswer {
|
|||||||
request: EMOutgoingMessageConfigGet;
|
request: EMOutgoingMessageConfigGet;
|
||||||
response: ExternalConfig;
|
response: ExternalConfig;
|
||||||
};
|
};
|
||||||
|
"entity/add_to/get_actions": {
|
||||||
|
request: EMOutgoingMessageEntityAddToGetActions;
|
||||||
|
response: ExternalEntityAddToActions;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EMOutgoingMessageExoplayerPlayHLS extends EMMessage {
|
interface EMOutgoingMessageExoplayerPlayHLS extends EMMessage {
|
||||||
@@ -157,6 +168,14 @@ interface EMOutgoingMessageThreadStoreInPlatformKeychain extends EMMessage {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EMOutgoingMessageAddEntityTo extends EMMessage {
|
||||||
|
type: "entity/add_to";
|
||||||
|
payload: {
|
||||||
|
entity_id: string;
|
||||||
|
app_payload: string; // Opaque string received from get_actions
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
type EMOutgoingMessageWithoutAnswer =
|
type EMOutgoingMessageWithoutAnswer =
|
||||||
| EMMessageResultError
|
| EMMessageResultError
|
||||||
| EMMessageResultSuccess
|
| EMMessageResultSuccess
|
||||||
@@ -177,7 +196,8 @@ type EMOutgoingMessageWithoutAnswer =
|
|||||||
| EMOutgoingMessageThemeUpdate
|
| EMOutgoingMessageThemeUpdate
|
||||||
| EMOutgoingMessageThreadStoreInPlatformKeychain
|
| EMOutgoingMessageThreadStoreInPlatformKeychain
|
||||||
| EMOutgoingMessageImprovScan
|
| EMOutgoingMessageImprovScan
|
||||||
| EMOutgoingMessageImprovConfigureDevice;
|
| EMOutgoingMessageImprovConfigureDevice
|
||||||
|
| EMOutgoingMessageAddEntityTo;
|
||||||
|
|
||||||
export interface EMIncomingMessageRestart {
|
export interface EMIncomingMessageRestart {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -293,18 +313,31 @@ type EMIncomingMessage =
|
|||||||
type EMIncomingMessageHandler = (msg: EMIncomingMessageCommands) => boolean;
|
type EMIncomingMessageHandler = (msg: EMIncomingMessageCommands) => boolean;
|
||||||
|
|
||||||
export interface ExternalConfig {
|
export interface ExternalConfig {
|
||||||
hasSettingsScreen: boolean;
|
hasSettingsScreen?: boolean;
|
||||||
hasSidebar: boolean;
|
hasSidebar?: boolean;
|
||||||
canWriteTag: boolean;
|
canWriteTag?: boolean;
|
||||||
hasExoPlayer: boolean;
|
hasExoPlayer?: boolean;
|
||||||
canCommissionMatter: boolean;
|
canCommissionMatter?: boolean;
|
||||||
canImportThreadCredentials: boolean;
|
canImportThreadCredentials?: boolean;
|
||||||
canTransferThreadCredentialsToKeychain: boolean;
|
canTransferThreadCredentialsToKeychain?: boolean;
|
||||||
hasAssist: boolean;
|
hasAssist?: boolean;
|
||||||
hasBarCodeScanner: number;
|
hasBarCodeScanner?: number;
|
||||||
canSetupImprov: boolean;
|
canSetupImprov?: boolean;
|
||||||
downloadFileSupported: boolean;
|
downloadFileSupported?: boolean;
|
||||||
appVersion: string;
|
appVersion?: string;
|
||||||
|
hasEntityAddTo?: boolean; // Supports "Add to" from more-info dialog, with action coming from external app
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExternalEntityAddToAction {
|
||||||
|
enabled: boolean;
|
||||||
|
name: string; // Translated name of the action to be displayed in the UI
|
||||||
|
details?: string; // Optional translated details of the action to be displayed in the UI
|
||||||
|
mdi_icon: string; // MDI icon name to be displayed in the UI (e.g., "mdi:car")
|
||||||
|
app_payload: string; // Opaque string to be sent back when the action is selected
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExternalEntityAddToActions {
|
||||||
|
actions: ExternalEntityAddToAction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExternalMessaging {
|
export class ExternalMessaging {
|
||||||
|
|||||||
@@ -97,6 +97,9 @@ export const ENTITY_COMPONENT_ICONS: Record<string, ComponentIcons> = {
|
|||||||
pm25: {
|
pm25: {
|
||||||
default: "mdi:molecule",
|
default: "mdi:molecule",
|
||||||
},
|
},
|
||||||
|
pm4: {
|
||||||
|
default: "mdi:molecule",
|
||||||
|
},
|
||||||
power: {
|
power: {
|
||||||
default: "mdi:flash",
|
default: "mdi:flash",
|
||||||
},
|
},
|
||||||
@@ -674,6 +677,9 @@ export const ENTITY_COMPONENT_ICONS: Record<string, ComponentIcons> = {
|
|||||||
pm25: {
|
pm25: {
|
||||||
default: "mdi:molecule",
|
default: "mdi:molecule",
|
||||||
},
|
},
|
||||||
|
pm4: {
|
||||||
|
default: "mdi:molecule",
|
||||||
|
},
|
||||||
power: {
|
power: {
|
||||||
default: "mdi:flash",
|
default: "mdi:flash",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,21 @@
|
|||||||
<meta name="color-scheme" content="dark light" />
|
<meta name="color-scheme" content="dark light" />
|
||||||
<%= renderTemplate("_style_base.html.template") %>
|
<%= renderTemplate("_style_base.html.template") %>
|
||||||
<style>
|
<style>
|
||||||
|
@keyframes fade-out {
|
||||||
|
from {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
::view-transition-group(launch-screen) {
|
||||||
|
animation-duration: var(--ha-animation-base-duration, 350ms);
|
||||||
|
animation-timing-function: ease-out;
|
||||||
|
}
|
||||||
|
::view-transition-old(launch-screen) {
|
||||||
|
animation: fade-out var(--ha-animation-base-duration, 350ms) ease-out;
|
||||||
|
}
|
||||||
html {
|
html {
|
||||||
background-color: var(--primary-background-color, #fafafa);
|
background-color: var(--primary-background-color, #fafafa);
|
||||||
color: var(--primary-text-color, #212121);
|
color: var(--primary-text-color, #212121);
|
||||||
@@ -32,11 +47,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ha-launch-screen {
|
#ha-launch-screen {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
view-transition-name: launch-screen;
|
||||||
|
background-color: var(--primary-background-color, #fafafa);
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
/* body selector to avoid minification causing bad jinja2 */
|
||||||
|
body #ha-launch-screen {
|
||||||
|
background-color: var(--primary-background-color, #111111);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ha-launch-screen.removing {
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
#ha-launch-screen svg {
|
#ha-launch-screen svg {
|
||||||
width: 112px;
|
width: 112px;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { PropertyValues, TemplateResult } from "lit";
|
import type { PropertyValues, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import type { HASSDomEvent } from "../common/dom/fire_event";
|
import type { HASSDomEvent } from "../common/dom/fire_event";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@@ -46,10 +46,13 @@ export class HomeAssistantMain extends LitElement {
|
|||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const sidebarNarrow = this._sidebarNarrow || this._externalSidebar;
|
const sidebarNarrow = this._sidebarNarrow || this._externalSidebar;
|
||||||
|
|
||||||
|
const isPanelReady =
|
||||||
|
this.hass.panels && this.hass.userData && this.hass.systemData;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-drawer
|
<ha-drawer
|
||||||
.type=${sidebarNarrow ? "modal" : ""}
|
.type=${sidebarNarrow ? "modal" : ""}
|
||||||
.open=${sidebarNarrow ? this._drawerOpen : undefined}
|
.open=${sidebarNarrow ? this._drawerOpen : false}
|
||||||
.direction=${computeRTLDirection(this.hass)}
|
.direction=${computeRTLDirection(this.hass)}
|
||||||
@MDCDrawer:closed=${this._drawerClosed}
|
@MDCDrawer:closed=${this._drawerClosed}
|
||||||
>
|
>
|
||||||
@@ -59,12 +62,14 @@ export class HomeAssistantMain extends LitElement {
|
|||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.alwaysExpand=${sidebarNarrow || this.hass.dockedSidebar === "docked"}
|
.alwaysExpand=${sidebarNarrow || this.hass.dockedSidebar === "docked"}
|
||||||
></ha-sidebar>
|
></ha-sidebar>
|
||||||
<partial-panel-resolver
|
${isPanelReady
|
||||||
.narrow=${this.narrow}
|
? html`<partial-panel-resolver
|
||||||
.hass=${this.hass}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.hass=${this.hass}
|
||||||
slot="appContent"
|
.route=${this.route}
|
||||||
></partial-panel-resolver>
|
slot="appContent"
|
||||||
|
></partial-panel-resolver>`
|
||||||
|
: nothing}
|
||||||
</ha-drawer>
|
</ha-drawer>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
import type { Connection } from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html } from "lit";
|
import { html } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import type { Connection } from "home-assistant-js-websocket";
|
import { storage } from "../common/decorators/storage";
|
||||||
import { isNavigationClick } from "../common/dom/is-navigation-click";
|
import { isNavigationClick } from "../common/dom/is-navigation-click";
|
||||||
import { navigate } from "../common/navigate";
|
import { navigate } from "../common/navigate";
|
||||||
import { getStorageDefaultPanelUrlPath } from "../data/panel";
|
|
||||||
import type { WindowWithPreloads } from "../data/preloads";
|
import type { WindowWithPreloads } from "../data/preloads";
|
||||||
import type { RecorderInfo } from "../data/recorder";
|
import type { RecorderInfo } from "../data/recorder";
|
||||||
import { getRecorderInfo } from "../data/recorder";
|
import { getRecorderInfo } from "../data/recorder";
|
||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
} from "../util/register-service-worker";
|
} from "../util/register-service-worker";
|
||||||
import "./ha-init-page";
|
import "./ha-init-page";
|
||||||
import "./home-assistant-main";
|
import "./home-assistant-main";
|
||||||
import { storage } from "../common/decorators/storage";
|
|
||||||
|
|
||||||
const useHash = __DEMO__;
|
const useHash = __DEMO__;
|
||||||
const curPath = () =>
|
const curPath = () =>
|
||||||
@@ -53,11 +52,12 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
super();
|
super();
|
||||||
const path = curPath();
|
const path = curPath();
|
||||||
|
|
||||||
if (["", "/"].includes(path)) {
|
// if (["", "/"].includes(path)) {
|
||||||
navigate(`/${getStorageDefaultPanelUrlPath()}${location.search}`, {
|
// const defaultPanel = getCachedDefaultPanelUrlPath();
|
||||||
replace: true,
|
// if (defaultPanel) {
|
||||||
});
|
// navigate(`/${defaultPanel}${location.search}`, { replace: true });
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
this._route = {
|
this._route = {
|
||||||
prefix: "",
|
prefix: "",
|
||||||
path,
|
path,
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ const COMPONENTS = {
|
|||||||
"media-browser": () =>
|
"media-browser": () =>
|
||||||
import("../panels/media-browser/ha-panel-media-browser"),
|
import("../panels/media-browser/ha-panel-media-browser"),
|
||||||
light: () => import("../panels/light/ha-panel-light"),
|
light: () => import("../panels/light/ha-panel-light"),
|
||||||
safety: () => import("../panels/safety/ha-panel-safety"),
|
security: () => import("../panels/security/ha-panel-security"),
|
||||||
climate: () => import("../panels/climate/ha-panel-climate"),
|
climate: () => import("../panels/climate/ha-panel-climate"),
|
||||||
|
home: () => import("../panels/home/ha-panel-home"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@customElement("partial-panel-resolver")
|
@customElement("partial-panel-resolver")
|
||||||
|
|||||||
133
src/mixins/conditional-listener-mixin.ts
Normal file
133
src/mixins/conditional-listener-mixin.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import type { ReactiveElement } from "lit";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
|
import {
|
||||||
|
setupMediaQueryListeners,
|
||||||
|
setupTimeListeners,
|
||||||
|
} from "../common/condition/listeners";
|
||||||
|
import type { Condition } from "../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
type Constructor<T> = abstract new (...args: any[]) => T;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base config type that can be used with conditional listeners
|
||||||
|
*/
|
||||||
|
export interface ConditionalConfig {
|
||||||
|
visibility?: Condition[];
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mixin to handle conditional listeners for visibility control
|
||||||
|
*
|
||||||
|
* Provides lifecycle management for listeners that control conditional
|
||||||
|
* visibility of components.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* 1. Extend your component with ConditionalListenerMixin<YourConfigType>(ReactiveElement)
|
||||||
|
* 2. Ensure component has config.visibility or _config.visibility property with conditions
|
||||||
|
* 3. Ensure component has _updateVisibility() or _updateElement() method
|
||||||
|
* 4. Override setupConditionalListeners() if custom behavior needed (e.g., filter conditions)
|
||||||
|
*
|
||||||
|
* The mixin automatically:
|
||||||
|
* - Sets up listeners when component connects to DOM
|
||||||
|
* - Cleans up listeners when component disconnects from DOM
|
||||||
|
* - Handles conditional visibility based on defined conditions
|
||||||
|
*/
|
||||||
|
export const ConditionalListenerMixin = <
|
||||||
|
TConfig extends ConditionalConfig = ConditionalConfig,
|
||||||
|
>(
|
||||||
|
superClass: Constructor<ReactiveElement>
|
||||||
|
) => {
|
||||||
|
abstract class ConditionalListenerClass extends superClass {
|
||||||
|
private __listeners: (() => void)[] = [];
|
||||||
|
|
||||||
|
protected _config?: TConfig;
|
||||||
|
|
||||||
|
public config?: TConfig;
|
||||||
|
|
||||||
|
public hass?: HomeAssistant;
|
||||||
|
|
||||||
|
protected _updateElement?(config: TConfig): void;
|
||||||
|
|
||||||
|
protected _updateVisibility?(conditionsMet?: boolean): void;
|
||||||
|
|
||||||
|
public connectedCallback() {
|
||||||
|
super.connectedCallback();
|
||||||
|
this.setupConditionalListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this.clearConditionalListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear conditional listeners
|
||||||
|
*
|
||||||
|
* This method is called when the component is disconnected from the DOM.
|
||||||
|
* It clears all the listeners that were set up by the setupConditionalListeners() method.
|
||||||
|
*/
|
||||||
|
protected clearConditionalListeners(): void {
|
||||||
|
this.__listeners.forEach((unsub) => unsub());
|
||||||
|
this.__listeners = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a conditional listener to the list of listeners
|
||||||
|
*
|
||||||
|
* This method is called when a new listener is added.
|
||||||
|
* It adds the listener to the list of listeners.
|
||||||
|
*
|
||||||
|
* @param unsubscribe - The unsubscribe function to call when the listener is no longer needed
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
protected addConditionalListener(unsubscribe: () => void): void {
|
||||||
|
this.__listeners.push(unsubscribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup conditional listeners for visibility control
|
||||||
|
*
|
||||||
|
* Default implementation:
|
||||||
|
* - Checks config.visibility or _config.visibility for conditions (if not provided)
|
||||||
|
* - Sets up appropriate listeners based on condition types
|
||||||
|
* - Calls _updateVisibility() or _updateElement() when conditions change
|
||||||
|
*
|
||||||
|
* Override this method to customize behavior (e.g., filter conditions first)
|
||||||
|
* and call super.setupConditionalListeners(customConditions) to reuse the base implementation
|
||||||
|
*
|
||||||
|
* @param conditions - Optional conditions array. If not provided, will check config.visibility or _config.visibility
|
||||||
|
*/
|
||||||
|
protected setupConditionalListeners(conditions?: Condition[]): void {
|
||||||
|
const config = this.config || this._config;
|
||||||
|
const finalConditions = conditions || config?.visibility;
|
||||||
|
|
||||||
|
if (!finalConditions || !this.hass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onUpdate = (conditionsMet: boolean) => {
|
||||||
|
if (this._updateVisibility) {
|
||||||
|
this._updateVisibility(conditionsMet);
|
||||||
|
} else if (this._updateElement && config) {
|
||||||
|
this._updateElement(config);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setupMediaQueryListeners(
|
||||||
|
finalConditions,
|
||||||
|
this.hass,
|
||||||
|
(unsub) => this.addConditionalListener(unsub),
|
||||||
|
onUpdate
|
||||||
|
);
|
||||||
|
|
||||||
|
setupTimeListeners(
|
||||||
|
finalConditions,
|
||||||
|
this.hass,
|
||||||
|
(unsub) => this.addConditionalListener(unsub),
|
||||||
|
onUpdate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ConditionalListenerClass;
|
||||||
|
};
|
||||||
@@ -332,6 +332,15 @@ class DialogCalendarEventEditor extends LitElement {
|
|||||||
|
|
||||||
private _allDayToggleChanged(ev) {
|
private _allDayToggleChanged(ev) {
|
||||||
this._allDay = ev.target.checked;
|
this._allDay = ev.target.checked;
|
||||||
|
// When switching to all-day mode, normalize dates to midnight so time portions don't interfere with date comparisons
|
||||||
|
if (this._allDay && this._dtstart && this._dtend) {
|
||||||
|
this._dtstart = new Date(
|
||||||
|
formatDate(this._dtstart, this._timeZone!) + "T00:00:00"
|
||||||
|
);
|
||||||
|
this._dtend = new Date(
|
||||||
|
formatDate(this._dtend, this._timeZone!) + "T00:00:00"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _startDateChanged(ev: CustomEvent) {
|
private _startDateChanged(ev: CustomEvent) {
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||||
import { LitElement, css, html } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { goBack } from "../../common/navigate";
|
import { goBack } from "../../common/navigate";
|
||||||
|
import { debounce } from "../../common/util/debounce";
|
||||||
|
import { deepEqual } from "../../common/util/deep-equal";
|
||||||
import "../../components/ha-icon-button-arrow-prev";
|
import "../../components/ha-icon-button-arrow-prev";
|
||||||
import "../../components/ha-menu-button";
|
import "../../components/ha-menu-button";
|
||||||
import type { LovelaceConfig } from "../../data/lovelace/config/types";
|
import type { LovelaceStrategyViewConfig } from "../../data/lovelace/config/view";
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { generateLovelaceViewStrategy } from "../lovelace/strategies/get-strategy";
|
||||||
import type { Lovelace } from "../lovelace/types";
|
import type { Lovelace } from "../lovelace/types";
|
||||||
import "../lovelace/views/hui-view";
|
import "../lovelace/views/hui-view";
|
||||||
import "../lovelace/views/hui-view-container";
|
import "../lovelace/views/hui-view-container";
|
||||||
|
|
||||||
const CLIMATE_LOVELACE_CONFIG: LovelaceConfig = {
|
const CLIMATE_LOVELACE_VIEW_CONFIG: LovelaceStrategyViewConfig = {
|
||||||
views: [
|
strategy: {
|
||||||
{
|
type: "climate",
|
||||||
strategy: {
|
},
|
||||||
type: "climate",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@customElement("ha-panel-climate")
|
@customElement("ha-panel-climate")
|
||||||
@@ -33,65 +32,119 @@ class PanelClimate extends LitElement {
|
|||||||
|
|
||||||
@state() private _searchParms = new URLSearchParams(window.location.search);
|
@state() private _searchParms = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
public firstUpdated(_changedProperties: PropertyValues): void {
|
|
||||||
super.firstUpdated(_changedProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public willUpdate(changedProps: PropertyValues) {
|
public willUpdate(changedProps: PropertyValues) {
|
||||||
|
super.willUpdate(changedProps);
|
||||||
|
// Initial setup
|
||||||
if (!this.hasUpdated) {
|
if (!this.hasUpdated) {
|
||||||
this.hass.loadFragmentTranslation("lovelace");
|
this.hass.loadFragmentTranslation("lovelace");
|
||||||
|
this._setLovelace();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changedProps.has("hass")) {
|
if (!changedProps.has("hass")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldHass = changedProps.get("hass") as this["hass"];
|
const oldHass = changedProps.get("hass") as this["hass"];
|
||||||
if (oldHass?.locale !== this.hass.locale) {
|
if (oldHass && oldHass.localize !== this.hass.localize) {
|
||||||
this._setLovelace();
|
this._setLovelace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldHass && this.hass) {
|
||||||
|
// If the entity registry changed, ask the user if they want to refresh the config
|
||||||
|
if (
|
||||||
|
oldHass.entities !== this.hass.entities ||
|
||||||
|
oldHass.devices !== this.hass.devices ||
|
||||||
|
oldHass.areas !== this.hass.areas ||
|
||||||
|
oldHass.floors !== this.hass.floors
|
||||||
|
) {
|
||||||
|
if (this.hass.config.state === "RUNNING") {
|
||||||
|
this._debounceRegistriesChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If ha started, refresh the config
|
||||||
|
if (
|
||||||
|
this.hass.config.state === "RUNNING" &&
|
||||||
|
oldHass.config.state !== "RUNNING"
|
||||||
|
) {
|
||||||
|
this._setLovelace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _debounceRegistriesChanged = debounce(
|
||||||
|
() => this._registriesChanged(),
|
||||||
|
200
|
||||||
|
);
|
||||||
|
|
||||||
|
private _registriesChanged = async () => {
|
||||||
|
this._setLovelace();
|
||||||
|
};
|
||||||
|
|
||||||
private _back(ev) {
|
private _back(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
goBack();
|
goBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
${this._searchParms.has("historyBack")
|
${
|
||||||
? html`
|
this._searchParms.has("historyBack")
|
||||||
<ha-icon-button-arrow-prev
|
? html`
|
||||||
@click=${this._back}
|
<ha-icon-button-arrow-prev
|
||||||
slot="navigationIcon"
|
@click=${this._back}
|
||||||
></ha-icon-button-arrow-prev>
|
slot="navigationIcon"
|
||||||
`
|
></ha-icon-button-arrow-prev>
|
||||||
: html`
|
`
|
||||||
<ha-menu-button
|
: html`
|
||||||
slot="navigationIcon"
|
<ha-menu-button
|
||||||
.hass=${this.hass}
|
slot="navigationIcon"
|
||||||
.narrow=${this.narrow}
|
.hass=${this.hass}
|
||||||
></ha-menu-button>
|
.narrow=${this.narrow}
|
||||||
`}
|
></ha-menu-button>
|
||||||
|
`
|
||||||
|
}
|
||||||
<div class="main-title">${this.hass.localize("panel.climate")}</div>
|
<div class="main-title">${this.hass.localize("panel.climate")}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
${
|
||||||
<hui-view-container .hass=${this.hass}>
|
this._lovelace
|
||||||
<hui-view
|
? html`
|
||||||
.hass=${this.hass}
|
<hui-view-container .hass=${this.hass}>
|
||||||
.narrow=${this.narrow}
|
<hui-view
|
||||||
.lovelace=${this._lovelace}
|
.hass=${this.hass}
|
||||||
.index=${this._viewIndex}
|
.narrow=${this.narrow}
|
||||||
></hui-view>
|
.lovelace=${this._lovelace}
|
||||||
|
.index=${this._viewIndex}
|
||||||
|
></hui-view
|
||||||
|
></hui-view-container>
|
||||||
|
`
|
||||||
|
: nothing
|
||||||
|
}
|
||||||
</hui-view-container>
|
</hui-view-container>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setLovelace() {
|
private async _setLovelace() {
|
||||||
|
const viewConfig = await generateLovelaceViewStrategy(
|
||||||
|
CLIMATE_LOVELACE_VIEW_CONFIG,
|
||||||
|
this.hass
|
||||||
|
);
|
||||||
|
|
||||||
|
const config = { views: [viewConfig] };
|
||||||
|
const rawConfig = { views: [CLIMATE_LOVELACE_VIEW_CONFIG] };
|
||||||
|
|
||||||
|
if (deepEqual(config, this._lovelace?.config)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._lovelace = {
|
this._lovelace = {
|
||||||
config: CLIMATE_LOVELACE_CONFIG,
|
config: config,
|
||||||
rawConfig: CLIMATE_LOVELACE_CONFIG,
|
rawConfig: rawConfig,
|
||||||
editMode: false,
|
editMode: false,
|
||||||
urlPath: "climate",
|
urlPath: "climate",
|
||||||
mode: "generated",
|
mode: "generated",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
getFloors,
|
getFloors,
|
||||||
} from "../../lovelace/strategies/areas/helpers/areas-strategy-helper";
|
} from "../../lovelace/strategies/areas/helpers/areas-strategy-helper";
|
||||||
import { getHomeStructure } from "../../lovelace/strategies/home/helpers/home-structure";
|
import { getHomeStructure } from "../../lovelace/strategies/home/helpers/home-structure";
|
||||||
|
import { floorDefaultIcon } from "../../../components/ha-floor-icon";
|
||||||
|
|
||||||
export interface ClimateViewStrategyConfig {
|
export interface ClimateViewStrategyConfig {
|
||||||
type: "climate";
|
type: "climate";
|
||||||
@@ -114,6 +115,24 @@ const processAreasForClimate = (
|
|||||||
return cards;
|
return cards;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const processUnassignedEntities = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entities: string[]
|
||||||
|
): LovelaceCardConfig[] => {
|
||||||
|
const unassignedFilter = generateEntityFilter(hass, {
|
||||||
|
area: null,
|
||||||
|
});
|
||||||
|
const unassignedEntities = entities.filter(unassignedFilter);
|
||||||
|
const areaCards: LovelaceCardConfig[] = [];
|
||||||
|
const computeTileCard = computeAreaTileCardConfig(hass, "", true);
|
||||||
|
|
||||||
|
for (const entityId of unassignedEntities) {
|
||||||
|
areaCards.push(computeTileCard(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return areaCards;
|
||||||
|
};
|
||||||
|
|
||||||
@customElement("climate-view-strategy")
|
@customElement("climate-view-strategy")
|
||||||
export class ClimateViewStrategy extends ReactiveElement {
|
export class ClimateViewStrategy extends ReactiveElement {
|
||||||
static async generate(
|
static async generate(
|
||||||
@@ -152,6 +171,7 @@ export class ClimateViewStrategy extends ReactiveElement {
|
|||||||
floorCount > 1
|
floorCount > 1
|
||||||
? floor.name
|
? floor.name
|
||||||
: hass.localize("ui.panel.lovelace.strategy.home.areas"),
|
: hass.localize("ui.panel.lovelace.strategy.home.areas"),
|
||||||
|
icon: floor.icon || floorDefaultIcon(floor),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -188,10 +208,33 @@ export class ClimateViewStrategy extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process unassigned entities
|
||||||
|
const unassignedCards = processUnassignedEntities(hass, entities);
|
||||||
|
|
||||||
|
if (unassignedCards.length > 0) {
|
||||||
|
const section: LovelaceSectionRawConfig = {
|
||||||
|
type: "grid",
|
||||||
|
column_span: 2,
|
||||||
|
cards: [
|
||||||
|
{
|
||||||
|
type: "heading",
|
||||||
|
heading:
|
||||||
|
sections.length > 0
|
||||||
|
? hass.localize(
|
||||||
|
"ui.panel.lovelace.strategy.climate.other_devices"
|
||||||
|
)
|
||||||
|
: hass.localize("ui.panel.lovelace.strategy.climate.devices"),
|
||||||
|
},
|
||||||
|
...unassignedCards,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
sections.push(section);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "sections",
|
type: "sections",
|
||||||
max_columns: 2,
|
max_columns: 2,
|
||||||
sections: sections || [],
|
sections: sections,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ export class HaConfigApplicationCredentials extends LitElement {
|
|||||||
),
|
),
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
direction: "asc",
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
title: "",
|
title: "",
|
||||||
|
|||||||
@@ -8,24 +8,24 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
|||||||
import "../../../components/chips/ha-chip-set";
|
import "../../../components/chips/ha-chip-set";
|
||||||
import "../../../components/chips/ha-input-chip";
|
import "../../../components/chips/ha-input-chip";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-button";
|
|
||||||
import "../../../components/ha-aliases-editor";
|
import "../../../components/ha-aliases-editor";
|
||||||
|
import "../../../components/ha-area-picker";
|
||||||
|
import "../../../components/ha-button";
|
||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
import "../../../components/ha-icon-picker";
|
import "../../../components/ha-icon-picker";
|
||||||
import "../../../components/ha-picture-upload";
|
import "../../../components/ha-picture-upload";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import "../../../components/ha-area-picker";
|
import { updateAreaRegistryEntry } from "../../../data/area_registry";
|
||||||
import type {
|
import type {
|
||||||
FloorRegistryEntry,
|
FloorRegistryEntry,
|
||||||
FloorRegistryEntryMutableParams,
|
FloorRegistryEntryMutableParams,
|
||||||
} from "../../../data/floor_registry";
|
} from "../../../data/floor_registry";
|
||||||
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import type { FloorRegistryDetailDialogParams } from "./show-dialog-floor-registry-detail";
|
|
||||||
import { showAreaRegistryDetailDialog } from "./show-dialog-area-registry-detail";
|
import { showAreaRegistryDetailDialog } from "./show-dialog-area-registry-detail";
|
||||||
import { updateAreaRegistryEntry } from "../../../data/area_registry";
|
import type { FloorRegistryDetailDialogParams } from "./show-dialog-floor-registry-detail";
|
||||||
|
|
||||||
class DialogFloorDetail extends LitElement {
|
class DialogFloorDetail extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -168,11 +168,6 @@ class DialogFloorDetail extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<p class="description">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.floors.editor.areas_description"
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
${areas.length
|
${areas.length
|
||||||
? html`<ha-chip-set>
|
? html`<ha-chip-set>
|
||||||
${repeat(
|
${repeat(
|
||||||
@@ -197,13 +192,17 @@ class DialogFloorDetail extends LitElement {
|
|||||||
</ha-input-chip>`
|
</ha-input-chip>`
|
||||||
)}
|
)}
|
||||||
</ha-chip-set>`
|
</ha-chip-set>`
|
||||||
: nothing}
|
: html`<p class="description">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.floors.editor.areas_description"
|
||||||
|
)}
|
||||||
|
</p>`}
|
||||||
<ha-area-picker
|
<ha-area-picker
|
||||||
no-add
|
no-add
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@value-changed=${this._addArea}
|
@value-changed=${this._addArea}
|
||||||
.excludeAreas=${areas.map((a) => a.area_id)}
|
.excludeAreas=${areas.map((a) => a.area_id)}
|
||||||
.label=${this.hass.localize(
|
.addButtonLabel=${this.hass.localize(
|
||||||
"ui.panel.config.floors.editor.add_area"
|
"ui.panel.config.floors.editor.add_area"
|
||||||
)}
|
)}
|
||||||
></ha-area-picker>
|
></ha-area-picker>
|
||||||
|
|||||||
@@ -588,7 +588,11 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
...this._clipboard,
|
...this._clipboard,
|
||||||
action: deepClone(this.action),
|
action: deepClone(this.action),
|
||||||
};
|
};
|
||||||
copyToClipboard(dump(this.action));
|
let action = this.action;
|
||||||
|
if ("sequence" in action) {
|
||||||
|
action = { ...this.action, metadata: {} };
|
||||||
|
}
|
||||||
|
copyToClipboard(dump(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onDisable = () => {
|
private _onDisable = () => {
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ class DialogAddAutomationElement
|
|||||||
|
|
||||||
const results = fuse.multiTermsSearch(filter);
|
const results = fuse.multiTermsSearch(filter);
|
||||||
if (results) {
|
if (results) {
|
||||||
return results.map((result) => result.item);
|
return results.map((result) => result.item).filter((item) => item.name);
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ class DialogAddAutomationElement
|
|||||||
|
|
||||||
const results = fuse.multiTermsSearch(filter);
|
const results = fuse.multiTermsSearch(filter);
|
||||||
if (results) {
|
if (results) {
|
||||||
return results.map((result) => result.item);
|
return results.map((result) => result.item).filter((item) => item.name);
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -383,9 +383,16 @@ class DialogAddAutomationElement
|
|||||||
|
|
||||||
generatedCollections.push({
|
generatedCollections.push({
|
||||||
titleKey: collection.titleKey,
|
titleKey: collection.titleKey,
|
||||||
groups: groups.sort((a, b) =>
|
groups: groups.sort((a, b) => {
|
||||||
stringCompare(a.name, b.name, this.hass.locale.language)
|
// make sure device is always on top
|
||||||
),
|
if (a.key === "device" || a.key === "device_id") {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (b.key === "device" || b.key === "device_id") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stringCompare(a.name, b.name, this.hass.locale.language);
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return generatedCollections;
|
return generatedCollections;
|
||||||
@@ -678,7 +685,7 @@ class DialogAddAutomationElement
|
|||||||
);
|
);
|
||||||
|
|
||||||
const typeTitle = this.hass.localize(
|
const typeTitle = this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.${automationElementType}s.header`
|
`ui.panel.config.automation.editor.${automationElementType}s.add`
|
||||||
);
|
);
|
||||||
|
|
||||||
const tabButtons = [
|
const tabButtons = [
|
||||||
@@ -895,7 +902,9 @@ class DialogAddAutomationElement
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="items-title ${this._itemsScrolled ? "scrolled" : ""}">
|
<div class="items-title ${this._itemsScrolled ? "scrolled" : ""}">
|
||||||
${title}
|
${this._tab === "blocks" && !this._filter
|
||||||
|
? this.hass.localize("ui.panel.config.automation.editor.blocks")
|
||||||
|
: title}
|
||||||
</div>
|
</div>
|
||||||
<ha-md-list
|
<ha-md-list
|
||||||
dialogInitialFocus=${ifDefined(this._fullScreen ? "" : undefined)}
|
dialogInitialFocus=${ifDefined(this._fullScreen ? "" : undefined)}
|
||||||
@@ -1045,6 +1054,7 @@ class DialogAddAutomationElement
|
|||||||
private _onSearchFocus(ev) {
|
private _onSearchFocus(ev) {
|
||||||
this._removeKeyboardShortcuts = tinykeys(ev.target, {
|
this._removeKeyboardShortcuts = tinykeys(ev.target, {
|
||||||
ArrowDown: this._focusSearchList,
|
ArrowDown: this._focusSearchList,
|
||||||
|
Enter: this._pickSingleItem,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,6 +1071,39 @@ class DialogAddAutomationElement
|
|||||||
this._itemsListFirstElement.focus();
|
this._itemsListFirstElement.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _pickSingleItem = (ev: KeyboardEvent) => {
|
||||||
|
if (!this._filter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev.preventDefault();
|
||||||
|
const automationElementType = this._params!.type;
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
...this._getFilteredItems(
|
||||||
|
automationElementType,
|
||||||
|
this._filter,
|
||||||
|
this.hass.localize,
|
||||||
|
this.hass.services,
|
||||||
|
this._manifests
|
||||||
|
),
|
||||||
|
...(automationElementType !== "trigger"
|
||||||
|
? this._getFilteredBuildingBlocks(
|
||||||
|
automationElementType,
|
||||||
|
this._filter,
|
||||||
|
this.hass.localize
|
||||||
|
)
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (items.length !== 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._params!.add(items[0].key);
|
||||||
|
this.closeDialog();
|
||||||
|
};
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
css`
|
css`
|
||||||
@@ -1137,11 +1180,11 @@ class DialogAddAutomationElement
|
|||||||
}
|
}
|
||||||
.groups .selected {
|
.groups .selected {
|
||||||
background-color: var(--ha-color-fill-primary-normal-active);
|
background-color: var(--ha-color-fill-primary-normal-active);
|
||||||
--md-list-item-label-text-color: var(--primary-color);
|
--md-list-item-label-text-color: var(--ha-color-on-primary-normal);
|
||||||
--icon-primary-color: var(--primary-color);
|
--icon-primary-color: var(--ha-color-on-primary-normal);
|
||||||
}
|
}
|
||||||
.groups .selected ha-svg-icon {
|
.groups .selected ha-svg-icon {
|
||||||
color: var(--primary-color);
|
color: var(--ha-color-on-primary-normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
.collection-title {
|
.collection-title {
|
||||||
|
|||||||
@@ -452,7 +452,10 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
|
|||||||
.indeterminate=${partial}
|
.indeterminate=${partial}
|
||||||
reducedTouchTarget
|
reducedTouchTarget
|
||||||
></ha-checkbox>
|
></ha-checkbox>
|
||||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
<ha-label
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
|
>
|
||||||
${label.icon
|
${label.icon
|
||||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import "../../../../components/ha-md-divider";
|
|||||||
import "../../../../components/ha-md-menu-item";
|
import "../../../../components/ha-md-menu-item";
|
||||||
import { ACTION_BUILDING_BLOCKS } from "../../../../data/action";
|
import { ACTION_BUILDING_BLOCKS } from "../../../../data/action";
|
||||||
import type { ActionSidebarConfig } from "../../../../data/automation";
|
import type { ActionSidebarConfig } from "../../../../data/automation";
|
||||||
import type { RepeatAction } from "../../../../data/script";
|
import { domainToName } from "../../../../data/integration";
|
||||||
|
import type { RepeatAction, ServiceAction } from "../../../../data/script";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import { isMac } from "../../../../util/is_mac";
|
import { isMac } from "../../../../util/is_mac";
|
||||||
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
|
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
|
||||||
@@ -83,11 +84,23 @@ export default class HaAutomationSidebarAction extends LitElement {
|
|||||||
"ui.panel.config.automation.editor.actions.action"
|
"ui.panel.config.automation.editor.actions.action"
|
||||||
);
|
);
|
||||||
|
|
||||||
const title =
|
let title =
|
||||||
this.hass.localize(
|
this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.actions.type.${type}.label` as LocalizeKeys
|
`ui.panel.config.automation.editor.actions.type.${type}.label` as LocalizeKeys
|
||||||
) || type;
|
) || type;
|
||||||
|
|
||||||
|
if (type === "service" && (actionConfig as ServiceAction).action) {
|
||||||
|
const [domain, service] = (actionConfig as ServiceAction).action!.split(
|
||||||
|
".",
|
||||||
|
2
|
||||||
|
);
|
||||||
|
title = `${domainToName(this.hass.localize, domain)}: ${
|
||||||
|
this.hass.localize(`component.${domain}.services.${service}.name`) ||
|
||||||
|
this.hass.services[domain][service]?.name ||
|
||||||
|
title
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
const description = isBuildingBlock
|
const description = isBuildingBlock
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.actions.type.${type}.description.picker` as LocalizeKeys
|
`ui.panel.config.automation.editor.actions.type.${type}.description.picker` as LocalizeKeys
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
mdiContentCopy,
|
mdiContentCopy,
|
||||||
mdiContentCut,
|
mdiContentCut,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
|
mdiIdentifier,
|
||||||
mdiPlayCircleOutline,
|
mdiPlayCircleOutline,
|
||||||
mdiPlaylistEdit,
|
mdiPlaylistEdit,
|
||||||
mdiPlusCircleMultipleOutline,
|
mdiPlusCircleMultipleOutline,
|
||||||
@@ -40,6 +41,8 @@ export default class HaAutomationSidebarTrigger extends LitElement {
|
|||||||
@property({ type: Number, attribute: "sidebar-key" })
|
@property({ type: Number, attribute: "sidebar-key" })
|
||||||
public sidebarKey?: number;
|
public sidebarKey?: number;
|
||||||
|
|
||||||
|
@state() private _requestShowId = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@query(".sidebar-editor")
|
@query(".sidebar-editor")
|
||||||
@@ -47,6 +50,7 @@ export default class HaAutomationSidebarTrigger extends LitElement {
|
|||||||
|
|
||||||
protected willUpdate(changedProperties) {
|
protected willUpdate(changedProperties) {
|
||||||
if (changedProperties.has("config")) {
|
if (changedProperties.has("config")) {
|
||||||
|
this._requestShowId = false;
|
||||||
this._warnings = undefined;
|
this._warnings = undefined;
|
||||||
if (this.config) {
|
if (this.config) {
|
||||||
this.yamlMode = this.config.yamlMode;
|
this.yamlMode = this.config.yamlMode;
|
||||||
@@ -101,6 +105,24 @@ export default class HaAutomationSidebarTrigger extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
</ha-md-menu-item>
|
</ha-md-menu-item>
|
||||||
|
|
||||||
|
${!this.yamlMode &&
|
||||||
|
!("id" in this.config.config) &&
|
||||||
|
!this._requestShowId
|
||||||
|
? html`<ha-md-menu-item
|
||||||
|
slot="menu-items"
|
||||||
|
.clickAction=${this._showTriggerId}
|
||||||
|
.disabled=${this.disabled || type === "list"}
|
||||||
|
>
|
||||||
|
<ha-svg-icon slot="start" .path=${mdiIdentifier}></ha-svg-icon>
|
||||||
|
<div class="overflow-label">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.edit_id"
|
||||||
|
)}
|
||||||
|
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
|
||||||
|
</div>
|
||||||
|
</ha-md-menu-item>`
|
||||||
|
: nothing}
|
||||||
|
|
||||||
<ha-md-divider
|
<ha-md-divider
|
||||||
slot="menu-items"
|
slot="menu-items"
|
||||||
role="separator"
|
role="separator"
|
||||||
@@ -250,6 +272,7 @@ export default class HaAutomationSidebarTrigger extends LitElement {
|
|||||||
@value-changed=${this._valueChangedSidebar}
|
@value-changed=${this._valueChangedSidebar}
|
||||||
@yaml-changed=${this._yamlChangedSidebar}
|
@yaml-changed=${this._yamlChangedSidebar}
|
||||||
.uiSupported=${this.config.uiSupported}
|
.uiSupported=${this.config.uiSupported}
|
||||||
|
.showId=${this._requestShowId}
|
||||||
.yamlMode=${this.yamlMode}
|
.yamlMode=${this.yamlMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@ui-mode-not-available=${this._handleUiModeNotAvailable}
|
@ui-mode-not-available=${this._handleUiModeNotAvailable}
|
||||||
@@ -292,6 +315,10 @@ export default class HaAutomationSidebarTrigger extends LitElement {
|
|||||||
fireEvent(this, "toggle-yaml-mode");
|
fireEvent(this, "toggle-yaml-mode");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _showTriggerId = () => {
|
||||||
|
this._requestShowId = true;
|
||||||
|
};
|
||||||
|
|
||||||
static styles = [sidebarEditorStyles, overflowStyles];
|
static styles = [sidebarEditorStyles, overflowStyles];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export default class HaAutomationTriggerEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean, attribute: "sidebar" }) public inSidebar = false;
|
@property({ type: Boolean, attribute: "sidebar" }) public inSidebar = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "show-id" }) public showId = false;
|
||||||
|
|
||||||
@query("ha-yaml-editor") public yamlEditor?: HaYamlEditor;
|
@query("ha-yaml-editor") public yamlEditor?: HaYamlEditor;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@@ -36,6 +38,8 @@ export default class HaAutomationTriggerEditor extends LitElement {
|
|||||||
|
|
||||||
const yamlMode = this.yamlMode || !this.uiSupported;
|
const yamlMode = this.yamlMode || !this.uiSupported;
|
||||||
|
|
||||||
|
const showId = "id" in this.trigger || this.showId;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@@ -70,20 +74,15 @@ export default class HaAutomationTriggerEditor extends LitElement {
|
|||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
${!isTriggerList(this.trigger)
|
${showId && !isTriggerList(this.trigger)
|
||||||
? html`
|
? html`
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
.label=${`${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.id"
|
"ui.panel.config.automation.editor.triggers.id"
|
||||||
)} (${this.hass.localize(
|
)}
|
||||||
"ui.panel.config.automation.editor.triggers.optional"
|
|
||||||
)})`}
|
|
||||||
.value=${this.trigger.id || ""}
|
.value=${this.trigger.id || ""}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@change=${this._idChanged}
|
@change=${this._idChanged}
|
||||||
.helper=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.triggers.id_helper"
|
|
||||||
)}
|
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|||||||
@@ -245,18 +245,20 @@ export class HaStateTrigger extends LitElement implements TriggerElement {
|
|||||||
newTrigger.to,
|
newTrigger.to,
|
||||||
newTrigger.attribute
|
newTrigger.attribute
|
||||||
);
|
);
|
||||||
|
if (Array.isArray(newTrigger.to) && newTrigger.to.length === 0) {
|
||||||
|
delete newTrigger.to;
|
||||||
|
}
|
||||||
newTrigger.from = this._applyAnyStateExclusive(
|
newTrigger.from = this._applyAnyStateExclusive(
|
||||||
newTrigger.from,
|
newTrigger.from,
|
||||||
newTrigger.attribute
|
newTrigger.attribute
|
||||||
);
|
);
|
||||||
|
if (Array.isArray(newTrigger.from) && newTrigger.from.length === 0) {
|
||||||
|
delete newTrigger.from;
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(newTrigger).forEach((key) => {
|
Object.keys(newTrigger).forEach((key) => {
|
||||||
const val = newTrigger[key];
|
const val = newTrigger[key];
|
||||||
if (
|
if (val === undefined || val === "") {
|
||||||
val === undefined ||
|
|
||||||
val === "" ||
|
|
||||||
(Array.isArray(val) && val.length === 0)
|
|
||||||
) {
|
|
||||||
delete newTrigger[key];
|
delete newTrigger[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -125,8 +125,6 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@query("#overflow-menu") private _overflowMenu?: HaMdMenu;
|
@query("#overflow-menu") private _overflowMenu?: HaMdMenu;
|
||||||
|
|
||||||
private _overflowBackup?: BackupContent;
|
|
||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
window.addEventListener("location-changed", this._locationChanged);
|
window.addEventListener("location-changed", this._locationChanged);
|
||||||
@@ -262,7 +260,7 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
type: "overflow-menu",
|
type: "overflow-menu",
|
||||||
template: (backup) => html`
|
template: (backup) => html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.selected=${backup}
|
.backup=${backup}
|
||||||
.label=${this.hass.localize("ui.common.overflow_menu")}
|
.label=${this.hass.localize("ui.common.overflow_menu")}
|
||||||
.path=${mdiDotsVertical}
|
.path=${mdiDotsVertical}
|
||||||
@click=${this._toggleOverflowMenu}
|
@click=${this._toggleOverflowMenu}
|
||||||
@@ -294,7 +292,6 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
this._overflowMenu.close();
|
this._overflowMenu.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._overflowBackup = ev.target.selected;
|
|
||||||
this._overflowMenu.anchorElement = ev.target;
|
this._overflowMenu.anchorElement = ev.target;
|
||||||
this._overflowMenu.show();
|
this._overflowMenu.show();
|
||||||
};
|
};
|
||||||
@@ -375,16 +372,14 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
clickable
|
clickable
|
||||||
id="backup_id"
|
id="backup_id"
|
||||||
has-filters
|
has-filters
|
||||||
.filters=${
|
.filters=${Object.values(this._filters).filter((filter) =>
|
||||||
Object.values(this._filters).filter((filter) =>
|
Array.isArray(filter)
|
||||||
Array.isArray(filter)
|
? filter.length
|
||||||
? filter.length
|
: filter &&
|
||||||
: filter &&
|
Object.values(filter).some((val) =>
|
||||||
Object.values(filter).some((val) =>
|
Array.isArray(val) ? val.length : val
|
||||||
Array.isArray(val) ? val.length : val
|
)
|
||||||
)
|
).length}
|
||||||
).length
|
|
||||||
}
|
|
||||||
selectable
|
selectable
|
||||||
.selected=${this._selected.length}
|
.selected=${this._selected.length}
|
||||||
.initialGroupColumn=${this._activeGrouping}
|
.initialGroupColumn=${this._activeGrouping}
|
||||||
@@ -426,30 +421,28 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div slot="selection-bar">
|
<div slot="selection-bar">
|
||||||
${
|
${!this.narrow
|
||||||
!this.narrow
|
? html`
|
||||||
? html`
|
<ha-button
|
||||||
<ha-button
|
appearance="plain"
|
||||||
appearance="plain"
|
@click=${this._deleteSelected}
|
||||||
@click=${this._deleteSelected}
|
variant="danger"
|
||||||
variant="danger"
|
>
|
||||||
>
|
${this.hass.localize(
|
||||||
${this.hass.localize(
|
"ui.panel.config.backup.backups.delete_selected"
|
||||||
"ui.panel.config.backup.backups.delete_selected"
|
)}
|
||||||
)}
|
</ha-button>
|
||||||
</ha-button>
|
`
|
||||||
`
|
: html`
|
||||||
: html`
|
<ha-icon-button
|
||||||
<ha-icon-button
|
.label=${this.hass.localize(
|
||||||
.label=${this.hass.localize(
|
"ui.panel.config.backup.backups.delete_selected"
|
||||||
"ui.panel.config.backup.backups.delete_selected"
|
)}
|
||||||
)}
|
.path=${mdiDelete}
|
||||||
.path=${mdiDelete}
|
class="warning"
|
||||||
class="warning"
|
@click=${this._deleteSelected}
|
||||||
@click=${this._deleteSelected}
|
></ha-icon-button>
|
||||||
></ha-icon-button>
|
`}
|
||||||
`
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-filter-states
|
<ha-filter-states
|
||||||
@@ -462,43 +455,39 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
expanded
|
expanded
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
></ha-filter-states>
|
></ha-filter-states>
|
||||||
${
|
${!this._needsOnboarding
|
||||||
!this._needsOnboarding
|
? html`
|
||||||
? html`
|
<ha-fab
|
||||||
<ha-fab
|
slot="fab"
|
||||||
slot="fab"
|
?disabled=${backupInProgress}
|
||||||
?disabled=${backupInProgress}
|
.label=${this.hass.localize(
|
||||||
.label=${this.hass.localize(
|
"ui.panel.config.backup.backups.new_backup"
|
||||||
"ui.panel.config.backup.backups.new_backup"
|
)}
|
||||||
)}
|
extended
|
||||||
extended
|
@click=${this._newBackup}
|
||||||
@click=${this._newBackup}
|
>
|
||||||
>
|
${backupInProgress
|
||||||
${backupInProgress
|
? html`<div slot="icon" class="loading">
|
||||||
? html`<div slot="icon" class="loading">
|
<ha-spinner .size=${"small"}></ha-spinner>
|
||||||
<ha-spinner .size=${"small"}></ha-spinner>
|
</div>`
|
||||||
</div>`
|
: html`<ha-svg-icon
|
||||||
: html`<ha-svg-icon
|
slot="icon"
|
||||||
slot="icon"
|
.path=${mdiPlus}
|
||||||
.path=${mdiPlus}
|
></ha-svg-icon>`}
|
||||||
></ha-svg-icon>`}
|
</ha-fab>
|
||||||
</ha-fab>
|
`
|
||||||
`
|
: nothing}
|
||||||
: nothing
|
|
||||||
}
|
|
||||||
</hass-tabs-subpage-data-table>
|
</hass-tabs-subpage-data-table>
|
||||||
<ha-md-menu id="overflow-menu" positioning="fixed">
|
<ha-md-menu id="overflow-menu" positioning="fixed">
|
||||||
<ha-md-menu-item .clickAction=${this._downloadBackup}>
|
<ha-md-menu-item .clickAction=${this._downloadBackup}>
|
||||||
<ha-svg-icon slot="start" .path=${mdiDownload}></ha-svg-icon>
|
<ha-svg-icon slot="start" .path=${mdiDownload}></ha-svg-icon>
|
||||||
${this.hass.localize("ui.common.download")}
|
${this.hass.localize("ui.common.download")}
|
||||||
</ha-md-menu-item>
|
</ha-md-menu-item>
|
||||||
<ha-md-menu-item class="warning" .clickAction=${this._deleteBackup}>
|
<ha-md-menu-item class="warning" .clickAction=${this._deleteBackup}>
|
||||||
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
|
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
|
||||||
${this.hass.localize("ui.common.delete")}
|
${this.hass.localize("ui.common.delete")}
|
||||||
</ha-md-menu-item>
|
</ha-md-menu-item>
|
||||||
</ha-md-menu>
|
</ha-md-menu>
|
||||||
>
|
|
||||||
</ha-icon-overflow-menu>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,15 +561,17 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
navigate(`/config/backup/details/${id}`);
|
navigate(`/config/backup/details/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _downloadBackup(): Promise<void> {
|
private _downloadBackup = async (ev): Promise<void> => {
|
||||||
if (!this._overflowBackup) {
|
const backup = ev.parentElement.anchorElement.backup;
|
||||||
|
if (!backup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadBackup(this.hass, this, this._overflowBackup, this.config);
|
downloadBackup(this.hass, this, backup, this.config);
|
||||||
}
|
};
|
||||||
|
|
||||||
private async _deleteBackup(): Promise<void> {
|
private _deleteBackup = async (ev): Promise<void> => {
|
||||||
if (!this._overflowBackup) {
|
const backup = ev.parentElement.anchorElement.backup;
|
||||||
|
if (!backup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,11 +587,9 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteBackup(this.hass, this._overflowBackup.backup_id);
|
await deleteBackup(this.hass, backup.backup_id);
|
||||||
if (this._selected.includes(this._overflowBackup.backup_id)) {
|
if (this._selected.includes(backup.backup_id)) {
|
||||||
this._selected = this._selected.filter(
|
this._selected = this._selected.filter((id) => id !== backup.backup_id);
|
||||||
(id) => id !== this._overflowBackup!.backup_id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
@@ -612,7 +601,7 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fireEvent(this, "ha-refresh-backup-info");
|
fireEvent(this, "ha-refresh-backup-info");
|
||||||
}
|
};
|
||||||
|
|
||||||
private async _deleteSelected() {
|
private async _deleteSelected() {
|
||||||
const confirm = await showConfirmationDialog(this, {
|
const confirm = await showConfirmationDialog(this, {
|
||||||
|
|||||||
@@ -182,13 +182,11 @@ class HaBlueprintOverview extends LitElement {
|
|||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
groupable: true,
|
groupable: true,
|
||||||
direction: "asc",
|
|
||||||
},
|
},
|
||||||
path: {
|
path: {
|
||||||
title: localize("ui.panel.config.blueprint.overview.headers.file_name"),
|
title: localize("ui.panel.config.blueprint.overview.headers.file_name"),
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
direction: "asc",
|
|
||||||
flex: 2,
|
flex: 2,
|
||||||
},
|
},
|
||||||
fullpath: {
|
fullpath: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { mdiTag, mdiPlus } from "@mdi/js";
|
import { mdiPlus, mdiTag } from "@mdi/js";
|
||||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
@@ -194,8 +194,9 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.category-picker.no_match"
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.category-picker.no_categories"
|
||||||
)}
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@@ -254,6 +255,11 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
|||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.category-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { subscribeEntityRegistry } from "../../../data/entity_registry";
|
|||||||
import type { UpdateEntity } from "../../../data/update";
|
import type { UpdateEntity } from "../../../data/update";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
import "../../../components/ha-progress-ring";
|
||||||
|
|
||||||
@customElement("ha-config-updates")
|
@customElement("ha-config-updates")
|
||||||
class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||||
@@ -56,6 +57,29 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
|||||||
this._entities?.find((entity) => entity.entity_id === entityId)
|
this._entities?.find((entity) => entity.entity_id === entityId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _renderUpdateProgress(entity: UpdateEntity) {
|
||||||
|
if (entity.attributes.update_percentage != null) {
|
||||||
|
return html`<ha-progress-ring
|
||||||
|
size="small"
|
||||||
|
.value=${entity.attributes.update_percentage}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.updates.update_in_progress"
|
||||||
|
)}
|
||||||
|
></ha-progress-ring>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.attributes.in_progress) {
|
||||||
|
return html`<ha-spinner
|
||||||
|
size="small"
|
||||||
|
.ariaLabel=${this.hass.localize(
|
||||||
|
"ui.panel.config.updates.update_in_progress"
|
||||||
|
)}
|
||||||
|
></ha-spinner>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`<ha-icon-next></ha-icon-next>`;
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.updateEntities?.length) {
|
if (!this.updateEntities?.length) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@@ -106,13 +130,9 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
|||||||
)}
|
)}
|
||||||
></state-badge>
|
></state-badge>
|
||||||
${this.narrow && entity.attributes.in_progress
|
${this.narrow && entity.attributes.in_progress
|
||||||
? html`<ha-spinner
|
? html`<div class="absolute">
|
||||||
class="absolute"
|
${this._renderUpdateProgress(entity)}
|
||||||
size="small"
|
</div>`
|
||||||
.ariaLabel=${this.hass.localize(
|
|
||||||
"ui.panel.config.updates.update_in_progress"
|
|
||||||
)}
|
|
||||||
></ha-spinner>`
|
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
<span slot="headline"
|
<span slot="headline"
|
||||||
@@ -128,16 +148,9 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
</span>
|
</span>
|
||||||
${!this.narrow
|
${!this.narrow
|
||||||
? entity.attributes.in_progress
|
? html`<div slot="end">
|
||||||
? html`<div slot="end">
|
${this._renderUpdateProgress(entity)}
|
||||||
<ha-spinner
|
</div>`
|
||||||
size="small"
|
|
||||||
.ariaLabel=${this.hass.localize(
|
|
||||||
"ui.panel.config.updates.update_in_progress"
|
|
||||||
)}
|
|
||||||
></ha-spinner>
|
|
||||||
</div>`
|
|
||||||
: html`<ha-icon-next slot="end"></ha-icon-next>`
|
|
||||||
: nothing}
|
: nothing}
|
||||||
</ha-md-list-item>
|
</ha-md-list-item>
|
||||||
`;
|
`;
|
||||||
@@ -193,13 +206,13 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
|||||||
div[slot="start"] {
|
div[slot="start"] {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
ha-spinner.absolute {
|
div.absolute {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 6px;
|
left: 6px;
|
||||||
top: 6px;
|
top: 6px;
|
||||||
}
|
}
|
||||||
state-badge.updating {
|
state-badge.updating {
|
||||||
opacity: 0.5;
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ export class HaDeviceEntitiesCard extends LitElement {
|
|||||||
addEntitiesToLovelaceView(
|
addEntitiesToLovelaceView(
|
||||||
this,
|
this,
|
||||||
this.hass,
|
this.hass,
|
||||||
computeCards(this.hass.states, entities, {
|
computeCards(this.hass, entities, {
|
||||||
title: this.deviceName,
|
title: this.deviceName,
|
||||||
}),
|
}),
|
||||||
computeSection(entities, {
|
computeSection(entities, {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
|
|||||||
import { computeDeviceNameDisplay } from "../../../../common/entity/compute_device_name";
|
import { computeDeviceNameDisplay } from "../../../../common/entity/compute_device_name";
|
||||||
import "../../../../components/ha-alert";
|
import "../../../../components/ha-alert";
|
||||||
import "../../../../components/ha-area-picker";
|
import "../../../../components/ha-area-picker";
|
||||||
import "../../../../components/ha-wa-dialog";
|
import "../../../../components/ha-dialog";
|
||||||
import "../../../../components/ha-dialog-footer";
|
|
||||||
import "../../../../components/ha-button";
|
import "../../../../components/ha-button";
|
||||||
import "../../../../components/ha-labels-picker";
|
import "../../../../components/ha-labels-picker";
|
||||||
import type { HaSwitch } from "../../../../components/ha-switch";
|
import type { HaSwitch } from "../../../../components/ha-switch";
|
||||||
@@ -20,8 +19,6 @@ import type { DeviceRegistryDetailDialogParams } from "./show-dialog-device-regi
|
|||||||
class DialogDeviceRegistryDetail extends LitElement {
|
class DialogDeviceRegistryDetail extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _open = false;
|
|
||||||
|
|
||||||
@state() private _nameByUser!: string;
|
@state() private _nameByUser!: string;
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
@@ -45,15 +42,10 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
this._areaId = this._params.device.area_id || "";
|
this._areaId = this._params.device.area_id || "";
|
||||||
this._labels = this._params.device.labels || [];
|
this._labels = this._params.device.labels || [];
|
||||||
this._disabledBy = this._params.device.disabled_by;
|
this._disabledBy = this._params.device.disabled_by;
|
||||||
this._open = true;
|
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
this._open = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _dialogClosed(): void {
|
|
||||||
this._error = "";
|
this._error = "";
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
@@ -65,12 +57,10 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
const device = this._params.device;
|
const device = this._params.device;
|
||||||
return html`
|
return html`
|
||||||
<ha-wa-dialog
|
<ha-dialog
|
||||||
.hass=${this.hass}
|
open
|
||||||
.open=${this._open}
|
@closed=${this.closeDialog}
|
||||||
header-title=${computeDeviceNameDisplay(device, this.hass)}
|
.heading=${computeDeviceNameDisplay(device, this.hass)}
|
||||||
prevent-scrim-close
|
|
||||||
@closed=${this._dialogClosed}
|
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
${this._error
|
${this._error
|
||||||
@@ -78,7 +68,6 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
autofocus
|
|
||||||
.value=${this._nameByUser}
|
.value=${this._nameByUser}
|
||||||
@input=${this._nameChanged}
|
@input=${this._nameChanged}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
@@ -86,6 +75,7 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
)}
|
)}
|
||||||
.placeholder=${device.name || ""}
|
.placeholder=${device.name || ""}
|
||||||
.disabled=${this._submitting}
|
.disabled=${this._submitting}
|
||||||
|
dialogInitialFocus
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
<ha-area-picker
|
<ha-area-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -141,25 +131,22 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ha-button
|
||||||
<ha-dialog-footer slot="footer">
|
slot="secondaryAction"
|
||||||
<ha-button
|
@click=${this.closeDialog}
|
||||||
slot="secondaryAction"
|
.disabled=${this._submitting}
|
||||||
@click=${this.closeDialog}
|
appearance="plain"
|
||||||
.disabled=${this._submitting}
|
>
|
||||||
appearance="plain"
|
${this.hass.localize("ui.common.cancel")}
|
||||||
>
|
</ha-button>
|
||||||
${this.hass.localize("ui.common.cancel")}
|
<ha-button
|
||||||
</ha-button>
|
slot="primaryAction"
|
||||||
<ha-button
|
@click=${this._updateEntry}
|
||||||
slot="primaryAction"
|
.disabled=${this._submitting}
|
||||||
@click=${this._updateEntry}
|
>
|
||||||
.disabled=${this._submitting}
|
${this.hass.localize("ui.dialogs.device-registry-detail.update")}
|
||||||
>
|
</ha-button>
|
||||||
${this.hass.localize("ui.dialogs.device-registry-detail.update")}
|
</ha-dialog>
|
||||||
</ha-button>
|
|
||||||
</ha-dialog-footer>
|
|
||||||
</ha-wa-dialog>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -771,7 +771,10 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
|
|||||||
.indeterminate=${partial}
|
.indeterminate=${partial}
|
||||||
reducedTouchTarget
|
reducedTouchTarget
|
||||||
></ha-checkbox>
|
></ha-checkbox>
|
||||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
<ha-label
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
|
>
|
||||||
${label.icon
|
${label.icon
|
||||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import type {
|
|||||||
EnergySource,
|
EnergySource,
|
||||||
FlowFromGridSourceEnergyPreference,
|
FlowFromGridSourceEnergyPreference,
|
||||||
FlowToGridSourceEnergyPreference,
|
FlowToGridSourceEnergyPreference,
|
||||||
|
GridPowerSourceEnergyPreference,
|
||||||
GridSourceTypeEnergyPreference,
|
GridSourceTypeEnergyPreference,
|
||||||
} from "../../../../data/energy";
|
} from "../../../../data/energy";
|
||||||
import {
|
import {
|
||||||
@@ -47,6 +48,7 @@ import { documentationUrl } from "../../../../util/documentation-url";
|
|||||||
import {
|
import {
|
||||||
showEnergySettingsGridFlowFromDialog,
|
showEnergySettingsGridFlowFromDialog,
|
||||||
showEnergySettingsGridFlowToDialog,
|
showEnergySettingsGridFlowToDialog,
|
||||||
|
showEnergySettingsGridPowerDialog,
|
||||||
} from "../dialogs/show-dialogs-energy";
|
} from "../dialogs/show-dialogs-energy";
|
||||||
import "./ha-energy-validation-result";
|
import "./ha-energy-validation-result";
|
||||||
import { energyCardStyles } from "./styles";
|
import { energyCardStyles } from "./styles";
|
||||||
@@ -226,6 +228,58 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
${this.hass.localize("ui.panel.config.energy.grid.grid_power")}
|
||||||
|
</h3>
|
||||||
|
${gridSource.power?.map((power) => {
|
||||||
|
const entityState = this.hass.states[power.stat_rate];
|
||||||
|
return html`
|
||||||
|
<div class="row" .source=${power}>
|
||||||
|
${entityState?.attributes.icon
|
||||||
|
? html`<ha-icon
|
||||||
|
.icon=${entityState.attributes.icon}
|
||||||
|
></ha-icon>`
|
||||||
|
: html`<ha-svg-icon
|
||||||
|
.path=${mdiTransmissionTower}
|
||||||
|
></ha-svg-icon>`}
|
||||||
|
<span class="content"
|
||||||
|
>${getStatisticLabel(
|
||||||
|
this.hass,
|
||||||
|
power.stat_rate,
|
||||||
|
this.statsMetadata?.[power.stat_rate]
|
||||||
|
)}</span
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.grid.edit_power"
|
||||||
|
)}
|
||||||
|
@click=${this._editPowerSource}
|
||||||
|
.path=${mdiPencil}
|
||||||
|
></ha-icon-button>
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.grid.delete_power"
|
||||||
|
)}
|
||||||
|
@click=${this._deletePowerSource}
|
||||||
|
.path=${mdiDelete}
|
||||||
|
></ha-icon-button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
})}
|
||||||
|
<div class="row border-bottom">
|
||||||
|
<ha-svg-icon .path=${mdiTransmissionTower}></ha-svg-icon>
|
||||||
|
<ha-button
|
||||||
|
@click=${this._addPowerSource}
|
||||||
|
appearance="filled"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ha-svg-icon .path=${mdiPlus} slot="start"></ha-svg-icon
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.grid.add_power"
|
||||||
|
)}</ha-button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.energy.grid.grid_carbon_footprint"
|
"ui.panel.config.energy.grid.grid_carbon_footprint"
|
||||||
@@ -499,6 +553,97 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
await this._savePreferences(cleanedPreferences);
|
await this._savePreferences(cleanedPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _addPowerSource() {
|
||||||
|
const gridSource = this.preferences.energy_sources.find(
|
||||||
|
(src) => src.type === "grid"
|
||||||
|
) as GridSourceTypeEnergyPreference | undefined;
|
||||||
|
showEnergySettingsGridPowerDialog(this, {
|
||||||
|
grid_source: gridSource,
|
||||||
|
saveCallback: async (power) => {
|
||||||
|
let preferences: EnergyPreferences;
|
||||||
|
if (!gridSource) {
|
||||||
|
preferences = {
|
||||||
|
...this.preferences,
|
||||||
|
energy_sources: [
|
||||||
|
...this.preferences.energy_sources,
|
||||||
|
{
|
||||||
|
...emptyGridSourceEnergyPreference(),
|
||||||
|
power: [power],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
preferences = {
|
||||||
|
...this.preferences,
|
||||||
|
energy_sources: this.preferences.energy_sources.map((src) =>
|
||||||
|
src.type === "grid"
|
||||||
|
? { ...src, power: [...(gridSource.power || []), power] }
|
||||||
|
: src
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await this._savePreferences(preferences);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _editPowerSource(ev) {
|
||||||
|
const origSource: GridPowerSourceEnergyPreference =
|
||||||
|
ev.currentTarget.closest(".row").source;
|
||||||
|
const gridSource = this.preferences.energy_sources.find(
|
||||||
|
(src) => src.type === "grid"
|
||||||
|
) as GridSourceTypeEnergyPreference | undefined;
|
||||||
|
showEnergySettingsGridPowerDialog(this, {
|
||||||
|
source: { ...origSource },
|
||||||
|
grid_source: gridSource,
|
||||||
|
saveCallback: async (source) => {
|
||||||
|
const power =
|
||||||
|
energySourcesByType(this.preferences).grid![0].power || [];
|
||||||
|
|
||||||
|
const preferences: EnergyPreferences = {
|
||||||
|
...this.preferences,
|
||||||
|
energy_sources: this.preferences.energy_sources.map((src) =>
|
||||||
|
src.type === "grid"
|
||||||
|
? {
|
||||||
|
...src,
|
||||||
|
power: power.map((p) => (p === origSource ? source : p)),
|
||||||
|
}
|
||||||
|
: src
|
||||||
|
),
|
||||||
|
};
|
||||||
|
await this._savePreferences(preferences);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _deletePowerSource(ev) {
|
||||||
|
const sourceToDelete: GridPowerSourceEnergyPreference =
|
||||||
|
ev.currentTarget.closest(".row").source;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!(await showConfirmationDialog(this, {
|
||||||
|
title: this.hass.localize("ui.panel.config.energy.delete_source"),
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const power =
|
||||||
|
energySourcesByType(this.preferences).grid![0].power?.filter(
|
||||||
|
(p) => p !== sourceToDelete
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
const preferences: EnergyPreferences = {
|
||||||
|
...this.preferences,
|
||||||
|
energy_sources: this.preferences.energy_sources.map((source) =>
|
||||||
|
source.type === "grid" ? { ...source, power } : source
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanedPreferences = this._removeEmptySources(preferences);
|
||||||
|
await this._savePreferences(cleanedPreferences);
|
||||||
|
}
|
||||||
|
|
||||||
private _removeEmptySources(preferences: EnergyPreferences) {
|
private _removeEmptySources(preferences: EnergyPreferences) {
|
||||||
// Check if grid sources became an empty type and remove if so
|
// Check if grid sources became an empty type and remove if so
|
||||||
preferences.energy_sources = preferences.energy_sources.reduce<
|
preferences.energy_sources = preferences.energy_sources.reduce<
|
||||||
@@ -507,7 +652,8 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
if (
|
if (
|
||||||
source.type !== "grid" ||
|
source.type !== "grid" ||
|
||||||
source.flow_from.length > 0 ||
|
source.flow_from.length > 0 ||
|
||||||
source.flow_to.length > 0
|
source.flow_to.length > 0 ||
|
||||||
|
(source.power && source.power.length > 0)
|
||||||
) {
|
) {
|
||||||
acc.push(source);
|
acc.push(source);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import type { HomeAssistant } from "../../../../types";
|
|||||||
import type { EnergySettingsBatteryDialogParams } from "./show-dialogs-energy";
|
import type { EnergySettingsBatteryDialogParams } from "./show-dialogs-energy";
|
||||||
|
|
||||||
const energyUnitClasses = ["energy"];
|
const energyUnitClasses = ["energy"];
|
||||||
|
const powerUnitClasses = ["power"];
|
||||||
|
|
||||||
@customElement("dialog-energy-battery-settings")
|
@customElement("dialog-energy-battery-settings")
|
||||||
export class DialogEnergyBatterySettings
|
export class DialogEnergyBatterySettings
|
||||||
@@ -32,10 +33,14 @@ export class DialogEnergyBatterySettings
|
|||||||
|
|
||||||
@state() private _energy_units?: string[];
|
@state() private _energy_units?: string[];
|
||||||
|
|
||||||
|
@state() private _power_units?: string[];
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
private _excludeList?: string[];
|
private _excludeList?: string[];
|
||||||
|
|
||||||
|
private _excludeListPower?: string[];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
params: EnergySettingsBatteryDialogParams
|
params: EnergySettingsBatteryDialogParams
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@@ -46,6 +51,9 @@ export class DialogEnergyBatterySettings
|
|||||||
this._energy_units = (
|
this._energy_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||||
).units;
|
).units;
|
||||||
|
this._power_units = (
|
||||||
|
await getSensorDeviceClassConvertibleUnits(this.hass, "power")
|
||||||
|
).units;
|
||||||
const allSources: string[] = [];
|
const allSources: string[] = [];
|
||||||
this._params.battery_sources.forEach((entry) => {
|
this._params.battery_sources.forEach((entry) => {
|
||||||
allSources.push(entry.stat_energy_from);
|
allSources.push(entry.stat_energy_from);
|
||||||
@@ -56,6 +64,9 @@ export class DialogEnergyBatterySettings
|
|||||||
id !== this._source?.stat_energy_from &&
|
id !== this._source?.stat_energy_from &&
|
||||||
id !== this._source?.stat_energy_to
|
id !== this._source?.stat_energy_to
|
||||||
);
|
);
|
||||||
|
this._excludeListPower = this._params.battery_sources
|
||||||
|
.map((entry) => entry.stat_rate)
|
||||||
|
.filter((id) => id && id !== this._source?.stat_rate) as string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
@@ -72,8 +83,6 @@ export class DialogEnergyBatterySettings
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickableUnit = this._energy_units?.join(", ") || "";
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@@ -85,12 +94,6 @@ export class DialogEnergyBatterySettings
|
|||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
>
|
>
|
||||||
${this._error ? html`<p class="error">${this._error}</p>` : ""}
|
${this._error ? html`<p class="error">${this._error}</p>` : ""}
|
||||||
<div>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.energy.battery.dialog.entity_para",
|
|
||||||
{ unit: pickableUnit }
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -105,6 +108,10 @@ export class DialogEnergyBatterySettings
|
|||||||
this._source.stat_energy_from,
|
this._source.stat_energy_from,
|
||||||
]}
|
]}
|
||||||
@value-changed=${this._statisticToChanged}
|
@value-changed=${this._statisticToChanged}
|
||||||
|
.helper=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.battery.dialog.energy_helper_into",
|
||||||
|
{ unit: this._energy_units?.join(", ") || "" }
|
||||||
|
)}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
@@ -121,6 +128,25 @@ export class DialogEnergyBatterySettings
|
|||||||
this._source.stat_energy_to,
|
this._source.stat_energy_to,
|
||||||
]}
|
]}
|
||||||
@value-changed=${this._statisticFromChanged}
|
@value-changed=${this._statisticFromChanged}
|
||||||
|
.helper=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.battery.dialog.energy_helper_out",
|
||||||
|
{ unit: this._energy_units?.join(", ") || "" }
|
||||||
|
)}
|
||||||
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
<ha-statistic-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.includeUnitClass=${powerUnitClasses}
|
||||||
|
.value=${this._source.stat_rate}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.battery.dialog.power"
|
||||||
|
)}
|
||||||
|
.excludeStatistics=${this._excludeListPower}
|
||||||
|
@value-changed=${this._powerChanged}
|
||||||
|
.helper=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.battery.dialog.power_helper",
|
||||||
|
{ unit: this._power_units?.join(", ") || "" }
|
||||||
|
)}
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
<ha-button
|
<ha-button
|
||||||
@@ -150,6 +176,10 @@ export class DialogEnergyBatterySettings
|
|||||||
this._source = { ...this._source!, stat_energy_from: ev.detail.value };
|
this._source = { ...this._source!, stat_energy_from: ev.detail.value };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _powerChanged(ev: CustomEvent<{ value: string }>) {
|
||||||
|
this._source = { ...this._source!, stat_rate: ev.detail.value };
|
||||||
|
}
|
||||||
|
|
||||||
private async _save() {
|
private async _save() {
|
||||||
try {
|
try {
|
||||||
await this._params!.saveCallback(this._source!);
|
await this._params!.saveCallback(this._source!);
|
||||||
@@ -168,7 +198,11 @@ export class DialogEnergyBatterySettings
|
|||||||
--mdc-dialog-max-width: 430px;
|
--mdc-dialog-max-width: 430px;
|
||||||
}
|
}
|
||||||
ha-statistic-picker {
|
ha-statistic-picker {
|
||||||
width: 100%;
|
display: block;
|
||||||
|
margin-bottom: var(--ha-space-4);
|
||||||
|
}
|
||||||
|
ha-statistic-picker:last-of-type {
|
||||||
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import type { HomeAssistant } from "../../../../types";
|
|||||||
import type { EnergySettingsDeviceDialogParams } from "./show-dialogs-energy";
|
import type { EnergySettingsDeviceDialogParams } from "./show-dialogs-energy";
|
||||||
|
|
||||||
const energyUnitClasses = ["energy"];
|
const energyUnitClasses = ["energy"];
|
||||||
|
const powerUnitClasses = ["power"];
|
||||||
|
|
||||||
@customElement("dialog-energy-device-settings")
|
@customElement("dialog-energy-device-settings")
|
||||||
export class DialogEnergyDeviceSettings
|
export class DialogEnergyDeviceSettings
|
||||||
@@ -35,10 +36,14 @@ export class DialogEnergyDeviceSettings
|
|||||||
|
|
||||||
@state() private _energy_units?: string[];
|
@state() private _energy_units?: string[];
|
||||||
|
|
||||||
|
@state() private _power_units?: string[];
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
private _excludeList?: string[];
|
private _excludeList?: string[];
|
||||||
|
|
||||||
|
private _excludeListPower?: string[];
|
||||||
|
|
||||||
private _possibleParents: DeviceConsumptionEnergyPreference[] = [];
|
private _possibleParents: DeviceConsumptionEnergyPreference[] = [];
|
||||||
|
|
||||||
public async showDialog(
|
public async showDialog(
|
||||||
@@ -50,9 +55,15 @@ export class DialogEnergyDeviceSettings
|
|||||||
this._energy_units = (
|
this._energy_units = (
|
||||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||||
).units;
|
).units;
|
||||||
|
this._power_units = (
|
||||||
|
await getSensorDeviceClassConvertibleUnits(this.hass, "power")
|
||||||
|
).units;
|
||||||
this._excludeList = this._params.device_consumptions
|
this._excludeList = this._params.device_consumptions
|
||||||
.map((entry) => entry.stat_consumption)
|
.map((entry) => entry.stat_consumption)
|
||||||
.filter((id) => id !== this._device?.stat_consumption);
|
.filter((id) => id !== this._device?.stat_consumption);
|
||||||
|
this._excludeListPower = this._params.device_consumptions
|
||||||
|
.map((entry) => entry.stat_rate)
|
||||||
|
.filter((id) => id && id !== this._device?.stat_rate) as string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computePossibleParents() {
|
private _computePossibleParents() {
|
||||||
@@ -93,8 +104,6 @@ export class DialogEnergyDeviceSettings
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickableUnit = this._energy_units?.join(", ") || "";
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@@ -108,12 +117,6 @@ export class DialogEnergyDeviceSettings
|
|||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
>
|
>
|
||||||
${this._error ? html`<p class="error">${this._error}</p>` : ""}
|
${this._error ? html`<p class="error">${this._error}</p>` : ""}
|
||||||
<div>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.energy.device_consumption.dialog.selected_stat_intro",
|
|
||||||
{ unit: pickableUnit }
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ha-statistic-picker
|
<ha-statistic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -125,9 +128,28 @@ export class DialogEnergyDeviceSettings
|
|||||||
)}
|
)}
|
||||||
.excludeStatistics=${this._excludeList}
|
.excludeStatistics=${this._excludeList}
|
||||||
@value-changed=${this._statisticChanged}
|
@value-changed=${this._statisticChanged}
|
||||||
|
.helper=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.device_consumption.dialog.selected_stat_intro",
|
||||||
|
{ unit: this._energy_units?.join(", ") || "" }
|
||||||
|
)}
|
||||||
dialogInitialFocus
|
dialogInitialFocus
|
||||||
></ha-statistic-picker>
|
></ha-statistic-picker>
|
||||||
|
|
||||||
|
<ha-statistic-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.includeUnitClass=${powerUnitClasses}
|
||||||
|
.value=${this._device?.stat_rate}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.device_consumption.dialog.device_consumption_power"
|
||||||
|
)}
|
||||||
|
.excludeStatistics=${this._excludeListPower}
|
||||||
|
@value-changed=${this._powerStatisticChanged}
|
||||||
|
.helper=${this.hass.localize(
|
||||||
|
"ui.panel.config.energy.device_consumption.dialog.selected_stat_intro",
|
||||||
|
{ unit: this._power_units?.join(", ") || "" }
|
||||||
|
)}
|
||||||
|
></ha-statistic-picker>
|
||||||
|
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.energy.device_consumption.dialog.display_name"
|
"ui.panel.config.energy.device_consumption.dialog.display_name"
|
||||||
@@ -210,6 +232,20 @@ export class DialogEnergyDeviceSettings
|
|||||||
this._computePossibleParents();
|
this._computePossibleParents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _powerStatisticChanged(ev: CustomEvent<{ value: string }>) {
|
||||||
|
if (!this._device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newDevice = {
|
||||||
|
...this._device,
|
||||||
|
stat_rate: ev.detail.value,
|
||||||
|
} as DeviceConsumptionEnergyPreference;
|
||||||
|
if (!newDevice.stat_rate) {
|
||||||
|
delete newDevice.stat_rate;
|
||||||
|
}
|
||||||
|
this._device = newDevice;
|
||||||
|
}
|
||||||
|
|
||||||
private _nameChanged(ev) {
|
private _nameChanged(ev) {
|
||||||
const newDevice = {
|
const newDevice = {
|
||||||
...this._device!,
|
...this._device!,
|
||||||
@@ -245,15 +281,19 @@ export class DialogEnergyDeviceSettings
|
|||||||
return [
|
return [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
css`
|
css`
|
||||||
|
ha-statistic-picker {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: var(--ha-space-2);
|
||||||
|
}
|
||||||
ha-statistic-picker {
|
ha-statistic-picker {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
ha-select {
|
ha-select {
|
||||||
margin-top: 16px;
|
margin-top: var(--ha-space-4);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
ha-textfield {
|
ha-textfield {
|
||||||
margin-top: 16px;
|
margin-top: var(--ha-space-4);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user