mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-17 21:29:35 +00:00
Compare commits
271 Commits
fix-backgr
...
card_featu
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0dd290cd85 | ||
![]() |
fb499f09fb | ||
![]() |
d3c83e0157 | ||
![]() |
60c7a0e545 | ||
![]() |
d0f3eed49e | ||
![]() |
c2d4873ac3 | ||
![]() |
c3507bac0b | ||
![]() |
1dbb70b964 | ||
![]() |
1eecc5c0e2 | ||
![]() |
81c0bcff0b | ||
![]() |
6ccbeb8a75 | ||
![]() |
f59ed0a72b | ||
![]() |
a9f00ded0f | ||
![]() |
74730ba201 | ||
![]() |
95b2f7d821 | ||
![]() |
661b14da54 | ||
![]() |
41e34c0d61 | ||
![]() |
5d044a06eb | ||
![]() |
f617426808 | ||
![]() |
3c3d54243c | ||
![]() |
afc624bf4b | ||
![]() |
0991628843 | ||
![]() |
34b9c7b9d1 | ||
![]() |
d52641b495 | ||
![]() |
80c7fd2bf2 | ||
![]() |
e0062cf190 | ||
![]() |
7d2cee650d | ||
![]() |
66560b1f1c | ||
![]() |
a500b582e3 | ||
![]() |
19f94ff8cc | ||
![]() |
0b6994d402 | ||
![]() |
9fe8f507ec | ||
![]() |
2113cf5280 | ||
![]() |
ae9e1b724f | ||
![]() |
9b28c7cf69 | ||
![]() |
d9bac06806 | ||
![]() |
b1e37cb1e1 | ||
![]() |
a2a89502d8 | ||
![]() |
4cc5d2d04b | ||
![]() |
79abcca3b3 | ||
![]() |
043f383a35 | ||
![]() |
d4dd767941 | ||
![]() |
174f1991b1 | ||
![]() |
e15495a626 | ||
![]() |
a8a9a797cb | ||
![]() |
914dbc1e28 | ||
![]() |
111816f08a | ||
![]() |
1b4534890c | ||
![]() |
ed6542469d | ||
![]() |
3774a3d6ba | ||
![]() |
bfa293ae3a | ||
![]() |
9264adb799 | ||
![]() |
829ea4a9e4 | ||
![]() |
be26f8bc24 | ||
![]() |
c864b34a9a | ||
![]() |
099ea61a94 | ||
![]() |
3ebe6027be | ||
![]() |
f5f2a5ad5b | ||
![]() |
d046700d06 | ||
![]() |
2ad84b2832 | ||
![]() |
f9ccb9fc72 | ||
![]() |
6d3940db1e | ||
![]() |
20d174431d | ||
![]() |
1900710e06 | ||
![]() |
ed86a48e1c | ||
![]() |
d2bdb52926 | ||
![]() |
9c57c9f151 | ||
![]() |
9e9cb15a42 | ||
![]() |
6421a9443d | ||
![]() |
f2b43ddad8 | ||
![]() |
e55b59d9b7 | ||
![]() |
4a77359a06 | ||
![]() |
505d7b6ddb | ||
![]() |
79cdc43699 | ||
![]() |
8ff9823cd7 | ||
![]() |
3488c60818 | ||
![]() |
43a422cdca | ||
![]() |
11f2bef05c | ||
![]() |
ff9f331287 | ||
![]() |
cdf64ccdaa | ||
![]() |
8b220acca2 | ||
![]() |
8fdb7fa1d5 | ||
![]() |
008c842431 | ||
![]() |
bc41de0d9c | ||
![]() |
7310c9cf6d | ||
![]() |
84b436c08e | ||
![]() |
1925a47bdc | ||
![]() |
438a426458 | ||
![]() |
f923deb71d | ||
![]() |
e79bc71ab7 | ||
![]() |
11b0990d2b | ||
![]() |
870cb0c65f | ||
![]() |
deda2009f8 | ||
![]() |
b2797ab8da | ||
![]() |
644dcb0381 | ||
![]() |
c65f4f7a6e | ||
![]() |
68a79490dc | ||
![]() |
6febe8552e | ||
![]() |
f611f23f6f | ||
![]() |
627e06663b | ||
![]() |
ab01633069 | ||
![]() |
17dcc90638 | ||
![]() |
d0df029ff1 | ||
![]() |
86a7e69812 | ||
![]() |
af9417f2a6 | ||
![]() |
7120ad99b9 | ||
![]() |
334c245b65 | ||
![]() |
bcb72d83b8 | ||
![]() |
c99e0e846b | ||
![]() |
ec3f63e8a3 | ||
![]() |
1bc33a30ec | ||
![]() |
8cca233b7c | ||
![]() |
a78608bfb4 | ||
![]() |
1a797b3415 | ||
![]() |
2b27a4da2b | ||
![]() |
1df92fa863 | ||
![]() |
cdde85315a | ||
![]() |
dc67f9faf4 | ||
![]() |
3ad1be50a2 | ||
![]() |
8aadfe7d28 | ||
![]() |
cff54b73a4 | ||
![]() |
b54cfeb0c0 | ||
![]() |
cefe612b11 | ||
![]() |
4bc874b497 | ||
![]() |
f3abaa8e02 | ||
![]() |
21a563fe98 | ||
![]() |
35d6c638ab | ||
![]() |
68f8239708 | ||
![]() |
0db64cca0b | ||
![]() |
accfda5f4b | ||
![]() |
c97c20f57d | ||
![]() |
2725d0191d | ||
![]() |
852cc62398 | ||
![]() |
654e3ce437 | ||
![]() |
20a3a00aec | ||
![]() |
22b927d666 | ||
![]() |
709d6be2e3 | ||
![]() |
fbda9ca418 | ||
![]() |
4e97e3763e | ||
![]() |
4c9c52d27d | ||
![]() |
87bcd3e471 | ||
![]() |
7e9b01b56d | ||
![]() |
713763fc21 | ||
![]() |
5b7ab1bfcb | ||
![]() |
4b0d19b615 | ||
![]() |
90e5d259af | ||
![]() |
af3a331f57 | ||
![]() |
67c60a4aa8 | ||
![]() |
62de16bb8e | ||
![]() |
d9b71e754d | ||
![]() |
5fc950f09f | ||
![]() |
0725c7b160 | ||
![]() |
469dbbcccc | ||
![]() |
ffdd661b1f | ||
![]() |
81922f5a3e | ||
![]() |
7e25366897 | ||
![]() |
8ab61b5468 | ||
![]() |
8239f6dd60 | ||
![]() |
45dce18e4d | ||
![]() |
a428ad0655 | ||
![]() |
1b54d51e4a | ||
![]() |
eb1354d229 | ||
![]() |
4d21f9e80c | ||
![]() |
62f46baacf | ||
![]() |
a3090796d2 | ||
![]() |
c34c5d64f9 | ||
![]() |
66228f5858 | ||
![]() |
ac378cfe6d | ||
![]() |
7ecf8b755e | ||
![]() |
141107f1f3 | ||
![]() |
b5277dee53 | ||
![]() |
4b593c1c96 | ||
![]() |
50ce1b94c8 | ||
![]() |
8bf27a83ec | ||
![]() |
389f0d3d23 | ||
![]() |
b966601e6a | ||
![]() |
f2a0881821 | ||
![]() |
50a49eae43 | ||
![]() |
1c04561004 | ||
![]() |
b80d94d260 | ||
![]() |
87012e23e7 | ||
![]() |
f39758b103 | ||
![]() |
697bbf428e | ||
![]() |
c7444a2605 | ||
![]() |
3a5f4d33d2 | ||
![]() |
c3dc62523b | ||
![]() |
424622061a | ||
![]() |
a3b021b11d | ||
![]() |
b60ad8b143 | ||
![]() |
e376efc579 | ||
![]() |
382035a1d4 | ||
![]() |
542e22fe0e | ||
![]() |
af37d57779 | ||
![]() |
fbef0b0186 | ||
![]() |
9e67d6add8 | ||
![]() |
25c702ad2b | ||
![]() |
6516597c93 | ||
![]() |
1df9c38a8c | ||
![]() |
bd7217145a | ||
![]() |
569fef38a4 | ||
![]() |
f21c89cf1a | ||
![]() |
02cc418969 | ||
![]() |
4faba159c0 | ||
![]() |
29816e6c5e | ||
![]() |
5317a11c39 | ||
![]() |
27c53b3241 | ||
![]() |
919befa961 | ||
![]() |
f9c02ed099 | ||
![]() |
b35c325f43 | ||
![]() |
b82f1128fe | ||
![]() |
178feb7330 | ||
![]() |
0118a5bf4c | ||
![]() |
e0087bd142 | ||
![]() |
c2d3e7900e | ||
![]() |
fb8312110b | ||
![]() |
16de57342e | ||
![]() |
ad6e041c04 | ||
![]() |
e22e3e88a0 | ||
![]() |
dc8a50965c | ||
![]() |
1914de7ddf | ||
![]() |
2e505cfb1f | ||
![]() |
ab49aca815 | ||
![]() |
c96968e476 | ||
![]() |
8f050516ec | ||
![]() |
27d2b244a4 | ||
![]() |
be2f2c6271 | ||
![]() |
8dc2797b16 | ||
![]() |
7ca8dabc44 | ||
![]() |
baeb55e217 | ||
![]() |
a8502fcc11 | ||
![]() |
9f5bc5b196 | ||
![]() |
7556ab9506 | ||
![]() |
bf176ac314 | ||
![]() |
9903e22eaa | ||
![]() |
1e0f7d9629 | ||
![]() |
e8a140af44 | ||
![]() |
b091d4f298 | ||
![]() |
35cf3063cb | ||
![]() |
7141ef17be | ||
![]() |
be2c68c0bb | ||
![]() |
7c944d3767 | ||
![]() |
1d4f02df2e | ||
![]() |
2007a74a20 | ||
![]() |
8c0839ad57 | ||
![]() |
516b9a54c4 | ||
![]() |
0d3e730c9c | ||
![]() |
c7a87d02b2 | ||
![]() |
dd082c204b | ||
![]() |
c4af3d1579 | ||
![]() |
10eadbcbbb | ||
![]() |
17141824f7 | ||
![]() |
4cfd6c010f | ||
![]() |
daa9024bff | ||
![]() |
e96aca90fe | ||
![]() |
0580a31961 | ||
![]() |
5c42c5130c | ||
![]() |
72d1e37a23 | ||
![]() |
61c9072a08 | ||
![]() |
08b25f9c2a | ||
![]() |
1a03b49700 | ||
![]() |
2d4a8e2e45 | ||
![]() |
8486377604 | ||
![]() |
4326519a3f | ||
![]() |
962b30adb9 | ||
![]() |
29eb73176a | ||
![]() |
4f1cf1110f | ||
![]() |
d3bf0da289 | ||
![]() |
fd06d434f2 | ||
![]() |
d24d29e42f | ||
![]() |
e02a47a16a | ||
![]() |
795c16a941 |
@@ -115,6 +115,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"unused-imports/no-unused-imports": "error",
|
"unused-imports/no-unused-imports": "error",
|
||||||
|
"lit/attribute-names": "warn",
|
||||||
"lit/attribute-value-entities": "off",
|
"lit/attribute-value-entities": "off",
|
||||||
"lit/no-template-map": "off",
|
"lit/no-template-map": "off",
|
||||||
"lit/no-native-attributes": "warn",
|
"lit/no-native-attributes": "warn",
|
||||||
|
4
.github/workflows/cast_deployment.yaml
vendored
4
.github/workflows/cast_deployment.yaml
vendored
@@ -21,7 +21,7 @@ jobs:
|
|||||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: dev
|
ref: dev
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ jobs:
|
|||||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: master
|
ref: master
|
||||||
|
|
||||||
|
12
.github/workflows/ci.yaml
vendored
12
.github/workflows/ci.yaml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
with:
|
with:
|
||||||
@@ -58,7 +58,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
with:
|
with:
|
||||||
@@ -76,7 +76,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
with:
|
with:
|
||||||
@@ -89,7 +89,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
IS_TEST: "true"
|
IS_TEST: "true"
|
||||||
- name: Upload bundle stats
|
- name: Upload bundle stats
|
||||||
uses: actions/upload-artifact@v4.3.1
|
uses: actions/upload-artifact@v4.3.3
|
||||||
with:
|
with:
|
||||||
name: frontend-bundle-stats
|
name: frontend-bundle-stats
|
||||||
path: build/stats/*.json
|
path: build/stats/*.json
|
||||||
@@ -100,7 +100,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
with:
|
with:
|
||||||
@@ -113,7 +113,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
IS_TEST: "true"
|
IS_TEST: "true"
|
||||||
- name: Upload bundle stats
|
- name: Upload bundle stats
|
||||||
uses: actions/upload-artifact@v4.3.1
|
uses: actions/upload-artifact@v4.3.3
|
||||||
with:
|
with:
|
||||||
name: supervisor-bundle-stats
|
name: supervisor-bundle-stats
|
||||||
path: build/stats/*.json
|
path: build/stats/*.json
|
||||||
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
# We must fetch at least the immediate parents so that if this is
|
# We must fetch at least the immediate parents so that if this is
|
||||||
# a pull request then we can checkout the head.
|
# a pull request then we can checkout the head.
|
||||||
|
4
.github/workflows/demo_deployment.yaml
vendored
4
.github/workflows/demo_deployment.yaml
vendored
@@ -22,7 +22,7 @@ jobs:
|
|||||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: dev
|
ref: dev
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ jobs:
|
|||||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
with:
|
with:
|
||||||
ref: master
|
ref: master
|
||||||
|
|
||||||
|
2
.github/workflows/design_deployment.yaml
vendored
2
.github/workflows/design_deployment.yaml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
|
2
.github/workflows/design_preview.yaml
vendored
2
.github/workflows/design_preview.yaml
vendored
@@ -21,7 +21,7 @@ jobs:
|
|||||||
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
|
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files from GitHub
|
- name: Check out files from GitHub
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v4.0.2
|
uses: actions/setup-node@v4.0.2
|
||||||
|
6
.github/workflows/nightly.yaml
vendored
6
.github/workflows/nightly.yaml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
@@ -57,14 +57,14 @@ jobs:
|
|||||||
run: tar -czvf translations.tar.gz translations
|
run: tar -czvf translations.tar.gz translations
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4.3.1
|
uses: actions/upload-artifact@v4.3.3
|
||||||
with:
|
with:
|
||||||
name: wheels
|
name: wheels
|
||||||
path: dist/home_assistant_frontend*.whl
|
path: dist/home_assistant_frontend*.whl
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: Upload translations
|
- name: Upload translations
|
||||||
uses: actions/upload-artifact@v4.3.1
|
uses: actions/upload-artifact@v4.3.3
|
||||||
with:
|
with:
|
||||||
name: translations
|
name: translations
|
||||||
path: translations.tar.gz
|
path: translations.tar.gz
|
||||||
|
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@@ -23,7 +23,7 @@ jobs:
|
|||||||
contents: write # Required to upload release assets
|
contents: write # Required to upload release assets
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
|
|
||||||
- name: Verify version
|
- name: Verify version
|
||||||
uses: home-assistant/actions/helpers/verify-version@master
|
uses: home-assistant/actions/helpers/verify-version@master
|
||||||
@@ -55,7 +55,7 @@ jobs:
|
|||||||
script/release
|
script/release
|
||||||
|
|
||||||
- name: Upload release assets
|
- name: Upload release assets
|
||||||
uses: softprops/action-gh-release@v2.0.4
|
uses: softprops/action-gh-release@v2.0.5
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
dist/*.whl
|
dist/*.whl
|
||||||
|
2
.github/workflows/translations.yaml
vendored
2
.github/workflows/translations.yaml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.6
|
||||||
|
|
||||||
- name: Upload Translations
|
- name: Upload Translations
|
||||||
run: |
|
run: |
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -6,4 +6,4 @@ enableGlobalCache: false
|
|||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-4.1.1.cjs
|
yarnPath: .yarn/releases/yarn-4.2.2.cjs
|
||||||
|
@@ -1,7 +1,23 @@
|
|||||||
import defineProvider from "@babel/helper-define-polyfill-provider";
|
import defineProvider from "@babel/helper-define-polyfill-provider";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import paths from "../paths.cjs";
|
||||||
|
|
||||||
|
const POLYFILL_DIR = join(paths.polymer_dir, "src/resources/polyfills");
|
||||||
|
|
||||||
// List of polyfill keys with supported browser targets for the functionality
|
// List of polyfill keys with supported browser targets for the functionality
|
||||||
const PolyfillSupport = {
|
const PolyfillSupport = {
|
||||||
|
// Note states and shadowRoot properties should be supported.
|
||||||
|
"element-internals": {
|
||||||
|
android: 90,
|
||||||
|
chrome: 90,
|
||||||
|
edge: 90,
|
||||||
|
firefox: 126,
|
||||||
|
ios: 17.4,
|
||||||
|
opera: 76,
|
||||||
|
opera_mobile: 64,
|
||||||
|
safari: 17.4,
|
||||||
|
samsung: 15.0,
|
||||||
|
},
|
||||||
fetch: {
|
fetch: {
|
||||||
android: 42,
|
android: 42,
|
||||||
chrome: 42,
|
chrome: 42,
|
||||||
@@ -24,16 +40,36 @@ const PolyfillSupport = {
|
|||||||
safari: 10.0,
|
safari: 10.0,
|
||||||
samsung: 5.0,
|
samsung: 5.0,
|
||||||
},
|
},
|
||||||
|
"resize-observer": {
|
||||||
|
android: 64,
|
||||||
|
chrome: 64,
|
||||||
|
edge: 79,
|
||||||
|
firefox: 69,
|
||||||
|
ios: 13.4,
|
||||||
|
opera: 51,
|
||||||
|
opera_mobile: 47,
|
||||||
|
safari: 13.1,
|
||||||
|
samsung: 9.0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Map of global variables and/or instance and static properties to the
|
// Map of global variables and/or instance and static properties to the
|
||||||
// corresponding polyfill key and actual module to import
|
// corresponding polyfill key and actual module to import
|
||||||
const polyfillMap = {
|
const polyfillMap = {
|
||||||
global: {
|
global: {
|
||||||
Proxy: { key: "proxy", module: "proxy-polyfill" },
|
|
||||||
fetch: { key: "fetch", module: "unfetch/polyfill" },
|
fetch: { key: "fetch", module: "unfetch/polyfill" },
|
||||||
|
Proxy: { key: "proxy", module: "proxy-polyfill" },
|
||||||
|
ResizeObserver: {
|
||||||
|
key: "resize-observer",
|
||||||
|
module: join(POLYFILL_DIR, "resize-observer.ts"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
instance: {
|
||||||
|
attachInternals: {
|
||||||
|
key: "element-internals",
|
||||||
|
module: "element-internals-polyfill",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
instance: {},
|
|
||||||
static: {},
|
static: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,7 +85,9 @@ export default defineProvider(
|
|||||||
if (polyfill && shouldInjectPolyfill(polyfill.desc.key)) {
|
if (polyfill && shouldInjectPolyfill(polyfill.desc.key)) {
|
||||||
debug(polyfill.desc.key);
|
debug(polyfill.desc.key);
|
||||||
utils.injectGlobalImport(polyfill.desc.module);
|
utils.injectGlobalImport(polyfill.desc.module);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@ const env = require("./env.cjs");
|
|||||||
const paths = require("./paths.cjs");
|
const paths = require("./paths.cjs");
|
||||||
const { dependencies } = require("../package.json");
|
const { dependencies } = require("../package.json");
|
||||||
|
|
||||||
|
const BABEL_PLUGINS = path.join(__dirname, "babel-plugins");
|
||||||
|
|
||||||
// GitHub base URL to use for production source maps
|
// GitHub base URL to use for production source maps
|
||||||
// Nightly builds use the commit SHA, otherwise assumes there is a tag that matches the version
|
// Nightly builds use the commit SHA, otherwise assumes there is a tag that matches the version
|
||||||
module.exports.sourceMapURL = () => {
|
module.exports.sourceMapURL = () => {
|
||||||
@@ -100,22 +102,12 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
|
|||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
[
|
[
|
||||||
path.resolve(
|
path.join(BABEL_PLUGINS, "inline-constants-plugin.cjs"),
|
||||||
paths.polymer_dir,
|
|
||||||
"build-scripts/babel-plugins/inline-constants-plugin.cjs"
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
modules: ["@mdi/js"],
|
modules: ["@mdi/js"],
|
||||||
ignoreModuleNotFound: true,
|
ignoreModuleNotFound: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
|
||||||
path.resolve(
|
|
||||||
paths.polymer_dir,
|
|
||||||
"build-scripts/babel-plugins/custom-polyfill-plugin.js"
|
|
||||||
),
|
|
||||||
{ method: "usage-global" },
|
|
||||||
],
|
|
||||||
// Minify template literals for production
|
// Minify template literals for production
|
||||||
isProdBuild && [
|
isProdBuild && [
|
||||||
"template-html-minifier",
|
"template-html-minifier",
|
||||||
@@ -153,6 +145,26 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
|
|||||||
],
|
],
|
||||||
sourceMaps: !isTestBuild,
|
sourceMaps: !isTestBuild,
|
||||||
overrides: [
|
overrides: [
|
||||||
|
{
|
||||||
|
// Add plugin to inject various polyfills, excluding the polyfills
|
||||||
|
// themselves to prevent self-injection.
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
path.join(BABEL_PLUGINS, "custom-polyfill-plugin.js"),
|
||||||
|
{ method: "usage-global" },
|
||||||
|
],
|
||||||
|
],
|
||||||
|
exclude: [
|
||||||
|
path.join(paths.polymer_dir, "src/resources/polyfills"),
|
||||||
|
...[
|
||||||
|
"@lit-labs/virtualizer/polyfills",
|
||||||
|
"@webcomponents/scoped-custom-element-registry",
|
||||||
|
"element-internals-polyfill",
|
||||||
|
"proxy-polyfill",
|
||||||
|
"unfetch",
|
||||||
|
].map((p) => new RegExp(`/node_modules/${p}/`)),
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// Use unambiguous for dependencies so that require() is correctly injected into CommonJS files
|
// Use unambiguous for dependencies so that require() is correctly injected into CommonJS files
|
||||||
// Exclusions are needed in some cases where ES modules have no static imports or exports, such as polyfills
|
// Exclusions are needed in some cases where ES modules have no static imports or exports, such as polyfills
|
||||||
|
@@ -9,7 +9,7 @@ import gulp from "gulp";
|
|||||||
import jszip from "jszip";
|
import jszip from "jszip";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import process from "process";
|
import process from "process";
|
||||||
import tar from "tar";
|
import { extract } from "tar";
|
||||||
|
|
||||||
const MAX_AGE = 24; // hours
|
const MAX_AGE = 24; // hours
|
||||||
const OWNER = "home-assistant";
|
const OWNER = "home-assistant";
|
||||||
@@ -156,7 +156,7 @@ gulp.task("fetch-nightly-translations", async function () {
|
|||||||
console.log("Unpacking downloaded translations...");
|
console.log("Unpacking downloaded translations...");
|
||||||
const zip = await jszip.loadAsync(downloadResponse.data);
|
const zip = await jszip.loadAsync(downloadResponse.data);
|
||||||
await deleteCurrent;
|
await deleteCurrent;
|
||||||
const extractStream = zip.file(/.*/)[0].nodeStream().pipe(tar.extract());
|
const extractStream = zip.file(/.*/)[0].nodeStream().pipe(extract());
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
extractStream.on("close", resolve).on("error", reject);
|
extractStream.on("close", resolve).on("error", reject);
|
||||||
});
|
});
|
||||||
|
@@ -1,92 +1,111 @@
|
|||||||
import { createHash } from "crypto";
|
/* eslint-disable max-classes-per-file */
|
||||||
import { deleteSync } from "del";
|
|
||||||
import { mkdirSync, readdirSync, readFileSync, renameSync } from "fs";
|
import { deleteAsync } from "del";
|
||||||
import { writeFile } from "node:fs/promises";
|
import { glob } from "glob";
|
||||||
import gulp from "gulp";
|
import gulp from "gulp";
|
||||||
import flatmap from "gulp-flatmap";
|
|
||||||
import transform from "gulp-json-transform";
|
|
||||||
import merge from "gulp-merge-json";
|
|
||||||
import rename from "gulp-rename";
|
import rename from "gulp-rename";
|
||||||
import path from "path";
|
import merge from "lodash.merge";
|
||||||
import vinylBuffer from "vinyl-buffer";
|
import { createHash } from "node:crypto";
|
||||||
import source from "vinyl-source-stream";
|
import { mkdir, readFile } from "node:fs/promises";
|
||||||
|
import { basename, join } from "node:path";
|
||||||
|
import { PassThrough, Transform } from "node:stream";
|
||||||
|
import { finished } from "node:stream/promises";
|
||||||
import env from "../env.cjs";
|
import env from "../env.cjs";
|
||||||
import paths from "../paths.cjs";
|
import paths from "../paths.cjs";
|
||||||
import { mapFiles } from "../util.cjs";
|
|
||||||
import "./fetch-nightly-translations.js";
|
import "./fetch-nightly-translations.js";
|
||||||
|
|
||||||
const inFrontendDir = "translations/frontend";
|
const inFrontendDir = "translations/frontend";
|
||||||
const inBackendDir = "translations/backend";
|
const inBackendDir = "translations/backend";
|
||||||
const workDir = "build/translations";
|
const workDir = "build/translations";
|
||||||
const fullDir = workDir + "/full";
|
const outDir = join(workDir, "output");
|
||||||
const coreDir = workDir + "/core";
|
const EN_SRC = join(paths.translations_src, "en.json");
|
||||||
const outDir = workDir + "/output";
|
|
||||||
let mergeBackend = false;
|
let mergeBackend = false;
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"translations-enable-merge-backend",
|
"translations-enable-merge-backend",
|
||||||
gulp.parallel((done) => {
|
gulp.parallel(async () => {
|
||||||
mergeBackend = true;
|
mergeBackend = true;
|
||||||
done();
|
|
||||||
}, "allow-setup-fetch-nightly-translations")
|
}, "allow-setup-fetch-nightly-translations")
|
||||||
);
|
);
|
||||||
|
|
||||||
// Panel translations which should be split from the core translations.
|
// Transform stream to apply a function on Vinyl JSON files (buffer mode only).
|
||||||
const TRANSLATION_FRAGMENTS = Object.keys(
|
// The provided function can either return a new object, or an array of
|
||||||
JSON.parse(
|
// [object, subdirectory] pairs for fragmentizing the JSON.
|
||||||
readFileSync(
|
class CustomJSON extends Transform {
|
||||||
path.resolve(paths.polymer_dir, "src/translations/en.json"),
|
constructor(func, reviver = null) {
|
||||||
"utf-8"
|
super({ objectMode: true });
|
||||||
)
|
this._func = func;
|
||||||
).ui.panel
|
this._reviver = reviver;
|
||||||
);
|
}
|
||||||
|
|
||||||
function recursiveFlatten(prefix, data) {
|
async _transform(file, _, callback) {
|
||||||
let output = {};
|
try {
|
||||||
Object.keys(data).forEach((key) => {
|
let obj = JSON.parse(file.contents.toString(), this._reviver);
|
||||||
if (typeof data[key] === "object") {
|
if (this._func) obj = this._func(obj, file.path);
|
||||||
output = {
|
for (const [outObj, dir] of Array.isArray(obj) ? obj : [[obj, ""]]) {
|
||||||
...output,
|
const outFile = file.clone({ contents: false });
|
||||||
...recursiveFlatten(prefix + key + ".", data[key]),
|
outFile.contents = Buffer.from(JSON.stringify(outObj));
|
||||||
};
|
outFile.dirname += `/${dir}`;
|
||||||
|
this.push(outFile);
|
||||||
|
}
|
||||||
|
callback(null);
|
||||||
|
} catch (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform stream to merge Vinyl JSON files (buffer mode only).
|
||||||
|
class MergeJSON extends Transform {
|
||||||
|
_objects = [];
|
||||||
|
|
||||||
|
constructor(stem, startObj = {}, reviver = null) {
|
||||||
|
super({ objectMode: true, allowHalfOpen: false });
|
||||||
|
this._stem = stem;
|
||||||
|
this._startObj = structuredClone(startObj);
|
||||||
|
this._reviver = reviver;
|
||||||
|
}
|
||||||
|
|
||||||
|
async _transform(file, _, callback) {
|
||||||
|
try {
|
||||||
|
this._objects.push(JSON.parse(file.contents.toString(), this._reviver));
|
||||||
|
if (!this._outFile) this._outFile = file.clone({ contents: false });
|
||||||
|
callback(null);
|
||||||
|
} catch (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _flush(callback) {
|
||||||
|
try {
|
||||||
|
const mergedObj = merge(this._startObj, ...this._objects);
|
||||||
|
this._outFile.contents = Buffer.from(JSON.stringify(mergedObj));
|
||||||
|
this._outFile.stem = this._stem;
|
||||||
|
callback(null, this._outFile);
|
||||||
|
} catch (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility to flatten object keys to single level using separator
|
||||||
|
const flatten = (data, prefix = "", sep = ".") => {
|
||||||
|
const output = {};
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
if (typeof value === "object") {
|
||||||
|
Object.assign(output, flatten(value, prefix + key + sep, sep));
|
||||||
} else {
|
} else {
|
||||||
output[prefix + key] = data[key];
|
output[prefix + key] = value;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
};
|
||||||
|
|
||||||
function flatten(data) {
|
// Filter functions that can be passed directly to JSON.parse()
|
||||||
return recursiveFlatten("", data);
|
const emptyReviver = (_key, value) => value || undefined;
|
||||||
}
|
const testReviver = (_key, value) =>
|
||||||
|
value && typeof value === "string" ? "TRANSLATED" : value;
|
||||||
function emptyFilter(data) {
|
|
||||||
const newData = {};
|
|
||||||
Object.keys(data).forEach((key) => {
|
|
||||||
if (data[key]) {
|
|
||||||
if (typeof data[key] === "object") {
|
|
||||||
newData[key] = emptyFilter(data[key]);
|
|
||||||
} else {
|
|
||||||
newData[key] = data[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return newData;
|
|
||||||
}
|
|
||||||
|
|
||||||
function recursiveEmpty(data) {
|
|
||||||
const newData = {};
|
|
||||||
Object.keys(data).forEach((key) => {
|
|
||||||
if (data[key]) {
|
|
||||||
if (typeof data[key] === "object") {
|
|
||||||
newData[key] = recursiveEmpty(data[key]);
|
|
||||||
} else {
|
|
||||||
newData[key] = "TRANSLATED";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return newData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace Lokalise key placeholders with their actual values.
|
* Replace Lokalise key placeholders with their actual values.
|
||||||
@@ -95,60 +114,44 @@ function recursiveEmpty(data) {
|
|||||||
* be included in src/translations/en.json, but still be usable while
|
* be included in src/translations/en.json, but still be usable while
|
||||||
* developing locally.
|
* developing locally.
|
||||||
*
|
*
|
||||||
* @link https://docs.lokalise.co/article/KO5SZWLLsy-key-referencing
|
* @link https://docs.lokalise.com/en/articles/1400528-key-referencing
|
||||||
*/
|
*/
|
||||||
const re_key_reference = /\[%key:([^%]+)%\]/;
|
const KEY_REFERENCE = /\[%key:([^%]+)%\]/;
|
||||||
function lokaliseTransform(data, original, file) {
|
const lokaliseTransform = (data, path, original = data) => {
|
||||||
const output = {};
|
const output = {};
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
if (value instanceof Object) {
|
if (typeof value === "object") {
|
||||||
output[key] = lokaliseTransform(value, original, file);
|
output[key] = lokaliseTransform(value, path, original);
|
||||||
} else {
|
} else {
|
||||||
output[key] = value.replace(re_key_reference, (_match, lokalise_key) => {
|
output[key] = value.replace(KEY_REFERENCE, (_match, lokalise_key) => {
|
||||||
const replace = lokalise_key.split("::").reduce((tr, k) => {
|
const replace = lokalise_key.split("::").reduce((tr, k) => {
|
||||||
if (!tr) {
|
if (!tr) {
|
||||||
throw Error(
|
throw Error(`Invalid key placeholder ${lokalise_key} in ${path}`);
|
||||||
`Invalid key placeholder ${lokalise_key} in ${file.path}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return tr[k];
|
return tr[k];
|
||||||
}, original);
|
}, original);
|
||||||
if (typeof replace !== "string") {
|
if (typeof replace !== "string") {
|
||||||
throw Error(
|
throw Error(`Invalid key placeholder ${lokalise_key} in ${path}`);
|
||||||
`Invalid key placeholder ${lokalise_key} in ${file.path}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return replace;
|
return replace;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
};
|
||||||
|
|
||||||
gulp.task("clean-translations", async () => deleteSync([workDir]));
|
gulp.task("clean-translations", () => deleteAsync([workDir]));
|
||||||
|
|
||||||
gulp.task("ensure-translations-build-dir", async () => {
|
const makeWorkDir = () => mkdir(workDir, { recursive: true });
|
||||||
mkdirSync(workDir, { recursive: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task("create-test-metadata", () =>
|
const createTestTranslation = () =>
|
||||||
env.isProdBuild()
|
|
||||||
? Promise.resolve()
|
|
||||||
: writeFile(
|
|
||||||
workDir + "/testMetadata.json",
|
|
||||||
JSON.stringify({ test: { nativeName: "Test" } })
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
gulp.task("create-test-translation", () =>
|
|
||||||
env.isProdBuild()
|
env.isProdBuild()
|
||||||
? Promise.resolve()
|
? Promise.resolve()
|
||||||
: gulp
|
: gulp
|
||||||
.src(path.join(paths.translations_src, "en.json"))
|
.src(EN_SRC)
|
||||||
.pipe(transform((data, _file) => recursiveEmpty(data)))
|
.pipe(new CustomJSON(null, testReviver))
|
||||||
.pipe(rename("test.json"))
|
.pipe(rename("test.json"))
|
||||||
.pipe(gulp.dest(workDir))
|
.pipe(gulp.dest(workDir));
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task will build a master translation file, to be used as the base for
|
* This task will build a master translation file, to be used as the base for
|
||||||
@@ -159,279 +162,164 @@ gulp.task("create-test-translation", () =>
|
|||||||
* project is buildable immediately after merging new translation keys, since
|
* project is buildable immediately after merging new translation keys, since
|
||||||
* the Lokalise update to translations/en.json will not happen immediately.
|
* the Lokalise update to translations/en.json will not happen immediately.
|
||||||
*/
|
*/
|
||||||
gulp.task("build-master-translation", () => {
|
const createMasterTranslation = () =>
|
||||||
const src = [path.join(paths.translations_src, "en.json")];
|
gulp
|
||||||
|
.src([EN_SRC, ...(mergeBackend ? [`${inBackendDir}/en.json`] : [])])
|
||||||
|
.pipe(new CustomJSON(lokaliseTransform))
|
||||||
|
.pipe(new MergeJSON("en"))
|
||||||
|
.pipe(gulp.dest(workDir));
|
||||||
|
|
||||||
if (mergeBackend) {
|
const FRAGMENTS = ["base"];
|
||||||
src.push(path.join(inBackendDir, "en.json"));
|
|
||||||
|
const toggleSupervisorFragment = async () => {
|
||||||
|
FRAGMENTS[0] = "supervisor";
|
||||||
|
};
|
||||||
|
|
||||||
|
const panelFragment = (fragment) =>
|
||||||
|
fragment !== "base" && fragment !== "supervisor";
|
||||||
|
|
||||||
|
const HASHES = new Map();
|
||||||
|
|
||||||
|
const createTranslations = async () => {
|
||||||
|
// Parse and store the master to avoid repeating this for each locale, then
|
||||||
|
// add the panel fragments when processing the app.
|
||||||
|
const enMaster = JSON.parse(await readFile(`${workDir}/en.json`, "utf-8"));
|
||||||
|
if (FRAGMENTS[0] === "base") {
|
||||||
|
FRAGMENTS.push(...Object.keys(enMaster.ui.panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
return gulp
|
// The downstream pipeline is setup first. It hashes the merged data for
|
||||||
.src(src)
|
// each locale, then fragmentizes and flattens the data for final output.
|
||||||
.pipe(transform((data, file) => lokaliseTransform(data, data, file)))
|
const translationFiles = await glob([
|
||||||
|
`${inFrontendDir}/!(en).json`,
|
||||||
|
...(env.isProdBuild() ? [] : [`${workDir}/test.json`]),
|
||||||
|
]);
|
||||||
|
const hashStream = new Transform({
|
||||||
|
objectMode: true,
|
||||||
|
transform: async (file, _, callback) => {
|
||||||
|
const hash = env.isProdBuild()
|
||||||
|
? createHash("md5").update(file.contents).digest("hex")
|
||||||
|
: "dev";
|
||||||
|
HASHES.set(file.stem, hash);
|
||||||
|
file.stem += `-${hash}`;
|
||||||
|
callback(null, file);
|
||||||
|
},
|
||||||
|
}).setMaxListeners(translationFiles.length + 1);
|
||||||
|
const fragmentsStream = hashStream
|
||||||
.pipe(
|
.pipe(
|
||||||
merge({
|
new CustomJSON((data) =>
|
||||||
fileName: "en.json",
|
FRAGMENTS.map((fragment) => {
|
||||||
})
|
switch (fragment) {
|
||||||
)
|
case "base":
|
||||||
.pipe(gulp.dest(fullDir));
|
// Remove the panels and supervisor to create the base translations
|
||||||
});
|
return [
|
||||||
|
flatten({
|
||||||
gulp.task("build-merged-translations", () =>
|
...data,
|
||||||
gulp
|
ui: { ...data.ui, panel: undefined },
|
||||||
.src([
|
supervisor: undefined,
|
||||||
inFrontendDir + "/*.json",
|
}),
|
||||||
"!" + inFrontendDir + "/en.json",
|
"",
|
||||||
...(env.isProdBuild() ? [] : [workDir + "/test.json"]),
|
];
|
||||||
])
|
case "supervisor":
|
||||||
.pipe(transform((data, file) => lokaliseTransform(data, data, file)))
|
// Supervisor key is at the top level
|
||||||
.pipe(
|
return [flatten(data.supervisor), ""];
|
||||||
flatmap((stream, file) => {
|
default:
|
||||||
// For each language generate a merged json file. It begins with the master
|
// Create a fragment with only the given panel
|
||||||
// translation as a failsafe for untranslated strings, and merges all parent
|
return [
|
||||||
// tags into one file for each specific subtag
|
flatten(data.ui.panel[fragment], `ui.panel.${fragment}.`),
|
||||||
//
|
fragment,
|
||||||
// TODO: This is a naive interpretation of BCP47 that should be improved.
|
];
|
||||||
// Will be OK for now as long as we don't have anything more complicated
|
|
||||||
// than a base translation + region.
|
|
||||||
const tr = path.basename(file.history[0], ".json");
|
|
||||||
const subtags = tr.split("-");
|
|
||||||
const src = [fullDir + "/en.json"];
|
|
||||||
for (let i = 1; i <= subtags.length; i++) {
|
|
||||||
const lang = subtags.slice(0, i).join("-");
|
|
||||||
if (lang === "test") {
|
|
||||||
src.push(workDir + "/test.json");
|
|
||||||
} else if (lang !== "en") {
|
|
||||||
src.push(inFrontendDir + "/" + lang + ".json");
|
|
||||||
if (mergeBackend) {
|
|
||||||
src.push(inBackendDir + "/" + lang + ".json");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return gulp
|
|
||||||
.src(src, { allowEmpty: true })
|
|
||||||
.pipe(transform((data) => emptyFilter(data)))
|
|
||||||
.pipe(
|
|
||||||
merge({
|
|
||||||
fileName: tr + ".json",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(fullDir));
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
let taskName;
|
|
||||||
|
|
||||||
const splitTasks = [];
|
|
||||||
TRANSLATION_FRAGMENTS.forEach((fragment) => {
|
|
||||||
taskName = "build-translation-fragment-" + fragment;
|
|
||||||
gulp.task(taskName, () =>
|
|
||||||
// Return only the translations for this fragment.
|
|
||||||
gulp
|
|
||||||
.src(fullDir + "/*.json")
|
|
||||||
.pipe(
|
|
||||||
transform((data) => ({
|
|
||||||
ui: {
|
|
||||||
panel: {
|
|
||||||
[fragment]: data.ui.panel[fragment],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(workDir + "/" + fragment))
|
|
||||||
);
|
|
||||||
splitTasks.push(taskName);
|
|
||||||
});
|
|
||||||
|
|
||||||
taskName = "build-translation-core";
|
|
||||||
gulp.task(taskName, () =>
|
|
||||||
// Remove the fragment translations from the core translation.
|
|
||||||
gulp
|
|
||||||
.src(fullDir + "/*.json")
|
|
||||||
.pipe(
|
|
||||||
transform((data, _file) => {
|
|
||||||
TRANSLATION_FRAGMENTS.forEach((fragment) => {
|
|
||||||
delete data.ui.panel[fragment];
|
|
||||||
});
|
|
||||||
delete data.supervisor;
|
|
||||||
return data;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(coreDir))
|
|
||||||
);
|
|
||||||
|
|
||||||
splitTasks.push(taskName);
|
|
||||||
|
|
||||||
gulp.task("build-flattened-translations", () =>
|
|
||||||
// Flatten the split versions of our translations, and move them into outDir
|
|
||||||
gulp
|
|
||||||
.src(
|
|
||||||
TRANSLATION_FRAGMENTS.map(
|
|
||||||
(fragment) => workDir + "/" + fragment + "/*.json"
|
|
||||||
).concat(coreDir + "/*.json"),
|
|
||||||
{ base: workDir }
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
transform((data) =>
|
|
||||||
// Polymer.AppLocalizeBehavior requires flattened json
|
|
||||||
flatten(data)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(gulp.dest(outDir));
|
||||||
rename((filePath) => {
|
|
||||||
if (filePath.dirname === "core") {
|
// Send the English master downstream first, then for each other locale
|
||||||
filePath.dirname = "";
|
// generate merged JSON data to continue piping. It begins with the master
|
||||||
|
// translation as a failsafe for untranslated strings, and merges all parent
|
||||||
|
// tags into one file for each specific subtag
|
||||||
|
//
|
||||||
|
// TODO: This is a naive interpretation of BCP47 that should be improved.
|
||||||
|
// Will be OK for now as long as we don't have anything more complicated
|
||||||
|
// than a base translation + region.
|
||||||
|
gulp
|
||||||
|
.src(`${workDir}/en.json`)
|
||||||
|
.pipe(new PassThrough({ objectMode: true }))
|
||||||
|
.pipe(hashStream, { end: false });
|
||||||
|
const mergesFinished = [];
|
||||||
|
for (const translationFile of translationFiles) {
|
||||||
|
const locale = basename(translationFile, ".json");
|
||||||
|
const subtags = locale.split("-");
|
||||||
|
const mergeFiles = [];
|
||||||
|
for (let i = 1; i <= subtags.length; i++) {
|
||||||
|
const lang = subtags.slice(0, i).join("-");
|
||||||
|
if (lang === "test") {
|
||||||
|
mergeFiles.push(`${workDir}/test.json`);
|
||||||
|
} else if (lang !== "en") {
|
||||||
|
mergeFiles.push(`${inFrontendDir}/${lang}.json`);
|
||||||
|
if (mergeBackend) {
|
||||||
|
mergeFiles.push(`${inBackendDir}/${lang}.json`);
|
||||||
}
|
}
|
||||||
// In dev we create the file with the fake hash in the filename
|
|
||||||
if (!env.isProdBuild()) {
|
|
||||||
filePath.basename += "-dev";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(outDir))
|
|
||||||
);
|
|
||||||
|
|
||||||
const fingerprints = {};
|
|
||||||
|
|
||||||
gulp.task("build-translation-fingerprints", () => {
|
|
||||||
// Fingerprint full file of each language
|
|
||||||
const files = readdirSync(fullDir);
|
|
||||||
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
|
||||||
fingerprints[files[i].split(".")[0]] = {
|
|
||||||
// In dev we create fake hashes
|
|
||||||
hash: env.isProdBuild()
|
|
||||||
? createHash("md5")
|
|
||||||
.update(readFileSync(path.join(fullDir, files[i]), "utf-8"))
|
|
||||||
.digest("hex")
|
|
||||||
: "dev",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// In dev we create the file with the fake hash in the filename
|
|
||||||
if (env.isProdBuild()) {
|
|
||||||
mapFiles(outDir, ".json", (filename) => {
|
|
||||||
const parsed = path.parse(filename);
|
|
||||||
|
|
||||||
// nl.json -> nl-<hash>.json
|
|
||||||
if (!(parsed.name in fingerprints)) {
|
|
||||||
throw new Error(`Unable to find hash for ${filename}`);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
renameSync(
|
const mergeStream = gulp
|
||||||
filename,
|
.src(mergeFiles, { allowEmpty: true })
|
||||||
`${parsed.dir}/${parsed.name}-${fingerprints[parsed.name].hash}${
|
.pipe(new MergeJSON(locale, enMaster, emptyReviver));
|
||||||
parsed.ext
|
mergesFinished.push(finished(mergeStream));
|
||||||
}`
|
mergeStream.pipe(hashStream, { end: false });
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = source("translationFingerprints.json");
|
// Wait for all merges to finish, then it's safe to end writing to the
|
||||||
stream.write(JSON.stringify(fingerprints));
|
// downstream pipeline and wait for all fragments to finish writing.
|
||||||
process.nextTick(() => stream.end());
|
await Promise.all(mergesFinished);
|
||||||
return stream.pipe(vinylBuffer()).pipe(gulp.dest(workDir));
|
hashStream.end();
|
||||||
});
|
await finished(fragmentsStream);
|
||||||
|
};
|
||||||
|
|
||||||
gulp.task("build-translation-fragment-supervisor", () =>
|
const writeTranslationMetaData = () =>
|
||||||
gulp
|
gulp
|
||||||
.src(fullDir + "/*.json")
|
.src([`${paths.translations_src}/translationMetadata.json`])
|
||||||
.pipe(transform((data) => data.supervisor))
|
|
||||||
.pipe(
|
.pipe(
|
||||||
rename((filePath) => {
|
new CustomJSON((meta) => {
|
||||||
// In dev we create the file with the fake hash in the filename
|
// Add the test translation in development.
|
||||||
if (!env.isProdBuild()) {
|
if (!env.isProdBuild()) {
|
||||||
filePath.basename += "-dev";
|
meta.test = { nativeName: "Test" };
|
||||||
}
|
}
|
||||||
})
|
// Filter out locales without a native name, and add the hashes.
|
||||||
)
|
for (const locale of Object.keys(meta)) {
|
||||||
.pipe(gulp.dest(workDir + "/supervisor"))
|
if (!meta[locale].nativeName) {
|
||||||
);
|
meta[locale] = undefined;
|
||||||
|
|
||||||
gulp.task("build-translation-flatten-supervisor", () =>
|
|
||||||
gulp
|
|
||||||
.src(workDir + "/supervisor/*.json")
|
|
||||||
.pipe(
|
|
||||||
transform((data) =>
|
|
||||||
// Polymer.AppLocalizeBehavior requires flattened json
|
|
||||||
flatten(data)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(outDir))
|
|
||||||
);
|
|
||||||
|
|
||||||
gulp.task("build-translation-write-metadata", () =>
|
|
||||||
gulp
|
|
||||||
.src([
|
|
||||||
path.join(paths.translations_src, "translationMetadata.json"),
|
|
||||||
...(env.isProdBuild() ? [] : [workDir + "/testMetadata.json"]),
|
|
||||||
workDir + "/translationFingerprints.json",
|
|
||||||
])
|
|
||||||
.pipe(merge({}))
|
|
||||||
.pipe(
|
|
||||||
transform((data) => {
|
|
||||||
const newData = {};
|
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
|
||||||
// Filter out translations without native name.
|
|
||||||
if (value.nativeName) {
|
|
||||||
newData[key] = value;
|
|
||||||
} else {
|
|
||||||
console.warn(
|
console.warn(
|
||||||
`Skipping language ${key}. Native name was not translated.`
|
`Skipping locale ${locale} because native name is not translated.`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
meta[locale].hash = HASHES.get(locale);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return newData;
|
return {
|
||||||
|
fragments: FRAGMENTS.filter(panelFragment),
|
||||||
|
translations: meta,
|
||||||
|
};
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(gulp.dest(workDir));
|
||||||
transform((data) => ({
|
|
||||||
fragments: TRANSLATION_FRAGMENTS,
|
|
||||||
translations: data,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.pipe(rename("translationMetadata.json"))
|
|
||||||
.pipe(gulp.dest(workDir))
|
|
||||||
);
|
|
||||||
|
|
||||||
gulp.task(
|
|
||||||
"create-translations",
|
|
||||||
gulp.series(
|
|
||||||
gulp.parallel("create-test-metadata", "create-test-translation"),
|
|
||||||
"build-master-translation",
|
|
||||||
"build-merged-translations",
|
|
||||||
gulp.parallel(...splitTasks),
|
|
||||||
"build-flattened-translations"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"build-translations",
|
"build-translations",
|
||||||
gulp.series(
|
gulp.series(
|
||||||
gulp.parallel(
|
gulp.parallel(
|
||||||
"fetch-nightly-translations",
|
"fetch-nightly-translations",
|
||||||
gulp.series("clean-translations", "ensure-translations-build-dir")
|
gulp.series("clean-translations", makeWorkDir)
|
||||||
),
|
),
|
||||||
"create-translations",
|
createTestTranslation,
|
||||||
"build-translation-fingerprints",
|
createMasterTranslation,
|
||||||
"build-translation-write-metadata"
|
createTranslations,
|
||||||
|
writeTranslationMetaData
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"build-supervisor-translations",
|
"build-supervisor-translations",
|
||||||
gulp.series(
|
gulp.series(toggleSupervisorFragment, "build-translations")
|
||||||
gulp.parallel(
|
|
||||||
"fetch-nightly-translations",
|
|
||||||
gulp.series("clean-translations", "ensure-translations-build-dir")
|
|
||||||
),
|
|
||||||
gulp.parallel("create-test-metadata", "create-test-translation"),
|
|
||||||
"build-master-translation",
|
|
||||||
"build-merged-translations",
|
|
||||||
"build-translation-fragment-supervisor",
|
|
||||||
"build-translation-flatten-supervisor",
|
|
||||||
"build-translation-fingerprints",
|
|
||||||
"build-translation-write-metadata"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
@@ -99,7 +99,7 @@ gulp.task("webpack-watch-app", () => {
|
|||||||
).watch({ poll: isWsl }, doneHandler());
|
).watch({ poll: isWsl }, doneHandler());
|
||||||
gulp.watch(
|
gulp.watch(
|
||||||
path.join(paths.translations_src, "en.json"),
|
path.join(paths.translations_src, "en.json"),
|
||||||
gulp.series("create-translations", "copy-translations-app")
|
gulp.series("build-translations", "copy-translations-app")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
// Helper function to map recursively over files in a folder and it's subfolders
|
|
||||||
module.exports.mapFiles = function mapFiles(startPath, filter, mapFunc) {
|
|
||||||
const files = fs.readdirSync(startPath);
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
|
||||||
const filename = path.join(startPath, files[i]);
|
|
||||||
const stat = fs.lstatSync(filename);
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
mapFiles(filename, filter, mapFunc);
|
|
||||||
} else if (filename.indexOf(filter) >= 0) {
|
|
||||||
mapFunc(filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@@ -10,6 +10,7 @@ const WebpackBar = require("webpackbar");
|
|||||||
const {
|
const {
|
||||||
TransformAsyncModulesPlugin,
|
TransformAsyncModulesPlugin,
|
||||||
} = require("transform-async-modules-webpack-plugin");
|
} = require("transform-async-modules-webpack-plugin");
|
||||||
|
const { dependencies } = require("../package.json");
|
||||||
const paths = require("./paths.cjs");
|
const paths = require("./paths.cjs");
|
||||||
const bundle = require("./bundle.cjs");
|
const bundle = require("./bundle.cjs");
|
||||||
|
|
||||||
@@ -156,11 +157,15 @@ const createWebpackConfig = ({
|
|||||||
transform: (stats) => JSON.stringify(filterStats(stats)),
|
transform: (stats) => JSON.stringify(filterStats(stats)),
|
||||||
}),
|
}),
|
||||||
!latestBuild &&
|
!latestBuild &&
|
||||||
new TransformAsyncModulesPlugin({ browserslistEnv: "legacy" }),
|
new TransformAsyncModulesPlugin({
|
||||||
|
browserslistEnv: "legacy",
|
||||||
|
runtime: { version: dependencies["@babel/runtime"] },
|
||||||
|
}),
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".js", ".json"],
|
extensions: [".ts", ".js", ".json"],
|
||||||
alias: {
|
alias: {
|
||||||
|
"lit/static-html$": "lit/static-html.js",
|
||||||
"lit/decorators$": "lit/decorators.js",
|
"lit/decorators$": "lit/decorators.js",
|
||||||
"lit/directive$": "lit/directive.js",
|
"lit/directive$": "lit/directive.js",
|
||||||
"lit/directives/until$": "lit/directives/until.js",
|
"lit/directives/until$": "lit/directives/until.js",
|
||||||
|
@@ -10,6 +10,7 @@ import {
|
|||||||
import { HomeAssistantAppEl } from "../../src/layouts/home-assistant";
|
import { HomeAssistantAppEl } from "../../src/layouts/home-assistant";
|
||||||
import { HomeAssistant } from "../../src/types";
|
import { HomeAssistant } from "../../src/types";
|
||||||
import { selectedDemoConfig } from "./configs/demo-configs";
|
import { selectedDemoConfig } from "./configs/demo-configs";
|
||||||
|
import { mockAreaRegistry } from "./stubs/area_registry";
|
||||||
import { mockAuth } from "./stubs/auth";
|
import { mockAuth } from "./stubs/auth";
|
||||||
import { mockConfigEntries } from "./stubs/config_entries";
|
import { mockConfigEntries } from "./stubs/config_entries";
|
||||||
import { mockEnergy } from "./stubs/energy";
|
import { mockEnergy } from "./stubs/energy";
|
||||||
@@ -23,10 +24,10 @@ import { mockLovelace } from "./stubs/lovelace";
|
|||||||
import { mockMediaPlayer } from "./stubs/media_player";
|
import { mockMediaPlayer } from "./stubs/media_player";
|
||||||
import { mockPersistentNotification } from "./stubs/persistent_notification";
|
import { mockPersistentNotification } from "./stubs/persistent_notification";
|
||||||
import { mockRecorder } from "./stubs/recorder";
|
import { mockRecorder } from "./stubs/recorder";
|
||||||
import { mockTodo } from "./stubs/todo";
|
|
||||||
import { mockSensor } from "./stubs/sensor";
|
import { mockSensor } from "./stubs/sensor";
|
||||||
import { mockSystemLog } from "./stubs/system_log";
|
import { mockSystemLog } from "./stubs/system_log";
|
||||||
import { mockTemplate } from "./stubs/template";
|
import { mockTemplate } from "./stubs/template";
|
||||||
|
import { mockTodo } from "./stubs/todo";
|
||||||
import { mockTranslations } from "./stubs/translations";
|
import { mockTranslations } from "./stubs/translations";
|
||||||
|
|
||||||
@customElement("ha-demo")
|
@customElement("ha-demo")
|
||||||
@@ -62,6 +63,7 @@ export class HaDemo extends HomeAssistantAppEl {
|
|||||||
mockEnergy(hass);
|
mockEnergy(hass);
|
||||||
mockPersistentNotification(hass);
|
mockPersistentNotification(hass);
|
||||||
mockConfigEntries(hass);
|
mockConfigEntries(hass);
|
||||||
|
mockAreaRegistry(hass);
|
||||||
mockEntityRegistry(hass, [
|
mockEntityRegistry(hass, [
|
||||||
{
|
{
|
||||||
config_entry_id: "co2signal",
|
config_entry_id: "co2signal",
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { format, startOfToday, startOfTomorrow } from "date-fns/esm";
|
import { format, startOfToday, startOfTomorrow } from "date-fns";
|
||||||
import {
|
import {
|
||||||
EnergyInfo,
|
EnergyInfo,
|
||||||
EnergyPreferences,
|
EnergyPreferences,
|
||||||
|
@@ -64,6 +64,12 @@ const ACTIONS = [
|
|||||||
entity_id: "input_boolean.toggle_4",
|
entity_id: "input_boolean.toggle_4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sequence: [
|
||||||
|
{ scene: "scene.kitchen_morning" },
|
||||||
|
{ service: "light.turn_off", target: { entity_id: "light.kitchen" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
parallel: [
|
parallel: [
|
||||||
{ scene: "scene.kitchen_morning" },
|
{ scene: "scene.kitchen_morning" },
|
||||||
@@ -136,7 +142,7 @@ export class DemoAutomationDescribeAction extends LitElement {
|
|||||||
<div class="action">
|
<div class="action">
|
||||||
<span>
|
<span>
|
||||||
${this._action
|
${this._action
|
||||||
? describeAction(this.hass, [], this._action)
|
? describeAction(this.hass, [], [], [], this._action)
|
||||||
: "<invalid YAML>"}
|
: "<invalid YAML>"}
|
||||||
</span>
|
</span>
|
||||||
<ha-yaml-editor
|
<ha-yaml-editor
|
||||||
@@ -149,7 +155,7 @@ export class DemoAutomationDescribeAction extends LitElement {
|
|||||||
${ACTIONS.map(
|
${ACTIONS.map(
|
||||||
(conf) => html`
|
(conf) => html`
|
||||||
<div class="action">
|
<div class="action">
|
||||||
<span>${describeAction(this.hass, [], conf as any)}</span>
|
<span>${describeAction(this.hass, [], [], [], conf as any)}</span>
|
||||||
<pre>${dump(conf)}</pre>
|
<pre>${dump(conf)}</pre>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@@ -20,6 +20,7 @@ import { HaWaitForTriggerAction } from "../../../../src/panels/config/automation
|
|||||||
import { HaWaitAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_template";
|
import { HaWaitAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_template";
|
||||||
import { Action } from "../../../../src/data/script";
|
import { Action } from "../../../../src/data/script";
|
||||||
import { HaConditionAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-condition";
|
import { HaConditionAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-condition";
|
||||||
|
import { HaSequenceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-sequence";
|
||||||
import { HaParallelAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-parallel";
|
import { HaParallelAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-parallel";
|
||||||
import { HaIfAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-if";
|
import { HaIfAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-if";
|
||||||
import { HaStopAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-stop";
|
import { HaStopAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-stop";
|
||||||
@@ -39,6 +40,7 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
|
|||||||
{ name: "If-Then", actions: [HaIfAction.defaultConfig] },
|
{ name: "If-Then", actions: [HaIfAction.defaultConfig] },
|
||||||
{ name: "Choose", actions: [HaChooseAction.defaultConfig] },
|
{ name: "Choose", actions: [HaChooseAction.defaultConfig] },
|
||||||
{ name: "Variables", actions: [{ variables: { hello: "1" } }] },
|
{ name: "Variables", actions: [{ variables: { hello: "1" } }] },
|
||||||
|
{ name: "Sequence", actions: [HaSequenceAction.defaultConfig] },
|
||||||
{ name: "Parallel", actions: [HaParallelAction.defaultConfig] },
|
{ name: "Parallel", actions: [HaParallelAction.defaultConfig] },
|
||||||
{ name: "Stop", actions: [HaStopAction.defaultConfig] },
|
{ name: "Stop", actions: [HaStopAction.defaultConfig] },
|
||||||
];
|
];
|
||||||
|
@@ -161,12 +161,14 @@ const LABELS: LabelRegistryEntry[] = [
|
|||||||
name: "Energy",
|
name: "Energy",
|
||||||
icon: null,
|
icon: null,
|
||||||
color: "yellow",
|
color: "yellow",
|
||||||
|
description: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label_id: "entertainment",
|
label_id: "entertainment",
|
||||||
name: "Entertainment",
|
name: "Entertainment",
|
||||||
icon: "mdi:popcorn",
|
icon: "mdi:popcorn",
|
||||||
color: "blue",
|
color: "blue",
|
||||||
|
description: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { customElement, query } from "lit/decorators";
|
import { customElement, query } from "lit/decorators";
|
||||||
import { CoverEntityFeature } from "../../../../src/data/cover";
|
import { CoverEntityFeature } from "../../../../src/data/cover";
|
||||||
import { LightColorMode } from "../../../../src/data/light";
|
import { LightColorMode } from "../../../../src/data/light";
|
||||||
|
import { LockEntityFeature } from "../../../../src/data/lock";
|
||||||
import { VacuumEntityFeature } from "../../../../src/data/vacuum";
|
import { VacuumEntityFeature } from "../../../../src/data/vacuum";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
@@ -20,6 +21,11 @@ const ENTITIES = [
|
|||||||
getEntity("light", "unavailable", "unavailable", {
|
getEntity("light", "unavailable", "unavailable", {
|
||||||
friendly_name: "Unavailable entity",
|
friendly_name: "Unavailable entity",
|
||||||
}),
|
}),
|
||||||
|
getEntity("lock", "front_door", "locked", {
|
||||||
|
friendly_name: "Front Door Lock",
|
||||||
|
device_class: "lock",
|
||||||
|
supported_features: LockEntityFeature.OPEN,
|
||||||
|
}),
|
||||||
getEntity("climate", "thermostat", "heat", {
|
getEntity("climate", "thermostat", "heat", {
|
||||||
current_temperature: 73,
|
current_temperature: 73,
|
||||||
min_temp: 45,
|
min_temp: 45,
|
||||||
@@ -138,6 +144,24 @@ const CONFIGS = [
|
|||||||
- type: "color-temp"
|
- type: "color-temp"
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
heading: "Lock commands feature",
|
||||||
|
config: `
|
||||||
|
- type: tile
|
||||||
|
entity: lock.front_door
|
||||||
|
features:
|
||||||
|
- type: "lock-commands"
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
heading: "Lock open door feature",
|
||||||
|
config: `
|
||||||
|
- type: tile
|
||||||
|
entity: lock.front_door
|
||||||
|
features:
|
||||||
|
- type: "lock-open-door"
|
||||||
|
`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
heading: "Vacuum commands feature",
|
heading: "Vacuum commands feature",
|
||||||
config: `
|
config: `
|
||||||
|
@@ -368,6 +368,7 @@ export class DemoEntityState extends LitElement {
|
|||||||
hass.localize,
|
hass.localize,
|
||||||
entry.stateObj,
|
entry.stateObj,
|
||||||
hass.locale,
|
hass.locale,
|
||||||
|
[], // numericDeviceClasses
|
||||||
hass.config,
|
hass.config,
|
||||||
hass.entities
|
hass.entities
|
||||||
)}`,
|
)}`,
|
||||||
|
@@ -36,6 +36,8 @@ const createConfigEntry = (
|
|||||||
pref_disable_new_entities: false,
|
pref_disable_new_entities: false,
|
||||||
pref_disable_polling: false,
|
pref_disable_polling: false,
|
||||||
reason: null,
|
reason: null,
|
||||||
|
error_reason_translation_key: null,
|
||||||
|
error_reason_translation_placeholders: null,
|
||||||
...override,
|
...override,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
import { globIterate } from "glob";
|
import { globIterate } from "glob";
|
||||||
|
import { availableParallelism } from "node:os";
|
||||||
|
|
||||||
|
process.env.UV_THREADPOOL_SIZE = availableParallelism();
|
||||||
|
|
||||||
const gulpImports = [];
|
const gulpImports = [];
|
||||||
|
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
import { mdiStorePlus, mdiUpdate } from "@mdi/js";
|
import { mdiRefresh, mdiStorePlus } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { atLeastVersion } from "../../../src/common/config/version";
|
import { atLeastVersion } from "../../../src/common/config/version";
|
||||||
|
import { fireEvent } from "../../../src/common/dom/fire_event";
|
||||||
import "../../../src/components/ha-fab";
|
import "../../../src/components/ha-fab";
|
||||||
|
import { reloadHassioAddons } from "../../../src/data/hassio/addon";
|
||||||
|
import { extractApiErrorMessage } from "../../../src/data/hassio/common";
|
||||||
import { Supervisor } from "../../../src/data/supervisor/supervisor";
|
import { Supervisor } from "../../../src/data/supervisor/supervisor";
|
||||||
|
import { showAlertDialog } from "../../../src/dialogs/generic/show-dialog-box";
|
||||||
|
import "../../../src/layouts/hass-subpage";
|
||||||
import "../../../src/layouts/hass-tabs-subpage";
|
import "../../../src/layouts/hass-tabs-subpage";
|
||||||
import { haStyle } from "../../../src/resources/styles";
|
import { haStyle } from "../../../src/resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../src/types";
|
import { HomeAssistant, Route } from "../../../src/types";
|
||||||
import { supervisorTabs } from "../hassio-tabs";
|
import { supervisorTabs } from "../hassio-tabs";
|
||||||
import "./hassio-addons";
|
import "./hassio-addons";
|
||||||
import "../../../src/layouts/hass-subpage";
|
|
||||||
import { reloadHassioAddons } from "../../../src/data/hassio/addon";
|
|
||||||
import { extractApiErrorMessage } from "../../../src/data/hassio/common";
|
|
||||||
import { showAlertDialog } from "../../../src/dialogs/generic/show-dialog-box";
|
|
||||||
import { fireEvent } from "../../../src/common/dom/fire_event";
|
|
||||||
|
|
||||||
@customElement("hassio-dashboard")
|
@customElement("hassio-dashboard")
|
||||||
class HassioDashboard extends LitElement {
|
class HassioDashboard extends LitElement {
|
||||||
@@ -43,7 +43,7 @@ class HassioDashboard extends LitElement {
|
|||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="toolbar-icon"
|
slot="toolbar-icon"
|
||||||
@click=${this._handleCheckUpdates}
|
@click=${this._handleCheckUpdates}
|
||||||
.path=${mdiUpdate}
|
.path=${mdiRefresh}
|
||||||
.label=${this.supervisor.localize("store.check_updates")}
|
.label=${this.supervisor.localize("store.check_updates")}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<hassio-addons
|
<hassio-addons
|
||||||
|
143
package.json
143
package.json
@@ -25,30 +25,30 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "7.24.1",
|
"@babel/runtime": "7.24.5",
|
||||||
"@braintree/sanitize-url": "7.0.1",
|
"@braintree/sanitize-url": "7.0.2",
|
||||||
"@codemirror/autocomplete": "6.15.0",
|
"@codemirror/autocomplete": "6.16.0",
|
||||||
"@codemirror/commands": "6.3.3",
|
"@codemirror/commands": "6.5.0",
|
||||||
"@codemirror/language": "6.10.1",
|
"@codemirror/language": "6.10.1",
|
||||||
"@codemirror/legacy-modes": "6.3.3",
|
"@codemirror/legacy-modes": "6.4.0",
|
||||||
"@codemirror/search": "6.5.6",
|
"@codemirror/search": "6.5.6",
|
||||||
"@codemirror/state": "6.4.1",
|
"@codemirror/state": "6.4.1",
|
||||||
"@codemirror/view": "6.26.1",
|
"@codemirror/view": "6.26.3",
|
||||||
"@egjs/hammerjs": "2.0.17",
|
"@egjs/hammerjs": "2.0.17",
|
||||||
"@formatjs/intl-datetimeformat": "6.12.3",
|
"@formatjs/intl-datetimeformat": "6.12.5",
|
||||||
"@formatjs/intl-displaynames": "6.6.6",
|
"@formatjs/intl-displaynames": "6.6.8",
|
||||||
"@formatjs/intl-getcanonicallocales": "2.3.0",
|
"@formatjs/intl-getcanonicallocales": "2.3.0",
|
||||||
"@formatjs/intl-listformat": "7.5.5",
|
"@formatjs/intl-listformat": "7.5.7",
|
||||||
"@formatjs/intl-locale": "3.4.5",
|
"@formatjs/intl-locale": "4.0.0",
|
||||||
"@formatjs/intl-numberformat": "8.10.1",
|
"@formatjs/intl-numberformat": "8.10.3",
|
||||||
"@formatjs/intl-pluralrules": "5.2.12",
|
"@formatjs/intl-pluralrules": "5.2.14",
|
||||||
"@formatjs/intl-relativetimeformat": "11.2.12",
|
"@formatjs/intl-relativetimeformat": "11.2.14",
|
||||||
"@fullcalendar/core": "6.1.11",
|
"@fullcalendar/core": "6.1.13",
|
||||||
"@fullcalendar/daygrid": "6.1.11",
|
"@fullcalendar/daygrid": "6.1.13",
|
||||||
"@fullcalendar/interaction": "6.1.11",
|
"@fullcalendar/interaction": "6.1.13",
|
||||||
"@fullcalendar/list": "6.1.11",
|
"@fullcalendar/list": "6.1.13",
|
||||||
"@fullcalendar/luxon3": "6.1.11",
|
"@fullcalendar/luxon3": "6.1.13",
|
||||||
"@fullcalendar/timegrid": "6.1.11",
|
"@fullcalendar/timegrid": "6.1.13",
|
||||||
"@lezer/highlight": "1.2.0",
|
"@lezer/highlight": "1.2.0",
|
||||||
"@lit-labs/context": "0.4.1",
|
"@lit-labs/context": "0.4.1",
|
||||||
"@lit-labs/motion": "1.0.7",
|
"@lit-labs/motion": "1.0.7",
|
||||||
@@ -70,7 +70,6 @@
|
|||||||
"@material/mwc-list": "0.27.0",
|
"@material/mwc-list": "0.27.0",
|
||||||
"@material/mwc-menu": "0.27.0",
|
"@material/mwc-menu": "0.27.0",
|
||||||
"@material/mwc-radio": "0.27.0",
|
"@material/mwc-radio": "0.27.0",
|
||||||
"@material/mwc-ripple": "0.27.0",
|
|
||||||
"@material/mwc-select": "0.27.0",
|
"@material/mwc-select": "0.27.0",
|
||||||
"@material/mwc-snackbar": "0.27.0",
|
"@material/mwc-snackbar": "0.27.0",
|
||||||
"@material/mwc-switch": "0.27.0",
|
"@material/mwc-switch": "0.27.0",
|
||||||
@@ -81,7 +80,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": "=1.3.0",
|
"@material/web": "1.4.1",
|
||||||
"@mdi/js": "7.4.47",
|
"@mdi/js": "7.4.47",
|
||||||
"@mdi/svg": "7.4.47",
|
"@mdi/svg": "7.4.47",
|
||||||
"@polymer/paper-item": "3.0.1",
|
"@polymer/paper-item": "3.0.1",
|
||||||
@@ -89,8 +88,8 @@
|
|||||||
"@polymer/paper-tabs": "3.1.0",
|
"@polymer/paper-tabs": "3.1.0",
|
||||||
"@polymer/polymer": "3.5.1",
|
"@polymer/polymer": "3.5.1",
|
||||||
"@thomasloven/round-slider": "0.6.0",
|
"@thomasloven/round-slider": "0.6.0",
|
||||||
"@vaadin/combo-box": "24.3.10",
|
"@vaadin/combo-box": "24.3.13",
|
||||||
"@vaadin/vaadin-themable-mixin": "24.3.10",
|
"@vaadin/vaadin-themable-mixin": "24.3.13",
|
||||||
"@vibrant/color": "3.2.1-alpha.1",
|
"@vibrant/color": "3.2.1-alpha.1",
|
||||||
"@vibrant/core": "3.2.1-alpha.1",
|
"@vibrant/core": "3.2.1-alpha.1",
|
||||||
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
|
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
|
||||||
@@ -98,28 +97,28 @@
|
|||||||
"@webcomponents/scoped-custom-element-registry": "0.0.9",
|
"@webcomponents/scoped-custom-element-registry": "0.0.9",
|
||||||
"@webcomponents/webcomponentsjs": "2.8.0",
|
"@webcomponents/webcomponentsjs": "2.8.0",
|
||||||
"app-datepicker": "5.1.1",
|
"app-datepicker": "5.1.1",
|
||||||
"chart.js": "4.4.2",
|
"chart.js": "4.4.3",
|
||||||
"color-name": "2.0.0",
|
"color-name": "2.0.0",
|
||||||
"comlink": "4.4.1",
|
"comlink": "4.4.1",
|
||||||
"core-js": "3.36.1",
|
"core-js": "3.37.1",
|
||||||
"cropperjs": "1.6.1",
|
"cropperjs": "1.6.2",
|
||||||
"date-fns": "2.30.0",
|
"date-fns": "3.6.0",
|
||||||
"date-fns-tz": "2.0.1",
|
"date-fns-tz": "3.1.3",
|
||||||
"deep-clone-simple": "1.1.1",
|
"deep-clone-simple": "1.1.1",
|
||||||
"deep-freeze": "0.0.1",
|
"deep-freeze": "0.0.1",
|
||||||
"element-internals-polyfill": "1.3.10",
|
"element-internals-polyfill": "1.3.11",
|
||||||
"fuse.js": "7.0.0",
|
"fuse.js": "7.0.0",
|
||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
||||||
"home-assistant-js-websocket": "9.2.1",
|
"home-assistant-js-websocket": "9.3.0",
|
||||||
"idb-keyval": "6.2.1",
|
"idb-keyval": "6.2.1",
|
||||||
"intl-messageformat": "10.5.11",
|
"intl-messageformat": "10.5.14",
|
||||||
"js-yaml": "4.1.0",
|
"js-yaml": "4.1.0",
|
||||||
"leaflet": "1.9.4",
|
"leaflet": "1.9.4",
|
||||||
"leaflet-draw": "1.0.4",
|
"leaflet-draw": "1.0.4",
|
||||||
"lit": "2.8.0",
|
"lit": "2.8.0",
|
||||||
"luxon": "3.4.4",
|
"luxon": "3.4.4",
|
||||||
"marked": "12.0.1",
|
"marked": "12.0.2",
|
||||||
"memoize-one": "6.0.0",
|
"memoize-one": "6.0.0",
|
||||||
"node-vibrant": "3.2.1-alpha.1",
|
"node-vibrant": "3.2.1-alpha.1",
|
||||||
"proxy-polyfill": "0.3.2",
|
"proxy-polyfill": "0.3.2",
|
||||||
@@ -141,57 +140,58 @@
|
|||||||
"vue": "2.7.16",
|
"vue": "2.7.16",
|
||||||
"vue2-daterange-picker": "0.6.8",
|
"vue2-daterange-picker": "0.6.8",
|
||||||
"weekstart": "2.0.0",
|
"weekstart": "2.0.0",
|
||||||
"workbox-cacheable-response": "7.0.0",
|
"workbox-cacheable-response": "7.1.0",
|
||||||
"workbox-core": "7.0.0",
|
"workbox-core": "7.1.0",
|
||||||
"workbox-expiration": "7.0.0",
|
"workbox-expiration": "7.1.0",
|
||||||
"workbox-precaching": "7.0.0",
|
"workbox-precaching": "7.1.0",
|
||||||
"workbox-routing": "7.0.0",
|
"workbox-routing": "7.1.0",
|
||||||
"workbox-strategies": "7.0.0",
|
"workbox-strategies": "7.1.0",
|
||||||
"xss": "1.0.15"
|
"xss": "1.0.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.24.3",
|
"@babel/core": "7.24.5",
|
||||||
"@babel/helper-define-polyfill-provider": "0.6.1",
|
"@babel/helper-define-polyfill-provider": "0.6.2",
|
||||||
"@babel/plugin-proposal-decorators": "7.24.1",
|
"@babel/plugin-proposal-decorators": "7.24.1",
|
||||||
"@babel/plugin-transform-runtime": "7.24.3",
|
"@babel/plugin-transform-runtime": "7.24.3",
|
||||||
"@babel/preset-env": "7.24.3",
|
"@babel/preset-env": "7.24.5",
|
||||||
"@babel/preset-typescript": "7.24.1",
|
"@babel/preset-typescript": "7.24.1",
|
||||||
"@bundle-stats/plugin-webpack-filter": "4.12.2",
|
"@bundle-stats/plugin-webpack-filter": "4.12.2",
|
||||||
"@koa/cors": "5.0.0",
|
"@koa/cors": "5.0.0",
|
||||||
"@lokalise/node-api": "12.3.0",
|
"@lokalise/node-api": "12.5.0",
|
||||||
"@octokit/auth-oauth-device": "7.0.1",
|
"@octokit/auth-oauth-device": "7.1.1",
|
||||||
"@octokit/plugin-retry": "7.0.3",
|
"@octokit/plugin-retry": "7.1.1",
|
||||||
"@octokit/rest": "20.0.2",
|
"@octokit/rest": "20.1.1",
|
||||||
"@open-wc/dev-server-hmr": "0.1.4",
|
"@open-wc/dev-server-hmr": "0.1.4",
|
||||||
"@rollup/plugin-babel": "6.0.4",
|
"@rollup/plugin-babel": "6.0.4",
|
||||||
"@rollup/plugin-commonjs": "25.0.7",
|
"@rollup/plugin-commonjs": "25.0.8",
|
||||||
"@rollup/plugin-json": "6.1.0",
|
"@rollup/plugin-json": "6.1.0",
|
||||||
"@rollup/plugin-node-resolve": "15.2.3",
|
"@rollup/plugin-node-resolve": "15.2.3",
|
||||||
"@rollup/plugin-replace": "5.0.5",
|
"@rollup/plugin-replace": "5.0.5",
|
||||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||||
"@types/chromecast-caf-receiver": "6.0.13",
|
"@types/chromecast-caf-receiver": "6.0.14",
|
||||||
"@types/chromecast-caf-sender": "1.0.9",
|
"@types/chromecast-caf-sender": "1.0.10",
|
||||||
"@types/color-name": "1.1.3",
|
"@types/color-name": "1.1.4",
|
||||||
"@types/glob": "8.1.0",
|
"@types/glob": "8.1.0",
|
||||||
"@types/html-minifier-terser": "7.0.2",
|
"@types/html-minifier-terser": "7.0.2",
|
||||||
"@types/js-yaml": "4.0.9",
|
"@types/js-yaml": "4.0.9",
|
||||||
"@types/leaflet": "1.9.8",
|
"@types/leaflet": "1.9.12",
|
||||||
"@types/leaflet-draw": "1.0.11",
|
"@types/leaflet-draw": "1.0.11",
|
||||||
|
"@types/lodash.merge": "4.6.9",
|
||||||
"@types/luxon": "3.4.2",
|
"@types/luxon": "3.4.2",
|
||||||
"@types/mocha": "10.0.6",
|
"@types/mocha": "10.0.6",
|
||||||
"@types/qrcode": "1.5.5",
|
"@types/qrcode": "1.5.5",
|
||||||
"@types/serve-handler": "6.1.4",
|
"@types/serve-handler": "6.1.4",
|
||||||
"@types/sortablejs": "1.15.8",
|
"@types/sortablejs": "1.15.8",
|
||||||
"@types/tar": "6.1.11",
|
"@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",
|
||||||
"@typescript-eslint/eslint-plugin": "7.4.0",
|
"@typescript-eslint/eslint-plugin": "7.10.0",
|
||||||
"@typescript-eslint/parser": "7.4.0",
|
"@typescript-eslint/parser": "7.10.0",
|
||||||
"@web/dev-server": "0.1.38",
|
"@web/dev-server": "0.1.38",
|
||||||
"@web/dev-server-rollup": "0.4.1",
|
"@web/dev-server-rollup": "0.4.1",
|
||||||
"babel-loader": "9.1.3",
|
"babel-loader": "9.1.3",
|
||||||
"babel-plugin-template-html-minifier": "4.1.0",
|
"babel-plugin-template-html-minifier": "4.1.0",
|
||||||
"chai": "5.1.0",
|
"chai": "5.1.1",
|
||||||
"del": "7.1.0",
|
"del": "7.1.0",
|
||||||
"eslint": "8.57.0",
|
"eslint": "8.57.0",
|
||||||
"eslint-config-airbnb-base": "15.0.0",
|
"eslint-config-airbnb-base": "15.0.0",
|
||||||
@@ -200,29 +200,28 @@
|
|||||||
"eslint-import-resolver-webpack": "0.13.8",
|
"eslint-import-resolver-webpack": "0.13.8",
|
||||||
"eslint-plugin-disable": "2.0.3",
|
"eslint-plugin-disable": "2.0.3",
|
||||||
"eslint-plugin-import": "2.29.1",
|
"eslint-plugin-import": "2.29.1",
|
||||||
"eslint-plugin-lit": "1.11.0",
|
"eslint-plugin-lit": "1.13.0",
|
||||||
"eslint-plugin-lit-a11y": "4.1.2",
|
"eslint-plugin-lit-a11y": "4.1.2",
|
||||||
"eslint-plugin-unused-imports": "3.1.0",
|
"eslint-plugin-unused-imports": "3.2.0",
|
||||||
"eslint-plugin-wc": "2.0.4",
|
"eslint-plugin-wc": "2.1.0",
|
||||||
"fancy-log": "2.0.0",
|
"fancy-log": "2.0.0",
|
||||||
"fs-extra": "11.2.0",
|
"fs-extra": "11.2.0",
|
||||||
"glob": "10.3.10",
|
"glob": "10.4.1",
|
||||||
"gulp": "4.0.2",
|
"gulp": "5.0.0",
|
||||||
"gulp-flatmap": "1.0.2",
|
|
||||||
"gulp-json-transform": "0.5.0",
|
"gulp-json-transform": "0.5.0",
|
||||||
"gulp-merge-json": "2.2.1",
|
|
||||||
"gulp-rename": "2.0.0",
|
"gulp-rename": "2.0.0",
|
||||||
"gulp-zopfli-green": "6.0.1",
|
"gulp-zopfli-green": "6.0.1",
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
"husky": "9.0.11",
|
"husky": "9.0.11",
|
||||||
"instant-mocha": "1.5.2",
|
"instant-mocha": "1.5.2",
|
||||||
"jszip": "3.10.1",
|
"jszip": "3.10.1",
|
||||||
"lint-staged": "15.2.2",
|
"lint-staged": "15.2.4",
|
||||||
"lit-analyzer": "2.0.3",
|
"lit-analyzer": "2.0.3",
|
||||||
|
"lodash.merge": "4.6.2",
|
||||||
"lodash.template": "4.5.0",
|
"lodash.template": "4.5.0",
|
||||||
"magic-string": "0.30.8",
|
"magic-string": "0.30.10",
|
||||||
"map-stream": "0.0.7",
|
"map-stream": "0.0.7",
|
||||||
"mocha": "10.3.0",
|
"mocha": "10.4.0",
|
||||||
"object-hash": "3.0.0",
|
"object-hash": "3.0.0",
|
||||||
"open": "10.1.0",
|
"open": "10.1.0",
|
||||||
"pinst": "3.0.0",
|
"pinst": "3.0.0",
|
||||||
@@ -232,23 +231,21 @@
|
|||||||
"rollup-plugin-terser": "7.0.2",
|
"rollup-plugin-terser": "7.0.2",
|
||||||
"rollup-plugin-visualizer": "5.12.0",
|
"rollup-plugin-visualizer": "5.12.0",
|
||||||
"serve-handler": "6.1.5",
|
"serve-handler": "6.1.5",
|
||||||
"sinon": "17.0.1",
|
"sinon": "18.0.0",
|
||||||
"source-map-url": "0.4.1",
|
"source-map-url": "0.4.1",
|
||||||
"systemjs": "6.14.3",
|
"systemjs": "6.15.1",
|
||||||
"tar": "6.2.1",
|
"tar": "7.1.0",
|
||||||
"terser-webpack-plugin": "5.3.10",
|
"terser-webpack-plugin": "5.3.10",
|
||||||
"transform-async-modules-webpack-plugin": "1.0.4",
|
"transform-async-modules-webpack-plugin": "1.1.1",
|
||||||
"ts-lit-plugin": "2.0.2",
|
"ts-lit-plugin": "2.0.2",
|
||||||
"typescript": "5.4.3",
|
"typescript": "5.4.5",
|
||||||
"vinyl-buffer": "1.0.1",
|
|
||||||
"vinyl-source-stream": "2.0.0",
|
|
||||||
"webpack": "5.91.0",
|
"webpack": "5.91.0",
|
||||||
"webpack-cli": "5.1.4",
|
"webpack-cli": "5.1.4",
|
||||||
"webpack-dev-server": "5.0.4",
|
"webpack-dev-server": "5.0.4",
|
||||||
"webpack-manifest-plugin": "5.0.0",
|
"webpack-manifest-plugin": "5.0.0",
|
||||||
"webpack-stats-plugin": "1.1.3",
|
"webpack-stats-plugin": "1.1.3",
|
||||||
"webpackbar": "6.0.1",
|
"webpackbar": "6.0.1",
|
||||||
"workbox-build": "7.0.0"
|
"workbox-build": "7.1.0"
|
||||||
},
|
},
|
||||||
"_comment": "Polymer 3.2 contained a bug, fixed in https://github.com/Polymer/polymer/pull/5569, add as patch",
|
"_comment": "Polymer 3.2 contained a bug, fixed in https://github.com/Polymer/polymer/pull/5569, add as patch",
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
@@ -260,5 +257,5 @@
|
|||||||
"sortablejs@1.15.2": "patch:sortablejs@npm%3A1.15.2#~/.yarn/patches/sortablejs-npm-1.15.2-73347ae85a.patch",
|
"sortablejs@1.15.2": "patch:sortablejs@npm%3A1.15.2#~/.yarn/patches/sortablejs-npm-1.15.2-73347ae85a.patch",
|
||||||
"leaflet-draw@1.0.4": "patch:leaflet-draw@npm%3A1.0.4#./.yarn/patches/leaflet-draw-npm-1.0.4-0ca0ebcf65.patch"
|
"leaflet-draw@1.0.4": "patch:leaflet-draw@npm%3A1.0.4#./.yarn/patches/leaflet-draw-npm-1.0.4-0ca0ebcf65.patch"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.1.1"
|
"packageManager": "yarn@4.2.2"
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20240403.1"
|
version = "20240501.0"
|
||||||
license = {text = "Apache-2.0"}
|
license = {text = "Apache-2.0"}
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@@ -40,6 +40,11 @@
|
|||||||
"matchPackageNames": ["tsparticles-engine"],
|
"matchPackageNames": ["tsparticles-engine"],
|
||||||
"matchPackagePrefixes": ["tsparticles-preset-"]
|
"matchPackagePrefixes": ["tsparticles-preset-"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "Group date-fns with dependent timezone package",
|
||||||
|
"groupName": "date-fns",
|
||||||
|
"matchPackageNames": ["date-fns", "date-fns-tz"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"description": "Group and temporarily disable WDS packages",
|
"description": "Group and temporarily disable WDS packages",
|
||||||
"groupName": "Web Dev Server",
|
"groupName": "Web Dev Server",
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { utcToZonedTime, zonedTimeToUtc } from "date-fns-tz";
|
import { toZonedTime, fromZonedTime } from "date-fns-tz";
|
||||||
import { HassConfig } from "home-assistant-js-websocket";
|
import { HassConfig } from "home-assistant-js-websocket";
|
||||||
import { FrontendLocaleData, TimeZone } from "../../data/translation";
|
import { FrontendLocaleData, TimeZone } from "../../data/translation";
|
||||||
|
|
||||||
@@ -8,10 +8,10 @@ const calcZonedDate = (
|
|||||||
fn: (date: Date, options?: any) => Date | number | boolean,
|
fn: (date: Date, options?: any) => Date | number | boolean,
|
||||||
options?
|
options?
|
||||||
) => {
|
) => {
|
||||||
const inputZoned = utcToZonedTime(date, tz);
|
const inputZoned = toZonedTime(date, tz);
|
||||||
const fnZoned = fn(inputZoned, options);
|
const fnZoned = fn(inputZoned, options);
|
||||||
if (fnZoned instanceof Date) {
|
if (fnZoned instanceof Date) {
|
||||||
return zonedTimeToUtc(fnZoned, tz) as Date;
|
return fromZonedTime(fnZoned, tz) as Date;
|
||||||
}
|
}
|
||||||
return fnZoned;
|
return fnZoned;
|
||||||
};
|
};
|
||||||
@@ -51,6 +51,6 @@ export const calcDateDifferenceProperty = (
|
|||||||
locale,
|
locale,
|
||||||
config,
|
config,
|
||||||
locale.time_zone === TimeZone.server
|
locale.time_zone === TimeZone.server
|
||||||
? utcToZonedTime(startDate, config.time_zone)
|
? toZonedTime(startDate, config.time_zone)
|
||||||
: startDate
|
: startDate
|
||||||
);
|
);
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
export type MediaQueriesListener = () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach a media query. Listener is called right away and when it matches.
|
* Attach a media query. Listener is called right away and when it matches.
|
||||||
* @param mediaQuery media query to match.
|
* @param mediaQuery media query to match.
|
||||||
@@ -7,7 +9,7 @@
|
|||||||
export const listenMediaQuery = (
|
export const listenMediaQuery = (
|
||||||
mediaQuery: string,
|
mediaQuery: string,
|
||||||
matchesChanged: (matches: boolean) => void
|
matchesChanged: (matches: boolean) => void
|
||||||
) => {
|
): MediaQueriesListener => {
|
||||||
const mql = matchMedia(mediaQuery);
|
const mql = matchMedia(mediaQuery);
|
||||||
const listener = (e) => matchesChanged(e.matches);
|
const listener = (e) => matchesChanged(e.matches);
|
||||||
mql.addListener(listener);
|
mql.addListener(listener);
|
||||||
|
@@ -19,28 +19,11 @@ import { blankBeforeUnit } from "../translations/blank_before_unit";
|
|||||||
import { LocalizeFunc } from "../translations/localize";
|
import { LocalizeFunc } from "../translations/localize";
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export const computeStateDisplaySingleEntity = (
|
|
||||||
localize: LocalizeFunc,
|
|
||||||
stateObj: HassEntity,
|
|
||||||
locale: FrontendLocaleData,
|
|
||||||
config: HassConfig,
|
|
||||||
entity: EntityRegistryDisplayEntry | undefined,
|
|
||||||
state?: string
|
|
||||||
): string =>
|
|
||||||
computeStateDisplayFromEntityAttributes(
|
|
||||||
localize,
|
|
||||||
locale,
|
|
||||||
config,
|
|
||||||
entity,
|
|
||||||
stateObj.entity_id,
|
|
||||||
stateObj.attributes,
|
|
||||||
state !== undefined ? state : stateObj.state
|
|
||||||
);
|
|
||||||
|
|
||||||
export const computeStateDisplay = (
|
export const computeStateDisplay = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
stateObj: HassEntity,
|
stateObj: HassEntity,
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
|
sensorNumericDeviceClasses: string[],
|
||||||
config: HassConfig,
|
config: HassConfig,
|
||||||
entities: HomeAssistant["entities"],
|
entities: HomeAssistant["entities"],
|
||||||
state?: string
|
state?: string
|
||||||
@@ -52,6 +35,7 @@ export const computeStateDisplay = (
|
|||||||
return computeStateDisplayFromEntityAttributes(
|
return computeStateDisplayFromEntityAttributes(
|
||||||
localize,
|
localize,
|
||||||
locale,
|
locale,
|
||||||
|
sensorNumericDeviceClasses,
|
||||||
config,
|
config,
|
||||||
entity,
|
entity,
|
||||||
stateObj.entity_id,
|
stateObj.entity_id,
|
||||||
@@ -63,6 +47,7 @@ export const computeStateDisplay = (
|
|||||||
export const computeStateDisplayFromEntityAttributes = (
|
export const computeStateDisplayFromEntityAttributes = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
|
sensorNumericDeviceClasses: string[],
|
||||||
config: HassConfig,
|
config: HassConfig,
|
||||||
entity: EntityRegistryDisplayEntry | undefined,
|
entity: EntityRegistryDisplayEntry | undefined,
|
||||||
entityId: string,
|
entityId: string,
|
||||||
@@ -73,8 +58,15 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
return localize(`state.default.${state}`);
|
return localize(`state.default.${state}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const domain = computeDomain(entityId);
|
||||||
|
|
||||||
// Entities with a `unit_of_measurement` or `state_class` are numeric values and should use `formatNumber`
|
// Entities with a `unit_of_measurement` or `state_class` are numeric values and should use `formatNumber`
|
||||||
if (isNumericFromAttributes(attributes)) {
|
if (
|
||||||
|
isNumericFromAttributes(
|
||||||
|
attributes,
|
||||||
|
domain === "sensor" ? sensorNumericDeviceClasses : []
|
||||||
|
)
|
||||||
|
) {
|
||||||
// state is duration
|
// state is duration
|
||||||
if (
|
if (
|
||||||
attributes.device_class === "duration" &&
|
attributes.device_class === "duration" &&
|
||||||
@@ -120,8 +112,6 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = computeDomain(entityId);
|
|
||||||
|
|
||||||
if (domain === "datetime") {
|
if (domain === "datetime") {
|
||||||
const time = new Date(state);
|
const time = new Date(state);
|
||||||
return formatDateTime(time, locale, config);
|
return formatDateTime(time, locale, config);
|
||||||
@@ -187,11 +177,14 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
"button",
|
"button",
|
||||||
|
"conversation",
|
||||||
"event",
|
"event",
|
||||||
"image",
|
"image",
|
||||||
"input_button",
|
"input_button",
|
||||||
|
"notify",
|
||||||
"scene",
|
"scene",
|
||||||
"stt",
|
"stt",
|
||||||
|
"tag",
|
||||||
"tts",
|
"tts",
|
||||||
"wake_word",
|
"wake_word",
|
||||||
].includes(domain) ||
|
].includes(domain) ||
|
||||||
|
@@ -28,7 +28,15 @@ export const FIXED_DOMAIN_STATES = {
|
|||||||
input_button: [],
|
input_button: [],
|
||||||
lawn_mower: ["error", "paused", "mowing", "docked"],
|
lawn_mower: ["error", "paused", "mowing", "docked"],
|
||||||
light: ["on", "off"],
|
light: ["on", "off"],
|
||||||
lock: ["jammed", "locked", "locking", "unlocked", "unlocking"],
|
lock: [
|
||||||
|
"jammed",
|
||||||
|
"locked",
|
||||||
|
"locking",
|
||||||
|
"unlocked",
|
||||||
|
"unlocking",
|
||||||
|
"opening",
|
||||||
|
"open",
|
||||||
|
],
|
||||||
media_player: [
|
media_player: [
|
||||||
"off",
|
"off",
|
||||||
"on",
|
"on",
|
||||||
|
@@ -14,8 +14,12 @@ export const isNumericState = (stateObj: HassEntity): boolean =>
|
|||||||
isNumericFromAttributes(stateObj.attributes);
|
isNumericFromAttributes(stateObj.attributes);
|
||||||
|
|
||||||
export const isNumericFromAttributes = (
|
export const isNumericFromAttributes = (
|
||||||
attributes: HassEntityAttributeBase
|
attributes: HassEntityAttributeBase,
|
||||||
): boolean => !!attributes.unit_of_measurement || !!attributes.state_class;
|
numericDeviceClasses?: string[]
|
||||||
|
): boolean =>
|
||||||
|
!!attributes.unit_of_measurement ||
|
||||||
|
!!attributes.state_class ||
|
||||||
|
(numericDeviceClasses || []).includes(attributes.device_class || "");
|
||||||
|
|
||||||
export const numberFormatToLocale = (
|
export const numberFormatToLocale = (
|
||||||
localeOptions: FrontendLocaleData
|
localeOptions: FrontendLocaleData
|
||||||
|
@@ -21,7 +21,8 @@ export const computeFormatFunctions = async (
|
|||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
config: HassConfig,
|
config: HassConfig,
|
||||||
entities: HomeAssistant["entities"]
|
entities: HomeAssistant["entities"],
|
||||||
|
sensorNumericDeviceClasses: string[]
|
||||||
): Promise<{
|
): Promise<{
|
||||||
formatEntityState: FormatEntityStateFunc;
|
formatEntityState: FormatEntityStateFunc;
|
||||||
formatEntityAttributeValue: FormatEntityAttributeValueFunc;
|
formatEntityAttributeValue: FormatEntityAttributeValueFunc;
|
||||||
@@ -35,7 +36,15 @@ export const computeFormatFunctions = async (
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
formatEntityState: (stateObj, state) =>
|
formatEntityState: (stateObj, state) =>
|
||||||
computeStateDisplay(localize, stateObj, locale, config, entities, state),
|
computeStateDisplay(
|
||||||
|
localize,
|
||||||
|
stateObj,
|
||||||
|
locale,
|
||||||
|
sensorNumericDeviceClasses,
|
||||||
|
config,
|
||||||
|
entities,
|
||||||
|
state
|
||||||
|
),
|
||||||
formatEntityAttributeValue: (stateObj, attribute, value) =>
|
formatEntityAttributeValue: (stateObj, attribute, value) =>
|
||||||
computeAttributeValueDisplay(
|
computeAttributeValueDisplay(
|
||||||
localize,
|
localize,
|
||||||
|
@@ -2,6 +2,7 @@ import IntlMessageFormat from "intl-messageformat";
|
|||||||
import type { HTMLTemplateResult } from "lit";
|
import type { HTMLTemplateResult } from "lit";
|
||||||
import { polyfillLocaleData } from "../../resources/locale-data-polyfill";
|
import { polyfillLocaleData } from "../../resources/locale-data-polyfill";
|
||||||
import { Resources, TranslationDict } from "../../types";
|
import { Resources, TranslationDict } from "../../types";
|
||||||
|
import { fireEvent } from "../dom/fire_event";
|
||||||
|
|
||||||
// Exclude some patterns from key type checking for now
|
// Exclude some patterns from key type checking for now
|
||||||
// These are intended to be removed as errors are fixed
|
// These are intended to be removed as errors are fixed
|
||||||
@@ -81,7 +82,9 @@ export interface FormatsType {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
||||||
cache: any,
|
cache: HTMLElement & {
|
||||||
|
_localizationCache?: Record<string, IntlMessageFormat>;
|
||||||
|
},
|
||||||
language: string,
|
language: string,
|
||||||
resources: Resources,
|
resources: Resources,
|
||||||
formats?: FormatsType
|
formats?: FormatsType
|
||||||
@@ -107,7 +110,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messageKey = key + translatedValue;
|
const messageKey = key + translatedValue;
|
||||||
let translatedMessage = cache._localizationCache[messageKey] as
|
let translatedMessage = cache._localizationCache![messageKey] as
|
||||||
| IntlMessageFormat
|
| IntlMessageFormat
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
return "Translation error: " + err.message;
|
return "Translation error: " + err.message;
|
||||||
}
|
}
|
||||||
cache._localizationCache[messageKey] = translatedMessage;
|
cache._localizationCache![messageKey] = translatedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
let argObject = {};
|
let argObject = {};
|
||||||
@@ -137,6 +140,12 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
try {
|
try {
|
||||||
return translatedMessage.format<string>(argObject) as string;
|
return translatedMessage.format<string>(argObject) as string;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error("Translation error", key, language, err);
|
||||||
|
fireEvent(cache, "write_log", {
|
||||||
|
level: "error",
|
||||||
|
message: `Failed to format translation for key '${key}' in language '${language}'. ${err}`,
|
||||||
|
});
|
||||||
return "Translation " + err;
|
return "Translation " + err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
9
src/common/util/promise-all-settled-results.ts
Normal file
9
src/common/util/promise-all-settled-results.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export const hasRejectedItems = <T = any>(results: PromiseSettledResult<T>[]) =>
|
||||||
|
results.some((result) => result.status === "rejected");
|
||||||
|
|
||||||
|
export const rejectedItems = <T = any>(
|
||||||
|
results: PromiseSettledResult<T>[]
|
||||||
|
): PromiseRejectedResult[] =>
|
||||||
|
results.filter(
|
||||||
|
(result) => result.status === "rejected"
|
||||||
|
) as PromiseRejectedResult[];
|
@@ -1,4 +1,4 @@
|
|||||||
import { differenceInDays, differenceInWeeks, startOfWeek } from "date-fns/esm";
|
import { differenceInDays, differenceInWeeks, startOfWeek } from "date-fns";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import { firstWeekdayIndex } from "../datetime/first_weekday";
|
import { firstWeekdayIndex } from "../datetime/first_weekday";
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ import {
|
|||||||
endOfMonth,
|
endOfMonth,
|
||||||
endOfQuarter,
|
endOfQuarter,
|
||||||
endOfYear,
|
endOfYear,
|
||||||
} from "date-fns/esm";
|
} from "date-fns";
|
||||||
import {
|
import {
|
||||||
formatDate,
|
formatDate,
|
||||||
formatDateMonth,
|
formatDateMonth,
|
||||||
|
@@ -313,31 +313,38 @@ export class HaChartBase extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _loading = false;
|
||||||
|
|
||||||
private async _setupChart() {
|
private async _setupChart() {
|
||||||
|
if (this._loading) return;
|
||||||
const ctx: CanvasRenderingContext2D = this.renderRoot
|
const ctx: CanvasRenderingContext2D = this.renderRoot
|
||||||
.querySelector("canvas")!
|
.querySelector("canvas")!
|
||||||
.getContext("2d")!;
|
.getContext("2d")!;
|
||||||
|
this._loading = true;
|
||||||
|
try {
|
||||||
|
const ChartConstructor = (await import("../../resources/chartjs")).Chart;
|
||||||
|
|
||||||
const ChartConstructor = (await import("../../resources/chartjs")).Chart;
|
const computedStyles = getComputedStyle(this);
|
||||||
|
|
||||||
const computedStyles = getComputedStyle(this);
|
ChartConstructor.defaults.borderColor =
|
||||||
|
computedStyles.getPropertyValue("--divider-color");
|
||||||
|
ChartConstructor.defaults.color = computedStyles.getPropertyValue(
|
||||||
|
"--secondary-text-color"
|
||||||
|
);
|
||||||
|
ChartConstructor.defaults.font.family =
|
||||||
|
computedStyles.getPropertyValue("--mdc-typography-body1-font-family") ||
|
||||||
|
computedStyles.getPropertyValue("--mdc-typography-font-family") ||
|
||||||
|
"Roboto, Noto, sans-serif";
|
||||||
|
|
||||||
ChartConstructor.defaults.borderColor =
|
this.chart = new ChartConstructor(ctx, {
|
||||||
computedStyles.getPropertyValue("--divider-color");
|
type: this.chartType,
|
||||||
ChartConstructor.defaults.color = computedStyles.getPropertyValue(
|
data: this.data,
|
||||||
"--secondary-text-color"
|
options: this._createOptions(),
|
||||||
);
|
plugins: this._createPlugins(),
|
||||||
ChartConstructor.defaults.font.family =
|
});
|
||||||
computedStyles.getPropertyValue("--mdc-typography-body1-font-family") ||
|
} finally {
|
||||||
computedStyles.getPropertyValue("--mdc-typography-font-family") ||
|
this._loading = false;
|
||||||
"Roboto, Noto, sans-serif";
|
}
|
||||||
|
|
||||||
this.chart = new ChartConstructor(ctx, {
|
|
||||||
type: this.chartType,
|
|
||||||
data: this.data,
|
|
||||||
options: this._createOptions(),
|
|
||||||
plugins: this._createPlugins(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createOptions() {
|
private _createOptions() {
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import "element-internals-polyfill";
|
|
||||||
import { MdAssistChip } from "@material/web/chips/assist-chip";
|
import { MdAssistChip } from "@material/web/chips/assist-chip";
|
||||||
import { css, html } from "lit";
|
import { css, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import "element-internals-polyfill";
|
|
||||||
import { MdChipSet } from "@material/web/chips/chip-set";
|
import { MdChipSet } from "@material/web/chips/chip-set";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import "element-internals-polyfill";
|
|
||||||
import { MdFilterChip } from "@material/web/chips/filter-chip";
|
import { MdFilterChip } from "@material/web/chips/filter-chip";
|
||||||
import { css, html } from "lit";
|
import { css, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import "element-internals-polyfill";
|
|
||||||
import { MdInputChip } from "@material/web/chips/input-chip";
|
import { MdInputChip } from "@material/web/chips/input-chip";
|
||||||
import { css } from "lit";
|
import { css } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
@@ -20,6 +19,7 @@ export class HaInputChip extends MdInputChip {
|
|||||||
0.15
|
0.15
|
||||||
);
|
);
|
||||||
--ha-input-chip-selected-container-opacity: 1;
|
--ha-input-chip-selected-container-opacity: 1;
|
||||||
|
--md-input-chip-label-text-font: Roboto, sans-serif;
|
||||||
}
|
}
|
||||||
/** Set the size of mdc icons **/
|
/** Set the size of mdc icons **/
|
||||||
::slotted([slot="icon"]) {
|
::slotted([slot="icon"]) {
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
import { mdiArrowDown, mdiArrowUp } from "@mdi/js";
|
import { mdiArrowDown, mdiArrowUp, mdiChevronUp } from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
import deepClone from "deep-clone-simple";
|
||||||
import {
|
import {
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
|
||||||
LitElement,
|
LitElement,
|
||||||
nothing,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
css,
|
||||||
|
html,
|
||||||
|
nothing,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import {
|
import {
|
||||||
customElement,
|
customElement,
|
||||||
@@ -22,7 +22,9 @@ import { styleMap } from "lit/directives/style-map";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { stringCompare } from "../../common/string/compare";
|
||||||
import { debounce } from "../../common/util/debounce";
|
import { debounce } from "../../common/util/debounce";
|
||||||
|
import { groupBy } from "../../common/util/group-by";
|
||||||
import { nextRender } from "../../common/util/render-status";
|
import { nextRender } from "../../common/util/render-status";
|
||||||
import { haStyleScrollbar } from "../../resources/styles";
|
import { haStyleScrollbar } from "../../resources/styles";
|
||||||
import { loadVirtualizer } from "../../resources/virtualizer";
|
import { loadVirtualizer } from "../../resources/virtualizer";
|
||||||
@@ -32,17 +34,6 @@ import type { HaCheckbox } from "../ha-checkbox";
|
|||||||
import "../ha-svg-icon";
|
import "../ha-svg-icon";
|
||||||
import "../search-input";
|
import "../search-input";
|
||||||
import { filterData, sortData } from "./sort-filter";
|
import { filterData, sortData } from "./sort-filter";
|
||||||
import { groupBy } from "../../common/util/group-by";
|
|
||||||
import { stringCompare } from "../../common/string/compare";
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
// for fire event
|
|
||||||
interface HASSDomEvents {
|
|
||||||
"selection-changed": SelectionChangedEvent;
|
|
||||||
"row-click": RowClickedEvent;
|
|
||||||
"sorting-changed": SortingChangedEvent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RowClickedEvent {
|
export interface RowClickedEvent {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -52,6 +43,10 @@ export interface SelectionChangedEvent {
|
|||||||
value: string[];
|
value: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CollapsedChangedEvent {
|
||||||
|
value: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface SortingChangedEvent {
|
export interface SortingChangedEvent {
|
||||||
column: string;
|
column: string;
|
||||||
direction: SortingDirection;
|
direction: SortingDirection;
|
||||||
@@ -142,10 +137,14 @@ export class HaDataTable extends LitElement {
|
|||||||
|
|
||||||
@property() public groupColumn?: string;
|
@property() public groupColumn?: string;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public groupOrder?: string[];
|
||||||
|
|
||||||
@property() public sortColumn?: string;
|
@property() public sortColumn?: string;
|
||||||
|
|
||||||
@property() public sortDirection: SortingDirection = null;
|
@property() public sortDirection: SortingDirection = null;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public initialCollapsedGroups?: string[];
|
||||||
|
|
||||||
@state() private _filterable = false;
|
@state() private _filterable = false;
|
||||||
|
|
||||||
@state() private _filter = "";
|
@state() private _filter = "";
|
||||||
@@ -158,6 +157,8 @@ export class HaDataTable extends LitElement {
|
|||||||
|
|
||||||
@state() private _items: DataTableRowData[] = [];
|
@state() private _items: DataTableRowData[] = [];
|
||||||
|
|
||||||
|
@state() private _collapsedGroups: string[] = [];
|
||||||
|
|
||||||
private _checkableRowsCount?: number;
|
private _checkableRowsCount?: number;
|
||||||
|
|
||||||
private _checkedRows: string[] = [];
|
private _checkedRows: string[] = [];
|
||||||
@@ -213,17 +214,19 @@ export class HaDataTable extends LitElement {
|
|||||||
(column) => column.filterable
|
(column) => column.filterable
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const columnId in this.columns) {
|
if (!this.sortColumn) {
|
||||||
if (this.columns[columnId].direction) {
|
for (const columnId in this.columns) {
|
||||||
this.sortDirection = this.columns[columnId].direction!;
|
if (this.columns[columnId].direction) {
|
||||||
this.sortColumn = columnId;
|
this.sortDirection = this.columns[columnId].direction!;
|
||||||
|
this.sortColumn = columnId;
|
||||||
|
|
||||||
fireEvent(this, "sorting-changed", {
|
fireEvent(this, "sorting-changed", {
|
||||||
column: columnId,
|
column: columnId,
|
||||||
direction: this.sortDirection,
|
direction: this.sortDirection,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,13 +251,23 @@ export class HaDataTable extends LitElement {
|
|||||||
).length;
|
).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.hasUpdated && this.initialCollapsedGroups) {
|
||||||
|
this._collapsedGroups = this.initialCollapsedGroups;
|
||||||
|
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
|
||||||
|
} else if (properties.has("groupColumn")) {
|
||||||
|
this._collapsedGroups = [];
|
||||||
|
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
properties.has("data") ||
|
properties.has("data") ||
|
||||||
properties.has("columns") ||
|
properties.has("columns") ||
|
||||||
properties.has("_filter") ||
|
properties.has("_filter") ||
|
||||||
properties.has("sortColumn") ||
|
properties.has("sortColumn") ||
|
||||||
properties.has("sortDirection") ||
|
properties.has("sortDirection") ||
|
||||||
properties.has("groupColumn")
|
properties.has("groupColumn") ||
|
||||||
|
properties.has("groupOrder") ||
|
||||||
|
properties.has("_collapsedGroups")
|
||||||
) {
|
) {
|
||||||
this._sortFilterData();
|
this._sortFilterData();
|
||||||
}
|
}
|
||||||
@@ -447,6 +460,8 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
|
@mouseover=${this._setTitle}
|
||||||
|
@focus=${this._setTitle}
|
||||||
role=${column.main ? "rowheader" : "cell"}
|
role=${column.main ? "rowheader" : "cell"}
|
||||||
class="mdc-data-table__cell ${classMap({
|
class="mdc-data-table__cell ${classMap({
|
||||||
"mdc-data-table__cell--flex": column.type === "flex",
|
"mdc-data-table__cell--flex": column.type === "flex",
|
||||||
@@ -514,11 +529,7 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.appendRow || this.hasFab || this.groupColumn) {
|
if (this.appendRow || this.hasFab || this.groupColumn) {
|
||||||
const items = [...data];
|
let items = [...data];
|
||||||
|
|
||||||
if (this.appendRow) {
|
|
||||||
items.push({ append: true, content: this.appendRow });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.groupColumn) {
|
if (this.groupColumn) {
|
||||||
const grouped = groupBy(items, (item) => item[this.groupColumn!]);
|
const grouped = groupBy(items, (item) => item[this.groupColumn!]);
|
||||||
@@ -530,45 +541,66 @@ export class HaDataTable extends LitElement {
|
|||||||
const sorted: {
|
const sorted: {
|
||||||
[key: string]: DataTableRowData[];
|
[key: string]: DataTableRowData[];
|
||||||
} = Object.keys(grouped)
|
} = Object.keys(grouped)
|
||||||
.sort((a, b) =>
|
.sort((a, b) => {
|
||||||
stringCompare(
|
const orderA = this.groupOrder?.indexOf(a) ?? -1;
|
||||||
|
const orderB = this.groupOrder?.indexOf(b) ?? -1;
|
||||||
|
if (orderA !== orderB) {
|
||||||
|
if (orderA === -1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (orderB === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return orderA - orderB;
|
||||||
|
}
|
||||||
|
return stringCompare(
|
||||||
["", "-", "—"].includes(a) ? "zzz" : a,
|
["", "-", "—"].includes(a) ? "zzz" : a,
|
||||||
["", "-", "—"].includes(b) ? "zzz" : b,
|
["", "-", "—"].includes(b) ? "zzz" : b,
|
||||||
this.hass.locale.language
|
this.hass.locale.language
|
||||||
)
|
);
|
||||||
)
|
})
|
||||||
.reduce((obj, key) => {
|
.reduce((obj, key) => {
|
||||||
obj[key] = grouped[key];
|
obj[key] = grouped[key];
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
const groupedItems: DataTableRowData[] = [];
|
const groupedItems: DataTableRowData[] = [];
|
||||||
Object.entries(sorted).forEach(([groupName, rows]) => {
|
Object.entries(sorted).forEach(([groupName, rows]) => {
|
||||||
if (
|
groupedItems.push({
|
||||||
groupName !== UNDEFINED_GROUP_KEY ||
|
append: true,
|
||||||
Object.keys(sorted).length > 1
|
content: html`<div
|
||||||
) {
|
class="mdc-data-table__cell group-header"
|
||||||
groupedItems.push({
|
role="cell"
|
||||||
append: true,
|
.group=${groupName}
|
||||||
content: html`<div
|
@click=${this._collapseGroup}
|
||||||
class="mdc-data-table__cell group-header"
|
>
|
||||||
role="cell"
|
<ha-icon-button
|
||||||
|
.path=${mdiChevronUp}
|
||||||
|
class=${this._collapsedGroups.includes(groupName)
|
||||||
|
? "collapsed"
|
||||||
|
: ""}
|
||||||
>
|
>
|
||||||
${groupName === UNDEFINED_GROUP_KEY ? "" : groupName || ""}
|
</ha-icon-button>
|
||||||
</div>`,
|
${groupName === UNDEFINED_GROUP_KEY
|
||||||
});
|
? this.hass.localize("ui.components.data-table.ungrouped")
|
||||||
|
: groupName || ""}
|
||||||
|
</div>`,
|
||||||
|
});
|
||||||
|
if (!this._collapsedGroups.includes(groupName)) {
|
||||||
|
groupedItems.push(...rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
groupedItems.push(...rows);
|
|
||||||
});
|
});
|
||||||
|
items = groupedItems;
|
||||||
|
}
|
||||||
|
|
||||||
this._items = groupedItems;
|
if (this.appendRow) {
|
||||||
} else {
|
items.push({ append: true, content: this.appendRow });
|
||||||
this._items = items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasFab) {
|
if (this.hasFab) {
|
||||||
this._items = [...this._items, { empty: true }];
|
items.push({ empty: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._items = items;
|
||||||
} else {
|
} else {
|
||||||
this._items = data;
|
this._items = data;
|
||||||
}
|
}
|
||||||
@@ -649,6 +681,13 @@ export class HaDataTable extends LitElement {
|
|||||||
fireEvent(this, "row-click", { id: rowId }, { bubbles: false });
|
fireEvent(this, "row-click", { id: rowId }, { bubbles: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _setTitle(ev: Event) {
|
||||||
|
const target = ev.currentTarget as HTMLElement;
|
||||||
|
if (target.scrollWidth > target.offsetWidth) {
|
||||||
|
target.setAttribute("title", target.innerText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _checkedRowsChanged() {
|
private _checkedRowsChanged() {
|
||||||
// force scroller to update, change it's items
|
// force scroller to update, change it's items
|
||||||
if (this._items.length) {
|
if (this._items.length) {
|
||||||
@@ -679,6 +718,18 @@ export class HaDataTable extends LitElement {
|
|||||||
this._savedScrollPos = (e.target as HTMLDivElement).scrollTop;
|
this._savedScrollPos = (e.target as HTMLDivElement).scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _collapseGroup = (ev: Event) => {
|
||||||
|
const groupName = (ev.currentTarget as any).group;
|
||||||
|
if (this._collapsedGroups.includes(groupName)) {
|
||||||
|
this._collapsedGroups = this._collapsedGroups.filter(
|
||||||
|
(grp) => grp !== groupName
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this._collapsedGroups = [...this._collapsedGroups, groupName];
|
||||||
|
}
|
||||||
|
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
|
||||||
|
};
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyleScrollbar,
|
haStyleScrollbar,
|
||||||
@@ -931,8 +982,22 @@ export class HaDataTable extends LitElement {
|
|||||||
|
|
||||||
.group-header {
|
.group-header {
|
||||||
padding-top: 12px;
|
padding-top: 12px;
|
||||||
|
padding-left: 12px;
|
||||||
|
padding-inline-start: 12px;
|
||||||
|
padding-inline-end: initial;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-header ha-icon-button {
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-header ha-icon-button.collapsed {
|
||||||
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
@@ -1031,4 +1096,12 @@ declare global {
|
|||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-data-table": HaDataTable;
|
"ha-data-table": HaDataTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for fire event
|
||||||
|
interface HASSDomEvents {
|
||||||
|
"selection-changed": SelectionChangedEvent;
|
||||||
|
"row-click": RowClickedEvent;
|
||||||
|
"sorting-changed": SortingChangedEvent;
|
||||||
|
"collapsed-changed": CollapsedChangedEvent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,10 +11,10 @@ import {
|
|||||||
} from "../common/datetime/localize_date";
|
} from "../common/datetime/localize_date";
|
||||||
import { mainWindow } from "../common/dom/get_main_window";
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
|
|
||||||
// Set the current date to the left picker instead of the right picker because the right is hidden
|
|
||||||
const CustomDateRangePicker = Vue.extend({
|
const CustomDateRangePicker = Vue.extend({
|
||||||
mixins: [DateRangePicker],
|
mixins: [DateRangePicker],
|
||||||
methods: {
|
methods: {
|
||||||
|
// Set the current date to the left picker instead of the right picker because the right is hidden
|
||||||
selectMonthDate() {
|
selectMonthDate() {
|
||||||
const dt: Date = this.end || new Date();
|
const dt: Date = this.end || new Date();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -23,6 +23,33 @@ const CustomDateRangePicker = Vue.extend({
|
|||||||
month: dt.getMonth() + 1,
|
month: dt.getMonth() + 1,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// Fix the start/end date calculation when selecting a date range. The
|
||||||
|
// original code keeps track of the first clicked date (in_selection) but it
|
||||||
|
// never sets it to either the start or end date variables, so if the
|
||||||
|
// in_selection date is between the start and end date that were set by the
|
||||||
|
// hover the selection will enter a broken state that's counter-intuitive
|
||||||
|
// when hovering between weeks and leads to a random date when selecting a
|
||||||
|
// range across months. This bug doesn't seem to be present on v0.6.7 of the
|
||||||
|
// lib
|
||||||
|
hoverDate(value: Date) {
|
||||||
|
if (this.readonly) return;
|
||||||
|
|
||||||
|
if (this.in_selection) {
|
||||||
|
const pickA = this.in_selection as Date;
|
||||||
|
const pickB = value;
|
||||||
|
|
||||||
|
this.start = this.normalizeDatetime(
|
||||||
|
Math.min(pickA.valueOf(), pickB.valueOf()),
|
||||||
|
this.start
|
||||||
|
);
|
||||||
|
this.end = this.normalizeDatetime(
|
||||||
|
Math.max(pickA.valueOf(), pickB.valueOf()),
|
||||||
|
this.end
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$emit("hover-date", value);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -76,6 +76,8 @@ class HaEntitiesPickerLight extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public entityFilter?: HaEntityPickerEntityFilterFunc;
|
public entityFilter?: HaEntityPickerEntityFilterFunc;
|
||||||
|
|
||||||
|
@property({ type: Array }) public createDomains?: string[];
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@@ -103,6 +105,7 @@ class HaEntitiesPickerLight extends LitElement {
|
|||||||
.value=${entityId}
|
.value=${entityId}
|
||||||
.label=${this.pickedEntityLabel}
|
.label=${this.pickedEntityLabel}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
.createDomains=${this.createDomains}
|
||||||
@value-changed=${this._entityChanged}
|
@value-changed=${this._entityChanged}
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
</div>
|
</div>
|
||||||
@@ -122,6 +125,7 @@ class HaEntitiesPickerLight extends LitElement {
|
|||||||
.label=${this.pickEntityLabel}
|
.label=${this.pickEntityLabel}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
.createDomains=${this.createDomains}
|
||||||
.required=${this.required && !currentEntities.length}
|
.required=${this.required && !currentEntities.length}
|
||||||
@value-changed=${this._addEntity}
|
@value-changed=${this._addEntity}
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
|
@@ -18,6 +18,12 @@ import "../ha-icon-button";
|
|||||||
import "../ha-svg-icon";
|
import "../ha-svg-icon";
|
||||||
import "./state-badge";
|
import "./state-badge";
|
||||||
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
|
import { showHelperDetailDialog } from "../../panels/config/helpers/show-dialog-helper-detail";
|
||||||
|
import { domainToName } from "../../data/integration";
|
||||||
|
import {
|
||||||
|
isHelperDomain,
|
||||||
|
HelperDomain,
|
||||||
|
} from "../../panels/config/helpers/const";
|
||||||
|
|
||||||
interface HassEntityWithCachedName extends HassEntity, ScorableTextItem {
|
interface HassEntityWithCachedName extends HassEntity, ScorableTextItem {
|
||||||
friendly_name: string;
|
friendly_name: string;
|
||||||
@@ -25,6 +31,8 @@ interface HassEntityWithCachedName extends HassEntity, ScorableTextItem {
|
|||||||
|
|
||||||
export type HaEntityPickerEntityFilterFunc = (entity: HassEntity) => boolean;
|
export type HaEntityPickerEntityFilterFunc = (entity: HassEntity) => boolean;
|
||||||
|
|
||||||
|
const CREATE_ID = "___create-new-entity___";
|
||||||
|
|
||||||
@customElement("ha-entity-picker")
|
@customElement("ha-entity-picker")
|
||||||
export class HaEntityPicker extends LitElement {
|
export class HaEntityPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -44,6 +52,8 @@ export class HaEntityPicker extends LitElement {
|
|||||||
|
|
||||||
@property() public helper?: string;
|
@property() public helper?: string;
|
||||||
|
|
||||||
|
@property({ type: Array }) public createDomains?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show entities from specific domains.
|
* Show entities from specific domains.
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
@@ -130,7 +140,11 @@ export class HaEntityPicker extends LitElement {
|
|||||||
></state-badge>`
|
></state-badge>`
|
||||||
: ""}
|
: ""}
|
||||||
<span>${item.friendly_name}</span>
|
<span>${item.friendly_name}</span>
|
||||||
<span slot="secondary">${item.entity_id}</span>
|
<span slot="secondary"
|
||||||
|
>${item.entity_id.startsWith(CREATE_ID)
|
||||||
|
? this.hass.localize("ui.components.entity.entity-picker.new_entity")
|
||||||
|
: item.entity_id}</span
|
||||||
|
>
|
||||||
</ha-list-item>`;
|
</ha-list-item>`;
|
||||||
|
|
||||||
private _getStates = memoizeOne(
|
private _getStates = memoizeOne(
|
||||||
@@ -143,7 +157,8 @@ export class HaEntityPicker extends LitElement {
|
|||||||
includeDeviceClasses: this["includeDeviceClasses"],
|
includeDeviceClasses: this["includeDeviceClasses"],
|
||||||
includeUnitOfMeasurement: this["includeUnitOfMeasurement"],
|
includeUnitOfMeasurement: this["includeUnitOfMeasurement"],
|
||||||
includeEntities: this["includeEntities"],
|
includeEntities: this["includeEntities"],
|
||||||
excludeEntities: this["excludeEntities"]
|
excludeEntities: this["excludeEntities"],
|
||||||
|
createDomains: this["createDomains"]
|
||||||
): HassEntityWithCachedName[] => {
|
): HassEntityWithCachedName[] => {
|
||||||
let states: HassEntityWithCachedName[] = [];
|
let states: HassEntityWithCachedName[] = [];
|
||||||
|
|
||||||
@@ -152,6 +167,34 @@ export class HaEntityPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
let entityIds = Object.keys(hass.states);
|
let entityIds = Object.keys(hass.states);
|
||||||
|
|
||||||
|
const createItems = createDomains?.length
|
||||||
|
? createDomains.map((domain) => {
|
||||||
|
const newFriendlyName = hass.localize(
|
||||||
|
"ui.components.entity.entity-picker.create_helper",
|
||||||
|
{
|
||||||
|
domain: isHelperDomain(domain)
|
||||||
|
? hass.localize(
|
||||||
|
`ui.panel.config.helpers.types.${domain as HelperDomain}`
|
||||||
|
)
|
||||||
|
: domainToName(hass.localize, domain),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
entity_id: CREATE_ID + domain,
|
||||||
|
state: "on",
|
||||||
|
last_changed: "",
|
||||||
|
last_updated: "",
|
||||||
|
context: { id: "", user_id: null, parent_id: null },
|
||||||
|
friendly_name: newFriendlyName,
|
||||||
|
attributes: {
|
||||||
|
icon: "mdi:plus",
|
||||||
|
},
|
||||||
|
strings: [domain, newFriendlyName],
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
|
||||||
if (!entityIds.length) {
|
if (!entityIds.length) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -171,6 +214,7 @@ export class HaEntityPicker extends LitElement {
|
|||||||
},
|
},
|
||||||
strings: [],
|
strings: [],
|
||||||
},
|
},
|
||||||
|
...createItems,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,9 +325,14 @@ export class HaEntityPicker extends LitElement {
|
|||||||
},
|
},
|
||||||
strings: [],
|
strings: [],
|
||||||
},
|
},
|
||||||
|
...createItems,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (createItems?.length) {
|
||||||
|
states.push(...createItems);
|
||||||
|
}
|
||||||
|
|
||||||
return states;
|
return states;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -310,13 +359,18 @@ export class HaEntityPicker extends LitElement {
|
|||||||
this.includeDeviceClasses,
|
this.includeDeviceClasses,
|
||||||
this.includeUnitOfMeasurement,
|
this.includeUnitOfMeasurement,
|
||||||
this.includeEntities,
|
this.includeEntities,
|
||||||
this.excludeEntities
|
this.excludeEntities,
|
||||||
|
this.createDomains
|
||||||
);
|
);
|
||||||
if (this._initedStates) {
|
if (this._initedStates) {
|
||||||
this.comboBox.filteredItems = this._states;
|
this.comboBox.filteredItems = this._states;
|
||||||
}
|
}
|
||||||
this._initedStates = true;
|
this._initedStates = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changedProps.has("createDomains") && this.createDomains?.length) {
|
||||||
|
this.hass.loadFragmentTranslation("config");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@@ -351,9 +405,21 @@ export class HaEntityPicker extends LitElement {
|
|||||||
this._opened = ev.detail.value;
|
this._opened = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: ValueChangedEvent<string>) {
|
private _valueChanged(ev: ValueChangedEvent<string | undefined>) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const newValue = ev.detail.value;
|
const newValue = ev.detail.value?.trim();
|
||||||
|
|
||||||
|
if (newValue && newValue.startsWith(CREATE_ID)) {
|
||||||
|
const domain = newValue.substring(CREATE_ID.length);
|
||||||
|
showHelperDetailDialog(this, {
|
||||||
|
domain,
|
||||||
|
dialogClosedCallback: (item) => {
|
||||||
|
if (item.entityId) this._setValue(item.entityId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (newValue !== this._value) {
|
if (newValue !== this._value) {
|
||||||
this._setValue(newValue);
|
this._setValue(newValue);
|
||||||
}
|
}
|
||||||
@@ -361,13 +427,13 @@ export class HaEntityPicker extends LitElement {
|
|||||||
|
|
||||||
private _filterChanged(ev: CustomEvent): void {
|
private _filterChanged(ev: CustomEvent): void {
|
||||||
const target = ev.target as HaComboBox;
|
const target = ev.target as HaComboBox;
|
||||||
const filterString = ev.detail.value.toLowerCase();
|
const filterString = ev.detail.value.trim().toLowerCase();
|
||||||
target.filteredItems = filterString.length
|
target.filteredItems = filterString.length
|
||||||
? fuzzyFilterSort<HassEntityWithCachedName>(filterString, this._states)
|
? fuzzyFilterSort<HassEntityWithCachedName>(filterString, this._states)
|
||||||
: this._states;
|
: this._states;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue(value: string) {
|
private _setValue(value: string | undefined) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
|
@@ -14,6 +14,8 @@ export class HaCard extends LitElement {
|
|||||||
--ha-card-background,
|
--ha-card-background,
|
||||||
var(--card-background-color, white)
|
var(--card-background-color, white)
|
||||||
);
|
);
|
||||||
|
-webkit-backdrop-filter: var(--ha-card-backdrop-filter, none);
|
||||||
|
backdrop-filter: var(--ha-card-backdrop-filter, none);
|
||||||
box-shadow: var(--ha-card-box-shadow, none);
|
box-shadow: var(--ha-card-box-shadow, none);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
border-radius: var(--ha-card-border-radius, 12px);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import "element-internals-polyfill";
|
|
||||||
import { MdCircularProgress } from "@material/web/progress/circular-progress";
|
import { MdCircularProgress } from "@material/web/progress/circular-progress";
|
||||||
import { CSSResult, PropertyValues, css } from "lit";
|
import { PropertyValues, css } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-circular-progress")
|
@customElement("ha-circular-progress")
|
||||||
@@ -32,17 +31,15 @@ export class HaCircularProgress extends MdCircularProgress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static override styles = [
|
||||||
return [
|
...super.styles,
|
||||||
...super.styles,
|
css`
|
||||||
css`
|
:host {
|
||||||
:host {
|
--md-sys-color-primary: var(--primary-color);
|
||||||
--md-sys-color-primary: var(--primary-color);
|
--md-circular-progress-size: 48px;
|
||||||
--md-circular-progress-size: 48px;
|
}
|
||||||
}
|
`,
|
||||||
`,
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,14 +1,7 @@
|
|||||||
import { Ripple } from "@material/mwc-ripple";
|
|
||||||
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import {
|
import { customElement, property } from "lit/decorators";
|
||||||
customElement,
|
|
||||||
eventOptions,
|
|
||||||
property,
|
|
||||||
queryAsync,
|
|
||||||
state,
|
|
||||||
} from "lit/decorators";
|
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import "./ha-ripple";
|
||||||
|
|
||||||
@customElement("ha-control-button")
|
@customElement("ha-control-button")
|
||||||
export class HaControlButton extends LitElement {
|
export class HaControlButton extends LitElement {
|
||||||
@@ -16,10 +9,6 @@ export class HaControlButton extends LitElement {
|
|||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;
|
|
||||||
|
|
||||||
@state() private _shouldRenderRipple = false;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<button
|
<button
|
||||||
@@ -28,54 +17,13 @@ export class HaControlButton extends LitElement {
|
|||||||
aria-label=${ifDefined(this.label)}
|
aria-label=${ifDefined(this.label)}
|
||||||
title=${ifDefined(this.label)}
|
title=${ifDefined(this.label)}
|
||||||
.disabled=${Boolean(this.disabled)}
|
.disabled=${Boolean(this.disabled)}
|
||||||
@focus=${this.handleRippleFocus}
|
|
||||||
@blur=${this.handleRippleBlur}
|
|
||||||
@mousedown=${this.handleRippleActivate}
|
|
||||||
@mouseup=${this.handleRippleDeactivate}
|
|
||||||
@mouseenter=${this.handleRippleMouseEnter}
|
|
||||||
@mouseleave=${this.handleRippleMouseLeave}
|
|
||||||
@touchstart=${this.handleRippleActivate}
|
|
||||||
@touchend=${this.handleRippleDeactivate}
|
|
||||||
@touchcancel=${this.handleRippleDeactivate}
|
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
${this._shouldRenderRipple && !this.disabled
|
<ha-ripple .disabled=${this.disabled}></ha-ripple>
|
||||||
? html`<mwc-ripple></mwc-ripple>`
|
|
||||||
: ""}
|
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
|
|
||||||
this._shouldRenderRipple = true;
|
|
||||||
return this._ripple;
|
|
||||||
});
|
|
||||||
|
|
||||||
@eventOptions({ passive: true })
|
|
||||||
private handleRippleActivate(evt?: Event) {
|
|
||||||
this._rippleHandlers.startPress(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleDeactivate() {
|
|
||||||
this._rippleHandlers.endPress();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseEnter() {
|
|
||||||
this._rippleHandlers.startHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseLeave() {
|
|
||||||
this._rippleHandlers.endHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleFocus() {
|
|
||||||
this._rippleHandlers.startFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleBlur() {
|
|
||||||
this._rippleHandlers.endFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
@@ -86,6 +34,7 @@ export class HaControlButton extends LitElement {
|
|||||||
--control-button-border-radius: 10px;
|
--control-button-border-radius: 10px;
|
||||||
--control-button-padding: 8px;
|
--control-button-padding: 8px;
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
|
--ha-ripple-color: var(--secondary-text-color);
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
@@ -113,12 +62,14 @@ export class HaControlButton extends LitElement {
|
|||||||
outline: none;
|
outline: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: none;
|
background: none;
|
||||||
--mdc-ripple-color: var(--control-button-background-color);
|
|
||||||
/* For safari border-radius overflow */
|
/* For safari border-radius overflow */
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
.button:focus-visible {
|
||||||
|
--control-button-background-opacity: 0.4;
|
||||||
|
}
|
||||||
.button::before {
|
.button::before {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@@ -1,22 +1,14 @@
|
|||||||
import { Ripple } from "@material/mwc-ripple";
|
|
||||||
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
|
|
||||||
import { SelectBase } from "@material/mwc-select/mwc-select-base";
|
import { SelectBase } from "@material/mwc-select/mwc-select-base";
|
||||||
import { mdiMenuDown } from "@mdi/js";
|
import { mdiMenuDown } from "@mdi/js";
|
||||||
import { css, html, nothing } from "lit";
|
import { css, html, nothing } from "lit";
|
||||||
import {
|
import { customElement, property, query } from "lit/decorators";
|
||||||
customElement,
|
|
||||||
eventOptions,
|
|
||||||
property,
|
|
||||||
query,
|
|
||||||
queryAsync,
|
|
||||||
state,
|
|
||||||
} from "lit/decorators";
|
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
import { nextRender } from "../common/util/render-status";
|
import { nextRender } from "../common/util/render-status";
|
||||||
import "./ha-icon";
|
import "./ha-icon";
|
||||||
import type { HaIcon } from "./ha-icon";
|
import type { HaIcon } from "./ha-icon";
|
||||||
|
import "./ha-ripple";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
import type { HaSvgIcon } from "./ha-svg-icon";
|
import type { HaSvgIcon } from "./ha-svg-icon";
|
||||||
|
|
||||||
@@ -32,10 +24,6 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
@property({ type: Boolean, attribute: "hide-label" })
|
@property({ type: Boolean, attribute: "hide-label" })
|
||||||
public hideLabel = false;
|
public hideLabel = false;
|
||||||
|
|
||||||
@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;
|
|
||||||
|
|
||||||
@state() private _shouldRenderRipple = false;
|
|
||||||
|
|
||||||
public override render() {
|
public override render() {
|
||||||
const classes = {
|
const classes = {
|
||||||
"select-disabled": this.disabled,
|
"select-disabled": this.disabled,
|
||||||
@@ -69,17 +57,10 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
aria-labelledby=${ifDefined(labelledby)}
|
aria-labelledby=${ifDefined(labelledby)}
|
||||||
aria-label=${ifDefined(labelAttribute)}
|
aria-label=${ifDefined(labelAttribute)}
|
||||||
aria-required=${this.required}
|
aria-required=${this.required}
|
||||||
@click=${this.onClick}
|
|
||||||
@focus=${this.onFocus}
|
@focus=${this.onFocus}
|
||||||
@blur=${this.onBlur}
|
@blur=${this.onBlur}
|
||||||
|
@click=${this.onClick}
|
||||||
@keydown=${this.onKeydown}
|
@keydown=${this.onKeydown}
|
||||||
@mousedown=${this.handleRippleActivate}
|
|
||||||
@mouseup=${this.handleRippleDeactivate}
|
|
||||||
@mouseenter=${this.handleRippleMouseEnter}
|
|
||||||
@mouseleave=${this.handleRippleMouseLeave}
|
|
||||||
@touchstart=${this.handleRippleActivate}
|
|
||||||
@touchend=${this.handleRippleDeactivate}
|
|
||||||
@touchcancel=${this.handleRippleDeactivate}
|
|
||||||
>
|
>
|
||||||
${this.renderIcon()}
|
${this.renderIcon()}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@@ -91,9 +72,7 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
${this.renderArrow()}
|
${this.renderArrow()}
|
||||||
${this._shouldRenderRipple && !this.disabled
|
<ha-ripple .disabled=${this.disabled}></ha-ripple>
|
||||||
? html` <mwc-ripple></mwc-ripple> `
|
|
||||||
: nothing}
|
|
||||||
</div>
|
</div>
|
||||||
${this.renderMenu()}
|
${this.renderMenu()}
|
||||||
</div>
|
</div>
|
||||||
@@ -104,7 +83,7 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
if (!this.showArrow) return nothing;
|
if (!this.showArrow) return nothing;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="icon">
|
<div class="icon arrow">
|
||||||
<ha-svg-icon .path=${mdiMenuDown}></ha-svg-icon>
|
<ha-svg-icon .path=${mdiMenuDown}></ha-svg-icon>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -135,46 +114,6 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onFocus() {
|
|
||||||
this.handleRippleFocus();
|
|
||||||
super.onFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onBlur() {
|
|
||||||
this.handleRippleBlur();
|
|
||||||
super.onBlur();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
|
|
||||||
this._shouldRenderRipple = true;
|
|
||||||
return this._ripple;
|
|
||||||
});
|
|
||||||
|
|
||||||
@eventOptions({ passive: true })
|
|
||||||
private handleRippleActivate(evt?: Event) {
|
|
||||||
this._rippleHandlers.startPress(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleDeactivate() {
|
|
||||||
this._rippleHandlers.endPress();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseEnter() {
|
|
||||||
this._rippleHandlers.startHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseLeave() {
|
|
||||||
this._rippleHandlers.endHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleFocus() {
|
|
||||||
this._rippleHandlers.startFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleBlur() {
|
|
||||||
this._rippleHandlers.endFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
window.addEventListener("translations-updated", this._translationsUpdated);
|
window.addEventListener("translations-updated", this._translationsUpdated);
|
||||||
@@ -204,6 +143,7 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
--control-select-menu-height: 48px;
|
--control-select-menu-height: 48px;
|
||||||
--control-select-menu-padding: 6px 10px;
|
--control-select-menu-padding: 6px 10px;
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
|
--ha-ripple-color: var(--secondary-text-color);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
width: auto;
|
width: auto;
|
||||||
@@ -224,7 +164,6 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
outline: none;
|
outline: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: none;
|
background: none;
|
||||||
--mdc-ripple-color: var(--control-select-menu-background-color);
|
|
||||||
/* For safari border-radius overflow */
|
/* For safari border-radius overflow */
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
transition: color 180ms ease-in-out;
|
transition: color 180ms ease-in-out;
|
||||||
@@ -240,7 +179,8 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex: 1;
|
width: 0;
|
||||||
|
flex-grow: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +193,13 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
margin-left: -10px;
|
||||||
|
margin-inline-end: initial;
|
||||||
|
margin-inline-start: -10px;
|
||||||
|
direction: var(--direction);
|
||||||
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
letter-spacing: 0.4px;
|
letter-spacing: 0.4px;
|
||||||
@@ -264,6 +211,10 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
letter-spacing: inherit;
|
letter-spacing: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.select-anchor:focus-visible {
|
||||||
|
--control-select-menu-background-opacity: 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
.select-anchor::before {
|
.select-anchor::before {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@@ -67,6 +67,9 @@ export class HaControlSlider extends LitElement {
|
|||||||
@property({ attribute: "tooltip-mode" })
|
@property({ attribute: "tooltip-mode" })
|
||||||
public tooltipMode: TooltipMode = "interaction";
|
public tooltipMode: TooltipMode = "interaction";
|
||||||
|
|
||||||
|
@property({ attribute: "touch-action" })
|
||||||
|
public touchAction?: string;
|
||||||
|
|
||||||
@property({ type: Number })
|
@property({ type: Number })
|
||||||
public value?: number;
|
public value?: number;
|
||||||
|
|
||||||
@@ -152,7 +155,7 @@ export class HaControlSlider extends LitElement {
|
|||||||
setupListeners() {
|
setupListeners() {
|
||||||
if (this.slider && !this._mc) {
|
if (this.slider && !this._mc) {
|
||||||
this._mc = new Manager(this.slider, {
|
this._mc = new Manager(this.slider, {
|
||||||
touchAction: this.vertical ? "pan-x" : "pan-y",
|
touchAction: this.touchAction ?? (this.vertical ? "pan-x" : "pan-y"),
|
||||||
});
|
});
|
||||||
this._mc.add(
|
this._mc.add(
|
||||||
new Pan({
|
new Pan({
|
||||||
|
@@ -33,6 +33,9 @@ export class HaControlSwitch extends LitElement {
|
|||||||
// SVG icon path (if you need a non SVG icon instead, use the provided off icon slot to pass an <ha-icon slot="icon-off"> in)
|
// SVG icon path (if you need a non SVG icon instead, use the provided off icon slot to pass an <ha-icon slot="icon-off"> in)
|
||||||
@property({ type: String }) pathOff?: string;
|
@property({ type: String }) pathOff?: string;
|
||||||
|
|
||||||
|
@property({ attribute: "touch-action" })
|
||||||
|
public touchAction?: string;
|
||||||
|
|
||||||
private _mc?: HammerManager;
|
private _mc?: HammerManager;
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
protected firstUpdated(changedProperties: PropertyValues): void {
|
||||||
@@ -73,7 +76,7 @@ export class HaControlSwitch extends LitElement {
|
|||||||
setupListeners() {
|
setupListeners() {
|
||||||
if (this.switch && !this._mc) {
|
if (this.switch && !this._mc) {
|
||||||
this._mc = new Manager(this.switch, {
|
this._mc = new Manager(this.switch, {
|
||||||
touchAction: this.vertical ? "pan-x" : "pan-y",
|
touchAction: this.touchAction ?? (this.vertical ? "pan-x" : "pan-y"),
|
||||||
});
|
});
|
||||||
this._mc.add(
|
this._mc.add(
|
||||||
new Swipe({
|
new Swipe({
|
||||||
|
@@ -19,6 +19,7 @@ import { HomeAssistant } from "../types";
|
|||||||
import "./ha-list-item";
|
import "./ha-list-item";
|
||||||
import "./ha-select";
|
import "./ha-select";
|
||||||
import type { HaSelect } from "./ha-select";
|
import type { HaSelect } from "./ha-select";
|
||||||
|
import { getExtendedEntityRegistryEntry } from "../data/entity_registry";
|
||||||
|
|
||||||
const NONE = "__NONE_OPTION__";
|
const NONE = "__NONE_OPTION__";
|
||||||
|
|
||||||
@@ -107,13 +108,23 @@ export class HaConversationAgentPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _maybeFetchConfigEntry() {
|
private async _maybeFetchConfigEntry() {
|
||||||
if (!this.value || this.value === "homeassistant") {
|
if (!this.value || !(this.value in this.hass.entities)) {
|
||||||
this._configEntry = undefined;
|
this._configEntry = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
const regEntry = await getExtendedEntityRegistryEntry(
|
||||||
|
this.hass,
|
||||||
|
this.value
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!regEntry.config_entry_id) {
|
||||||
|
this._configEntry = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._configEntry = (
|
this._configEntry = (
|
||||||
await getConfigEntry(this.hass, this.value)
|
await getConfigEntry(this.hass, regEntry.config_entry_id)
|
||||||
).config_entry;
|
).config_entry;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._configEntry = undefined;
|
this._configEntry = undefined;
|
||||||
|
@@ -75,8 +75,14 @@ export class HaDialog extends DialogBase {
|
|||||||
var(--divider-color)
|
var(--divider-color)
|
||||||
);
|
);
|
||||||
z-index: var(--dialog-z-index, 8);
|
z-index: var(--dialog-z-index, 8);
|
||||||
-webkit-backdrop-filter: var(--dialog-backdrop-filter, none);
|
-webkit-backdrop-filter: var(
|
||||||
backdrop-filter: var(--dialog-backdrop-filter, none);
|
--ha-dialog-scrim-backdrop-filter,
|
||||||
|
var(--dialog-backdrop-filter, none)
|
||||||
|
);
|
||||||
|
backdrop-filter: var(
|
||||||
|
--ha-dialog-scrim-backdrop-filter,
|
||||||
|
var(--dialog-backdrop-filter, none)
|
||||||
|
);
|
||||||
--mdc-dialog-box-shadow: var(--dialog-box-shadow, none);
|
--mdc-dialog-box-shadow: var(--dialog-box-shadow, none);
|
||||||
--mdc-typography-headline6-font-weight: 400;
|
--mdc-typography-headline6-font-weight: 400;
|
||||||
--mdc-typography-headline6-font-size: 1.574rem;
|
--mdc-typography-headline6-font-size: 1.574rem;
|
||||||
@@ -119,6 +125,12 @@ export class HaDialog extends DialogBase {
|
|||||||
margin-top: var(--dialog-surface-margin-top);
|
margin-top: var(--dialog-surface-margin-top);
|
||||||
min-height: var(--mdc-dialog-min-height, auto);
|
min-height: var(--mdc-dialog-min-height, auto);
|
||||||
border-radius: var(--ha-dialog-border-radius, 28px);
|
border-radius: var(--ha-dialog-border-radius, 28px);
|
||||||
|
-webkit-backdrop-filter: var(--ha-dialog-surface-backdrop-filter, none);
|
||||||
|
backdrop-filter: var(--ha-dialog-surface-backdrop-filter, none);
|
||||||
|
background: var(
|
||||||
|
--ha-dialog-surface-background,
|
||||||
|
var(--mdc-theme-surface, #fff)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
:host([flexContent]) .mdc-dialog .mdc-dialog__content {
|
:host([flexContent]) .mdc-dialog .mdc-dialog__content {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@@ -69,7 +69,7 @@ export class HaFilterDevices extends LitElement {
|
|||||||
@value-changed=${this._handleSearchChange}
|
@value-changed=${this._handleSearchChange}
|
||||||
>
|
>
|
||||||
</search-input-outlined>
|
</search-input-outlined>
|
||||||
<mwc-list class="ha-scrollbar">
|
<mwc-list class="ha-scrollbar" multi>
|
||||||
<lit-virtualizer
|
<lit-virtualizer
|
||||||
.items=${this._devices(
|
.items=${this._devices(
|
||||||
this.hass.devices,
|
this.hass.devices,
|
||||||
@@ -94,7 +94,7 @@ export class HaFilterDevices extends LitElement {
|
|||||||
? nothing
|
? nothing
|
||||||
: html`<ha-check-list-item
|
: html`<ha-check-list-item
|
||||||
.value=${device.id}
|
.value=${device.id}
|
||||||
.selected=${this.value?.includes(device.id)}
|
.selected=${this.value?.includes(device.id) ?? false}
|
||||||
>
|
>
|
||||||
${computeDeviceName(device, this.hass)}
|
${computeDeviceName(device, this.hass)}
|
||||||
</ha-check-list-item>`;
|
</ha-check-list-item>`;
|
||||||
|
204
src/components/ha-filter-domains.ts
Normal file
204
src/components/ha-filter-domains.ts
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
import { mdiFilterVariantRemove } from "@mdi/js";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { repeat } from "lit/directives/repeat";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import { stringCompare } from "../common/string/compare";
|
||||||
|
import { domainToName } from "../data/integration";
|
||||||
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./ha-domain-icon";
|
||||||
|
import "./search-input-outlined";
|
||||||
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
|
|
||||||
|
@customElement("ha-filter-domains")
|
||||||
|
export class HaFilterDomains extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public value?: string[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true }) public expanded = false;
|
||||||
|
|
||||||
|
@state() private _shouldRender = false;
|
||||||
|
|
||||||
|
@state() private _filter?: string;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
return html`
|
||||||
|
<ha-expansion-panel
|
||||||
|
leftChevron
|
||||||
|
.expanded=${this.expanded}
|
||||||
|
@expanded-will-change=${this._expandedWillChange}
|
||||||
|
@expanded-changed=${this._expandedChanged}
|
||||||
|
>
|
||||||
|
<div slot="header" class="header">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.entities.picker.headers.domain"
|
||||||
|
)}
|
||||||
|
${this.value?.length
|
||||||
|
? html`<div class="badge">${this.value?.length}</div>
|
||||||
|
<ha-icon-button
|
||||||
|
.path=${mdiFilterVariantRemove}
|
||||||
|
@click=${this._clearFilter}
|
||||||
|
></ha-icon-button>`
|
||||||
|
: nothing}
|
||||||
|
</div>
|
||||||
|
${this._shouldRender
|
||||||
|
? html`<search-input-outlined
|
||||||
|
.hass=${this.hass}
|
||||||
|
.filter=${this._filter}
|
||||||
|
@value-changed=${this._handleSearchChange}
|
||||||
|
>
|
||||||
|
</search-input-outlined>
|
||||||
|
<mwc-list
|
||||||
|
class="ha-scrollbar"
|
||||||
|
@click=${this._handleItemClick}
|
||||||
|
multi
|
||||||
|
>
|
||||||
|
${repeat(
|
||||||
|
this._domains(this.hass.states, this._filter),
|
||||||
|
(i) => i,
|
||||||
|
(domain) =>
|
||||||
|
html`<ha-check-list-item
|
||||||
|
.value=${domain}
|
||||||
|
.selected=${(this.value || []).includes(domain)}
|
||||||
|
graphic="icon"
|
||||||
|
>
|
||||||
|
<ha-domain-icon
|
||||||
|
slot="graphic"
|
||||||
|
.hass=${this.hass}
|
||||||
|
.domain=${domain}
|
||||||
|
brandFallback
|
||||||
|
></ha-domain-icon>
|
||||||
|
${domainToName(this.hass.localize, domain)}
|
||||||
|
</ha-check-list-item>`
|
||||||
|
)}
|
||||||
|
</mwc-list> `
|
||||||
|
: nothing}
|
||||||
|
</ha-expansion-panel>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _domains = memoizeOne((states, filter) => {
|
||||||
|
const domains = new Set<string>();
|
||||||
|
Object.keys(states).forEach((entityId) => {
|
||||||
|
domains.add(computeDomain(entityId));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.from(domains.values())
|
||||||
|
.filter(
|
||||||
|
(entry) =>
|
||||||
|
!filter ||
|
||||||
|
entry.toLowerCase().includes(filter) ||
|
||||||
|
domainToName(this.hass.localize, entry).toLowerCase().includes(filter)
|
||||||
|
)
|
||||||
|
.sort((a, b) => stringCompare(a, b, this.hass.locale.language));
|
||||||
|
});
|
||||||
|
|
||||||
|
protected updated(changed) {
|
||||||
|
if (changed.has("expanded") && this.expanded) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.expanded) return;
|
||||||
|
this.renderRoot.querySelector("mwc-list")!.style.height =
|
||||||
|
`${this.clientHeight - 49 - 32}px`; // 32px is the height of the search input
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _expandedWillChange(ev) {
|
||||||
|
this._shouldRender = ev.detail.expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _expandedChanged(ev) {
|
||||||
|
this.expanded = ev.detail.expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleItemClick(ev) {
|
||||||
|
const listItem = ev.target.closest("ha-check-list-item");
|
||||||
|
const value = listItem?.value;
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.value?.includes(value)) {
|
||||||
|
this.value = this.value?.filter((val) => val !== value);
|
||||||
|
} else {
|
||||||
|
this.value = [...(this.value || []), value];
|
||||||
|
}
|
||||||
|
|
||||||
|
listItem.selected = this.value.includes(value);
|
||||||
|
|
||||||
|
fireEvent(this, "data-table-filter-changed", {
|
||||||
|
value: this.value,
|
||||||
|
items: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _clearFilter(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.value = undefined;
|
||||||
|
fireEvent(this, "data-table-filter-changed", {
|
||||||
|
value: undefined,
|
||||||
|
items: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleSearchChange(ev: CustomEvent) {
|
||||||
|
this._filter = ev.detail.value.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
haStyleScrollbar,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
border-bottom: 1px solid var(--divider-color);
|
||||||
|
}
|
||||||
|
:host([expanded]) {
|
||||||
|
flex: 1;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
ha-expansion-panel {
|
||||||
|
--ha-card-border-radius: 0;
|
||||||
|
--expansion-panel-content-padding: 0;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.header ha-icon-button {
|
||||||
|
margin-inline-start: initial;
|
||||||
|
margin-inline-end: 8px;
|
||||||
|
}
|
||||||
|
.badge {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 8px;
|
||||||
|
margin-inline-start: 8px;
|
||||||
|
margin-inline-end: initial;
|
||||||
|
min-width: 16px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 50%;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 11px;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
line-height: 16px;
|
||||||
|
text-align: center;
|
||||||
|
padding: 0px 2px;
|
||||||
|
color: var(--text-primary-color);
|
||||||
|
}
|
||||||
|
search-input-outlined {
|
||||||
|
display: block;
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-filter-domains": HaFilterDomains;
|
||||||
|
}
|
||||||
|
}
|
@@ -71,7 +71,7 @@ export class HaFilterEntities extends LitElement {
|
|||||||
@value-changed=${this._handleSearchChange}
|
@value-changed=${this._handleSearchChange}
|
||||||
>
|
>
|
||||||
</search-input-outlined>
|
</search-input-outlined>
|
||||||
<mwc-list class="ha-scrollbar">
|
<mwc-list class="ha-scrollbar" multi>
|
||||||
<lit-virtualizer
|
<lit-virtualizer
|
||||||
.items=${this._entities(
|
.items=${this._entities(
|
||||||
this.hass.states,
|
this.hass.states,
|
||||||
@@ -108,7 +108,7 @@ export class HaFilterEntities extends LitElement {
|
|||||||
? nothing
|
? nothing
|
||||||
: html`<ha-check-list-item
|
: html`<ha-check-list-item
|
||||||
.value=${entity.entity_id}
|
.value=${entity.entity_id}
|
||||||
.selected=${this.value?.includes(entity.entity_id)}
|
.selected=${this.value?.includes(entity.entity_id) ?? false}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
>
|
>
|
||||||
<ha-state-icon
|
<ha-state-icon
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { SelectedDetail } from "@material/mwc-list";
|
|
||||||
import { mdiFilterVariantRemove } from "@mdi/js";
|
import { mdiFilterVariantRemove } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@@ -57,9 +56,9 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
>
|
>
|
||||||
</search-input-outlined>
|
</search-input-outlined>
|
||||||
<mwc-list
|
<mwc-list
|
||||||
@selected=${this._integrationsSelected}
|
|
||||||
multi
|
|
||||||
class="ha-scrollbar"
|
class="ha-scrollbar"
|
||||||
|
@click=${this._handleItemClick}
|
||||||
|
multi
|
||||||
>
|
>
|
||||||
${repeat(
|
${repeat(
|
||||||
this._integrations(this._manifests, this._filter, this.value),
|
this._integrations(this._manifests, this._filter, this.value),
|
||||||
@@ -131,34 +130,21 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
private async _integrationsSelected(
|
private _handleItemClick(ev) {
|
||||||
ev: CustomEvent<SelectedDetail<Set<number>>>
|
const listItem = ev.target.closest("ha-check-list-item");
|
||||||
) {
|
const value = listItem?.value;
|
||||||
const integrations = this._integrations(
|
if (!value) {
|
||||||
this._manifests!,
|
|
||||||
this._filter,
|
|
||||||
this.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!ev.detail.index.size) {
|
|
||||||
fireEvent(this, "data-table-filter-changed", {
|
|
||||||
value: [],
|
|
||||||
items: undefined,
|
|
||||||
});
|
|
||||||
this.value = [];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.value?.includes(value)) {
|
||||||
const value: string[] = [];
|
this.value = this.value?.filter((val) => val !== value);
|
||||||
|
} else {
|
||||||
for (const index of ev.detail.index) {
|
this.value = [...(this.value || []), value];
|
||||||
const domain = integrations[index].domain;
|
|
||||||
value.push(domain);
|
|
||||||
}
|
}
|
||||||
this.value = value;
|
listItem.selected = this.value?.includes(value);
|
||||||
|
|
||||||
fireEvent(this, "data-table-filter-changed", {
|
fireEvent(this, "data-table-filter-changed", {
|
||||||
value,
|
value: this.value,
|
||||||
items: undefined,
|
items: undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -62,8 +62,8 @@ export class HaFilterStates extends LitElement {
|
|||||||
(item) =>
|
(item) =>
|
||||||
html`<ha-check-list-item
|
html`<ha-check-list-item
|
||||||
.value=${item.value}
|
.value=${item.value}
|
||||||
.selected=${this.value?.includes(item.value)}
|
.selected=${this.value?.includes(item.value) ?? false}
|
||||||
.graphic=${hasIcon ? "icon" : undefined}
|
.graphic=${hasIcon ? "icon" : null}
|
||||||
>
|
>
|
||||||
${item.icon
|
${item.icon
|
||||||
? html`<ha-icon
|
? html`<ha-icon
|
||||||
|
@@ -71,6 +71,10 @@ export const computeInitialHaFormData = (
|
|||||||
if (selector.country?.countries?.length) {
|
if (selector.country?.countries?.length) {
|
||||||
data[field.name] = selector.country.countries[0];
|
data[field.name] = selector.country.countries[0];
|
||||||
}
|
}
|
||||||
|
} else if ("language" in selector) {
|
||||||
|
if (selector.language?.languages?.length) {
|
||||||
|
data[field.name] = selector.language.languages[0];
|
||||||
|
}
|
||||||
} else if ("duration" in selector) {
|
} else if ("duration" in selector) {
|
||||||
data[field.name] = {
|
data[field.name] = {
|
||||||
hours: 0,
|
hours: 0,
|
||||||
@@ -93,7 +97,9 @@ export const computeInitialHaFormData = (
|
|||||||
) {
|
) {
|
||||||
data[field.name] = {};
|
data[field.name] = {};
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Selector not supported in initial form data");
|
throw new Error(
|
||||||
|
`Selector ${Object.keys(selector)[0]} not supported in initial form data`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,29 @@
|
|||||||
import { FormfieldBase } from "@material/mwc-formfield/mwc-formfield-base";
|
import { FormfieldBase } from "@material/mwc-formfield/mwc-formfield-base";
|
||||||
import { styles } from "@material/mwc-formfield/mwc-formfield.css";
|
import { styles } from "@material/mwc-formfield/mwc-formfield.css";
|
||||||
import { css } from "lit";
|
import { css, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
|
||||||
@customElement("ha-formfield")
|
@customElement("ha-formfield")
|
||||||
export class HaFormfield extends FormfieldBase {
|
export class HaFormfield extends FormfieldBase {
|
||||||
@property({ type: Boolean, reflect: true }) public disabled = false;
|
@property({ type: Boolean, reflect: true }) public disabled = false;
|
||||||
|
|
||||||
|
protected override render() {
|
||||||
|
const classes = {
|
||||||
|
"mdc-form-field--align-end": this.alignEnd,
|
||||||
|
"mdc-form-field--space-between": this.spaceBetween,
|
||||||
|
"mdc-form-field--nowrap": this.nowrap,
|
||||||
|
};
|
||||||
|
|
||||||
|
return html` <div class="mdc-form-field ${classMap(classes)}">
|
||||||
|
<slot></slot>
|
||||||
|
<label class="mdc-label" @click=${this._labelClick}
|
||||||
|
><slot name="label">${this.label}</slot></label
|
||||||
|
>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
protected _labelClick() {
|
protected _labelClick() {
|
||||||
const input = this.input as HTMLInputElement | undefined;
|
const input = this.input as HTMLInputElement | undefined;
|
||||||
if (!input) return;
|
if (!input) return;
|
||||||
@@ -39,6 +55,9 @@ export class HaFormfield extends FormfieldBase {
|
|||||||
margin-inline-end: 10px;
|
margin-inline-end: 10px;
|
||||||
margin-inline-start: inline;
|
margin-inline-start: inline;
|
||||||
}
|
}
|
||||||
|
.mdc-form-field {
|
||||||
|
align-items: var(--ha-formfield-align-items, center);
|
||||||
|
}
|
||||||
.mdc-form-field > label {
|
.mdc-form-field > label {
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
margin-inline-start: 0;
|
margin-inline-start: 0;
|
||||||
|
@@ -302,6 +302,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
name: this.hass.localize("ui.components.label-picker.no_match"),
|
name: this.hass.localize("ui.components.label-picker.no_match"),
|
||||||
icon: null,
|
icon: null,
|
||||||
color: null,
|
color: null,
|
||||||
|
description: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -315,6 +316,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
name: this.hass.localize("ui.components.label-picker.add_new"),
|
name: this.hass.localize("ui.components.label-picker.add_new"),
|
||||||
icon: "mdi:plus",
|
icon: "mdi:plus",
|
||||||
color: null,
|
color: null,
|
||||||
|
description: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import "@material/web/ripple/ripple";
|
|
||||||
|
|
||||||
@customElement("ha-label")
|
@customElement("ha-label")
|
||||||
class HaLabel extends LitElement {
|
class HaLabel extends LitElement {
|
||||||
@@ -11,7 +10,6 @@ class HaLabel extends LitElement {
|
|||||||
<span class="content">
|
<span class="content">
|
||||||
<slot name="icon"></slot>
|
<slot name="icon"></slot>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<md-ripple></md-ripple>
|
|
||||||
</span>
|
</span>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -27,7 +25,6 @@ class HaLabel extends LitElement {
|
|||||||
0.15
|
0.15
|
||||||
);
|
);
|
||||||
--ha-label-background-opacity: 1;
|
--ha-label-background-opacity: 1;
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
@@ -1,25 +1,22 @@
|
|||||||
import { customElement } from "lit/decorators";
|
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { MdListItem } from "@material/web/list/list-item";
|
import { MdListItem } from "@material/web/list/list-item";
|
||||||
import { CSSResult, css } from "lit";
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-list-item-new")
|
@customElement("ha-list-item-new")
|
||||||
export class HaListItemNew extends MdListItem {
|
export class HaListItemNew extends MdListItem {
|
||||||
static get styles(): CSSResult[] {
|
static override styles = [
|
||||||
return [
|
...super.styles,
|
||||||
...MdListItem.styles,
|
css`
|
||||||
css`
|
:host {
|
||||||
:host {
|
--ha-icon-display: block;
|
||||||
--ha-icon-display: block;
|
--md-sys-color-primary: var(--primary-text-color);
|
||||||
--md-sys-color-primary: var(--primary-text-color);
|
--md-sys-color-secondary: var(--secondary-text-color);
|
||||||
--md-sys-color-secondary: var(--secondary-text-color);
|
--md-sys-color-surface: var(--card-background-color);
|
||||||
--md-sys-color-surface: var(--card-background-color);
|
--md-sys-color-on-surface: var(--primary-text-color);
|
||||||
--md-sys-color-on-surface: var(--primary-text-color);
|
--md-sys-color-on-surface-variant: var(--secondary-text-color);
|
||||||
--md-sys-color-on-surface-variant: var(--secondary-text-color);
|
}
|
||||||
}
|
`,
|
||||||
`,
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,20 +1,17 @@
|
|||||||
import { customElement } from "lit/decorators";
|
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { MdList } from "@material/web/list/list";
|
import { MdList } from "@material/web/list/list";
|
||||||
import { CSSResult, css } from "lit";
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-list-new")
|
@customElement("ha-list-new")
|
||||||
export class HaListNew extends MdList {
|
export class HaListNew extends MdList {
|
||||||
static get styles(): CSSResult[] {
|
static override styles = [
|
||||||
return [
|
...super.styles,
|
||||||
...MdList.styles,
|
css`
|
||||||
css`
|
:host {
|
||||||
:host {
|
--md-sys-color-surface: var(--card-background-color);
|
||||||
--md-sys-color-surface: var(--card-background-color);
|
}
|
||||||
}
|
`,
|
||||||
`,
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
import { MdMenuItem } from "@material/web/menu/menu-item";
|
import { MdMenuItem } from "@material/web/menu/menu-item";
|
||||||
import "element-internals-polyfill";
|
import { css } from "lit";
|
||||||
import { CSSResult, css } from "lit";
|
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-menu-item")
|
@customElement("ha-menu-item")
|
||||||
export class HaMenuItem extends MdMenuItem {
|
export class HaMenuItem extends MdMenuItem {
|
||||||
static override styles: CSSResult[] = [
|
static override styles = [
|
||||||
...MdMenuItem.styles,
|
...super.styles,
|
||||||
css`
|
css`
|
||||||
:host {
|
:host {
|
||||||
--ha-icon-display: block;
|
--ha-icon-display: block;
|
||||||
@@ -25,6 +24,7 @@ export class HaMenuItem extends MdMenuItem {
|
|||||||
|
|
||||||
--md-sys-color-on-primary-container: var(--primary-text-color);
|
--md-sys-color-on-primary-container: var(--primary-text-color);
|
||||||
--md-sys-color-on-secondary-container: var(--primary-text-color);
|
--md-sys-color-on-secondary-container: var(--primary-text-color);
|
||||||
|
--md-menu-item-label-text-font: Roboto, sans-serif;
|
||||||
}
|
}
|
||||||
:host(.warning) {
|
:host(.warning) {
|
||||||
--md-menu-item-label-text-color: var(--error-color);
|
--md-menu-item-label-text-color: var(--error-color);
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
import { customElement } from "lit/decorators";
|
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { CSSResult, css } from "lit";
|
|
||||||
import { MdMenu } from "@material/web/menu/menu";
|
import { MdMenu } from "@material/web/menu/menu";
|
||||||
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-menu")
|
@customElement("ha-menu")
|
||||||
export class HaMenu extends MdMenu {
|
export class HaMenu extends MdMenu {
|
||||||
static override styles: CSSResult[] = [
|
static override styles = [
|
||||||
...MdMenu.styles,
|
...super.styles,
|
||||||
css`
|
css`
|
||||||
:host {
|
:host {
|
||||||
--md-sys-color-surface-container: var(--card-background-color);
|
--md-sys-color-surface-container: var(--card-background-color);
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
|
import { MdOutlinedButton } from "@material/web/button/outlined-button";
|
||||||
import { css } from "lit";
|
import { css } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { MdOutlinedButton } from "@material/web/button/outlined-button";
|
|
||||||
|
|
||||||
@customElement("ha-outlined-button")
|
@customElement("ha-outlined-button")
|
||||||
export class HaOutlinedButton extends MdOutlinedButton {
|
export class HaOutlinedButton extends MdOutlinedButton {
|
||||||
|
39
src/components/ha-outlined-field.ts
Normal file
39
src/components/ha-outlined-field.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { MdOutlinedField } from "@material/web/field/outlined-field";
|
||||||
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
import { literal } from "lit/static-html";
|
||||||
|
|
||||||
|
@customElement("ha-outlined-field")
|
||||||
|
export class HaOutlinedField extends MdOutlinedField {
|
||||||
|
protected readonly fieldTag = literal`ha-outlined-field`;
|
||||||
|
|
||||||
|
static override styles = [
|
||||||
|
...super.styles,
|
||||||
|
css`
|
||||||
|
.container::before {
|
||||||
|
display: block;
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background-color: var(--ha-outlined-field-container-color, transparent);
|
||||||
|
opacity: var(--ha-outlined-field-container-opacity, 1);
|
||||||
|
border-start-start-radius: var(--_container-shape-start-start);
|
||||||
|
border-start-end-radius: var(--_container-shape-start-end);
|
||||||
|
border-end-start-radius: var(--_container-shape-end-start);
|
||||||
|
border-end-end-radius: var(--_container-shape-end-end);
|
||||||
|
}
|
||||||
|
.with-start .start {
|
||||||
|
margin-inline-end: var(--ha-outlined-field-start-margin, 4px);
|
||||||
|
}
|
||||||
|
.with-end .end {
|
||||||
|
margin-inline-start: var(--ha-outlined-field-end-margin, 4px);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-outlined-field": HaOutlinedField;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
|
import { MdOutlinedIconButton } from "@material/web/iconbutton/outlined-icon-button";
|
||||||
import { css } from "lit";
|
import { css } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { MdOutlinedIconButton } from "@material/web/iconbutton/outlined-icon-button";
|
|
||||||
|
|
||||||
@customElement("ha-outlined-icon-button")
|
@customElement("ha-outlined-icon-button")
|
||||||
export class HaOutlinedIconButton extends MdOutlinedIconButton {
|
export class HaOutlinedIconButton extends MdOutlinedIconButton {
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
import { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field";
|
import { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field";
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { css } from "lit";
|
import { css } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
import { literal } from "lit/static-html";
|
||||||
|
import "./ha-outlined-field";
|
||||||
|
|
||||||
@customElement("ha-outlined-text-field")
|
@customElement("ha-outlined-text-field")
|
||||||
export class HaOutlinedTextField extends MdOutlinedTextField {
|
export class HaOutlinedTextField extends MdOutlinedTextField {
|
||||||
|
protected readonly fieldTag = literal`ha-outlined-field`;
|
||||||
|
|
||||||
static override styles = [
|
static override styles = [
|
||||||
...super.styles,
|
...super.styles,
|
||||||
css`
|
css`
|
||||||
@@ -25,16 +28,10 @@ export class HaOutlinedTextField extends MdOutlinedTextField {
|
|||||||
--md-outlined-field-container-shape-end-end: 10px;
|
--md-outlined-field-container-shape-end-end: 10px;
|
||||||
--md-outlined-field-container-shape-end-start: 10px;
|
--md-outlined-field-container-shape-end-start: 10px;
|
||||||
--md-outlined-field-focus-outline-width: 1px;
|
--md-outlined-field-focus-outline-width: 1px;
|
||||||
|
--ha-outlined-field-start-margin: -4px;
|
||||||
|
--ha-outlined-field-end-margin: -4px;
|
||||||
--mdc-icon-size: var(--md-input-chip-icon-size, 18px);
|
--mdc-icon-size: var(--md-input-chip-icon-size, 18px);
|
||||||
}
|
}
|
||||||
md-outlined-field {
|
|
||||||
background: var(--ha-outlined-text-field-container-color, transparent);
|
|
||||||
opacity: var(--ha-outlined-text-field-container-opacity, 1);
|
|
||||||
border-start-start-radius: var(--_container-shape-start-start);
|
|
||||||
border-start-end-radius: var(--_container-shape-start-end);
|
|
||||||
border-end-end-radius: var(--_container-shape-end-end);
|
|
||||||
border-end-start-radius: var(--_container-shape-end-start);
|
|
||||||
}
|
|
||||||
.input {
|
.input {
|
||||||
font-family: Roboto, sans-serif;
|
font-family: Roboto, sans-serif;
|
||||||
}
|
}
|
||||||
|
62
src/components/ha-ripple.ts
Normal file
62
src/components/ha-ripple.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { AttachableController } from "@material/web/internal/controller/attachable-controller";
|
||||||
|
import { MdRipple } from "@material/web/ripple/ripple";
|
||||||
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
|
@customElement("ha-ripple")
|
||||||
|
export class HaRipple extends MdRipple {
|
||||||
|
private readonly attachableTouchController = new AttachableController(
|
||||||
|
this,
|
||||||
|
this.onTouchControlChange.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
attach(control: HTMLElement) {
|
||||||
|
super.attach(control);
|
||||||
|
this.attachableTouchController.attach(control);
|
||||||
|
}
|
||||||
|
|
||||||
|
detach() {
|
||||||
|
super.detach();
|
||||||
|
this.attachableTouchController.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleTouchEnd = () => {
|
||||||
|
if (!this.disabled) {
|
||||||
|
// @ts-ignore
|
||||||
|
super.endPressAnimation();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private onTouchControlChange(
|
||||||
|
prev: HTMLElement | null,
|
||||||
|
next: HTMLElement | null
|
||||||
|
) {
|
||||||
|
// Add touchend event to clean ripple on touch devices using action handler
|
||||||
|
prev?.removeEventListener("touchend", this._handleTouchEnd);
|
||||||
|
next?.addEventListener("touchend", this._handleTouchEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static override styles = [
|
||||||
|
...super.styles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
--md-ripple-hover-opacity: var(--ha-ripple-hover-opacity, 0.08);
|
||||||
|
--md-ripple-pressed-opacity: var(--ha-ripple-pressed-opacity, 0.12);
|
||||||
|
--md-ripple-hover-color: var(
|
||||||
|
--ha-ripple-hover-color,
|
||||||
|
var(--ha-ripple-color, var(--secondary-text-color))
|
||||||
|
);
|
||||||
|
--md-ripple-pressed-color: var(
|
||||||
|
--ha-ripple-pressed-color,
|
||||||
|
var(--ha-ripple-color, var(--secondary-text-color))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-ripple": HaRipple;
|
||||||
|
}
|
||||||
|
}
|
@@ -8,7 +8,10 @@ import {
|
|||||||
fetchEntitySourcesWithCache,
|
fetchEntitySourcesWithCache,
|
||||||
} from "../../data/entity_sources";
|
} from "../../data/entity_sources";
|
||||||
import type { EntitySelector } from "../../data/selector";
|
import type { EntitySelector } from "../../data/selector";
|
||||||
import { filterSelectorEntities } from "../../data/selector";
|
import {
|
||||||
|
filterSelectorEntities,
|
||||||
|
computeCreateDomains,
|
||||||
|
} from "../../data/selector";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "../entity/ha-entities-picker";
|
import "../entity/ha-entities-picker";
|
||||||
import "../entity/ha-entity-picker";
|
import "../entity/ha-entity-picker";
|
||||||
@@ -31,6 +34,8 @@ export class HaEntitySelector extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
@property({ type: Boolean }) public required = true;
|
||||||
|
|
||||||
|
@state() private _createDomains: string[] | undefined;
|
||||||
|
|
||||||
private _hasIntegration(selector: EntitySelector) {
|
private _hasIntegration(selector: EntitySelector) {
|
||||||
return (
|
return (
|
||||||
selector.entity?.filter &&
|
selector.entity?.filter &&
|
||||||
@@ -64,6 +69,7 @@ export class HaEntitySelector extends LitElement {
|
|||||||
.includeEntities=${this.selector.entity?.include_entities}
|
.includeEntities=${this.selector.entity?.include_entities}
|
||||||
.excludeEntities=${this.selector.entity?.exclude_entities}
|
.excludeEntities=${this.selector.entity?.exclude_entities}
|
||||||
.entityFilter=${this._filterEntities}
|
.entityFilter=${this._filterEntities}
|
||||||
|
.createDomains=${this._createDomains}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
@@ -79,6 +85,7 @@ export class HaEntitySelector extends LitElement {
|
|||||||
.includeEntities=${this.selector.entity.include_entities}
|
.includeEntities=${this.selector.entity.include_entities}
|
||||||
.excludeEntities=${this.selector.entity.exclude_entities}
|
.excludeEntities=${this.selector.entity.exclude_entities}
|
||||||
.entityFilter=${this._filterEntities}
|
.entityFilter=${this._filterEntities}
|
||||||
|
.createDomains=${this._createDomains}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
></ha-entities-picker>
|
></ha-entities-picker>
|
||||||
@@ -96,6 +103,9 @@ export class HaEntitySelector extends LitElement {
|
|||||||
this._entitySources = sources;
|
this._entitySources = sources;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (changedProps.has("selector")) {
|
||||||
|
this._createDomains = computeCreateDomains(this.selector);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filterEntities = (entity: HassEntity): boolean => {
|
private _filterEntities = (entity: HassEntity): boolean => {
|
||||||
|
@@ -7,8 +7,10 @@ import type {
|
|||||||
LocationSelectorValue,
|
LocationSelectorValue,
|
||||||
} from "../../data/selector";
|
} from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { SchemaUnion } from "../ha-form/types";
|
||||||
import type { MarkerLocation } from "../map/ha-locations-editor";
|
import type { MarkerLocation } from "../map/ha-locations-editor";
|
||||||
import "../map/ha-locations-editor";
|
import "../map/ha-locations-editor";
|
||||||
|
import "../ha-form/ha-form";
|
||||||
|
|
||||||
@customElement("ha-selector-location")
|
@customElement("ha-selector-location")
|
||||||
export class HaLocationSelector extends LitElement {
|
export class HaLocationSelector extends LitElement {
|
||||||
@@ -24,6 +26,49 @@ export class HaLocationSelector extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public disabled = false;
|
@property({ type: Boolean, reflect: true }) public disabled = false;
|
||||||
|
|
||||||
|
private _schema = memoizeOne(
|
||||||
|
(radius?: boolean, radius_readonly?: boolean) =>
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
type: "grid",
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
name: "latitude",
|
||||||
|
required: true,
|
||||||
|
selector: { number: { step: "any" } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "longitude",
|
||||||
|
required: true,
|
||||||
|
selector: { number: { step: "any" } },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
...(radius
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
name: "radius",
|
||||||
|
required: true,
|
||||||
|
default: 1000,
|
||||||
|
disabled: !!radius_readonly,
|
||||||
|
selector: { number: { min: 0, step: 1, mode: "box" } as const },
|
||||||
|
} as const,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
] as const
|
||||||
|
);
|
||||||
|
|
||||||
|
protected willUpdate() {
|
||||||
|
if (!this.value) {
|
||||||
|
this.value = {
|
||||||
|
latitude: this.hass.config.latitude,
|
||||||
|
longitude: this.hass.config.longitude,
|
||||||
|
radius: this.selector.location?.radius ? 1000 : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<p>${this.label ? this.label : ""}</p>
|
<p>${this.label ? this.label : ""}</p>
|
||||||
@@ -35,6 +80,17 @@ export class HaLocationSelector extends LitElement {
|
|||||||
@location-updated=${this._locationChanged}
|
@location-updated=${this._locationChanged}
|
||||||
@radius-updated=${this._radiusChanged}
|
@radius-updated=${this._radiusChanged}
|
||||||
></ha-locations-editor>
|
></ha-locations-editor>
|
||||||
|
<ha-form
|
||||||
|
.hass=${this.hass}
|
||||||
|
.schema=${this._schema(
|
||||||
|
this.selector.location?.radius,
|
||||||
|
this.selector.location?.radius_readonly
|
||||||
|
)}
|
||||||
|
.data=${this.value}
|
||||||
|
.computeLabel=${this._computeLabel}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
@value-changed=${this._valueChanged}
|
||||||
|
></ha-form>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +122,8 @@ export class HaLocationSelector extends LitElement {
|
|||||||
? "mdi:map-marker-radius"
|
? "mdi:map-marker-radius"
|
||||||
: "mdi:map-marker",
|
: "mdi:map-marker",
|
||||||
location_editable: true,
|
location_editable: true,
|
||||||
radius_editable: true,
|
radius_editable:
|
||||||
|
!!selector.location?.radius && !selector.location?.radius_readonly,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -80,14 +137,39 @@ export class HaLocationSelector extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _radiusChanged(ev: CustomEvent) {
|
private _radiusChanged(ev: CustomEvent) {
|
||||||
const radius = ev.detail.radius;
|
const radius = Math.round(ev.detail.radius);
|
||||||
fireEvent(this, "value-changed", { value: { ...this.value, radius } });
|
fireEvent(this, "value-changed", { value: { ...this.value, radius } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const value = ev.detail.value;
|
||||||
|
const radius = Math.round(ev.detail.value.radius);
|
||||||
|
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: {
|
||||||
|
latitude: value.latitude,
|
||||||
|
longitude: value.longitude,
|
||||||
|
...(this.selector.location?.radius &&
|
||||||
|
!this.selector.location?.radius_readonly
|
||||||
|
? {
|
||||||
|
radius,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _computeLabel = (
|
||||||
|
entry: SchemaUnion<ReturnType<typeof this._schema>>
|
||||||
|
): string =>
|
||||||
|
this.hass.localize(`ui.components.selectors.location.${entry.name}`);
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
ha-locations-editor {
|
ha-locations-editor {
|
||||||
display: block;
|
display: block;
|
||||||
height: 400px;
|
height: 400px;
|
||||||
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
p {
|
p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
@@ -278,6 +278,14 @@ export class HaSelectSelector extends LitElement {
|
|||||||
|
|
||||||
private _valueChanged(ev) {
|
private _valueChanged(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
|
if (ev.detail?.index === -1 && this.value !== undefined) {
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: undefined,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const value = ev.detail?.value || ev.target.value;
|
const value = ev.detail?.value || ev.target.value;
|
||||||
if (this.disabled || value === undefined || value === (this.value ?? "")) {
|
if (this.disabled || value === undefined || value === (this.value ?? "")) {
|
||||||
return;
|
return;
|
||||||
|
@@ -22,6 +22,7 @@ import {
|
|||||||
filterSelectorDevices,
|
filterSelectorDevices,
|
||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
TargetSelector,
|
TargetSelector,
|
||||||
|
computeCreateDomains,
|
||||||
} from "../../data/selector";
|
} from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-target-picker";
|
import "../ha-target-picker";
|
||||||
@@ -42,6 +43,8 @@ export class HaTargetSelector extends LitElement {
|
|||||||
|
|
||||||
@state() private _entitySources?: EntitySources;
|
@state() private _entitySources?: EntitySources;
|
||||||
|
|
||||||
|
@state() private _createDomains: string[] | undefined;
|
||||||
|
|
||||||
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
||||||
|
|
||||||
private _hasIntegration(selector: TargetSelector) {
|
private _hasIntegration(selector: TargetSelector) {
|
||||||
@@ -68,6 +71,9 @@ export class HaTargetSelector extends LitElement {
|
|||||||
this._entitySources = sources;
|
this._entitySources = sources;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (changedProperties.has("selector")) {
|
||||||
|
this._createDomains = computeCreateDomains(this.selector);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@@ -82,6 +88,7 @@ export class HaTargetSelector extends LitElement {
|
|||||||
.deviceFilter=${this._filterDevices}
|
.deviceFilter=${this._filterDevices}
|
||||||
.entityFilter=${this._filterEntities}
|
.entityFilter=${this._filterEntities}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
.createDomains=${this._createDomains}
|
||||||
></ha-target-picker>`;
|
></ha-target-picker>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ import {
|
|||||||
expandFloorTarget,
|
expandFloorTarget,
|
||||||
expandLabelTarget,
|
expandLabelTarget,
|
||||||
Selector,
|
Selector,
|
||||||
|
TargetSelector,
|
||||||
} from "../data/selector";
|
} from "../data/selector";
|
||||||
import { HomeAssistant, ValueChangedEvent } from "../types";
|
import { HomeAssistant, ValueChangedEvent } from "../types";
|
||||||
import { documentationUrl } from "../util/documentation-url";
|
import { documentationUrl } from "../util/documentation-url";
|
||||||
@@ -363,6 +364,11 @@ export class HaServiceControl extends LitElement {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _targetSelector = memoizeOne(
|
||||||
|
(targetSelector: TargetSelector | null | undefined) =>
|
||||||
|
targetSelector ? { target: { ...targetSelector } } : { target: {} }
|
||||||
|
);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const serviceData = this._getServiceInfo(
|
const serviceData = this._getServiceInfo(
|
||||||
this._value?.service,
|
this._value?.service,
|
||||||
@@ -401,157 +407,151 @@ export class HaServiceControl extends LitElement {
|
|||||||
)) ||
|
)) ||
|
||||||
serviceData?.description;
|
serviceData?.description;
|
||||||
|
|
||||||
return html`
|
return html`${this.hidePicker
|
||||||
${this.hidePicker
|
? nothing
|
||||||
? nothing
|
: html`<ha-service-picker
|
||||||
: html`<ha-service-picker
|
.hass=${this.hass}
|
||||||
|
.value=${this._value?.service}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
@value-changed=${this._serviceChanged}
|
||||||
|
></ha-service-picker>`}
|
||||||
|
${this.hideDescription
|
||||||
|
? nothing
|
||||||
|
: html`
|
||||||
|
<div class="description">
|
||||||
|
${description ? html`<p>${description}</p>` : ""}
|
||||||
|
${this._manifest
|
||||||
|
? html` <a
|
||||||
|
href=${this._manifest.is_built_in
|
||||||
|
? documentationUrl(
|
||||||
|
this.hass,
|
||||||
|
`/integrations/${this._manifest.domain}`
|
||||||
|
)
|
||||||
|
: this._manifest.documentation}
|
||||||
|
title=${this.hass.localize(
|
||||||
|
"ui.components.service-control.integration_doc"
|
||||||
|
)}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
<ha-icon-button
|
||||||
|
.path=${mdiHelpCircle}
|
||||||
|
class="help-icon"
|
||||||
|
></ha-icon-button>
|
||||||
|
</a>`
|
||||||
|
: nothing}
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
|
${serviceData && "target" in serviceData
|
||||||
|
? html`<ha-settings-row .narrow=${this.narrow}>
|
||||||
|
${hasOptional
|
||||||
|
? html`<div slot="prefix" class="checkbox-spacer"></div>`
|
||||||
|
: ""}
|
||||||
|
<span slot="heading"
|
||||||
|
>${this.hass.localize("ui.components.service-control.target")}</span
|
||||||
|
>
|
||||||
|
<span slot="description"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.components.service-control.target_description"
|
||||||
|
)}</span
|
||||||
|
><ha-selector
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._value?.service}
|
.selector=${this._targetSelector(
|
||||||
|
serviceData.target as TargetSelector
|
||||||
|
)}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._serviceChanged}
|
@value-changed=${this._targetChanged}
|
||||||
></ha-service-picker>`}
|
.value=${this._value?.target}
|
||||||
${this.hideDescription
|
></ha-selector
|
||||||
? nothing
|
></ha-settings-row>`
|
||||||
: html`
|
: entityId
|
||||||
<div class="description">
|
? html`<ha-entity-picker
|
||||||
${description ? html`<p>${description}</p>` : ""}
|
|
||||||
${this._manifest
|
|
||||||
? html` <a
|
|
||||||
href=${this._manifest.is_built_in
|
|
||||||
? documentationUrl(
|
|
||||||
this.hass,
|
|
||||||
`/integrations/${this._manifest.domain}`
|
|
||||||
)
|
|
||||||
: this._manifest.documentation}
|
|
||||||
title=${this.hass.localize(
|
|
||||||
"ui.components.service-control.integration_doc"
|
|
||||||
)}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
<ha-icon-button
|
|
||||||
.path=${mdiHelpCircle}
|
|
||||||
class="help-icon"
|
|
||||||
></ha-icon-button>
|
|
||||||
</a>`
|
|
||||||
: nothing}
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
${serviceData && "target" in serviceData
|
|
||||||
? html`<ha-settings-row .narrow=${this.narrow}>
|
|
||||||
${hasOptional
|
|
||||||
? html`<div slot="prefix" class="checkbox-spacer"></div>`
|
|
||||||
: ""}
|
|
||||||
<span slot="heading"
|
|
||||||
>${this.hass.localize(
|
|
||||||
"ui.components.service-control.target"
|
|
||||||
)}</span
|
|
||||||
>
|
|
||||||
<span slot="description"
|
|
||||||
>${this.hass.localize(
|
|
||||||
"ui.components.service-control.target_description"
|
|
||||||
)}</span
|
|
||||||
><ha-selector
|
|
||||||
.hass=${this.hass}
|
|
||||||
.selector=${serviceData.target
|
|
||||||
? { target: serviceData.target }
|
|
||||||
: { target: {} }}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
@value-changed=${this._targetChanged}
|
|
||||||
.value=${this._value?.target}
|
|
||||||
></ha-selector
|
|
||||||
></ha-settings-row>`
|
|
||||||
: entityId
|
|
||||||
? html`<ha-entity-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.value=${this._value?.data?.entity_id}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
`component.${domain}.services.${serviceName}.fields.entity_id.description`
|
|
||||||
) || entityId.description}
|
|
||||||
@value-changed=${this._entityPicked}
|
|
||||||
allow-custom-entity
|
|
||||||
></ha-entity-picker>`
|
|
||||||
: ""}
|
|
||||||
${shouldRenderServiceDataYaml
|
|
||||||
? html`<ha-yaml-editor
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.label=${this.hass.localize("ui.components.service-control.data")}
|
.disabled=${this.disabled}
|
||||||
.name=${"data"}
|
.value=${this._value?.data?.entity_id}
|
||||||
.readOnly=${this.disabled}
|
.label=${this.hass.localize(
|
||||||
.defaultValue=${this._value?.data}
|
`component.${domain}.services.${serviceName}.fields.entity_id.description`
|
||||||
@value-changed=${this._dataChanged}
|
) || entityId.description}
|
||||||
></ha-yaml-editor>`
|
@value-changed=${this._entityPicked}
|
||||||
: filteredFields?.map((dataField) => {
|
allow-custom-entity
|
||||||
const selector = dataField?.selector ?? { text: undefined };
|
></ha-entity-picker>`
|
||||||
const type = Object.keys(selector)[0];
|
: ""}
|
||||||
const enhancedSelector = [
|
${shouldRenderServiceDataYaml
|
||||||
"action",
|
? html`<ha-yaml-editor
|
||||||
"condition",
|
.hass=${this.hass}
|
||||||
"trigger",
|
.label=${this.hass.localize("ui.components.service-control.data")}
|
||||||
].includes(type)
|
.name=${"data"}
|
||||||
? {
|
.readOnly=${this.disabled}
|
||||||
[type]: {
|
.defaultValue=${this._value?.data}
|
||||||
...selector[type],
|
@value-changed=${this._dataChanged}
|
||||||
path: [dataField.key],
|
></ha-yaml-editor>`
|
||||||
},
|
: filteredFields?.map((dataField) => {
|
||||||
}
|
const selector = dataField?.selector ?? { text: undefined };
|
||||||
: selector;
|
const type = Object.keys(selector)[0];
|
||||||
|
const enhancedSelector = ["action", "condition", "trigger"].includes(
|
||||||
|
type
|
||||||
|
)
|
||||||
|
? {
|
||||||
|
[type]: {
|
||||||
|
...selector[type],
|
||||||
|
path: [dataField.key],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: selector;
|
||||||
|
|
||||||
const showOptional = showOptionalToggle(dataField);
|
const showOptional = showOptionalToggle(dataField);
|
||||||
|
|
||||||
return dataField.selector &&
|
return dataField.selector &&
|
||||||
(!dataField.advanced ||
|
(!dataField.advanced ||
|
||||||
this.showAdvanced ||
|
this.showAdvanced ||
|
||||||
(this._value?.data &&
|
(this._value?.data &&
|
||||||
this._value.data[dataField.key] !== undefined))
|
this._value.data[dataField.key] !== undefined))
|
||||||
? html`<ha-settings-row .narrow=${this.narrow}>
|
? html`<ha-settings-row .narrow=${this.narrow}>
|
||||||
${!showOptional
|
${!showOptional
|
||||||
? hasOptional
|
? hasOptional
|
||||||
? html`<div slot="prefix" class="checkbox-spacer"></div>`
|
? html`<div slot="prefix" class="checkbox-spacer"></div>`
|
||||||
: ""
|
: ""
|
||||||
: html`<ha-checkbox
|
: html`<ha-checkbox
|
||||||
.key=${dataField.key}
|
.key=${dataField.key}
|
||||||
.checked=${this._checkedKeys.has(dataField.key) ||
|
.checked=${this._checkedKeys.has(dataField.key) ||
|
||||||
(this._value?.data &&
|
(this._value?.data &&
|
||||||
this._value.data[dataField.key] !== undefined)}
|
this._value.data[dataField.key] !== undefined)}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@change=${this._checkboxChanged}
|
@change=${this._checkboxChanged}
|
||||||
slot="prefix"
|
slot="prefix"
|
||||||
></ha-checkbox>`}
|
></ha-checkbox>`}
|
||||||
<span slot="heading"
|
<span slot="heading"
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
`component.${domain}.services.${serviceName}.fields.${dataField.key}.name`
|
`component.${domain}.services.${serviceName}.fields.${dataField.key}.name`
|
||||||
) ||
|
) ||
|
||||||
dataField.name ||
|
dataField.name ||
|
||||||
dataField.key}</span
|
dataField.key}</span
|
||||||
>
|
>
|
||||||
<span slot="description"
|
<span slot="description"
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description`
|
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description`
|
||||||
) || dataField?.description}</span
|
) || dataField?.description}</span
|
||||||
>
|
>
|
||||||
<ha-selector
|
<ha-selector
|
||||||
.disabled=${this.disabled ||
|
.disabled=${this.disabled ||
|
||||||
(showOptional &&
|
(showOptional &&
|
||||||
!this._checkedKeys.has(dataField.key) &&
|
!this._checkedKeys.has(dataField.key) &&
|
||||||
(!this._value?.data ||
|
(!this._value?.data ||
|
||||||
this._value.data[dataField.key] === undefined))}
|
this._value.data[dataField.key] === undefined))}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.selector=${enhancedSelector}
|
.selector=${enhancedSelector}
|
||||||
.key=${dataField.key}
|
.key=${dataField.key}
|
||||||
@value-changed=${this._serviceDataChanged}
|
@value-changed=${this._serviceDataChanged}
|
||||||
.value=${this._value?.data
|
.value=${this._value?.data
|
||||||
? this._value.data[dataField.key]
|
? this._value.data[dataField.key]
|
||||||
: undefined}
|
: undefined}
|
||||||
.placeholder=${dataField.default}
|
.placeholder=${dataField.default}
|
||||||
.localizeValue=${this._localizeValueCallback}
|
.localizeValue=${this._localizeValueCallback}
|
||||||
@item-moved=${this._itemMoved}
|
@item-moved=${this._itemMoved}
|
||||||
></ha-selector>
|
></ha-selector>
|
||||||
</ha-settings-row>`
|
</ha-settings-row>`
|
||||||
: "";
|
: "";
|
||||||
})}
|
})} `;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _localizeValueCallback = (key: string) => {
|
private _localizeValueCallback = (key: string) => {
|
||||||
|
@@ -8,6 +8,9 @@ export class HaSettingsRow extends LitElement {
|
|||||||
@property({ type: Boolean, attribute: "three-line" })
|
@property({ type: Boolean, attribute: "three-line" })
|
||||||
public threeLine = false;
|
public threeLine = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "wrap-heading", reflect: true })
|
||||||
|
public wrapHeading = false;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="prefix-wrap">
|
<div class="prefix-wrap">
|
||||||
@@ -51,7 +54,7 @@ export class HaSettingsRow extends LitElement {
|
|||||||
.body[three-line] {
|
.body[three-line] {
|
||||||
min-height: var(--paper-item-body-three-line-min-height, 88px);
|
min-height: var(--paper-item-body-three-line-min-height, 88px);
|
||||||
}
|
}
|
||||||
.body > * {
|
:host(:not([wrap-heading])) body > * {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import { customElement } from "lit/decorators";
|
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { MdSlider } from "@material/web/slider/slider";
|
import { MdSlider } from "@material/web/slider/slider";
|
||||||
import { CSSResult, css } from "lit";
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
import { mainWindow } from "../common/dom/get_main_window";
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
|
|
||||||
@customElement("ha-slider")
|
@customElement("ha-slider")
|
||||||
@@ -11,8 +10,8 @@ export class HaSlider extends MdSlider {
|
|||||||
this.dir = mainWindow.document.dir;
|
this.dir = mainWindow.document.dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
static override styles: CSSResult[] = [
|
static override styles = [
|
||||||
...MdSlider.styles,
|
...super.styles,
|
||||||
css`
|
css`
|
||||||
:host {
|
:host {
|
||||||
--md-sys-color-primary: var(--primary-color);
|
--md-sys-color-primary: var(--primary-color);
|
||||||
|
@@ -82,7 +82,7 @@ export class HaSortable extends LitElement {
|
|||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this._shouldBeDestroy = false;
|
this._shouldBeDestroy = false;
|
||||||
if (this.hasUpdated) {
|
if (this.hasUpdated && !this.disabled) {
|
||||||
this._createSortable();
|
this._createSortable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
import { customElement } from "lit/decorators";
|
|
||||||
import "element-internals-polyfill";
|
|
||||||
import { CSSResult, css } from "lit";
|
|
||||||
import { MdSubMenu } from "@material/web/menu/sub-menu";
|
import { MdSubMenu } from "@material/web/menu/sub-menu";
|
||||||
|
import { css } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
@customElement("ha-sub-menu")
|
@customElement("ha-sub-menu")
|
||||||
// @ts-expect-error
|
|
||||||
export class HaSubMenu extends MdSubMenu {
|
export class HaSubMenu extends MdSubMenu {
|
||||||
static override styles: CSSResult[] = [
|
async show() {
|
||||||
MdSubMenu.styles,
|
super.show();
|
||||||
|
this.menu.hasOverflow = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static override styles = [
|
||||||
|
...super.styles,
|
||||||
css`
|
css`
|
||||||
:host {
|
:host {
|
||||||
--ha-icon-display: block;
|
--ha-icon-display: block;
|
||||||
|
@@ -1,15 +1,7 @@
|
|||||||
import type { Ripple } from "@material/mwc-ripple";
|
|
||||||
import "@material/mwc-ripple/mwc-ripple";
|
|
||||||
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
|
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import {
|
import { customElement, property } from "lit/decorators";
|
||||||
customElement,
|
|
||||||
eventOptions,
|
|
||||||
property,
|
|
||||||
queryAsync,
|
|
||||||
state,
|
|
||||||
} from "lit/decorators";
|
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import "./ha-ripple";
|
||||||
|
|
||||||
@customElement("ha-tab")
|
@customElement("ha-tab")
|
||||||
export class HaTab extends LitElement {
|
export class HaTab extends LitElement {
|
||||||
@@ -19,10 +11,6 @@ export class HaTab extends LitElement {
|
|||||||
|
|
||||||
@property() public name?: string;
|
@property() public name?: string;
|
||||||
|
|
||||||
@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;
|
|
||||||
|
|
||||||
@state() private _shouldRenderRipple = false;
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
@@ -30,60 +18,21 @@ export class HaTab extends LitElement {
|
|||||||
role="tab"
|
role="tab"
|
||||||
aria-selected=${this.active}
|
aria-selected=${this.active}
|
||||||
aria-label=${ifDefined(this.name)}
|
aria-label=${ifDefined(this.name)}
|
||||||
@focus=${this.handleRippleFocus}
|
|
||||||
@blur=${this.handleRippleBlur}
|
|
||||||
@mousedown=${this.handleRippleActivate}
|
|
||||||
@mouseup=${this.handleRippleDeactivate}
|
|
||||||
@mouseenter=${this.handleRippleMouseEnter}
|
|
||||||
@mouseleave=${this.handleRippleMouseLeave}
|
|
||||||
@touchstart=${this.handleRippleActivate}
|
|
||||||
@touchend=${this.handleRippleDeactivate}
|
|
||||||
@touchcancel=${this.handleRippleDeactivate}
|
|
||||||
@keydown=${this._handleKeyDown}
|
@keydown=${this._handleKeyDown}
|
||||||
>
|
>
|
||||||
${this.narrow ? html`<slot name="icon"></slot>` : ""}
|
${this.narrow ? html`<slot name="icon"></slot>` : ""}
|
||||||
<span class="name">${this.name}</span>
|
<span class="name">${this.name}</span>
|
||||||
${this._shouldRenderRipple ? html`<mwc-ripple></mwc-ripple>` : ""}
|
<ha-ripple></ha-ripple>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
|
|
||||||
this._shouldRenderRipple = true;
|
|
||||||
return this._ripple;
|
|
||||||
});
|
|
||||||
|
|
||||||
private _handleKeyDown(ev: KeyboardEvent): void {
|
private _handleKeyDown(ev: KeyboardEvent): void {
|
||||||
if (ev.key === "Enter") {
|
if (ev.key === "Enter") {
|
||||||
(ev.target as HTMLElement).click();
|
(ev.target as HTMLElement).click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@eventOptions({ passive: true })
|
|
||||||
private handleRippleActivate(evt?: Event) {
|
|
||||||
this._rippleHandlers.startPress(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleDeactivate() {
|
|
||||||
this._rippleHandlers.endPress();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseEnter() {
|
|
||||||
this._rippleHandlers.startHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleMouseLeave() {
|
|
||||||
this._rippleHandlers.endHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleFocus() {
|
|
||||||
this._rippleHandlers.startFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleRippleBlur() {
|
|
||||||
this._rippleHandlers.endFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
div {
|
div {
|
||||||
@@ -126,6 +75,15 @@ export class HaTab extends LitElement {
|
|||||||
:host([narrow]) div {
|
:host([narrow]) div {
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div:focus-visible:before {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
content: "";
|
||||||
|
inset: 0;
|
||||||
|
background-color: var(--secondary-text-color);
|
||||||
|
opacity: 0.08;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public helper?: string;
|
@property() public helper?: string;
|
||||||
|
|
||||||
|
@property({ type: Array }) public createDomains?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only targets with entities from specific domains.
|
* Show only targets with entities from specific domains.
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
@@ -468,6 +470,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||||
.includeDomains=${this.includeDomains}
|
.includeDomains=${this.includeDomains}
|
||||||
.excludeEntities=${ensureArray(this.value?.entity_id)}
|
.excludeEntities=${ensureArray(this.value?.entity_id)}
|
||||||
|
.createDomains=${this.createDomains}
|
||||||
@value-changed=${this._targetPicked}
|
@value-changed=${this._targetPicked}
|
||||||
@click=${this._preventDefault}
|
@click=${this._preventDefault}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
|
@@ -19,7 +19,7 @@ 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 type { LeafletModuleType } from "../../common/dom/setup-leaflet-map";
|
import type { LeafletModuleType } from "../../common/dom/setup-leaflet-map";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant, ThemeMode } from "../../types";
|
||||||
import "../ha-input-helper-text";
|
import "../ha-input-helper-text";
|
||||||
import "./ha-map";
|
import "./ha-map";
|
||||||
import type { HaMap } from "./ha-map";
|
import type { HaMap } from "./ha-map";
|
||||||
@@ -61,7 +61,8 @@ export class HaLocationsEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Number }) public zoom = 16;
|
@property({ type: Number }) public zoom = 16;
|
||||||
|
|
||||||
@property({ type: Boolean }) public darkMode = false;
|
@property({ attribute: "theme-mode", type: String })
|
||||||
|
public themeMode: ThemeMode = "auto";
|
||||||
|
|
||||||
@state() private _locationMarkers?: Record<string, Marker | Circle>;
|
@state() private _locationMarkers?: Record<string, Marker | Circle>;
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ export class HaLocationsEditor extends LitElement {
|
|||||||
.layers=${this._getLayers(this._circles, this._locationMarkers)}
|
.layers=${this._getLayers(this._circles, this._locationMarkers)}
|
||||||
.zoom=${this.zoom}
|
.zoom=${this.zoom}
|
||||||
.autoFit=${this.autoFit}
|
.autoFit=${this.autoFit}
|
||||||
?darkMode=${this.darkMode}
|
.themeMode=${this.themeMode}
|
||||||
></ha-map>
|
></ha-map>
|
||||||
${this.helper
|
${this.helper
|
||||||
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||||
|
@@ -1,32 +1,31 @@
|
|||||||
|
import { isToday } from "date-fns";
|
||||||
import type {
|
import type {
|
||||||
Circle,
|
Circle,
|
||||||
CircleMarker,
|
CircleMarker,
|
||||||
LatLngTuple,
|
|
||||||
LatLngExpression,
|
LatLngExpression,
|
||||||
|
LatLngTuple,
|
||||||
Layer,
|
Layer,
|
||||||
Map,
|
Map,
|
||||||
Marker,
|
Marker,
|
||||||
Polyline,
|
Polyline,
|
||||||
} from "leaflet";
|
} from "leaflet";
|
||||||
import { isToday } from "date-fns";
|
import { CSSResultGroup, PropertyValues, ReactiveElement, css } from "lit";
|
||||||
import { css, CSSResultGroup, PropertyValues, ReactiveElement } from "lit";
|
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { formatDateTime } from "../../common/datetime/format_date_time";
|
||||||
|
import {
|
||||||
|
formatTimeWeekday,
|
||||||
|
formatTimeWithSeconds,
|
||||||
|
} from "../../common/datetime/format_time";
|
||||||
import {
|
import {
|
||||||
LeafletModuleType,
|
LeafletModuleType,
|
||||||
setupLeafletMap,
|
setupLeafletMap,
|
||||||
} from "../../common/dom/setup-leaflet-map";
|
} from "../../common/dom/setup-leaflet-map";
|
||||||
import {
|
|
||||||
formatTimeWithSeconds,
|
|
||||||
formatTimeWeekday,
|
|
||||||
} from "../../common/datetime/format_time";
|
|
||||||
import { formatDateTime } from "../../common/datetime/format_date_time";
|
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { loadPolyfillIfNeeded } from "../../resources/resize-observer.polyfill";
|
import { HomeAssistant, ThemeMode } from "../../types";
|
||||||
import { HomeAssistant } from "../../types";
|
import { isTouch } from "../../util/is_touch";
|
||||||
import "../ha-icon-button";
|
import "../ha-icon-button";
|
||||||
import "./ha-entity-marker";
|
import "./ha-entity-marker";
|
||||||
import { isTouch } from "../../util/is_touch";
|
|
||||||
|
|
||||||
const getEntityId = (entity: string | HaMapEntity): string =>
|
const getEntityId = (entity: string | HaMapEntity): string =>
|
||||||
typeof entity === "string" ? entity : entity.entity_id;
|
typeof entity === "string" ? entity : entity.entity_id;
|
||||||
@@ -69,7 +68,8 @@ export class HaMap extends ReactiveElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public fitZones = false;
|
@property({ type: Boolean }) public fitZones = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public darkMode = false;
|
@property({ attribute: "theme-mode", type: String })
|
||||||
|
public themeMode: ThemeMode = "auto";
|
||||||
|
|
||||||
@property({ type: Number }) public zoom = 14;
|
@property({ type: Number }) public zoom = 14;
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ export class HaMap extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!changedProps.has("darkMode") &&
|
!changedProps.has("themeMode") &&
|
||||||
(!changedProps.has("hass") ||
|
(!changedProps.has("hass") ||
|
||||||
(oldHass && oldHass.themes?.darkMode === this.hass.themes?.darkMode))
|
(oldHass && oldHass.themes?.darkMode === this.hass.themes?.darkMode))
|
||||||
) {
|
) {
|
||||||
@@ -163,24 +163,38 @@ export class HaMap extends ReactiveElement {
|
|||||||
this._updateMapStyle();
|
this._updateMapStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _updateMapStyle(): void {
|
private get _darkMode() {
|
||||||
const darkMode = this.darkMode || (this.hass.themes.darkMode ?? false);
|
return (
|
||||||
const forcedDark = this.darkMode;
|
this.themeMode === "dark" ||
|
||||||
const map = this.renderRoot.querySelector("#map");
|
(this.themeMode === "auto" && Boolean(this.hass.themes.darkMode))
|
||||||
map!.classList.toggle("dark", darkMode);
|
);
|
||||||
map!.classList.toggle("forced-dark", forcedDark);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _updateMapStyle(): void {
|
||||||
|
const map = this.renderRoot.querySelector("#map");
|
||||||
|
map!.classList.toggle("dark", this._darkMode);
|
||||||
|
map!.classList.toggle("forced-dark", this.themeMode === "dark");
|
||||||
|
map!.classList.toggle("forced-light", this.themeMode === "light");
|
||||||
|
}
|
||||||
|
|
||||||
|
private _loading = false;
|
||||||
|
|
||||||
private async _loadMap(): Promise<void> {
|
private async _loadMap(): Promise<void> {
|
||||||
|
if (this._loading) return;
|
||||||
let map = this.shadowRoot!.getElementById("map");
|
let map = this.shadowRoot!.getElementById("map");
|
||||||
if (!map) {
|
if (!map) {
|
||||||
map = document.createElement("div");
|
map = document.createElement("div");
|
||||||
map.id = "map";
|
map.id = "map";
|
||||||
this.shadowRoot!.append(map);
|
this.shadowRoot!.append(map);
|
||||||
}
|
}
|
||||||
[this.leafletMap, this.Leaflet] = await setupLeafletMap(map);
|
this._loading = true;
|
||||||
this._updateMapStyle();
|
try {
|
||||||
this._loaded = true;
|
[this.leafletMap, this.Leaflet] = await setupLeafletMap(map);
|
||||||
|
this._updateMapStyle();
|
||||||
|
this._loaded = true;
|
||||||
|
} finally {
|
||||||
|
this._loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fitMap(options?: { zoom?: number; pad?: number }): void {
|
public fitMap(options?: { zoom?: number; pad?: number }): void {
|
||||||
@@ -398,8 +412,7 @@ export class HaMap extends ReactiveElement {
|
|||||||
"--dark-primary-color"
|
"--dark-primary-color"
|
||||||
);
|
);
|
||||||
|
|
||||||
const className =
|
const className = this._darkMode ? "dark" : "light";
|
||||||
this.darkMode || this.hass.themes.darkMode ? "dark" : "light";
|
|
||||||
|
|
||||||
for (const entity of this.entities) {
|
for (const entity of this.entities) {
|
||||||
const stateObj = hass.states[getEntityId(entity)];
|
const stateObj = hass.states[getEntityId(entity)];
|
||||||
@@ -522,7 +535,6 @@ export class HaMap extends ReactiveElement {
|
|||||||
|
|
||||||
private async _attachObserver(): Promise<void> {
|
private async _attachObserver(): Promise<void> {
|
||||||
if (!this._resizeObserver) {
|
if (!this._resizeObserver) {
|
||||||
await loadPolyfillIfNeeded();
|
|
||||||
this._resizeObserver = new ResizeObserver(() => {
|
this._resizeObserver = new ResizeObserver(() => {
|
||||||
this.leafletMap?.invalidateSize({ debounceMoveend: true });
|
this.leafletMap?.invalidateSize({ debounceMoveend: true });
|
||||||
});
|
});
|
||||||
@@ -543,27 +555,30 @@ export class HaMap extends ReactiveElement {
|
|||||||
background: #090909;
|
background: #090909;
|
||||||
}
|
}
|
||||||
#map.forced-dark {
|
#map.forced-dark {
|
||||||
|
color: #ffffff;
|
||||||
--map-filter: invert(0.9) hue-rotate(170deg) brightness(1.5)
|
--map-filter: invert(0.9) hue-rotate(170deg) brightness(1.5)
|
||||||
contrast(1.2) saturate(0.3);
|
contrast(1.2) saturate(0.3);
|
||||||
}
|
}
|
||||||
|
#map.forced-light {
|
||||||
|
background: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
--map-filter: invert(0);
|
||||||
|
}
|
||||||
#map:active {
|
#map:active {
|
||||||
cursor: grabbing;
|
cursor: grabbing;
|
||||||
cursor: -moz-grabbing;
|
cursor: -moz-grabbing;
|
||||||
cursor: -webkit-grabbing;
|
cursor: -webkit-grabbing;
|
||||||
}
|
}
|
||||||
.light {
|
|
||||||
color: #000000;
|
|
||||||
}
|
|
||||||
.dark {
|
|
||||||
color: #ffffff;
|
|
||||||
}
|
|
||||||
.leaflet-tile-pane {
|
.leaflet-tile-pane {
|
||||||
filter: var(--map-filter);
|
filter: var(--map-filter);
|
||||||
}
|
}
|
||||||
.dark .leaflet-bar a {
|
.dark .leaflet-bar a {
|
||||||
background-color: var(--card-background-color, #1c1c1c);
|
background-color: #1c1c1c;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
.dark .leaflet-bar a:hover {
|
||||||
|
background-color: #313131;
|
||||||
|
}
|
||||||
.leaflet-marker-draggable {
|
.leaflet-marker-draggable {
|
||||||
cursor: move !important;
|
cursor: move !important;
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,6 @@ import {
|
|||||||
import { browseLocalMediaPlayer } from "../../data/media_source";
|
import { browseLocalMediaPlayer } from "../../data/media_source";
|
||||||
import { isTTSMediaSource } from "../../data/tts";
|
import { isTTSMediaSource } from "../../data/tts";
|
||||||
import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
|
||||||
import { loadPolyfillIfNeeded } from "../../resources/resize-observer.polyfill";
|
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -770,7 +769,6 @@ export class HaMediaPlayerBrowse extends LitElement {
|
|||||||
|
|
||||||
private async _attachResizeObserver(): Promise<void> {
|
private async _attachResizeObserver(): Promise<void> {
|
||||||
if (!this._resizeObserver) {
|
if (!this._resizeObserver) {
|
||||||
await loadPolyfillIfNeeded();
|
|
||||||
this._resizeObserver = new ResizeObserver(
|
this._resizeObserver = new ResizeObserver(
|
||||||
debounce(() => this._measureCard(), 250, false)
|
debounce(() => this._measureCard(), 250, false)
|
||||||
);
|
);
|
||||||
|
@@ -79,7 +79,7 @@ class SearchInputOutlined extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _filterInputChanged(e) {
|
private async _filterInputChanged(e) {
|
||||||
this._filterChanged(e.target.value);
|
this._filterChanged(e.target.value?.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _clearSearch() {
|
private async _clearSearch() {
|
||||||
@@ -97,7 +97,7 @@ class SearchInputOutlined extends LitElement {
|
|||||||
ha-outlined-text-field {
|
ha-outlined-text-field {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
--ha-outlined-text-field-container-color: var(--card-background-color);
|
--ha-outlined-field-container-color: var(--card-background-color);
|
||||||
}
|
}
|
||||||
ha-svg-icon,
|
ha-svg-icon,
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
|
@@ -67,7 +67,7 @@ class SearchInput extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _filterInputChanged(e) {
|
private async _filterInputChanged(e) {
|
||||||
this._filterChanged(e.target.value);
|
this._filterChanged(e.target.value?.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _clearSearch() {
|
private async _clearSearch() {
|
||||||
|
@@ -13,6 +13,7 @@ import {
|
|||||||
mdiClose,
|
mdiClose,
|
||||||
mdiCodeBraces,
|
mdiCodeBraces,
|
||||||
mdiCodeBrackets,
|
mdiCodeBrackets,
|
||||||
|
mdiFormatListNumbered,
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
mdiRoomService,
|
mdiRoomService,
|
||||||
mdiShuffleDisabled,
|
mdiShuffleDisabled,
|
||||||
@@ -29,6 +30,7 @@ import {
|
|||||||
ManualScriptConfig,
|
ManualScriptConfig,
|
||||||
ParallelAction,
|
ParallelAction,
|
||||||
RepeatAction,
|
RepeatAction,
|
||||||
|
SequenceAction,
|
||||||
ServiceAction,
|
ServiceAction,
|
||||||
WaitAction,
|
WaitAction,
|
||||||
WaitForTriggerAction,
|
WaitForTriggerAction,
|
||||||
@@ -119,6 +121,7 @@ export class HatScriptGraph extends LitElement {
|
|||||||
repeat: this.render_repeat_node,
|
repeat: this.render_repeat_node,
|
||||||
choose: this.render_choose_node,
|
choose: this.render_choose_node,
|
||||||
if: this.render_if_node,
|
if: this.render_if_node,
|
||||||
|
sequence: this.render_sequence_node,
|
||||||
parallel: this.render_parallel_node,
|
parallel: this.render_parallel_node,
|
||||||
other: this.render_other_node,
|
other: this.render_other_node,
|
||||||
};
|
};
|
||||||
@@ -460,6 +463,44 @@ export class HatScriptGraph extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private render_sequence_node(
|
||||||
|
node: SequenceAction,
|
||||||
|
path: string,
|
||||||
|
graphStart = false,
|
||||||
|
disabled = false
|
||||||
|
) {
|
||||||
|
const trace: any = this.trace.trace[path];
|
||||||
|
return html`
|
||||||
|
<hat-graph-branch
|
||||||
|
tabindex=${trace === undefined ? "-1" : "0"}
|
||||||
|
@focus=${this.selectNode(node, path)}
|
||||||
|
?track=${path in this.trace.trace}
|
||||||
|
?active=${this.selected === path}
|
||||||
|
.notEnabled=${disabled || node.enabled === false}
|
||||||
|
>
|
||||||
|
<div class="graph-container" ?track=${path in this.trace.trace}>
|
||||||
|
<hat-graph-node
|
||||||
|
.graphStart=${graphStart}
|
||||||
|
.iconPath=${mdiFormatListNumbered}
|
||||||
|
?track=${path in this.trace.trace}
|
||||||
|
?active=${this.selected === path}
|
||||||
|
.notEnabled=${disabled || node.enabled === false}
|
||||||
|
slot="head"
|
||||||
|
nofocus
|
||||||
|
></hat-graph-node>
|
||||||
|
${ensureArray(node.sequence).map((action, i) =>
|
||||||
|
this.render_action_node(
|
||||||
|
action,
|
||||||
|
`${path}/sequence/${i}`,
|
||||||
|
false,
|
||||||
|
disabled || node.enabled === false
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</hat-graph-branch>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
private render_parallel_node(
|
private render_parallel_node(
|
||||||
node: ParallelAction,
|
node: ParallelAction,
|
||||||
path: string,
|
path: string,
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { consume } from "@lit-labs/context";
|
||||||
import {
|
import {
|
||||||
mdiAlertCircle,
|
mdiAlertCircle,
|
||||||
mdiCircle,
|
mdiCircle,
|
||||||
@@ -6,14 +7,13 @@ import {
|
|||||||
mdiProgressWrench,
|
mdiProgressWrench,
|
||||||
mdiRecordCircleOutline,
|
mdiRecordCircleOutline,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
|
||||||
import {
|
import {
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
|
||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
css,
|
||||||
|
html,
|
||||||
nothing,
|
nothing,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@@ -23,27 +23,32 @@ import { relativeTime } from "../../common/datetime/relative_time";
|
|||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { toggleAttribute } from "../../common/dom/toggle_attribute";
|
import { toggleAttribute } from "../../common/dom/toggle_attribute";
|
||||||
import {
|
import {
|
||||||
EntityRegistryEntry,
|
floorsContext,
|
||||||
subscribeEntityRegistry,
|
fullEntitiesContext,
|
||||||
} from "../../data/entity_registry";
|
labelsContext,
|
||||||
|
} from "../../data/context";
|
||||||
|
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||||
|
import { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
|
import { LabelRegistryEntry } from "../../data/label_registry";
|
||||||
import { LogbookEntry } from "../../data/logbook";
|
import { LogbookEntry } from "../../data/logbook";
|
||||||
import {
|
import {
|
||||||
ChooseAction,
|
ChooseAction,
|
||||||
ChooseActionChoice,
|
ChooseActionChoice,
|
||||||
getActionType,
|
|
||||||
IfAction,
|
IfAction,
|
||||||
ParallelAction,
|
ParallelAction,
|
||||||
RepeatAction,
|
RepeatAction,
|
||||||
|
SequenceAction,
|
||||||
|
getActionType,
|
||||||
} from "../../data/script";
|
} from "../../data/script";
|
||||||
import { describeAction } from "../../data/script_i18n";
|
import { describeAction } from "../../data/script_i18n";
|
||||||
import {
|
import {
|
||||||
ActionTraceStep,
|
ActionTraceStep,
|
||||||
AutomationTraceExtended,
|
AutomationTraceExtended,
|
||||||
ChooseActionTraceStep,
|
ChooseActionTraceStep,
|
||||||
getDataFromPath,
|
|
||||||
IfActionTraceStep,
|
IfActionTraceStep,
|
||||||
isTriggerPath,
|
|
||||||
TriggerTraceStep,
|
TriggerTraceStep,
|
||||||
|
getDataFromPath,
|
||||||
|
isTriggerPath,
|
||||||
} from "../../data/trace";
|
} from "../../data/trace";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "./ha-timeline";
|
import "./ha-timeline";
|
||||||
@@ -200,6 +205,8 @@ class ActionRenderer {
|
|||||||
constructor(
|
constructor(
|
||||||
private hass: HomeAssistant,
|
private hass: HomeAssistant,
|
||||||
private entityReg: EntityRegistryEntry[],
|
private entityReg: EntityRegistryEntry[],
|
||||||
|
private labelReg: LabelRegistryEntry[],
|
||||||
|
private floorReg: FloorRegistryEntry[],
|
||||||
private entries: TemplateResult[],
|
private entries: TemplateResult[],
|
||||||
private trace: AutomationTraceExtended,
|
private trace: AutomationTraceExtended,
|
||||||
private logbookRenderer: LogbookRenderer,
|
private logbookRenderer: LogbookRenderer,
|
||||||
@@ -304,13 +311,24 @@ class ActionRenderer {
|
|||||||
return this._handleIf(index);
|
return this._handleIf(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionType === "sequence") {
|
||||||
|
return this._handleSequence(index);
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType === "parallel") {
|
if (actionType === "parallel") {
|
||||||
return this._handleParallel(index);
|
return this._handleParallel(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._renderEntry(
|
this._renderEntry(
|
||||||
path,
|
path,
|
||||||
describeAction(this.hass, this.entityReg, data, actionType),
|
describeAction(
|
||||||
|
this.hass,
|
||||||
|
this.entityReg,
|
||||||
|
this.labelReg,
|
||||||
|
this.floorReg,
|
||||||
|
data,
|
||||||
|
actionType
|
||||||
|
),
|
||||||
undefined,
|
undefined,
|
||||||
data.enabled === false
|
data.enabled === false
|
||||||
);
|
);
|
||||||
@@ -475,7 +493,13 @@ class ActionRenderer {
|
|||||||
|
|
||||||
const name =
|
const name =
|
||||||
repeatConfig.alias ||
|
repeatConfig.alias ||
|
||||||
describeAction(this.hass, this.entityReg, repeatConfig);
|
describeAction(
|
||||||
|
this.hass,
|
||||||
|
this.entityReg,
|
||||||
|
this.labelReg,
|
||||||
|
this.floorReg,
|
||||||
|
repeatConfig
|
||||||
|
);
|
||||||
|
|
||||||
this._renderEntry(repeatPath, name, undefined, disabled);
|
this._renderEntry(repeatPath, name, undefined, disabled);
|
||||||
|
|
||||||
@@ -560,6 +584,37 @@ class ActionRenderer {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleSequence(index: number): number {
|
||||||
|
const sequencePath = this.keys[index];
|
||||||
|
const sequenceConfig = this._getDataFromPath(
|
||||||
|
this.keys[index]
|
||||||
|
) as SequenceAction;
|
||||||
|
|
||||||
|
this._renderEntry(
|
||||||
|
sequencePath,
|
||||||
|
sequenceConfig.alias ||
|
||||||
|
describeAction(
|
||||||
|
this.hass,
|
||||||
|
this.entityReg,
|
||||||
|
this.labelReg,
|
||||||
|
this.floorReg,
|
||||||
|
sequenceConfig,
|
||||||
|
"sequence"
|
||||||
|
),
|
||||||
|
undefined,
|
||||||
|
sequenceConfig.enabled === false
|
||||||
|
);
|
||||||
|
|
||||||
|
let i: number;
|
||||||
|
|
||||||
|
for (i = index + 1; i < this.keys.length; i++) {
|
||||||
|
const path = this.keys[i];
|
||||||
|
this._renderItem(i, getActionType(this._getDataFromPath(path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
private _handleParallel(index: number): number {
|
private _handleParallel(index: number): number {
|
||||||
const parallelPath = this.keys[index];
|
const parallelPath = this.keys[index];
|
||||||
const startLevel = parallelPath.split("/").length;
|
const startLevel = parallelPath.split("/").length;
|
||||||
@@ -631,15 +686,17 @@ export class HaAutomationTracer extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public allowPick = false;
|
@property({ type: Boolean }) public allowPick = false;
|
||||||
|
|
||||||
@state() private _entityReg: EntityRegistryEntry[] = [];
|
@state()
|
||||||
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
|
_entityReg!: EntityRegistryEntry[];
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
@state()
|
||||||
return [
|
@consume({ context: labelsContext, subscribe: true })
|
||||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
_labelReg!: LabelRegistryEntry[];
|
||||||
this._entityReg = entities;
|
|
||||||
}),
|
@state()
|
||||||
];
|
@consume({ context: floorsContext, subscribe: true })
|
||||||
}
|
_floorReg!: FloorRegistryEntry[];
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.trace) {
|
if (!this.trace) {
|
||||||
@@ -657,6 +714,8 @@ export class HaAutomationTracer extends LitElement {
|
|||||||
const actionRenderer = new ActionRenderer(
|
const actionRenderer = new ActionRenderer(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._entityReg,
|
this._entityReg,
|
||||||
|
this._labelReg,
|
||||||
|
this._floorReg,
|
||||||
entries,
|
entries,
|
||||||
this.trace,
|
this.trace,
|
||||||
logbookRenderer,
|
logbookRenderer,
|
||||||
@@ -774,6 +833,7 @@ export class HaAutomationTracer extends LitElement {
|
|||||||
description: html`${this.hass.localize(
|
description: html`${this.hass.localize(
|
||||||
`ui.panel.config.automation.trace.messages.${message}`,
|
`ui.panel.config.automation.trace.messages.${message}`,
|
||||||
{
|
{
|
||||||
|
reason: this.trace.script_execution,
|
||||||
time: renderFinishedAt(),
|
time: renderFinishedAt(),
|
||||||
executiontime: renderRuntime(),
|
executiontime: renderRuntime(),
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import {
|
|||||||
mdiDevices,
|
mdiDevices,
|
||||||
mdiDotsHorizontal,
|
mdiDotsHorizontal,
|
||||||
mdiExcavator,
|
mdiExcavator,
|
||||||
|
mdiFormatListNumbered,
|
||||||
mdiGestureDoubleTap,
|
mdiGestureDoubleTap,
|
||||||
mdiHandBackRight,
|
mdiHandBackRight,
|
||||||
mdiPalette,
|
mdiPalette,
|
||||||
@@ -35,6 +36,7 @@ export const ACTION_ICONS = {
|
|||||||
if: mdiCallSplit,
|
if: mdiCallSplit,
|
||||||
device_id: mdiDevices,
|
device_id: mdiDevices,
|
||||||
stop: mdiHandBackRight,
|
stop: mdiHandBackRight,
|
||||||
|
sequence: mdiFormatListNumbered,
|
||||||
parallel: mdiShuffleDisabled,
|
parallel: mdiShuffleDisabled,
|
||||||
variables: mdiApplicationVariableOutline,
|
variables: mdiApplicationVariableOutline,
|
||||||
set_conversation_response: mdiBullhorn,
|
set_conversation_response: mdiBullhorn,
|
||||||
@@ -61,6 +63,7 @@ export const ACTION_GROUPS: AutomationElementGroup = {
|
|||||||
choose: {},
|
choose: {},
|
||||||
if: {},
|
if: {},
|
||||||
stop: {},
|
stop: {},
|
||||||
|
sequence: {},
|
||||||
parallel: {},
|
parallel: {},
|
||||||
variables: {},
|
variables: {},
|
||||||
},
|
},
|
||||||
|
@@ -11,6 +11,7 @@ import {
|
|||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
|
|
||||||
export const FORMAT_TEXT = "text";
|
export const FORMAT_TEXT = "text";
|
||||||
export const FORMAT_NUMBER = "number";
|
export const FORMAT_NUMBER = "number";
|
||||||
@@ -96,3 +97,9 @@ export const ALARM_MODES: Record<AlarmMode, AlarmConfig> = {
|
|||||||
path: mdiShieldOff,
|
path: mdiShieldOff,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const supportedAlarmModes = (stateObj: AlarmControlPanelEntity) =>
|
||||||
|
(Object.keys(ALARM_MODES) as AlarmMode[]).filter((mode) => {
|
||||||
|
const feature = ALARM_MODES[mode].feature;
|
||||||
|
return !feature || supportsFeature(stateObj, feature);
|
||||||
|
});
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { EntityFilter } from "../common/entity/entity_filter";
|
import { EntityFilter } from "../common/entity/entity_filter";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
|
type StrictConnectionMode = "disabled" | "guard_page" | "drop_connection";
|
||||||
|
|
||||||
interface CloudStatusNotLoggedIn {
|
interface CloudStatusNotLoggedIn {
|
||||||
logged_in: false;
|
logged_in: false;
|
||||||
cloud: "disconnected" | "connecting" | "connected";
|
cloud: "disconnected" | "connecting" | "connected";
|
||||||
@@ -19,6 +21,7 @@ export interface CloudPreferences {
|
|||||||
alexa_enabled: boolean;
|
alexa_enabled: boolean;
|
||||||
remote_enabled: boolean;
|
remote_enabled: boolean;
|
||||||
remote_allow_remote_enable: boolean;
|
remote_allow_remote_enable: boolean;
|
||||||
|
strict_connection: StrictConnectionMode;
|
||||||
google_secure_devices_pin: string | undefined;
|
google_secure_devices_pin: string | undefined;
|
||||||
cloudhooks: { [webhookId: string]: CloudWebhook };
|
cloudhooks: { [webhookId: string]: CloudWebhook };
|
||||||
alexa_report_state: boolean;
|
alexa_report_state: boolean;
|
||||||
@@ -141,6 +144,7 @@ export const updateCloudPref = (
|
|||||||
google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"];
|
google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"];
|
||||||
tts_default_voice?: CloudPreferences["tts_default_voice"];
|
tts_default_voice?: CloudPreferences["tts_default_voice"];
|
||||||
remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"];
|
remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"];
|
||||||
|
strict_connection?: CloudPreferences["strict_connection"];
|
||||||
}
|
}
|
||||||
) =>
|
) =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
|
@@ -23,6 +23,8 @@ export interface ConfigEntry {
|
|||||||
pref_disable_polling: boolean;
|
pref_disable_polling: boolean;
|
||||||
disabled_by: "user" | null;
|
disabled_by: "user" | null;
|
||||||
reason: string | null;
|
reason: string | null;
|
||||||
|
error_reason_translation_key: string | null;
|
||||||
|
error_reason_translation_placeholders: Record<string, string> | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConfigEntryMutableParams = Partial<
|
export type ConfigEntryMutableParams = Partial<
|
||||||
|
@@ -2,6 +2,8 @@ import { createContext } from "@lit-labs/context";
|
|||||||
import { HassConfig } from "home-assistant-js-websocket";
|
import { HassConfig } from "home-assistant-js-websocket";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { EntityRegistryEntry } from "./entity_registry";
|
import { EntityRegistryEntry } from "./entity_registry";
|
||||||
|
import { FloorRegistryEntry } from "./floor_registry";
|
||||||
|
import { LabelRegistryEntry } from "./label_registry";
|
||||||
|
|
||||||
export const connectionContext =
|
export const connectionContext =
|
||||||
createContext<HomeAssistant["connection"]>("connection");
|
createContext<HomeAssistant["connection"]>("connection");
|
||||||
@@ -25,3 +27,7 @@ export const panelsContext = createContext<HomeAssistant["panels"]>("panels");
|
|||||||
|
|
||||||
export const fullEntitiesContext =
|
export const fullEntitiesContext =
|
||||||
createContext<EntityRegistryEntry[]>("extendedEntities");
|
createContext<EntityRegistryEntry[]>("extendedEntities");
|
||||||
|
|
||||||
|
export const floorsContext = createContext<FloorRegistryEntry[]>("floors");
|
||||||
|
|
||||||
|
export const labelsContext = createContext<LabelRegistryEntry[]>("labels");
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user