mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-13 11:19:25 +00:00
Compare commits
306 Commits
20230801.0
...
delay-init
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7f2fcc73b5 | ||
![]() |
4b5c7021ff | ||
![]() |
3349031cbd | ||
![]() |
5e107d43d7 | ||
![]() |
e46f2cd9bf | ||
![]() |
713ebfcc22 | ||
![]() |
46e4eafe95 | ||
![]() |
e6fd18e23b | ||
![]() |
71cd71dfd5 | ||
![]() |
1019ccfd26 | ||
![]() |
577c1d8522 | ||
![]() |
63f0b469cc | ||
![]() |
e688417863 | ||
![]() |
a19633e2d4 | ||
![]() |
8797142cca | ||
![]() |
2a7403b6fd | ||
![]() |
22efe14149 | ||
![]() |
7cce24bcd1 | ||
![]() |
b8f0bb66cd | ||
![]() |
b950f990b4 | ||
![]() |
b511e7a37d | ||
![]() |
50f4b78f2e | ||
![]() |
7b0b4cdfe4 | ||
![]() |
c60e5c4c61 | ||
![]() |
709a63e6da | ||
![]() |
f689eed073 | ||
![]() |
cd55eee2fc | ||
![]() |
cf27e68748 | ||
![]() |
472ed2fe82 | ||
![]() |
d0a60984ed | ||
![]() |
24d401061c | ||
![]() |
2352d05573 | ||
![]() |
87d53e38c4 | ||
![]() |
db3c535884 | ||
![]() |
158b24f902 | ||
![]() |
19c4ed4690 | ||
![]() |
eae4ca1271 | ||
![]() |
0276430ab5 | ||
![]() |
db7caf1c32 | ||
![]() |
7176a51fec | ||
![]() |
4a6539d75b | ||
![]() |
850699ea70 | ||
![]() |
c17cc22f88 | ||
![]() |
9e3f2d5cb7 | ||
![]() |
0677c9c7b0 | ||
![]() |
af7e385884 | ||
![]() |
ba88fef09b | ||
![]() |
ad0e59c8f4 | ||
![]() |
14e6f5e8ca | ||
![]() |
3c48157793 | ||
![]() |
3a07af6ad2 | ||
![]() |
c1c05f8d22 | ||
![]() |
29aed5371c | ||
![]() |
76c878df57 | ||
![]() |
d6e7ebe71d | ||
![]() |
085b26d5ea | ||
![]() |
32472ca627 | ||
![]() |
c3c4bb4421 | ||
![]() |
f7f1a0c32d | ||
![]() |
d4872b177f | ||
![]() |
5bb8c51d25 | ||
![]() |
77c08fd00f | ||
![]() |
d8894a0078 | ||
![]() |
4fd9c63633 | ||
![]() |
5e1583f925 | ||
![]() |
5d5894cae6 | ||
![]() |
5417513f49 | ||
![]() |
546ba8f12f | ||
![]() |
a398b37380 | ||
![]() |
321f35f30e | ||
![]() |
82dfb06a04 | ||
![]() |
e666aac1bd | ||
![]() |
9e9a0e377e | ||
![]() |
ba3f9a318b | ||
![]() |
f3b4eefb72 | ||
![]() |
6ac1db6953 | ||
![]() |
1b42189dd6 | ||
![]() |
0d893b3d2b | ||
![]() |
7b167a4d7e | ||
![]() |
8e2f1026e7 | ||
![]() |
fe3a63af80 | ||
![]() |
5da4e1860a | ||
![]() |
6dcb7f2273 | ||
![]() |
53ae7e5a0c | ||
![]() |
56381f9914 | ||
![]() |
be31aecf00 | ||
![]() |
cc5fffc174 | ||
![]() |
dd8a50af31 | ||
![]() |
c8feded4f2 | ||
![]() |
0d0fe75f4e | ||
![]() |
fb69deb617 | ||
![]() |
c291af5d97 | ||
![]() |
6d63028406 | ||
![]() |
3917739ad2 | ||
![]() |
e98e59a265 | ||
![]() |
16ed60902d | ||
![]() |
6c7efc17c2 | ||
![]() |
9c60a047c1 | ||
![]() |
1825749036 | ||
![]() |
93846a2867 | ||
![]() |
f3ed0160af | ||
![]() |
38b275f7f9 | ||
![]() |
c3a36efaa4 | ||
![]() |
68fa67e77a | ||
![]() |
806cebb024 | ||
![]() |
fa788a8223 | ||
![]() |
dfbaee1649 | ||
![]() |
cfb698d0a6 | ||
![]() |
63c3d6406d | ||
![]() |
d817e92a57 | ||
![]() |
40c7bc08d9 | ||
![]() |
b8cd1760f7 | ||
![]() |
24dd45c8cd | ||
![]() |
e06bd41b5e | ||
![]() |
c0793fad83 | ||
![]() |
e002c5d96c | ||
![]() |
099e317d17 | ||
![]() |
ca1a183512 | ||
![]() |
c1cacf735e | ||
![]() |
515cfdb6d1 | ||
![]() |
3a6cffd6c1 | ||
![]() |
c84a826937 | ||
![]() |
c485e8d03e | ||
![]() |
2ab67328d4 | ||
![]() |
d350c35c4e | ||
![]() |
034ce56da5 | ||
![]() |
ae9fcebfd5 | ||
![]() |
6197b55da8 | ||
![]() |
4e5d57b5f3 | ||
![]() |
7040c6d469 | ||
![]() |
6f99a39b55 | ||
![]() |
7483833dcd | ||
![]() |
38fb48b231 | ||
![]() |
166acee1c6 | ||
![]() |
916a6df39b | ||
![]() |
70f37158fb | ||
![]() |
5011bba20e | ||
![]() |
8897bc703d | ||
![]() |
ea6e7d441a | ||
![]() |
f91396c986 | ||
![]() |
4598b530af | ||
![]() |
dfabb4bc36 | ||
![]() |
66e0100c95 | ||
![]() |
a08a989ef5 | ||
![]() |
000c28abf9 | ||
![]() |
6b67397c83 | ||
![]() |
f68823a09e | ||
![]() |
fc1782e676 | ||
![]() |
b4975344a1 | ||
![]() |
2dc08d782f | ||
![]() |
ed92958735 | ||
![]() |
5ce31f3177 | ||
![]() |
370ec9cd98 | ||
![]() |
52c12b5659 | ||
![]() |
3de4cfbc00 | ||
![]() |
4215854414 | ||
![]() |
88eba92f57 | ||
![]() |
f773c968f9 | ||
![]() |
bbb6fccaec | ||
![]() |
aa2b2b0d16 | ||
![]() |
5cc06ebf0b | ||
![]() |
85977e505b | ||
![]() |
3249a5225f | ||
![]() |
7e7205627a | ||
![]() |
d33430e53f | ||
![]() |
e3f53e90e2 | ||
![]() |
811edfcc0f | ||
![]() |
2483249b5f | ||
![]() |
3534617f81 | ||
![]() |
216a3c4c7e | ||
![]() |
567bd9831f | ||
![]() |
98d1a55d35 | ||
![]() |
92358b4859 | ||
![]() |
eca3ec7f98 | ||
![]() |
bfcdbbd70b | ||
![]() |
e764076b1a | ||
![]() |
693c77ce1c | ||
![]() |
a725b6c9de | ||
![]() |
014bbf12ce | ||
![]() |
07dceb8e6d | ||
![]() |
53f18bec53 | ||
![]() |
ac3e858738 | ||
![]() |
c76b2fb357 | ||
![]() |
5f015ac9af | ||
![]() |
ac7c354bfc | ||
![]() |
dddee87de3 | ||
![]() |
e8bd77a84e | ||
![]() |
46a036ddbe | ||
![]() |
bf912f7bd3 | ||
![]() |
196c15ff3e | ||
![]() |
d0a6e727f2 | ||
![]() |
09697148cf | ||
![]() |
76093d898d | ||
![]() |
00c69c0fc3 | ||
![]() |
93dd119ce5 | ||
![]() |
e4f3211e9f | ||
![]() |
c6ecdc9d5d | ||
![]() |
6bdd2d234d | ||
![]() |
9d169bcbeb | ||
![]() |
5c06ec1084 | ||
![]() |
38a317b7e7 | ||
![]() |
593b176ab8 | ||
![]() |
1a15c8da8c | ||
![]() |
060e67397a | ||
![]() |
d6de29ca8a | ||
![]() |
220767b347 | ||
![]() |
79e1fbe076 | ||
![]() |
cd19894ab0 | ||
![]() |
705b6aeb4b | ||
![]() |
6e27fbe10f | ||
![]() |
bbb99a6eee | ||
![]() |
8411efc1c3 | ||
![]() |
88721df637 | ||
![]() |
265faddfa9 | ||
![]() |
6584dc70b7 | ||
![]() |
d6b4dbe6a2 | ||
![]() |
d579f93aa7 | ||
![]() |
b91261a789 | ||
![]() |
872128d9a8 | ||
![]() |
4972db4648 | ||
![]() |
821cd7fe05 | ||
![]() |
8c24ffa710 | ||
![]() |
d50a130345 | ||
![]() |
ee8997fbd2 | ||
![]() |
613cf932b5 | ||
![]() |
12b61aea2f | ||
![]() |
51d9271c83 | ||
![]() |
bd5264308f | ||
![]() |
2c17d2fead | ||
![]() |
9f0b9782a0 | ||
![]() |
88ff4c2fa8 | ||
![]() |
cba246fc7f | ||
![]() |
f4d575f456 | ||
![]() |
6dff2f691e | ||
![]() |
917b7bd1dd | ||
![]() |
54a9f4592c | ||
![]() |
baba02f563 | ||
![]() |
f6087f3805 | ||
![]() |
4979e89251 | ||
![]() |
b1c826326b | ||
![]() |
961e8bc149 | ||
![]() |
3b3a37dc81 | ||
![]() |
c98cdb91e2 | ||
![]() |
255137992b | ||
![]() |
b8fcb9272a | ||
![]() |
fa3625985c | ||
![]() |
3f05712c18 | ||
![]() |
67441a63b4 | ||
![]() |
c561df70dd | ||
![]() |
aa85b87e11 | ||
![]() |
25b4d91d72 | ||
![]() |
134d1978f8 | ||
![]() |
43ac8f9a27 | ||
![]() |
bfad8a07c5 | ||
![]() |
d5cc5bd6c2 | ||
![]() |
2af3a68f94 | ||
![]() |
14c84c3d75 | ||
![]() |
4992007f13 | ||
![]() |
9e31b2bb29 | ||
![]() |
5dee92b214 | ||
![]() |
ebee8f670e | ||
![]() |
023f13cd12 | ||
![]() |
416661f3d1 | ||
![]() |
a2b1be754f | ||
![]() |
ade430f326 | ||
![]() |
782e41dcda | ||
![]() |
ac20cf292a | ||
![]() |
4986b013a2 | ||
![]() |
89e96e4681 | ||
![]() |
85733655c2 | ||
![]() |
7a446ba2ad | ||
![]() |
e40bdd5d91 | ||
![]() |
accc8bc644 | ||
![]() |
4884108123 | ||
![]() |
827a57499b | ||
![]() |
945c8e0320 | ||
![]() |
edcdc865c4 | ||
![]() |
c2123a0a90 | ||
![]() |
e9e31d51ec | ||
![]() |
2bbce135bb | ||
![]() |
27e93d63fe | ||
![]() |
068708578e | ||
![]() |
8da7eef88d | ||
![]() |
e3da4d7c39 | ||
![]() |
ccfa5c782d | ||
![]() |
716e68fc5e | ||
![]() |
0d630aa5f5 | ||
![]() |
7b6d9106d4 | ||
![]() |
7dbae75e50 | ||
![]() |
40141923b6 | ||
![]() |
725c8685fd | ||
![]() |
e01dda4379 | ||
![]() |
052ffbb1d6 | ||
![]() |
bfb439c776 | ||
![]() |
2fdd1464f8 | ||
![]() |
b4e2f4b0f5 | ||
![]() |
a8debb8daa | ||
![]() |
a81050182e | ||
![]() |
f49e103f17 | ||
![]() |
7d80eb06b0 | ||
![]() |
6653a8f634 | ||
![]() |
bde93c44bd | ||
![]() |
788e48a5a6 | ||
![]() |
0f56e8f985 | ||
![]() |
5f95968c8f | ||
![]() |
e8aa08b717 |
8
.github/workflows/cast_deployment.yaml
vendored
8
.github/workflows/cast_deployment.yaml
vendored
@@ -21,12 +21,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
ref: dev
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
@@ -57,12 +57,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
18
.github/workflows/ci.yaml
vendored
18
.github/workflows/ci.yaml
vendored
@@ -24,9 +24,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
- name: Build resources
|
||||
run: ./node_modules/.bin/gulp gen-icons-json build-translations build-locale-data gather-gallery-pages
|
||||
- name: Setup lint cache
|
||||
uses: actions/cache@v3.3.1
|
||||
uses: actions/cache@v3.3.2
|
||||
with:
|
||||
path: |
|
||||
node_modules/.cache/prettier
|
||||
@@ -55,9 +55,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
@@ -73,9 +73,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
@@ -91,9 +91,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
|
8
.github/workflows/demo_deployment.yaml
vendored
8
.github/workflows/demo_deployment.yaml
vendored
@@ -22,12 +22,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
ref: dev
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
@@ -58,12 +58,12 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
4
.github/workflows/design_deployment.yaml
vendored
4
.github/workflows/design_deployment.yaml
vendored
@@ -16,10 +16,10 @@ jobs:
|
||||
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
4
.github/workflows/design_preview.yaml
vendored
4
.github/workflows/design_preview.yaml
vendored
@@ -21,10 +21,10 @@ jobs:
|
||||
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
4
.github/workflows/nightly.yaml
vendored
4
.github/workflows/nightly.yaml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||
uses: actions/setup-python@v4
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
contents: write # Required to upload release assets
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Verify version
|
||||
uses: home-assistant/actions/helpers/verify-version@master
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3.7.0
|
||||
uses: actions/setup-node@v3.8.1
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: yarn
|
||||
|
2
.github/workflows/translations.yaml
vendored
2
.github/workflows/translations.yaml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3.5.3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Upload Translations
|
||||
run: |
|
||||
|
File diff suppressed because one or more lines are too long
@@ -8,4 +8,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.6.1.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.6.3.cjs
|
||||
|
@@ -8,7 +8,7 @@ module.exports.sourceMapURL = () => {
|
||||
const ref = env.version().endsWith("dev")
|
||||
? process.env.GITHUB_SHA || "dev"
|
||||
: env.version();
|
||||
return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}`;
|
||||
return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}/`;
|
||||
};
|
||||
|
||||
// Files from NPM Packages that should not be imported
|
||||
@@ -98,8 +98,9 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
|
||||
"@babel/preset-env",
|
||||
{
|
||||
useBuiltIns: latestBuild ? false : "entry",
|
||||
corejs: latestBuild ? false : { version: "3.31", proposals: true },
|
||||
corejs: latestBuild ? false : { version: "3.32", proposals: true },
|
||||
bugfixes: true,
|
||||
shippedProposals: true,
|
||||
},
|
||||
],
|
||||
"@babel/preset-typescript",
|
||||
|
@@ -2,44 +2,15 @@
|
||||
|
||||
import gulp from "gulp";
|
||||
import zopfli from "gulp-zopfli-green";
|
||||
import merge from "merge-stream";
|
||||
import path from "path";
|
||||
import paths from "../paths.cjs";
|
||||
|
||||
const zopfliOptions = { threshold: 150 };
|
||||
|
||||
gulp.task("compress-app", function compressApp() {
|
||||
const jsLatest = gulp
|
||||
.src(path.resolve(paths.app_output_latest, "**/*.js"))
|
||||
const compressDist = (rootDir) =>
|
||||
gulp
|
||||
.src([`${rootDir}/**/*.{js,json,css,svg}`])
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(paths.app_output_latest));
|
||||
.pipe(gulp.dest(rootDir));
|
||||
|
||||
const jsEs5 = gulp
|
||||
.src(path.resolve(paths.app_output_es5, "**/*.js"))
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(paths.app_output_es5));
|
||||
|
||||
const polyfills = gulp
|
||||
.src(path.resolve(paths.app_output_static, "polyfills/*.js"))
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(path.resolve(paths.app_output_static, "polyfills")));
|
||||
|
||||
const translations = gulp
|
||||
.src(path.resolve(paths.app_output_static, "translations/**/*.json"))
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(path.resolve(paths.app_output_static, "translations")));
|
||||
|
||||
const icons = gulp
|
||||
.src(path.resolve(paths.app_output_static, "mdi/*.json"))
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(path.resolve(paths.app_output_static, "mdi")));
|
||||
|
||||
return merge(jsLatest, jsEs5, polyfills, translations, icons);
|
||||
});
|
||||
|
||||
gulp.task("compress-hassio", function compressApp() {
|
||||
return gulp
|
||||
.src(path.resolve(paths.hassio_output_root, "**/*.js"))
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
.pipe(gulp.dest(paths.hassio_output_root));
|
||||
});
|
||||
gulp.task("compress-app", () => compressDist(paths.app_output_root));
|
||||
gulp.task("compress-hassio", () => compressDist(paths.hassio_output_root));
|
||||
|
@@ -1,10 +1,14 @@
|
||||
import fs from "fs/promises";
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import mapStream from "map-stream";
|
||||
import transform from "gulp-json-transform";
|
||||
import { LokaliseApi } from "@lokalise/node-api";
|
||||
import JSZip from "jszip";
|
||||
|
||||
const inDirFrontend = "translations/frontend";
|
||||
const inDirBackend = "translations/backend";
|
||||
const inDir = "translations";
|
||||
const inDirFrontend = `${inDir}/frontend`;
|
||||
const inDirBackend = `${inDir}/backend`;
|
||||
const srcMeta = "src/translations/translationMetadata.json";
|
||||
const encoding = "utf8";
|
||||
|
||||
@@ -68,8 +72,9 @@ gulp.task("convert-backend-translations", function () {
|
||||
});
|
||||
|
||||
gulp.task("check-translations-html", function () {
|
||||
// We exclude backend translations because they are not compliant with the HTML rule for now
|
||||
return gulp.src([`${inDirFrontend}/*.json`]).pipe(checkHtml());
|
||||
return gulp
|
||||
.src([`${inDirFrontend}/*.json`, `${inDirBackend}/*.json`])
|
||||
.pipe(checkHtml());
|
||||
});
|
||||
|
||||
gulp.task("check-all-files-exist", async function () {
|
||||
@@ -89,7 +94,83 @@ gulp.task("check-all-files-exist", async function () {
|
||||
await Promise.allSettled(writings);
|
||||
});
|
||||
|
||||
const lokaliseProjects = {
|
||||
backend: "130246255a974bd3b5e8a1.51616605",
|
||||
frontend: "3420425759f6d6d241f598.13594006",
|
||||
};
|
||||
|
||||
gulp.task("fetch-lokalise", async function () {
|
||||
let apiKey;
|
||||
try {
|
||||
apiKey =
|
||||
process.env.LOKALISE_TOKEN ||
|
||||
(await fs.readFile(".lokalise_token", { encoding }));
|
||||
} catch {
|
||||
throw new Error(
|
||||
"An Administrator Lokalise API token is required to download the latest set of translations. Place your token in a new file `.lokalise_token` in the repo root directory."
|
||||
);
|
||||
}
|
||||
const lokaliseApi = new LokaliseApi({ apiKey });
|
||||
|
||||
const mkdirPromise = Promise.all([
|
||||
fs.mkdir(inDirFrontend, { recursive: true }),
|
||||
fs.mkdir(inDirBackend, { recursive: true }),
|
||||
]);
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(lokaliseProjects).map(([project, projectId]) =>
|
||||
lokaliseApi
|
||||
.files()
|
||||
.download(projectId, {
|
||||
format: "json",
|
||||
original_filenames: false,
|
||||
replace_breaks: false,
|
||||
json_unescaped_slashes: true,
|
||||
export_empty_as: "skip",
|
||||
})
|
||||
.then((download) => fetch(download.bundle_url))
|
||||
.then((response) => {
|
||||
if (response.status === 200 || response.status === 0) {
|
||||
return response.arrayBuffer();
|
||||
}
|
||||
throw new Error(response.statusText);
|
||||
})
|
||||
.then(JSZip.loadAsync)
|
||||
.then(async (contents) => {
|
||||
await mkdirPromise;
|
||||
return Promise.all(
|
||||
Object.keys(contents.files).map(async (filename) => {
|
||||
const file = contents.file(filename);
|
||||
if (!file) {
|
||||
// no file, probably a directory
|
||||
return Promise.resolve();
|
||||
}
|
||||
return file
|
||||
.async("nodebuffer")
|
||||
.then((content) =>
|
||||
fs.writeFile(
|
||||
path.join(
|
||||
inDir,
|
||||
project,
|
||||
filename.split("/").splice(-1)[0]
|
||||
),
|
||||
content,
|
||||
{ flag: "w", encoding }
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
gulp.task(
|
||||
"check-downloaded-translations",
|
||||
gulp.series("check-translations-html", "check-all-files-exist")
|
||||
"download-translations",
|
||||
gulp.series(
|
||||
"fetch-lokalise",
|
||||
"convert-backend-translations",
|
||||
"check-translations-html",
|
||||
"check-all-files-exist"
|
||||
)
|
||||
);
|
||||
|
@@ -1,18 +1,12 @@
|
||||
import { deleteSync } from "del";
|
||||
import fs from "fs";
|
||||
import { mkdir, readFile, writeFile } from "fs/promises";
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import paths from "../paths.cjs";
|
||||
|
||||
const outDir = "build/locale-data";
|
||||
const outDir = path.join(paths.build_dir, "locale-data");
|
||||
|
||||
gulp.task("clean-locale-data", async () => deleteSync([outDir]));
|
||||
|
||||
gulp.task("ensure-locale-data-build-dir", async () => {
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
});
|
||||
|
||||
const modules = {
|
||||
const INTL_PACKAGES = {
|
||||
"intl-relativetimeformat": "RelativeTimeFormat",
|
||||
"intl-datetimeformat": "DateTimeFormat",
|
||||
"intl-numberformat": "NumberFormat",
|
||||
@@ -20,53 +14,60 @@ const modules = {
|
||||
"intl-listformat": "ListFormat",
|
||||
};
|
||||
|
||||
gulp.task("create-locale-data", (done) => {
|
||||
const convertToJSON = async (pkg, lang) => {
|
||||
let localeData;
|
||||
try {
|
||||
localeData = await readFile(
|
||||
path.resolve(
|
||||
paths.polymer_dir,
|
||||
`node_modules/@formatjs/${pkg}/locale-data/${lang}.js`
|
||||
),
|
||||
"utf-8"
|
||||
);
|
||||
} catch (e) {
|
||||
// Ignore if language is missing (i.e. not supported by @formatjs)
|
||||
if (e.code === "ENOENT") {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// Convert to JSON
|
||||
const className = INTL_PACKAGES[pkg];
|
||||
localeData = localeData
|
||||
.replace(
|
||||
new RegExp(
|
||||
`\\/\\*\\s*@generated\\s*\\*\\/\\s*\\/\\/\\s*prettier-ignore\\s*if\\s*\\(Intl\\.${className}\\s*&&\\s*typeof\\s*Intl\\.${className}\\.__addLocaleData\\s*===\\s*'function'\\)\\s*{\\s*Intl\\.${className}\\.__addLocaleData\\(`,
|
||||
"im"
|
||||
),
|
||||
""
|
||||
)
|
||||
.replace(/\)\s*}/im, "");
|
||||
// Parse to validate JSON, then stringify to minify
|
||||
localeData = JSON.stringify(JSON.parse(localeData));
|
||||
await writeFile(path.join(outDir, `${pkg}/${lang}.json`), localeData);
|
||||
};
|
||||
|
||||
gulp.task("clean-locale-data", async () => deleteSync([outDir]));
|
||||
|
||||
gulp.task("create-locale-data", async () => {
|
||||
const translationMeta = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(paths.translations_src, "translationMetadata.json")
|
||||
await readFile(
|
||||
path.resolve(paths.translations_src, "translationMetadata.json"),
|
||||
"utf-8"
|
||||
)
|
||||
);
|
||||
Object.entries(modules).forEach(([module, className]) => {
|
||||
Object.keys(translationMeta).forEach((lang) => {
|
||||
try {
|
||||
const localeData = fs
|
||||
.readFileSync(
|
||||
path.resolve(
|
||||
paths.polymer_dir,
|
||||
`node_modules/@formatjs/${module}/locale-data/${lang}.js`
|
||||
),
|
||||
"utf-8"
|
||||
)
|
||||
.replace(
|
||||
new RegExp(
|
||||
`\\/\\*\\s*@generated\\s*\\*\\/\\s*\\/\\/\\s*prettier-ignore\\s*if\\s*\\(Intl\\.${className}\\s*&&\\s*typeof\\s*Intl\\.${className}\\.__addLocaleData\\s*===\\s*'function'\\)\\s*{\\s*Intl\\.${className}\\.__addLocaleData\\(`,
|
||||
"im"
|
||||
),
|
||||
""
|
||||
)
|
||||
.replace(/\)\s*}/im, "");
|
||||
// make sure we have valid JSON
|
||||
JSON.parse(localeData);
|
||||
fs.mkdirSync(path.join(outDir, module), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(outDir, `${module}/${lang}.json`),
|
||||
localeData
|
||||
);
|
||||
} catch (e) {
|
||||
if (e.code !== "ENOENT") {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
done();
|
||||
});
|
||||
const conversions = [];
|
||||
for (const pkg of Object.keys(INTL_PACKAGES)) {
|
||||
await mkdir(path.join(outDir, pkg), { recursive: true });
|
||||
for (const lang of Object.keys(translationMeta)) {
|
||||
conversions.push(convertToJSON(pkg, lang));
|
||||
}
|
||||
}
|
||||
await Promise.all(conversions);
|
||||
});
|
||||
|
||||
gulp.task(
|
||||
"build-locale-data",
|
||||
gulp.series(
|
||||
"clean-locale-data",
|
||||
"ensure-locale-data-build-dir",
|
||||
"create-locale-data"
|
||||
)
|
||||
gulp.series("clean-locale-data", "create-locale-data")
|
||||
);
|
||||
|
@@ -415,7 +415,7 @@ gulp.task("build-translation-write-metadata", () =>
|
||||
gulp.task(
|
||||
"create-translations",
|
||||
gulp.series(
|
||||
env.isProdBuild() ? (done) => done() : "create-test-translation",
|
||||
...(env.isProdBuild() ? [] : ["create-test-translation"]),
|
||||
"build-master-translation",
|
||||
"build-merged-translations",
|
||||
gulp.parallel(...splitTasks),
|
||||
|
@@ -1,9 +1,9 @@
|
||||
// Tasks to run webpack.
|
||||
|
||||
import log from "fancy-log";
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import log from "fancy-log";
|
||||
import gulp from "gulp";
|
||||
import webpack from "webpack";
|
||||
import WebpackDevServer from "webpack-dev-server";
|
||||
import env from "../env.cjs";
|
||||
@@ -44,6 +44,7 @@ const runDevServer = async ({
|
||||
}) => {
|
||||
const server = new WebpackDevServer(
|
||||
{
|
||||
hot: false,
|
||||
open: true,
|
||||
host: listenHost,
|
||||
port,
|
||||
|
@@ -6,6 +6,8 @@ import presetEnv from "@babel/preset-env";
|
||||
import compilationTargets from "@babel/helper-compilation-targets";
|
||||
import coreJSCompat from "core-js-compat";
|
||||
import { logPlugin } from "@babel/preset-env/lib/debug.js";
|
||||
// eslint-disable-next-line import/no-relative-packages
|
||||
import shippedPolyfills from "../node_modules/babel-plugin-polyfill-corejs3/lib/shipped-proposals.js";
|
||||
import { babelOptions } from "./bundle.cjs";
|
||||
|
||||
const detailsOpen = (heading) =>
|
||||
@@ -26,6 +28,22 @@ const dummyAPI = {
|
||||
targets: () => ({}),
|
||||
};
|
||||
|
||||
// Generate filter function based on proposal/method inputs
|
||||
// Copied and adapted from babel-plugin-polyfill-corejs3/esm/index.mjs
|
||||
const polyfillFilter = (method, proposals, shippedProposals) => (name) => {
|
||||
if (proposals || method === "entry-global") return true;
|
||||
if (shippedProposals && shippedPolyfills.default.has(name)) {
|
||||
return true;
|
||||
}
|
||||
if (name.startsWith("esnext.")) {
|
||||
const esName = `es.${name.slice(7)}`;
|
||||
// If its imaginative esName is not in latest compat data, it means the proposal is not stage 4
|
||||
return esName in coreJSCompat.data;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// Log the plugins and polyfills for each build environment
|
||||
for (const buildType of ["Modern", "Legacy"]) {
|
||||
const browserslistEnv = buildType.toLowerCase();
|
||||
const babelOpts = babelOptions({ latestBuild: browserslistEnv === "modern" });
|
||||
@@ -46,7 +64,13 @@ for (const buildType of ["Modern", "Legacy"]) {
|
||||
const targets = compilationTargets.default(babelOpts?.targets, {
|
||||
browserslistEnv,
|
||||
});
|
||||
const polyfillList = coreJSCompat({ targets }).list;
|
||||
const polyfillList = coreJSCompat({ targets }).list.filter(
|
||||
polyfillFilter(
|
||||
`${presetEnvOpts.useBuiltIns}-global`,
|
||||
presetEnvOpts?.corejs?.proposals,
|
||||
presetEnvOpts?.shippedProposals
|
||||
)
|
||||
);
|
||||
console.log(
|
||||
"The following %i polyfills may be injected by Babel:\n",
|
||||
polyfillList.length
|
||||
|
@@ -1,5 +1,6 @@
|
||||
const webpack = require("webpack");
|
||||
const { existsSync } = require("fs");
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
|
||||
const log = require("fancy-log");
|
||||
@@ -191,19 +192,26 @@ const createWebpackConfig = ({
|
||||
// Since production source maps don't include sources, we need to point to them elsewhere
|
||||
// For dependencies, just provide the path (no source in browser)
|
||||
// Otherwise, point to the raw code on GitHub for browser to load
|
||||
devtoolModuleFilenameTemplate:
|
||||
!isTestBuild && isProdBuild
|
||||
? (info) => {
|
||||
const sourcePath = info.resourcePath.replace(/^\.\//, "");
|
||||
if (
|
||||
sourcePath.startsWith("node_modules") ||
|
||||
sourcePath.startsWith("webpack")
|
||||
) {
|
||||
return `no-source/${sourcePath}`;
|
||||
...Object.fromEntries(
|
||||
["", "Fallback"].map((v) => [
|
||||
`devtool${v}ModuleFilenameTemplate`,
|
||||
!isTestBuild && isProdBuild
|
||||
? (info) => {
|
||||
if (
|
||||
!path.isAbsolute(info.absoluteResourcePath) ||
|
||||
!existsSync(info.resourcePath) ||
|
||||
info.resourcePath.startsWith("./node_modules")
|
||||
) {
|
||||
// Source URLs are unknown for dependencies, so we use a relative URL with a
|
||||
// non - existent top directory. This results in a clean source tree in browser
|
||||
// dev tools, and they stay happy getting 404s with valid requests.
|
||||
return `/unknown${path.resolve("/", info.resourcePath)}`;
|
||||
}
|
||||
return new URL(info.resourcePath, bundle.sourceMapURL()).href;
|
||||
}
|
||||
return `${bundle.sourceMapURL()}/${sourcePath}`;
|
||||
}
|
||||
: undefined,
|
||||
: undefined,
|
||||
])
|
||||
),
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
|
File diff suppressed because one or more lines are too long
4
gallery/public/images/brand/README.md
Normal file
4
gallery/public/images/brand/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Note!
|
||||
|
||||
Note, the assets in this folder, are not part of the CC license this repository is shipped in.
|
||||
All rights reserved.
|
BIN
gallery/public/images/brand/logo-exclusion-zone.png
Normal file
BIN
gallery/public/images/brand/logo-exclusion-zone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
gallery/public/images/brand/logo-layout-variants.png
Normal file
BIN
gallery/public/images/brand/logo-layout-variants.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
BIN
gallery/public/images/brand/logo.png
Normal file
BIN
gallery/public/images/brand/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
@@ -1,4 +1,3 @@
|
||||
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
||||
import { html, css, LitElement } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { applyThemesOnElement } from "../../../src/common/dom/apply_themes_on_element";
|
||||
@@ -7,6 +6,7 @@ import "../../../src/components/ha-switch";
|
||||
import { HomeAssistant } from "../../../src/types";
|
||||
import "./demo-card";
|
||||
import type { DemoCardConfig } from "./demo-card";
|
||||
import "../ha-demo-options";
|
||||
|
||||
@customElement("demo-cards")
|
||||
class DemoCards extends LitElement {
|
||||
@@ -20,20 +20,14 @@ class DemoCards extends LitElement {
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<app-toolbar>
|
||||
<div class="filters">
|
||||
<ha-formfield label="Show config">
|
||||
<ha-switch
|
||||
.checked=${this._showConfig}
|
||||
@change=${this._showConfigToggled}
|
||||
>
|
||||
</ha-switch>
|
||||
</ha-formfield>
|
||||
<ha-formfield label="Dark theme">
|
||||
<ha-switch @change=${this._darkThemeToggled}> </ha-switch>
|
||||
</ha-formfield>
|
||||
</div>
|
||||
</app-toolbar>
|
||||
<ha-demo-options>
|
||||
<ha-formfield label="Show config">
|
||||
<ha-switch @change=${this._showConfigToggled}> </ha-switch>
|
||||
</ha-formfield>
|
||||
<ha-formfield label="Dark theme">
|
||||
<ha-switch @change=${this._darkThemeToggled}> </ha-switch>
|
||||
</ha-formfield>
|
||||
</ha-demo-options>
|
||||
<div id="container">
|
||||
<div class="cards">
|
||||
${this.configs.map(
|
||||
@@ -69,12 +63,6 @@ class DemoCards extends LitElement {
|
||||
demo-card {
|
||||
margin: 16px 16px 32px;
|
||||
}
|
||||
app-toolbar {
|
||||
background-color: var(--light-primary-color);
|
||||
}
|
||||
.filters {
|
||||
margin-left: 60px;
|
||||
}
|
||||
ha-formfield {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
@@ -1,93 +0,0 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
/* eslint-plugin-disable lit */
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
import "../../../src/components/ha-card";
|
||||
import "../../../src/dialogs/more-info/more-info-content";
|
||||
import "../../../src/state-summary/state-card-content";
|
||||
|
||||
class DemoMoreInfo extends PolymerElement {
|
||||
static get template() {
|
||||
return html`
|
||||
<style>
|
||||
.root {
|
||||
display: flex;
|
||||
}
|
||||
#card {
|
||||
max-width: 400px;
|
||||
width: 100vw;
|
||||
}
|
||||
ha-card {
|
||||
width: 352px;
|
||||
padding: 20px 24px;
|
||||
}
|
||||
state-card-content {
|
||||
display: block;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
pre {
|
||||
width: 400px;
|
||||
margin: 0 16px;
|
||||
overflow: auto;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
@media only screen and (max-width: 800px) {
|
||||
.root {
|
||||
flex-direction: column;
|
||||
}
|
||||
pre {
|
||||
margin: 16px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="root">
|
||||
<div id="card">
|
||||
<ha-card>
|
||||
<state-card-content
|
||||
state-obj="[[_stateObj]]"
|
||||
hass="[[hass]]"
|
||||
in-dialog
|
||||
></state-card-content>
|
||||
|
||||
<more-info-content
|
||||
hass="[[hass]]"
|
||||
state-obj="[[_stateObj]]"
|
||||
></more-info-content>
|
||||
</ha-card>
|
||||
</div>
|
||||
<template is="dom-if" if="[[showConfig]]">
|
||||
<pre>[[_jsonEntity(_stateObj)]]</pre>
|
||||
</template>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
hass: Object,
|
||||
entityId: String,
|
||||
showConfig: Boolean,
|
||||
_stateObj: {
|
||||
type: Object,
|
||||
computed: "_getState(entityId, hass.states)",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
_getState(entityId, states) {
|
||||
return states[entityId];
|
||||
}
|
||||
|
||||
_jsonEntity(stateObj) {
|
||||
// We are caching some things on stateObj
|
||||
// (it sucks, we will remove in the future)
|
||||
const tmp = {};
|
||||
Object.keys(stateObj).forEach((key) => {
|
||||
if (key[0] !== "_") {
|
||||
tmp[key] = stateObj[key];
|
||||
}
|
||||
});
|
||||
return JSON.stringify(tmp, null, 2);
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("demo-more-info", DemoMoreInfo);
|
93
gallery/src/components/demo-more-info.ts
Normal file
93
gallery/src/components/demo-more-info.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import "../../../src/components/ha-card";
|
||||
import "../../../src/dialogs/more-info/more-info-content";
|
||||
import "../../../src/state-summary/state-card-content";
|
||||
import "../ha-demo-options";
|
||||
import { HomeAssistant } from "../../../src/types";
|
||||
|
||||
@customElement("demo-more-info")
|
||||
class DemoMoreInfo extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public entityId!: string;
|
||||
|
||||
@property() public showConfig!: boolean;
|
||||
|
||||
render() {
|
||||
const state = this._getState(this.entityId, this.hass.states);
|
||||
return html`
|
||||
<div class="root">
|
||||
<div id="card">
|
||||
<ha-card>
|
||||
<state-card-content
|
||||
.stateObj=${state}
|
||||
.hass=${this.hass}
|
||||
in-dialog
|
||||
></state-card-content>
|
||||
|
||||
<more-info-content
|
||||
.hass=${this.hass}
|
||||
.stateObj=${state}
|
||||
></more-info-content>
|
||||
</ha-card>
|
||||
</div>
|
||||
${this.showConfig ? html`<pre>${this._jsonEntity(state)}</pre>` : ""}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private _getState(entityId, states) {
|
||||
return states[entityId];
|
||||
}
|
||||
|
||||
private _jsonEntity(stateObj) {
|
||||
// We are caching some things on stateObj
|
||||
// (it sucks, we will remove in the future)
|
||||
const tmp = {};
|
||||
Object.keys(stateObj).forEach((key) => {
|
||||
if (key[0] !== "_") {
|
||||
tmp[key] = stateObj[key];
|
||||
}
|
||||
});
|
||||
return JSON.stringify(tmp, null, 2);
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
.root {
|
||||
display: flex;
|
||||
}
|
||||
#card {
|
||||
max-width: 400px;
|
||||
width: 100vw;
|
||||
}
|
||||
ha-card {
|
||||
width: 352px;
|
||||
padding: 20px 24px;
|
||||
}
|
||||
state-card-content {
|
||||
display: block;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
pre {
|
||||
width: 400px;
|
||||
margin: 0 16px;
|
||||
overflow: auto;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
@media only screen and (max-width: 800px) {
|
||||
.root {
|
||||
flex-direction: column;
|
||||
}
|
||||
pre {
|
||||
margin: 16px 0;
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-more-info": DemoMoreInfo;
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
/* eslint-plugin-disable lit */
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
import { applyThemesOnElement } from "../../../src/common/dom/apply_themes_on_element";
|
||||
import "../../../src/components/ha-formfield";
|
||||
import "../../../src/components/ha-switch";
|
||||
import "./demo-more-info";
|
||||
|
||||
class DemoMoreInfos extends PolymerElement {
|
||||
static get template() {
|
||||
return html`
|
||||
<style>
|
||||
#container {
|
||||
min-height: calc(100vh - 128px);
|
||||
background: var(--primary-background-color);
|
||||
}
|
||||
.cards {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
demo-more-info {
|
||||
margin: 16px 16px 32px;
|
||||
}
|
||||
app-toolbar {
|
||||
background-color: var(--light-primary-color);
|
||||
}
|
||||
.filters {
|
||||
margin-left: 60px;
|
||||
}
|
||||
ha-formfield {
|
||||
margin-right: 16px;
|
||||
}
|
||||
</style>
|
||||
<app-toolbar>
|
||||
<div class="filters">
|
||||
<ha-formfield label="Show entities">
|
||||
<ha-switch checked="[[_showConfig]]" on-change="_showConfigToggled">
|
||||
</ha-switch>
|
||||
</ha-formfield>
|
||||
<ha-formfield label="Dark theme">
|
||||
<ha-switch on-change="_darkThemeToggled"> </ha-switch>
|
||||
</ha-formfield>
|
||||
</div>
|
||||
</app-toolbar>
|
||||
<div id="container">
|
||||
<div class="cards">
|
||||
<template is="dom-repeat" items="[[entities]]">
|
||||
<demo-more-info
|
||||
entity-id="[[item]]"
|
||||
show-config="[[_showConfig]]"
|
||||
hass="[[hass]]"
|
||||
></demo-more-info>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
entities: Array,
|
||||
hass: Object,
|
||||
_showConfig: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
_showConfigToggled(ev) {
|
||||
this._showConfig = ev.target.checked;
|
||||
}
|
||||
|
||||
_darkThemeToggled(ev) {
|
||||
applyThemesOnElement(this.$.container, { themes: {} }, "default", {
|
||||
dark: ev.target.checked,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("demo-more-infos", DemoMoreInfos);
|
87
gallery/src/components/demo-more-infos.ts
Normal file
87
gallery/src/components/demo-more-infos.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { applyThemesOnElement } from "../../../src/common/dom/apply_themes_on_element";
|
||||
import "../../../src/components/ha-formfield";
|
||||
import "../../../src/components/ha-switch";
|
||||
import "./demo-more-info";
|
||||
import "../ha-demo-options";
|
||||
import { HomeAssistant } from "../../../src/types";
|
||||
|
||||
@customElement("demo-more-infos")
|
||||
class DemoMoreInfos extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public entities!: [];
|
||||
|
||||
@property({ attribute: false }) _showConfig: boolean = false;
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<ha-demo-options>
|
||||
<ha-formfield label="Show config">
|
||||
<ha-switch @change=${this._showConfigToggled}> </ha-switch>
|
||||
</ha-formfield>
|
||||
<ha-formfield label="Dark theme">
|
||||
<ha-switch @change=${this._darkThemeToggled}> </ha-switch>
|
||||
</ha-formfield>
|
||||
</ha-demo-options>
|
||||
<div id="container">
|
||||
<div class="cards">
|
||||
${this.entities.map(
|
||||
(item) =>
|
||||
html`<demo-more-info
|
||||
.entityId=${item}
|
||||
.showConfig=${this._showConfig}
|
||||
.hass=${this.hass}
|
||||
></demo-more-info>`
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
#container {
|
||||
min-height: calc(100vh - 128px);
|
||||
background: var(--primary-background-color);
|
||||
}
|
||||
.cards {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
demo-more-info {
|
||||
margin: 16px 16px 32px;
|
||||
}
|
||||
ha-formfield {
|
||||
margin-right: 16px;
|
||||
}
|
||||
`;
|
||||
|
||||
_showConfigToggled(ev) {
|
||||
this._showConfig = ev.target.checked;
|
||||
}
|
||||
|
||||
_darkThemeToggled(ev) {
|
||||
applyThemesOnElement(
|
||||
this.shadowRoot!.querySelector("#container"),
|
||||
{
|
||||
default_theme: "default",
|
||||
default_dark_theme: "default",
|
||||
themes: {},
|
||||
darkMode: false,
|
||||
theme: "default",
|
||||
},
|
||||
"default",
|
||||
{
|
||||
dark: ev.target.checked,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-more-infos": DemoMoreInfos;
|
||||
}
|
||||
}
|
47
gallery/src/ha-demo-options.ts
Normal file
47
gallery/src/ha-demo-options.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import "@material/mwc-drawer";
|
||||
import "@material/mwc-top-app-bar-fixed";
|
||||
import { html, css, LitElement } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import "../../src/components/ha-icon-button";
|
||||
import "../../src/managers/notification-manager";
|
||||
import { haStyle } from "../../src/resources/styles";
|
||||
import "./components/page-description";
|
||||
|
||||
@customElement("ha-demo-options")
|
||||
class HaDemoOptions extends LitElement {
|
||||
render() {
|
||||
return html`<slot></slot>`;
|
||||
}
|
||||
|
||||
static styles = [
|
||||
haStyle,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
background-color: var(--light-primary-color);
|
||||
margin-left: 60px
|
||||
margin-right: 60px;
|
||||
display: var(--layout-horizontal_-_display);
|
||||
-ms-flex-direction: var(--layout-horizontal_-_-ms-flex-direction);
|
||||
-webkit-flex-direction: var(
|
||||
--layout-horizontal_-_-webkit-flex-direction
|
||||
);
|
||||
flex-direction: var(--layout-horizontal_-_flex-direction);
|
||||
-ms-flex-align: var(--layout-center_-_-ms-flex-align);
|
||||
-webkit-align-items: var(--layout-center_-_-webkit-align-items);
|
||||
align-items: var(--layout-center_-_align-items);
|
||||
position: relative;
|
||||
height: 64px;
|
||||
padding: 0 16px;
|
||||
pointer-events: none;
|
||||
font-size: 20px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-demo-options": HaDemoOptions;
|
||||
}
|
||||
}
|
@@ -2,30 +2,86 @@
|
||||
title: "Logo"
|
||||
---
|
||||
|
||||
# Using our logo
|
||||
# Our logo
|
||||
|
||||
As a community, we are proud of our logo. Follow these guidelines to ensure it always looks its best. Our logo follows Google's material design spec and uses the blue interface color.
|
||||
As a community, we are proud of our logo. Follow these guidelines to ensure it always represents the identity of the Home Assistant project and community the best way possible.
|
||||
|
||||
[Download Logo](https://github.com/home-assistant/assets/tree/master/logo)
|
||||
|
||||

|
||||

|
||||
|
||||
## Using the icon
|
||||
Please note that this logo is not released under the CC license. All rights reserved.
|
||||
|
||||
Our icon is a shorter and most used version of our logo. The icon can exist without the wordmark, the wordmark should never exist without the icon.
|
||||
# Design
|
||||
|
||||

|
||||
At the core of the Home Assistant logomark is the Blue House with Antenna, the three most recognizable and distinct features of the previous logo throughout the past decade.
|
||||
|
||||
## Using the right variant
|
||||
### Blue
|
||||
|
||||
The pretty blue logo with a background shadow, pictured top left, is our primary logo. It should only be used with black, white, and non-duotone photography.
|
||||
Blue feels stable and essential. A bright sky blue is joyful, clear, and free of clouds.
|
||||
|
||||
When needed you can use our logo without a shadow, as seen as the second variant.
|
||||
### House
|
||||
|
||||
The outlined logo should only be used on packaging.
|
||||
Of all possible combinations of shapes, a home is best abstracted in the shape of a structure with a pitched roof. With the vast amount of logos based on this shape, the best we can do is to make it more iconic. The house is further simplified - there is no gable and there is no chimney - to an orthogonal shape with an elegant and deliberate proportion.
|
||||
|
||||
## Exclusion zone
|
||||
### Antenna
|
||||
|
||||
The logo needs some personal space. It's exclusion zone is equal to a quarter the height of the icon.
|
||||
Call it a tree, a set of nodes, a PCB, or an antenna. The antenna is the most recognizable and memorable part of the previous Home Assistant logo, and is an easily understandable symbol that conveys technologies that are smart, connected, and growing evergreen.
|
||||
|
||||

|
||||
# Usage
|
||||
|
||||
The default variation is the static colored wordmark in horizontal layout and dark text on a light background.
|
||||
|
||||
## Layout variations
|
||||
|
||||

|
||||
|
||||
The default layout is the wordmark in horizontal layout. It provides the clearest context to the brand identity of Home Assistant.
|
||||
|
||||
Use the logomark variant when the context is clear that the logo is about Home Assistant. For example, inside the Home Assistant app where users are already aware of where they are at, the logomark variant without the wordmark can be used. The logomark can exist without the wordmark, however, the wordmark should never exist without the icon.
|
||||
|
||||
Use the wordmark in vertical layout when the space available has an aspect ratio less than 4:3. For example, in a square space on a t-shirt where a logo is needed, since there is no established context of Home Assistant, the wordmark in vertical layout should be used.
|
||||
|
||||
Lastly, use the wordmark in vertical layout with small logomark when Home Assistant is displayed in context of other Home Assistant-related projects. For example, in a flowchart showing the voice pipeline, use this layout for Home Assistant and its other related projects.
|
||||
|
||||
## Color variations, backgrounds, and placement
|
||||
|
||||
The default color is the colored version on light background with dark text.
|
||||
|
||||
For backgrounds that are dark, for example, when it is used on a page in a dark theme, use the colored version on dark background with light text.
|
||||
|
||||
In printed materials where color is unavailable, use the monochrome color variations.
|
||||
|
||||
On background that are dark or photographic, use the light monochrome color on dark background variation.
|
||||
|
||||
On backgrounds that are light or photographic, use the colored version. Do not use the monochrome variations.
|
||||
|
||||
Do not enclose the logmark in a square or color or any confined backgrounds, except in specific situations enforced by another company's marketplace guidelines, for example, an iOS app icon.
|
||||
|
||||
Do not add drop shadow to the logomark or the wordmark. If legibility is compromised due to the background, change the background to provide more contrast, or in last resort, add a heavily blurred drop shadaow.
|
||||
|
||||
It should only be used with black, white, and non-duotone photography.
|
||||
|
||||
Unlike the previous version of our logo, no outlined variants are available. Use the monochrome variants in those spaces.
|
||||
|
||||
### Exclusion zone
|
||||
|
||||
The logo needs some personal space. Its exclusion zone is equal to a quarter the height of the icon.
|
||||
|
||||

|
||||
|
||||
## Animation
|
||||
|
||||
The default is the static variant.
|
||||
|
||||
Use the animated variant only for introductory purposes, for example, in the beginning of a video or on a loading screen.
|
||||
|
||||
Use the animated with sound variant only when sound is warranted in the user's context. For example, use it in the beginning of a video since sounds are expected in a video, but do not use it on a loading screen since sounds are not expected in a user interface.
|
||||
|
||||
Do not repeat the logo animation.
|
||||
|
||||
## Sizes and app icon variants
|
||||
|
||||
Special variants are created for specific contexts.
|
||||
|
||||
Use the tiny variants when the logomark is used in a very small space (16x16 dp), for example, the favicon of the Home Assistant website, a notification on Android, or the menubar of macOS.
|
||||
|
@@ -150,17 +150,13 @@ export class DemoHaCircularSlider extends LitElement {
|
||||
}
|
||||
ha-control-circular-slider {
|
||||
--control-circular-slider-color: #ff9800;
|
||||
--control-circular-slider-background: #ff9800;
|
||||
--control-circular-slider-background-opacity: 0.3;
|
||||
}
|
||||
ha-control-circular-slider[inverted] {
|
||||
--control-circular-slider-color: #2196f3;
|
||||
--control-circular-slider-background: #2196f3;
|
||||
}
|
||||
ha-control-circular-slider[dual] {
|
||||
--control-circular-slider-high-color: #2196f3;
|
||||
--control-circular-slider-low-color: #ff9800;
|
||||
--control-circular-slider-background: var(--disabled-color);
|
||||
}
|
||||
.field {
|
||||
display: flex;
|
||||
|
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Control Number Buttons
|
||||
---
|
100
gallery/src/pages/components/ha-control-number-buttons.ts
Normal file
100
gallery/src/pages/components/ha-control-number-buttons.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { LitElement, TemplateResult, css, html } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/components/ha-control-number-buttons";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
|
||||
const buttons: {
|
||||
id: string;
|
||||
label: string;
|
||||
min?: number;
|
||||
max?: number;
|
||||
step?: number;
|
||||
class?: string;
|
||||
}[] = [
|
||||
{
|
||||
id: "basic",
|
||||
label: "Basic",
|
||||
},
|
||||
{
|
||||
id: "min_max_step",
|
||||
label: "With min/max and step",
|
||||
min: 5,
|
||||
max: 25,
|
||||
step: 0.5,
|
||||
},
|
||||
{
|
||||
id: "custom",
|
||||
label: "Custom",
|
||||
class: "custom",
|
||||
},
|
||||
];
|
||||
|
||||
@customElement("demo-components-ha-control-number-buttons")
|
||||
export class DemoHarControlNumberButtons extends LitElement {
|
||||
@state() value = 5;
|
||||
|
||||
private _valueChanged(ev) {
|
||||
this.value = ev.detail.value;
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
${repeat(buttons, (button) => {
|
||||
const { id, label, ...config } = button;
|
||||
return html`
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<label id=${id}>${label}</label>
|
||||
<pre>Config: ${JSON.stringify(config)}</pre>
|
||||
<ha-control-number-buttons
|
||||
.value=${this.value}
|
||||
.min=${config.min}
|
||||
.max=${config.max}
|
||||
.step=${config.step}
|
||||
class=${ifDefined(config.class)}
|
||||
@value-changed=${this._valueChanged}
|
||||
.label=${label}
|
||||
>
|
||||
</ha-control-number-buttons>
|
||||
</div>
|
||||
</ha-card>
|
||||
`;
|
||||
})}
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
ha-card {
|
||||
max-width: 600px;
|
||||
margin: 24px auto;
|
||||
}
|
||||
pre {
|
||||
margin-top: 0;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
label {
|
||||
font-weight: 600;
|
||||
}
|
||||
.custom {
|
||||
color: #2196f3;
|
||||
--control-number-buttons-color: #2196f3;
|
||||
--control-number-buttons-background-color: #2196f3;
|
||||
--control-number-buttons-background-opacity: 0.1;
|
||||
--control-number-buttons-thickness: 100px;
|
||||
--control-number-buttons-border-radius: 24px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-components-ha-control-number-buttons": DemoHarControlNumberButtons;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Control Select Menu
|
||||
---
|
146
gallery/src/pages/components/ha-control-select-menu.ts
Normal file
146
gallery/src/pages/components/ha-control-select-menu.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import { mdiFan, mdiFanSpeed1, mdiFanSpeed2, mdiFanSpeed3 } from "@mdi/js";
|
||||
import { LitElement, TemplateResult, css, html, nothing } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/components/ha-control-select-menu";
|
||||
import "../../../../src/components/ha-list-item";
|
||||
import "../../../../src/components/ha-svg-icon";
|
||||
|
||||
type SelectMenuOptions = {
|
||||
label: string;
|
||||
value: string;
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
type SelectMenu = {
|
||||
label: string;
|
||||
icon: string;
|
||||
class?: string;
|
||||
disabled?: boolean;
|
||||
options: SelectMenuOptions[];
|
||||
};
|
||||
|
||||
const selects: SelectMenu[] = [
|
||||
{
|
||||
label: "Basic select",
|
||||
icon: mdiFan,
|
||||
options: [
|
||||
{
|
||||
value: "low",
|
||||
label: "Low",
|
||||
},
|
||||
{
|
||||
value: "medium",
|
||||
label: "Medium",
|
||||
},
|
||||
{
|
||||
value: "high",
|
||||
label: "High",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "Select with icons",
|
||||
icon: mdiFan,
|
||||
options: [
|
||||
{
|
||||
value: "low",
|
||||
label: "Low",
|
||||
icon: mdiFanSpeed1,
|
||||
},
|
||||
{
|
||||
value: "medium",
|
||||
label: "Medium",
|
||||
icon: mdiFanSpeed2,
|
||||
},
|
||||
{
|
||||
value: "high",
|
||||
label: "High",
|
||||
icon: mdiFanSpeed3,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "Disabled select",
|
||||
icon: mdiFan,
|
||||
options: [],
|
||||
disabled: true,
|
||||
},
|
||||
];
|
||||
|
||||
@customElement("demo-components-ha-control-select-menu")
|
||||
export class DemoHaControlSelectMenu extends LitElement {
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<ha-card>
|
||||
${repeat(
|
||||
selects,
|
||||
(select) => html`
|
||||
<div class="card-content">
|
||||
<ha-control-select-menu
|
||||
.label=${select.label}
|
||||
?disabled=${select.disabled}
|
||||
fixedMenuPosition
|
||||
naturalMenuWidth
|
||||
>
|
||||
<ha-svg-icon slot="icon" .path=${select.icon}></ha-svg-icon>
|
||||
${select.options.map(
|
||||
(option) => html`
|
||||
<ha-list-item
|
||||
.value=${option.value}
|
||||
.graphic=${option.icon ? "icon" : undefined}
|
||||
>
|
||||
${option.icon
|
||||
? html`
|
||||
<ha-svg-icon
|
||||
slot="graphic"
|
||||
.path=${option.icon}
|
||||
></ha-svg-icon>
|
||||
`
|
||||
: nothing}
|
||||
${option.label ?? option.value}
|
||||
</ha-list-item>
|
||||
`
|
||||
)}
|
||||
</ha-control-select-menu>
|
||||
</div>
|
||||
`
|
||||
)}
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
ha-card {
|
||||
max-width: 600px;
|
||||
margin: 24px auto;
|
||||
}
|
||||
pre {
|
||||
margin-top: 0;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
label {
|
||||
font-weight: 600;
|
||||
}
|
||||
.custom {
|
||||
--control-button-icon-color: var(--primary-color);
|
||||
--control-button-background-color: var(--primary-color);
|
||||
--control-button-background-opacity: 0.2;
|
||||
--control-button-border-radius: 18px;
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-components-ha-control-select-menu": DemoHaControlSelectMenu;
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
---
|
||||
title: Temp Color Picker
|
||||
---
|
@@ -1,117 +0,0 @@
|
||||
import "../../../../src/components/ha-temp-color-picker";
|
||||
|
||||
import { css, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/components/ha-slider";
|
||||
|
||||
@customElement("demo-components-ha-temp-color-picker")
|
||||
export class DemoHaTempColorPicker extends LitElement {
|
||||
@state()
|
||||
min = 3000;
|
||||
|
||||
@state()
|
||||
max = 7000;
|
||||
|
||||
@state()
|
||||
value = 4000;
|
||||
|
||||
@state()
|
||||
liveValue?: number;
|
||||
|
||||
private _minChanged(ev) {
|
||||
this.min = Number(ev.target.value);
|
||||
}
|
||||
|
||||
private _maxChanged(ev) {
|
||||
this.max = Number(ev.target.value);
|
||||
}
|
||||
|
||||
private _valueChanged(ev) {
|
||||
this.value = Number(ev.target.value);
|
||||
}
|
||||
|
||||
private _tempColorCursor(ev) {
|
||||
this.liveValue = ev.detail.value;
|
||||
}
|
||||
|
||||
private _tempColorChanged(ev) {
|
||||
this.value = ev.detail.value;
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<p class="value">${this.liveValue ?? this.value} K</p>
|
||||
<ha-temp-color-picker
|
||||
.min=${this.min}
|
||||
.max=${this.max}
|
||||
.value=${this.value}
|
||||
@value-changed=${this._tempColorChanged}
|
||||
@cursor-moved=${this._tempColorCursor}
|
||||
></ha-temp-color-picker>
|
||||
<p>Min temp : ${this.min} K</p>
|
||||
<ha-slider
|
||||
step="1"
|
||||
pin
|
||||
min="2000"
|
||||
max="10000"
|
||||
.value=${this.min}
|
||||
@change=${this._minChanged}
|
||||
>
|
||||
</ha-slider>
|
||||
<p>Max temp : ${this.max} K</p>
|
||||
<ha-slider
|
||||
step="1"
|
||||
pin
|
||||
min="2000"
|
||||
max="10000"
|
||||
.value=${this.max}
|
||||
@change=${this._maxChanged}
|
||||
>
|
||||
</ha-slider>
|
||||
<p>Value : ${this.value} K</p>
|
||||
<ha-slider
|
||||
step="1"
|
||||
pin
|
||||
min=${this.min}
|
||||
max=${this.max}
|
||||
.value=${this.value}
|
||||
@change=${this._valueChanged}
|
||||
>
|
||||
</ha-slider>
|
||||
</div>
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
ha-card {
|
||||
max-width: 600px;
|
||||
margin: 24px auto;
|
||||
}
|
||||
.card-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
ha-temp-color-picker {
|
||||
width: 400px;
|
||||
}
|
||||
.value {
|
||||
font-size: 22px;
|
||||
font-weight: bold;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-components-ha-temp-color-picker": DemoHaTempColorPicker;
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ We want to make it as easy for designers to contribute as it is for developers.
|
||||
|
||||
- Meet us at <a href="https://discord.gg/BPBc8rZ9" rel="noopener noreferrer" target="_blank">devs_ux Discord</a>. Feel free to share your designs, user test or strategic ideas.
|
||||
- Start designing with our <a href="https://www.figma.com/community/file/967153512097289521/Home-Assistant-DesignKit" rel="noopener noreferrer" target="_blank">Figma DesignKit</a>.
|
||||
- Find the lates UX <a href="https://github.com/home-assistant/frontend/discussions?discussions_q=label%3Aux" rel="noopener noreferrer" target="_blank">discussions</a> and <a href="https://github.com/home-assistant/frontend/labels/ux" rel="noopener noreferrer" target="_blank">issues</a> on GitHub. Everyone can start a new issue or discussion!
|
||||
- Find the latest UX <a href="https://github.com/home-assistant/frontend/discussions?discussions_q=label%3Aux" rel="noopener noreferrer" target="_blank">discussions</a> and <a href="https://github.com/home-assistant/frontend/labels/ux" rel="noopener noreferrer" target="_blank">issues</a> on GitHub. Everyone can start a new issue or discussion!
|
||||
|
||||
## Developers
|
||||
|
||||
|
@@ -14,7 +14,7 @@ const ENTITIES = [
|
||||
}),
|
||||
getEntity("light", "bed_light", "on", {
|
||||
friendly_name: "Bed Light",
|
||||
supported_color_modes: [LightColorMode.HS],
|
||||
supported_color_modes: [LightColorMode.HS, LightColorMode.COLOR_TEMP],
|
||||
}),
|
||||
getEntity("light", "unavailable", "unavailable", {
|
||||
friendly_name: "Unavailable entity",
|
||||
@@ -116,6 +116,15 @@ const CONFIGS = [
|
||||
- type: "light-brightness"
|
||||
`,
|
||||
},
|
||||
{
|
||||
heading: "Light color temperature feature",
|
||||
config: `
|
||||
- type: tile
|
||||
entity: light.bed_light
|
||||
features:
|
||||
- type: "color-temp"
|
||||
`,
|
||||
},
|
||||
{
|
||||
heading: "Vacuum commands feature",
|
||||
config: `
|
||||
|
@@ -284,6 +284,13 @@ const ENTITIES: HassEntity[] = [
|
||||
installed_version: "1.0.0",
|
||||
latest_version: "2.0.0",
|
||||
}),
|
||||
createEntity("water_heater.off", "off"),
|
||||
createEntity("water_heater.eco", "eco"),
|
||||
createEntity("water_heater.electric", "electric"),
|
||||
createEntity("water_heater.performance", "performance"),
|
||||
createEntity("water_heater.high_demand", "high_demand"),
|
||||
createEntity("water_heater.heat_pump", "heat_pump"),
|
||||
createEntity("water_heater.gas", "gas"),
|
||||
];
|
||||
|
||||
function createEntity(
|
||||
@@ -336,7 +343,7 @@ export class DemoEntityState extends LitElement {
|
||||
const columns: DataTableColumnContainer<EntityRowData> = {
|
||||
icon: {
|
||||
title: "Icon",
|
||||
template: (_, entry) => html`
|
||||
template: (entry) => html`
|
||||
<state-badge
|
||||
.stateObj=${entry.stateObj}
|
||||
.stateColor=${true}
|
||||
@@ -353,7 +360,7 @@ export class DemoEntityState extends LitElement {
|
||||
title: "State",
|
||||
width: "20%",
|
||||
sortable: true,
|
||||
template: (_, entry) =>
|
||||
template: (entry) =>
|
||||
html`${computeStateDisplay(
|
||||
hass.localize,
|
||||
entry.stateObj,
|
||||
@@ -364,14 +371,14 @@ export class DemoEntityState extends LitElement {
|
||||
},
|
||||
device_class: {
|
||||
title: "Device class",
|
||||
template: (dc) => html`${dc ?? "-"}`,
|
||||
template: (entry) => html`${entry.device_class ?? "-"}`,
|
||||
width: "20%",
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
},
|
||||
domain: {
|
||||
title: "Domain",
|
||||
template: (_, entry) => html`${computeDomain(entry.entity_id)}`,
|
||||
template: (entry) => html`${computeDomain(entry.entity_id)}`,
|
||||
width: "20%",
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
|
3
gallery/src/pages/more-info/climate.markdown
Normal file
3
gallery/src/pages/more-info/climate.markdown
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Climate
|
||||
---
|
105
gallery/src/pages/more-info/climate.ts
Normal file
105
gallery/src/pages/more-info/climate.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/dialogs/more-info/more-info-content";
|
||||
import { getEntity } from "../../../../src/fake_data/entity";
|
||||
import {
|
||||
MockHomeAssistant,
|
||||
provideHass,
|
||||
} from "../../../../src/fake_data/provide_hass";
|
||||
import "../../components/demo-more-infos";
|
||||
import { ClimateEntityFeature } from "../../../../src/data/climate";
|
||||
|
||||
const ENTITIES = [
|
||||
getEntity("climate", "thermostat", "heat", {
|
||||
friendly_name: "Basic heater",
|
||||
hvac_modes: ["heat", "off"],
|
||||
hvac_mode: "heat",
|
||||
current_temperature: 18,
|
||||
temperature: 20,
|
||||
min_temp: 10,
|
||||
max_temp: 30,
|
||||
supported_features: ClimateEntityFeature.TARGET_TEMPERATURE,
|
||||
}),
|
||||
getEntity("climate", "ac", "cool", {
|
||||
friendly_name: "Basic air conditioning",
|
||||
hvac_modes: ["cool", "off"],
|
||||
hvac_mode: "cool",
|
||||
current_temperature: 18,
|
||||
temperature: 20,
|
||||
min_temp: 10,
|
||||
max_temp: 30,
|
||||
supported_features: ClimateEntityFeature.TARGET_TEMPERATURE,
|
||||
}),
|
||||
getEntity("climate", "hvac", "auto", {
|
||||
friendly_name: "Basic hvac",
|
||||
hvac_modes: ["auto", "off"],
|
||||
hvac_mode: "auto",
|
||||
current_temperature: 18,
|
||||
min_temp: 10,
|
||||
max_temp: 30,
|
||||
target_temp_step: 1,
|
||||
supported_features: ClimateEntityFeature.TARGET_TEMPERATURE_RANGE,
|
||||
target_temp_low: 20,
|
||||
target_temp_high: 25,
|
||||
}),
|
||||
getEntity("climate", "advanced", "auto", {
|
||||
friendly_name: "Advanced hvac",
|
||||
supported_features:
|
||||
// eslint-disable-next-line no-bitwise
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE |
|
||||
ClimateEntityFeature.TARGET_HUMIDITY |
|
||||
ClimateEntityFeature.PRESET_MODE,
|
||||
hvac_modes: ["auto", "off"],
|
||||
hvac_mode: "auto",
|
||||
preset_modes: ["eco", "comfort", "boost"],
|
||||
preset_mode: "eco",
|
||||
current_temperature: 18,
|
||||
min_temp: 10,
|
||||
max_temp: 30,
|
||||
target_temp_step: 1,
|
||||
target_temp_low: 20,
|
||||
target_temp_high: 25,
|
||||
current_humidity: 40,
|
||||
min_humidity: 0,
|
||||
max_humidity: 100,
|
||||
humidity: 50,
|
||||
}),
|
||||
getEntity("climate", "unavailable", "unavailable", {
|
||||
friendly_name: "Unavailable heater",
|
||||
hvac_modes: ["heat", "off"],
|
||||
hvac_mode: "heat",
|
||||
min_temp: 10,
|
||||
max_temp: 30,
|
||||
supported_features: ClimateEntityFeature.TARGET_TEMPERATURE,
|
||||
}),
|
||||
];
|
||||
|
||||
@customElement("demo-more-info-climate")
|
||||
class DemoMoreInfoClimate extends LitElement {
|
||||
@property() public hass!: MockHomeAssistant;
|
||||
|
||||
@query("demo-more-infos") private _demoRoot!: HTMLElement;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<demo-more-infos
|
||||
.hass=${this.hass}
|
||||
.entities=${ENTITIES.map((ent) => ent.entityId)}
|
||||
></demo-more-infos>
|
||||
`;
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProperties: PropertyValues) {
|
||||
super.firstUpdated(changedProperties);
|
||||
const hass = provideHass(this._demoRoot);
|
||||
hass.updateTranslations(null, "en");
|
||||
hass.addEntities(ENTITIES);
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-more-info-climate": DemoMoreInfoClimate;
|
||||
}
|
||||
}
|
3
gallery/src/pages/more-info/humidifier.markdown
Normal file
3
gallery/src/pages/more-info/humidifier.markdown
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Humidifier
|
||||
---
|
57
gallery/src/pages/more-info/humidifier.ts
Normal file
57
gallery/src/pages/more-info/humidifier.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/dialogs/more-info/more-info-content";
|
||||
import { getEntity } from "../../../../src/fake_data/entity";
|
||||
import {
|
||||
MockHomeAssistant,
|
||||
provideHass,
|
||||
} from "../../../../src/fake_data/provide_hass";
|
||||
import "../../components/demo-more-infos";
|
||||
|
||||
const ENTITIES = [
|
||||
getEntity("humidifier", "humidifier", "on", {
|
||||
friendly_name: "Humidifier",
|
||||
device_class: "humidifier",
|
||||
current_humidity: 50,
|
||||
humidity: 30,
|
||||
}),
|
||||
getEntity("humidifier", "dehumidifier", "on", {
|
||||
friendly_name: "Dehumidifier",
|
||||
device_class: "dehumidifier",
|
||||
current_humidity: 50,
|
||||
humidity: 30,
|
||||
}),
|
||||
getEntity("humidifier", "unavailable", "unavailable", {
|
||||
friendly_name: "Unavailable humidifier",
|
||||
}),
|
||||
];
|
||||
|
||||
@customElement("demo-more-info-humidifier")
|
||||
class DemoMoreInfoHumidifier extends LitElement {
|
||||
@property() public hass!: MockHomeAssistant;
|
||||
|
||||
@query("demo-more-infos") private _demoRoot!: HTMLElement;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<demo-more-infos
|
||||
.hass=${this.hass}
|
||||
.entities=${ENTITIES.map((ent) => ent.entityId)}
|
||||
></demo-more-infos>
|
||||
`;
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProperties: PropertyValues) {
|
||||
super.firstUpdated(changedProperties);
|
||||
const hass = provideHass(this._demoRoot);
|
||||
hass.updateTranslations(null, "en");
|
||||
hass.addEntities(ENTITIES);
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-more-info-humidifier": DemoMoreInfoHumidifier;
|
||||
}
|
||||
}
|
3
gallery/src/pages/more-info/water-heater.markdown
Normal file
3
gallery/src/pages/more-info/water-heater.markdown
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Water Heater
|
||||
---
|
70
gallery/src/pages/more-info/water-heater.ts
Normal file
70
gallery/src/pages/more-info/water-heater.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import "../../../../src/components/ha-card";
|
||||
import { WaterHeaterEntityFeature } from "../../../../src/data/water_heater";
|
||||
import "../../../../src/dialogs/more-info/more-info-content";
|
||||
import { getEntity } from "../../../../src/fake_data/entity";
|
||||
import {
|
||||
MockHomeAssistant,
|
||||
provideHass,
|
||||
} from "../../../../src/fake_data/provide_hass";
|
||||
import "../../components/demo-more-infos";
|
||||
|
||||
const ENTITIES = [
|
||||
getEntity("water_heater", "basic", "eco", {
|
||||
friendly_name: "Basic heater",
|
||||
operation_list: ["heat_pump", "eco", "performance", "off"],
|
||||
operation_mode: "eco",
|
||||
away_mode: "off",
|
||||
target_temp_step: 1,
|
||||
current_temperature: 55,
|
||||
temperature: 60,
|
||||
min_temp: 20,
|
||||
max_temp: 70,
|
||||
supported_features:
|
||||
// eslint-disable-next-line no-bitwise
|
||||
WaterHeaterEntityFeature.TARGET_TEMPERATURE |
|
||||
WaterHeaterEntityFeature.OPERATION_MODE |
|
||||
WaterHeaterEntityFeature.AWAY_MODE,
|
||||
}),
|
||||
getEntity("water_heater", "unavailable", "unavailable", {
|
||||
friendly_name: "Unavailable heater",
|
||||
operation_list: ["heat_pump", "eco", "performance", "off"],
|
||||
operation_mode: "off",
|
||||
min_temp: 20,
|
||||
max_temp: 70,
|
||||
supported_features:
|
||||
// eslint-disable-next-line no-bitwise
|
||||
WaterHeaterEntityFeature.TARGET_TEMPERATURE |
|
||||
WaterHeaterEntityFeature.OPERATION_MODE,
|
||||
}),
|
||||
];
|
||||
|
||||
@customElement("demo-more-info-water-heater")
|
||||
class DemoMoreInfoWaterHeater extends LitElement {
|
||||
@property() public hass!: MockHomeAssistant;
|
||||
|
||||
@query("demo-more-infos") private _demoRoot!: HTMLElement;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<demo-more-infos
|
||||
.hass=${this.hass}
|
||||
.entities=${ENTITIES.map((ent) => ent.entityId)}
|
||||
></demo-more-infos>
|
||||
`;
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProperties: PropertyValues) {
|
||||
super.firstUpdated(changedProperties);
|
||||
const hass = provideHass(this._demoRoot);
|
||||
hass.updateTranslations(null, "en");
|
||||
hass.addEntities(ENTITIES);
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-more-info-water-heater": DemoMoreInfoWaterHeater;
|
||||
}
|
||||
}
|
@@ -49,6 +49,10 @@ import { showHassioCreateBackupDialog } from "../dialogs/backup/show-dialog-hass
|
||||
import { supervisorTabs } from "../hassio-tabs";
|
||||
import { hassioStyle } from "../resources/hassio-style";
|
||||
|
||||
type BackupItem = HassioBackup & {
|
||||
secondary: string;
|
||||
};
|
||||
|
||||
@customElement("hassio-backups")
|
||||
export class HassioBackups extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@@ -117,15 +121,15 @@ export class HassioBackups extends LitElement {
|
||||
}
|
||||
|
||||
private _columns = memoizeOne(
|
||||
(narrow: boolean): DataTableColumnContainer => ({
|
||||
(narrow: boolean): DataTableColumnContainer<BackupItem> => ({
|
||||
name: {
|
||||
title: this.supervisor.localize("backup.name"),
|
||||
main: true,
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
grows: true,
|
||||
template: (entry: string, backup: any) =>
|
||||
html`${entry || backup.slug}
|
||||
template: (backup) =>
|
||||
html`${backup.name || backup.slug}
|
||||
<div class="secondary">${backup.secondary}</div>`,
|
||||
},
|
||||
size: {
|
||||
@@ -134,7 +138,7 @@ export class HassioBackups extends LitElement {
|
||||
hidden: narrow,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
template: (entry: number) => Math.ceil(entry * 10) / 10 + " MB",
|
||||
template: (backup) => Math.ceil(backup.size * 10) / 10 + " MB",
|
||||
},
|
||||
location: {
|
||||
title: this.supervisor.localize("backup.location"),
|
||||
@@ -142,8 +146,8 @@ export class HassioBackups extends LitElement {
|
||||
hidden: narrow,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
template: (entry: string | null) =>
|
||||
entry || this.supervisor.localize("backup.data_disk"),
|
||||
template: (backup) =>
|
||||
backup.location || this.supervisor.localize("backup.data_disk"),
|
||||
},
|
||||
date: {
|
||||
title: this.supervisor.localize("backup.created"),
|
||||
@@ -152,8 +156,8 @@ export class HassioBackups extends LitElement {
|
||||
hidden: narrow,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
template: (entry: string) =>
|
||||
relativeTime(new Date(entry), this.hass.locale),
|
||||
template: (backup) =>
|
||||
relativeTime(new Date(backup.date), this.hass.locale),
|
||||
},
|
||||
secondary: {
|
||||
title: "",
|
||||
@@ -163,7 +167,7 @@ export class HassioBackups extends LitElement {
|
||||
})
|
||||
);
|
||||
|
||||
private _backupData = memoizeOne((backups: HassioBackup[]) =>
|
||||
private _backupData = memoizeOne((backups: HassioBackup[]): BackupItem[] =>
|
||||
backups.map((backup) => ({
|
||||
...backup,
|
||||
secondary: this._computeBackupContent(backup),
|
||||
|
@@ -31,8 +31,8 @@ export class HassioUploadBackup extends LitElement {
|
||||
.icon=${mdiFolderUpload}
|
||||
accept="application/x-tar"
|
||||
label="Upload backup"
|
||||
supports="Supports .TAR files"
|
||||
@file-picked=${this._uploadFile}
|
||||
auto-open-file-dialog
|
||||
></ha-file-upload>
|
||||
`;
|
||||
}
|
||||
|
@@ -173,6 +173,7 @@ class HassioBackupDialog
|
||||
private async _restoreClicked() {
|
||||
const backupDetails = this._backupContent.backupDetails();
|
||||
this._restoringBackup = true;
|
||||
this._dialogParams?.onRestoring?.();
|
||||
if (this._backupContent.backupType === "full") {
|
||||
await this._fullRestoreClicked(backupDetails);
|
||||
} else {
|
||||
@@ -219,7 +220,7 @@ class HassioBackupDialog
|
||||
this._error = error.body.message;
|
||||
}
|
||||
} else {
|
||||
fireEvent(this, "restoring");
|
||||
this._dialogParams?.onRestoring?.();
|
||||
await fetch(`/api/hassio/backups/${this._backup!.slug}/restore/partial`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(backupDetails),
|
||||
@@ -268,7 +269,7 @@ class HassioBackupDialog
|
||||
}
|
||||
);
|
||||
} else {
|
||||
fireEvent(this, "restoring");
|
||||
this._dialogParams?.onRestoring?.();
|
||||
fetch(`/api/hassio/backups/${this._backup!.slug}/restore/full`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(backupDetails),
|
||||
|
@@ -5,6 +5,7 @@ import { Supervisor } from "../../../../src/data/supervisor/supervisor";
|
||||
export interface HassioBackupDialogParams {
|
||||
slug: string;
|
||||
onDelete?: () => void;
|
||||
onRestoring?: () => void;
|
||||
onboarding?: boolean;
|
||||
supervisor?: Supervisor;
|
||||
localize?: LocalizeFunc;
|
||||
|
143
package.json
143
package.json
@@ -25,24 +25,24 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.22.6",
|
||||
"@braintree/sanitize-url": "6.0.2",
|
||||
"@codemirror/autocomplete": "6.9.0",
|
||||
"@codemirror/commands": "6.2.4",
|
||||
"@codemirror/language": "6.8.0",
|
||||
"@babel/runtime": "7.22.15",
|
||||
"@braintree/sanitize-url": "6.0.4",
|
||||
"@codemirror/autocomplete": "6.9.1",
|
||||
"@codemirror/commands": "6.2.5",
|
||||
"@codemirror/language": "6.9.0",
|
||||
"@codemirror/legacy-modes": "6.3.3",
|
||||
"@codemirror/search": "6.5.0",
|
||||
"@codemirror/search": "6.5.3",
|
||||
"@codemirror/state": "6.2.1",
|
||||
"@codemirror/view": "6.15.3",
|
||||
"@codemirror/view": "6.19.0",
|
||||
"@egjs/hammerjs": "2.0.17",
|
||||
"@formatjs/intl-datetimeformat": "6.10.0",
|
||||
"@formatjs/intl-displaynames": "6.5.0",
|
||||
"@formatjs/intl-datetimeformat": "6.10.2",
|
||||
"@formatjs/intl-displaynames": "6.5.2",
|
||||
"@formatjs/intl-getcanonicallocales": "2.2.1",
|
||||
"@formatjs/intl-listformat": "7.4.0",
|
||||
"@formatjs/intl-locale": "3.3.2",
|
||||
"@formatjs/intl-numberformat": "8.7.0",
|
||||
"@formatjs/intl-pluralrules": "5.2.4",
|
||||
"@formatjs/intl-relativetimeformat": "11.2.4",
|
||||
"@formatjs/intl-listformat": "7.4.2",
|
||||
"@formatjs/intl-locale": "3.3.4",
|
||||
"@formatjs/intl-numberformat": "8.7.2",
|
||||
"@formatjs/intl-pluralrules": "5.2.6",
|
||||
"@formatjs/intl-relativetimeformat": "11.2.6",
|
||||
"@fullcalendar/core": "6.1.8",
|
||||
"@fullcalendar/daygrid": "6.1.8",
|
||||
"@fullcalendar/interaction": "6.1.8",
|
||||
@@ -50,10 +50,10 @@
|
||||
"@fullcalendar/luxon3": "6.1.8",
|
||||
"@fullcalendar/timegrid": "6.1.8",
|
||||
"@lezer/highlight": "1.1.6",
|
||||
"@lit-labs/context": "0.3.3",
|
||||
"@lit-labs/motion": "1.0.3",
|
||||
"@lit-labs/virtualizer": "2.0.4",
|
||||
"@lrnwebcomponents/simple-tooltip": "7.0.11",
|
||||
"@lit-labs/context": "0.4.1",
|
||||
"@lit-labs/motion": "1.0.4",
|
||||
"@lit-labs/virtualizer": "2.0.7",
|
||||
"@lrnwebcomponents/simple-tooltip": "7.0.18",
|
||||
"@material/chips": "=14.0.0-canary.53b3cad2f.0",
|
||||
"@material/data-table": "=14.0.0-canary.53b3cad2f.0",
|
||||
"@material/mwc-button": "0.27.0",
|
||||
@@ -79,10 +79,9 @@
|
||||
"@material/mwc-top-app-bar": "0.27.0",
|
||||
"@material/mwc-top-app-bar-fixed": "0.27.0",
|
||||
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
|
||||
"@material/web": "=1.0.0-pre.13",
|
||||
"@material/web": "=1.0.0-pre.17",
|
||||
"@mdi/js": "7.2.96",
|
||||
"@mdi/svg": "7.2.96",
|
||||
"@polymer/app-layout": "3.1.0",
|
||||
"@polymer/iron-flex-layout": "3.0.1",
|
||||
"@polymer/iron-input": "3.0.1",
|
||||
"@polymer/iron-resizable-behavior": "3.0.1",
|
||||
@@ -94,8 +93,8 @@
|
||||
"@polymer/paper-toast": "3.0.1",
|
||||
"@polymer/polymer": "3.5.1",
|
||||
"@thomasloven/round-slider": "0.6.0",
|
||||
"@vaadin/combo-box": "24.1.4",
|
||||
"@vaadin/vaadin-themable-mixin": "24.1.4",
|
||||
"@vaadin/combo-box": "24.1.7",
|
||||
"@vaadin/vaadin-themable-mixin": "24.1.7",
|
||||
"@vibrant/color": "3.2.1-alpha.1",
|
||||
"@vibrant/core": "3.2.1-alpha.1",
|
||||
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
|
||||
@@ -103,26 +102,26 @@
|
||||
"@webcomponents/scoped-custom-element-registry": "0.0.9",
|
||||
"@webcomponents/webcomponentsjs": "2.8.0",
|
||||
"app-datepicker": "5.1.1",
|
||||
"chart.js": "3.3.2",
|
||||
"chart.js": "4.3.3",
|
||||
"comlink": "4.4.1",
|
||||
"core-js": "3.31.1",
|
||||
"cropperjs": "1.5.13",
|
||||
"core-js": "3.32.2",
|
||||
"cropperjs": "1.6.0",
|
||||
"date-fns": "2.30.0",
|
||||
"date-fns-tz": "2.0.0",
|
||||
"deep-clone-simple": "1.1.1",
|
||||
"deep-freeze": "0.0.1",
|
||||
"fuse.js": "6.6.2",
|
||||
"google-timezones-json": "1.2.0",
|
||||
"hls.js": "1.4.10",
|
||||
"hls.js": "1.4.12",
|
||||
"home-assistant-js-websocket": "8.2.0",
|
||||
"idb-keyval": "6.2.1",
|
||||
"intl-messageformat": "10.5.0",
|
||||
"intl-messageformat": "10.5.2",
|
||||
"js-yaml": "4.1.0",
|
||||
"leaflet": "1.9.4",
|
||||
"leaflet-draw": "1.0.4",
|
||||
"lit": "2.7.6",
|
||||
"luxon": "3.3.0",
|
||||
"marked": "4.3.0",
|
||||
"lit": "2.8.0",
|
||||
"luxon": "3.4.3",
|
||||
"marked": "7.0.5",
|
||||
"memoize-one": "6.0.0",
|
||||
"node-vibrant": "3.2.1-alpha.1",
|
||||
"proxy-polyfill": "0.3.2",
|
||||
@@ -133,12 +132,14 @@
|
||||
"roboto-fontface": "0.10.0",
|
||||
"rrule": "2.7.2",
|
||||
"sortablejs": "1.15.0",
|
||||
"stacktrace-js": "2.0.2",
|
||||
"superstruct": "1.0.3",
|
||||
"tinykeys": "2.1.0",
|
||||
"tsparticles-engine": "2.11.0",
|
||||
"tsparticles-preset-links": "2.11.0",
|
||||
"tsparticles-engine": "2.12.0",
|
||||
"tsparticles-preset-links": "2.12.0",
|
||||
"ua-parser-js": "1.0.36",
|
||||
"unfetch": "5.0.0",
|
||||
"vis-data": "7.1.6",
|
||||
"vis-data": "7.1.7",
|
||||
"vis-network": "9.1.6",
|
||||
"vue": "2.7.14",
|
||||
"vue2-daterange-picker": "0.6.8",
|
||||
@@ -152,61 +153,62 @@
|
||||
"xss": "1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.22.9",
|
||||
"@babel/plugin-proposal-decorators": "7.22.7",
|
||||
"@babel/plugin-transform-runtime": "7.22.9",
|
||||
"@babel/preset-env": "7.22.9",
|
||||
"@babel/preset-typescript": "7.22.5",
|
||||
"@babel/core": "7.22.20",
|
||||
"@babel/plugin-proposal-decorators": "7.22.15",
|
||||
"@babel/plugin-transform-runtime": "7.22.15",
|
||||
"@babel/preset-env": "7.22.20",
|
||||
"@babel/preset-typescript": "7.22.15",
|
||||
"@koa/cors": "4.0.0",
|
||||
"@lokalise/node-api": "11.0.1",
|
||||
"@octokit/auth-oauth-device": "6.0.0",
|
||||
"@octokit/plugin-retry": "6.0.0",
|
||||
"@octokit/rest": "20.0.1",
|
||||
"@open-wc/dev-server-hmr": "0.1.4",
|
||||
"@rollup/plugin-babel": "6.0.3",
|
||||
"@rollup/plugin-commonjs": "25.0.3",
|
||||
"@rollup/plugin-commonjs": "25.0.4",
|
||||
"@rollup/plugin-json": "6.0.0",
|
||||
"@rollup/plugin-node-resolve": "15.1.0",
|
||||
"@rollup/plugin-node-resolve": "15.2.1",
|
||||
"@rollup/plugin-replace": "5.0.2",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.2",
|
||||
"@types/chromecast-caf-receiver": "6.0.9",
|
||||
"@types/chromecast-caf-sender": "1.0.5",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.3",
|
||||
"@types/chromecast-caf-receiver": "6.0.10",
|
||||
"@types/chromecast-caf-sender": "1.0.6",
|
||||
"@types/esprima": "4.0.3",
|
||||
"@types/glob": "8.1.0",
|
||||
"@types/html-minifier-terser": "7.0.0",
|
||||
"@types/js-yaml": "4.0.5",
|
||||
"@types/leaflet": "1.9.3",
|
||||
"@types/leaflet-draw": "1.0.7",
|
||||
"@types/luxon": "3.3.1",
|
||||
"@types/marked": "4.3.1",
|
||||
"@types/js-yaml": "4.0.6",
|
||||
"@types/leaflet": "1.9.4",
|
||||
"@types/leaflet-draw": "1.0.8",
|
||||
"@types/luxon": "3.3.2",
|
||||
"@types/mocha": "10.0.1",
|
||||
"@types/qrcode": "1.5.1",
|
||||
"@types/qrcode": "1.5.2",
|
||||
"@types/serve-handler": "6.1.1",
|
||||
"@types/sortablejs": "1.15.1",
|
||||
"@types/tar": "6.1.5",
|
||||
"@types/sortablejs": "1.15.2",
|
||||
"@types/tar": "6.1.6",
|
||||
"@types/ua-parser-js": "0.7.37",
|
||||
"@types/webspeechapi": "0.0.29",
|
||||
"@typescript-eslint/eslint-plugin": "6.2.0",
|
||||
"@typescript-eslint/parser": "6.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "6.7.0",
|
||||
"@typescript-eslint/parser": "6.7.0",
|
||||
"@web/dev-server": "0.1.38",
|
||||
"@web/dev-server-rollup": "0.4.1",
|
||||
"babel-loader": "9.1.3",
|
||||
"babel-plugin-template-html-minifier": "4.1.0",
|
||||
"chai": "4.3.7",
|
||||
"del": "7.0.0",
|
||||
"eslint": "8.46.0",
|
||||
"chai": "4.3.8",
|
||||
"del": "7.1.0",
|
||||
"eslint": "8.49.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-airbnb-typescript": "17.1.0",
|
||||
"eslint-config-prettier": "8.9.0",
|
||||
"eslint-import-resolver-webpack": "0.13.2",
|
||||
"eslint-config-prettier": "9.0.0",
|
||||
"eslint-import-resolver-webpack": "0.13.7",
|
||||
"eslint-plugin-disable": "2.0.3",
|
||||
"eslint-plugin-import": "2.28.0",
|
||||
"eslint-plugin-lit": "1.8.3",
|
||||
"eslint-plugin-import": "2.28.1",
|
||||
"eslint-plugin-lit": "1.9.1",
|
||||
"eslint-plugin-lit-a11y": "3.0.0",
|
||||
"eslint-plugin-unused-imports": "3.0.0",
|
||||
"eslint-plugin-wc": "1.5.0",
|
||||
"esprima": "4.0.1",
|
||||
"fancy-log": "2.0.0",
|
||||
"fs-extra": "11.1.1",
|
||||
"glob": "10.3.3",
|
||||
"glob": "10.3.4",
|
||||
"gulp": "4.0.2",
|
||||
"gulp-flatmap": "1.0.2",
|
||||
"gulp-json-transform": "0.4.8",
|
||||
@@ -215,31 +217,30 @@
|
||||
"gulp-zopfli-green": "6.0.1",
|
||||
"html-minifier-terser": "7.2.0",
|
||||
"husky": "8.0.3",
|
||||
"instant-mocha": "1.5.1",
|
||||
"instant-mocha": "1.5.2",
|
||||
"jszip": "3.10.1",
|
||||
"lint-staged": "13.2.3",
|
||||
"lint-staged": "14.0.1",
|
||||
"lit-analyzer": "2.0.0-pre.3",
|
||||
"lodash.template": "4.5.0",
|
||||
"magic-string": "0.30.1",
|
||||
"magic-string": "0.30.3",
|
||||
"map-stream": "0.0.7",
|
||||
"merge-stream": "2.0.0",
|
||||
"mocha": "10.2.0",
|
||||
"object-hash": "3.0.0",
|
||||
"open": "9.1.0",
|
||||
"pinst": "3.0.0",
|
||||
"prettier": "3.0.0",
|
||||
"prettier": "3.0.3",
|
||||
"rollup": "2.79.1",
|
||||
"rollup-plugin-string": "3.0.0",
|
||||
"rollup-plugin-terser": "7.0.2",
|
||||
"rollup-plugin-visualizer": "5.9.2",
|
||||
"serve-handler": "6.1.5",
|
||||
"sinon": "15.2.0",
|
||||
"sinon": "16.0.0",
|
||||
"source-map-url": "0.4.1",
|
||||
"systemjs": "6.14.1",
|
||||
"tar": "6.1.15",
|
||||
"systemjs": "6.14.2",
|
||||
"tar": "6.2.0",
|
||||
"terser-webpack-plugin": "5.3.9",
|
||||
"ts-lit-plugin": "2.0.0-pre.1",
|
||||
"typescript": "5.1.6",
|
||||
"typescript": "5.2.2",
|
||||
"vinyl-buffer": "1.0.1",
|
||||
"vinyl-source-stream": "2.0.0",
|
||||
"webpack": "5.88.2",
|
||||
@@ -256,5 +257,5 @@
|
||||
"sortablejs@1.15.0": "patch:sortablejs@npm%3A1.15.0#./.yarn/patches/sortablejs-npm-1.15.0-f3a393abcc.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@3.6.1"
|
||||
"packageManager": "yarn@3.6.3"
|
||||
}
|
||||
|
BIN
public/static/images/logo_discord.png
Normal file
BIN
public/static/images/logo_discord.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
public/static/images/logo_twitter.png
Normal file
BIN
public/static/images/logo_twitter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20230801.0"
|
||||
version = "20230911.0"
|
||||
license = {text = "Apache-2.0"}
|
||||
description = "The Home Assistant frontend"
|
||||
readme = "README.md"
|
||||
|
@@ -15,7 +15,7 @@
|
||||
"lockFileMaintenance": {
|
||||
"description": ["Run after patch releases but before next beta"],
|
||||
"enabled": true,
|
||||
"schedule": ["on the 19th day of the month"]
|
||||
"schedule": ["on the 19th day of the month before 4am"]
|
||||
},
|
||||
"packageRules": [
|
||||
{
|
||||
|
@@ -8,40 +8,4 @@ set -eu -o pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if [ -z "${LOKALISE_TOKEN-}" ] && [ ! -f .lokalise_token ] ; then
|
||||
echo "Lokalise API token is required to download the latest set of" \
|
||||
"translations. Please create an account by using the following link:" \
|
||||
"https://lokalise.co/signup/3420425759f6d6d241f598.13594006/all/" \
|
||||
"Place your token in a new file \".lokalise_token\" in the repo" \
|
||||
"root directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load token from file if not already in the environment
|
||||
[ -z "${LOKALISE_TOKEN-}" ] && LOKALISE_TOKEN="$(<.lokalise_token)"
|
||||
|
||||
declare -A PROJECT_ID=( \
|
||||
[frontend]="3420425759f6d6d241f598.13594006" \
|
||||
[backend]="130246255a974bd3b5e8a1.51616605" \
|
||||
)
|
||||
|
||||
for project in ${!PROJECT_ID[*]}; do
|
||||
LOCAL_DIR=`pwd`/translations/${project}
|
||||
rm -f ${LOCAL_DIR}/* || mkdir -p ${LOCAL_DIR}
|
||||
docker run \
|
||||
-v ${LOCAL_DIR}:/opt/dest/locale \
|
||||
--rm \
|
||||
lokalise/lokalise-cli-2@sha256:f1860b26be22fa73b8c93bc5f8690f2afc867610a42de6fc27adc790e5d4425d \
|
||||
lokalise2 \
|
||||
--token ${LOKALISE_TOKEN} \
|
||||
--project-id ${PROJECT_ID[${project}]} \
|
||||
file download \
|
||||
--export-empty-as skip \
|
||||
--format json \
|
||||
--json-unescaped-slashes=true \
|
||||
--replace-breaks=false \
|
||||
--original-filenames=false \
|
||||
--unzip-to /opt/dest
|
||||
done
|
||||
|
||||
./node_modules/.bin/gulp check-downloaded-translations
|
||||
./node_modules/.bin/gulp download-translations
|
@@ -1,8 +1,16 @@
|
||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import punycode from "punycode";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
html,
|
||||
LitElement,
|
||||
nothing,
|
||||
PropertyValues,
|
||||
} from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
|
||||
import { extractSearchParamsObject } from "../common/url/search-params";
|
||||
import "../components/ha-alert";
|
||||
import {
|
||||
AuthProvider,
|
||||
AuthUrlSearchParams,
|
||||
@@ -14,6 +22,11 @@ import "./ha-auth-flow";
|
||||
|
||||
import("./ha-pick-auth-provider");
|
||||
|
||||
const appNames = {
|
||||
"https://home-assistant.io/iOS": "iOS",
|
||||
"https://home-assistant.io/android": "Android",
|
||||
};
|
||||
|
||||
@customElement("ha-authorize")
|
||||
export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
@property() public clientId?: string;
|
||||
@@ -22,13 +35,18 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
|
||||
@property() public oauth2State?: string;
|
||||
|
||||
@property() public translationFragment = "page-authorize";
|
||||
|
||||
@state() private _authProvider?: AuthProvider;
|
||||
|
||||
@state() private _authProviders?: AuthProvider[];
|
||||
|
||||
@state() private _ownInstance = false;
|
||||
|
||||
@state() private _error?: string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.translationFragment = "page-authorize";
|
||||
const query = extractSearchParamsObject() as AuthUrlSearchParams;
|
||||
if (query.client_id) {
|
||||
this.clientId = query.client_id;
|
||||
@@ -42,42 +60,49 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (this._error) {
|
||||
return html`<ha-alert alert-type="error"
|
||||
>${this._error} ${this.redirectUri}</ha-alert
|
||||
>`;
|
||||
}
|
||||
|
||||
if (!this._authProviders) {
|
||||
return html`
|
||||
<p>${this.localize("ui.panel.page-authorize.initializing")}</p>
|
||||
`;
|
||||
}
|
||||
|
||||
// We don't have a good approach yet to map text markup in localization.
|
||||
// So we sanitize the translation with innerText and then inject
|
||||
// the name with a bold tag.
|
||||
const loggingInWith = document.createElement("div");
|
||||
loggingInWith.innerText = this.localize(
|
||||
"ui.panel.page-authorize.logging_in_with",
|
||||
"authProviderName",
|
||||
"NAME"
|
||||
);
|
||||
loggingInWith.innerHTML = loggingInWith.innerHTML.replace(
|
||||
"**NAME**",
|
||||
`<b>${this._authProvider!.name}</b>`
|
||||
);
|
||||
|
||||
const inactiveProviders = this._authProviders.filter(
|
||||
(prv) => prv !== this._authProvider
|
||||
);
|
||||
|
||||
const app = this.clientId && this.clientId in appNames;
|
||||
|
||||
return html`
|
||||
<p>
|
||||
${this.localize(
|
||||
"ui.panel.page-authorize.authorizing_client",
|
||||
"clientId",
|
||||
this.clientId ? punycode.toASCII(this.clientId) : this.clientId
|
||||
)}
|
||||
</p>
|
||||
${loggingInWith}
|
||||
${!this._ownInstance
|
||||
? html`<ha-alert .alertType=${app ? "info" : "warning"}>
|
||||
${app
|
||||
? this.localize("ui.panel.page-authorize.authorizing_app", {
|
||||
app: appNames[this.clientId!],
|
||||
})
|
||||
: this.localize("ui.panel.page-authorize.authorizing_client", {
|
||||
clientId: html`<b
|
||||
>${this.clientId
|
||||
? punycode.toASCII(this.clientId)
|
||||
: this.clientId}</b
|
||||
>`,
|
||||
})}
|
||||
</ha-alert>`
|
||||
: html`<p>${this.localize("ui.panel.page-authorize.authorizing")}</p>`}
|
||||
${inactiveProviders.length > 0
|
||||
? html`<p>
|
||||
${this.localize("ui.panel.page-authorize.logging_in_with", {
|
||||
authProviderName: html`<b>${this._authProvider!.name}</b>`,
|
||||
})}
|
||||
</p>`
|
||||
: nothing}
|
||||
|
||||
<ha-auth-flow
|
||||
.resources=${this.resources}
|
||||
.clientId=${this.clientId}
|
||||
.redirectUri=${this.redirectUri}
|
||||
.oauth2State=${this.oauth2State}
|
||||
@@ -100,6 +125,31 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues) {
|
||||
super.firstUpdated(changedProps);
|
||||
|
||||
if (!this.redirectUri) {
|
||||
this._error = "Invalid redirect URI";
|
||||
return;
|
||||
}
|
||||
|
||||
let url: URL;
|
||||
|
||||
try {
|
||||
url = new URL(this.redirectUri);
|
||||
} catch (err) {
|
||||
this._error = "Invalid redirect URI";
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
// eslint-disable-next-line no-script-url
|
||||
["javascript:", "data:", "vbscript:", "file:", "about:"].includes(
|
||||
url.protocol
|
||||
)
|
||||
) {
|
||||
this._error = "Invalid redirect URI";
|
||||
return;
|
||||
}
|
||||
|
||||
this._fetchAuthProviders();
|
||||
|
||||
if (matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
@@ -118,15 +168,10 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.redirectUri) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are logging into the instance that is hosting this auth form
|
||||
// we will register the service worker to start preloading.
|
||||
const tempA = document.createElement("a");
|
||||
tempA.href = this.redirectUri!;
|
||||
if (tempA.host === location.host) {
|
||||
if (url.host === location.host) {
|
||||
this._ownInstance = true;
|
||||
registerServiceWorker(this, false);
|
||||
}
|
||||
}
|
||||
@@ -156,13 +201,14 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
}
|
||||
|
||||
if (authProviders.length === 0) {
|
||||
alert("No auth providers returned. Unable to finish login.");
|
||||
this._error = "No auth providers returned. Unable to finish login.";
|
||||
return;
|
||||
}
|
||||
|
||||
this._authProviders = authProviders;
|
||||
this._authProvider = authProviders[0];
|
||||
} catch (err: any) {
|
||||
this._error = "Unable to fetch auth providers.";
|
||||
// eslint-disable-next-line
|
||||
console.error("Error loading auth providers", err);
|
||||
}
|
||||
@@ -182,6 +228,10 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
||||
display: block;
|
||||
margin-top: 24px;
|
||||
}
|
||||
ha-alert {
|
||||
display: block;
|
||||
margin: 16px 0;
|
||||
}
|
||||
p {
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
|
@@ -35,20 +35,47 @@ export class HaPasswordManagerPolyfill extends LitElement {
|
||||
super.connectedCallback();
|
||||
this._styleElement = document.createElement("style");
|
||||
this._styleElement.textContent = css`
|
||||
/* Polyfill form is sized and vertically aligned with true form, then positioned offscreen
|
||||
rather than hiding so it does not create a new stacking context */
|
||||
.password-manager-polyfill {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
z-index: -1;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.password-manager-polyfill input {
|
||||
/* Excluding our wrapper, move any children back on screen, including anything injected that might not already be positioned */
|
||||
.password-manager-polyfill > *:not(.wrapper),
|
||||
.password-manager-polyfill > .wrapper > * {
|
||||
position: relative;
|
||||
left: 10000px;
|
||||
}
|
||||
/* Size and hide our polyfill fields */
|
||||
.password-manager-polyfill .underneath {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 62px;
|
||||
padding: 0;
|
||||
padding: 0 16px;
|
||||
border: 0;
|
||||
z-index: -1;
|
||||
height: 21px;
|
||||
/* Transparency is only needed to hide during paint or in case of misalignment,
|
||||
but LastPass will fail if it's 0, so we use 1% */
|
||||
opacity: 0.01;
|
||||
}
|
||||
.password-manager-polyfill input[type="submit"] {
|
||||
width: 0;
|
||||
height: 0;
|
||||
.password-manager-polyfill input.underneath {
|
||||
height: 28px;
|
||||
margin-bottom: 30.5px;
|
||||
}
|
||||
/* Button position is not important, but size should not be zero */
|
||||
.password-manager-polyfill > input.underneath[type="submit"] {
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
/* Ensure injected elements will be on top */
|
||||
.password-manager-polyfill > *:not(.underneath, .wrapper),
|
||||
.password-manager-polyfill > .wrapper > *:not(.underneath) {
|
||||
isolation: isolate;
|
||||
z-index: auto;
|
||||
}
|
||||
`.toString();
|
||||
document.head.append(this._styleElement);
|
||||
@@ -77,16 +104,25 @@ export class HaPasswordManagerPolyfill extends LitElement {
|
||||
class="password-manager-polyfill"
|
||||
style=${styleMap({
|
||||
top: `${this.boundingRect?.y || 148}px`,
|
||||
left: `calc(50% - ${(this.boundingRect?.width || 360) / 2}px)`,
|
||||
left: `calc(50% - ${
|
||||
(this.boundingRect?.width || 360) / 2
|
||||
}px - 10000px)`,
|
||||
width: `${this.boundingRect?.width || 360}px`,
|
||||
})}
|
||||
aria-hidden="true"
|
||||
action="/auth"
|
||||
method="post"
|
||||
@submit=${this._handleSubmit}
|
||||
>
|
||||
${autocompleteLoginFields(this.step.data_schema).map((input) =>
|
||||
this.render_input(input)
|
||||
)}
|
||||
<input type="submit" />
|
||||
<input
|
||||
type="submit"
|
||||
value="Login"
|
||||
class="underneath"
|
||||
tabindex="-2"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</form>
|
||||
`;
|
||||
}
|
||||
@@ -99,25 +135,35 @@ export class HaPasswordManagerPolyfill extends LitElement {
|
||||
return "";
|
||||
}
|
||||
return html`
|
||||
<input
|
||||
tabindex="-1"
|
||||
.id=${schema.name}
|
||||
.name=${schema.name}
|
||||
.type=${inputType}
|
||||
.value=${this.stepData[schema.name] || ""}
|
||||
.autocomplete=${schema.autocomplete}
|
||||
@input=${this._valueChanged}
|
||||
/>
|
||||
<!-- Label is a sibling so it can be stacked underneath without affecting injections adjacent to input (e.g. LastPass) -->
|
||||
<label for=${schema.name} class="underneath" aria-hidden="true">
|
||||
${schema.name}
|
||||
</label>
|
||||
<!-- LastPass fails if the input is hidden directly, so we trick it and hide a wrapper instead -->
|
||||
<div class="wrapper" aria-hidden="true">
|
||||
<!-- LastPass fails with tabindex of -1, so we trick with -2 -->
|
||||
<input
|
||||
class="underneath"
|
||||
tabindex="-2"
|
||||
.id=${schema.name}
|
||||
.name=${schema.name}
|
||||
.type=${inputType}
|
||||
.value=${this.stepData[schema.name] || ""}
|
||||
.autocomplete=${schema.autocomplete}
|
||||
@input=${this._valueChanged}
|
||||
@change=${this._valueChanged}
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private _handleSubmit(ev: Event) {
|
||||
private _handleSubmit(ev: SubmitEvent) {
|
||||
ev.preventDefault();
|
||||
fireEvent(this, "form-submitted");
|
||||
}
|
||||
|
||||
private _valueChanged(ev: Event) {
|
||||
const target = ev.target! as HTMLInputElement;
|
||||
const target = ev.target as HTMLInputElement;
|
||||
this.stepData = { ...this.stepData, [target.id]: target.value };
|
||||
fireEvent(this, "value-changed", {
|
||||
value: this.stepData,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { clamp } from "../number/clamp";
|
||||
|
||||
const DEFAULT_MIN_KELVIN = 2700;
|
||||
const DEFAULT_MAX_KELVIN = 6500;
|
||||
export const DEFAULT_MIN_KELVIN = 2700;
|
||||
export const DEFAULT_MAX_KELVIN = 6500;
|
||||
|
||||
export const temperature2rgb = (
|
||||
temperature: number
|
||||
|
@@ -49,6 +49,7 @@ import {
|
||||
mdiProgressClock,
|
||||
mdiRayVertex,
|
||||
mdiRemote,
|
||||
mdiRobotMower,
|
||||
mdiRobotVacuum,
|
||||
mdiScriptText,
|
||||
mdiSineWave,
|
||||
@@ -99,6 +100,7 @@ export const FIXED_DOMAIN_ICONS = {
|
||||
input_number: mdiRayVertex,
|
||||
input_select: mdiFormatListBulleted,
|
||||
input_text: mdiFormTextbox,
|
||||
lawn_mower: mdiRobotMower,
|
||||
light: mdiLightbulb,
|
||||
mailbox: mdiMailbox,
|
||||
notify: mdiCommentAlert,
|
||||
@@ -176,6 +178,7 @@ export const FIXED_DEVICE_CLASS_ICONS = {
|
||||
|
||||
/** Domains that have a state card. */
|
||||
export const DOMAINS_WITH_CARD = [
|
||||
"alert",
|
||||
"button",
|
||||
"climate",
|
||||
"cover",
|
||||
@@ -186,6 +189,7 @@ export const DOMAINS_WITH_CARD = [
|
||||
"input_number",
|
||||
"input_text",
|
||||
"humidifier",
|
||||
"lawn_mower",
|
||||
"lock",
|
||||
"media_player",
|
||||
"number",
|
||||
|
@@ -1,7 +1,11 @@
|
||||
import { HassConfig, HassEntity } from "home-assistant-js-websocket";
|
||||
import { html, TemplateResult } from "lit";
|
||||
import { until } from "lit/directives/until";
|
||||
import {
|
||||
DOMAIN_ATTRIBUTES_UNITS,
|
||||
TEMPERATURE_ATTRIBUTES,
|
||||
} from "../../data/entity_attributes";
|
||||
import { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
||||
import { FrontendLocaleData } from "../../data/translation";
|
||||
import { WeatherEntity, getWeatherUnit } from "../../data/weather";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import checkValidDate from "../datetime/check_valid_date";
|
||||
import { formatDate } from "../datetime/format_date";
|
||||
@@ -10,11 +14,10 @@ import { formatNumber } from "../number/format_number";
|
||||
import { capitalizeFirstLetter } from "../string/capitalize-first-letter";
|
||||
import { isDate } from "../string/is_date";
|
||||
import { isTimestamp } from "../string/is_timestamp";
|
||||
import { blankBeforePercent } from "../translations/blank_before_percent";
|
||||
import { LocalizeFunc } from "../translations/localize";
|
||||
import { computeDomain } from "./compute_domain";
|
||||
import { FrontendLocaleData } from "../../data/translation";
|
||||
|
||||
let jsYamlPromise: Promise<typeof import("../../resources/js-yaml-dump")>;
|
||||
import { computeStateDomain } from "./compute_state_domain";
|
||||
|
||||
export const computeAttributeValueDisplay = (
|
||||
localize: LocalizeFunc,
|
||||
@@ -24,7 +27,7 @@ export const computeAttributeValueDisplay = (
|
||||
entities: HomeAssistant["entities"],
|
||||
attribute: string,
|
||||
value?: any
|
||||
): string | TemplateResult => {
|
||||
): string => {
|
||||
const attributeValue =
|
||||
value !== undefined ? value : stateObj.attributes[attribute];
|
||||
|
||||
@@ -35,28 +38,44 @@ export const computeAttributeValueDisplay = (
|
||||
|
||||
// Number value, return formatted number
|
||||
if (typeof attributeValue === "number") {
|
||||
return formatNumber(attributeValue, locale);
|
||||
const formattedValue = formatNumber(attributeValue, locale);
|
||||
|
||||
const domain = computeStateDomain(stateObj);
|
||||
|
||||
let unit = DOMAIN_ATTRIBUTES_UNITS[domain]?.[attribute] as
|
||||
| string
|
||||
| undefined;
|
||||
|
||||
if (domain === "light" && attribute === "brightness") {
|
||||
const percentage = Math.round((attributeValue / 255) * 100);
|
||||
return `${percentage}${blankBeforePercent(locale)}%`;
|
||||
}
|
||||
|
||||
if (domain === "weather") {
|
||||
unit = getWeatherUnit(config, stateObj as WeatherEntity, attribute);
|
||||
}
|
||||
|
||||
if (unit === "%") {
|
||||
return `${formattedValue}${blankBeforePercent(locale)}${unit}`;
|
||||
}
|
||||
|
||||
if (unit === "°") {
|
||||
return `${formattedValue}${unit}`;
|
||||
}
|
||||
|
||||
if (unit) {
|
||||
return `${formattedValue} ${unit}`;
|
||||
}
|
||||
|
||||
if (TEMPERATURE_ATTRIBUTES.has(attribute)) {
|
||||
return `${formattedValue} ${config.unit_system.temperature}`;
|
||||
}
|
||||
|
||||
return formattedValue;
|
||||
}
|
||||
|
||||
// Special handling in case this is a string with an known format
|
||||
if (typeof attributeValue === "string") {
|
||||
// URL handling
|
||||
if (attributeValue.startsWith("http")) {
|
||||
try {
|
||||
// If invalid URL, exception will be raised
|
||||
const url = new URL(attributeValue);
|
||||
if (url.protocol === "http:" || url.protocol === "https:")
|
||||
return html`<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href=${attributeValue}
|
||||
>${attributeValue}</a
|
||||
>`;
|
||||
} catch (_) {
|
||||
// Nothing to do here
|
||||
}
|
||||
}
|
||||
|
||||
// Date handling
|
||||
if (isDate(attributeValue, true)) {
|
||||
// Timestamp handling
|
||||
@@ -81,13 +100,8 @@ export const computeAttributeValueDisplay = (
|
||||
attributeValue.some((val) => val instanceof Object)) ||
|
||||
(!Array.isArray(attributeValue) && attributeValue instanceof Object)
|
||||
) {
|
||||
if (!jsYamlPromise) {
|
||||
jsYamlPromise = import("../../resources/js-yaml-dump");
|
||||
}
|
||||
const yaml = jsYamlPromise.then((jsYaml) => jsYaml.dump(attributeValue));
|
||||
return html`<pre>${until(yaml, "")}</pre>`;
|
||||
return JSON.stringify(attributeValue);
|
||||
}
|
||||
|
||||
// If this is an array, try to determine the display value for each item
|
||||
if (Array.isArray(attributeValue)) {
|
||||
return attributeValue
|
||||
|
@@ -26,6 +26,7 @@ export const FIXED_DOMAIN_STATES = {
|
||||
humidifier: ["on", "off"],
|
||||
input_boolean: ["on", "off"],
|
||||
input_button: [],
|
||||
lawn_mower: ["error", "paused", "mowing", "docked"],
|
||||
light: ["on", "off"],
|
||||
lock: ["jammed", "locked", "locking", "unlocked", "unlocking"],
|
||||
media_player: [
|
||||
|
@@ -34,6 +34,8 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||
case "device_tracker":
|
||||
case "person":
|
||||
return compareState !== "not_home";
|
||||
case "lawn_mower":
|
||||
return ["mowing", "error"].includes(compareState);
|
||||
case "lock":
|
||||
return compareState !== "locked";
|
||||
case "media_player":
|
||||
|
@@ -22,6 +22,7 @@ const STATE_COLORED_DOMAIN = new Set([
|
||||
"group",
|
||||
"humidifier",
|
||||
"input_boolean",
|
||||
"lawn_mower",
|
||||
"light",
|
||||
"lock",
|
||||
"media_player",
|
||||
@@ -36,6 +37,7 @@ const STATE_COLORED_DOMAIN = new Set([
|
||||
"timer",
|
||||
"update",
|
||||
"vacuum",
|
||||
"water_heater",
|
||||
]);
|
||||
|
||||
export const stateColorCss = (stateObj: HassEntity, state?: string) => {
|
||||
|
@@ -4,7 +4,7 @@ export const clamp = (value: number, min: number, max: number) =>
|
||||
// Variant that only applies the clamping to a border if the border is defined
|
||||
export const conditionalClamp = (value: number, min?: number, max?: number) => {
|
||||
let result: number;
|
||||
result = min ? Math.max(value, min) : value;
|
||||
result = max ? Math.min(result, max) : result;
|
||||
result = min != null ? Math.max(value, min) : value;
|
||||
result = max != null ? Math.min(result, max) : result;
|
||||
return result;
|
||||
};
|
||||
|
@@ -108,7 +108,7 @@ export const formatNumber = (
|
||||
* @returns An `Intl.NumberFormatOptions` object with `maximumFractionDigits` set to 0, or `undefined`
|
||||
*/
|
||||
export const getNumberFormatOptions = (
|
||||
entityState: HassEntity,
|
||||
entityState?: HassEntity,
|
||||
entity?: EntityRegistryDisplayEntry
|
||||
): Intl.NumberFormatOptions | undefined => {
|
||||
const precision = entity?.display_precision;
|
||||
@@ -119,8 +119,8 @@ export const getNumberFormatOptions = (
|
||||
};
|
||||
}
|
||||
if (
|
||||
Number.isInteger(Number(entityState.attributes?.step)) &&
|
||||
Number.isInteger(Number(entityState.state))
|
||||
Number.isInteger(Number(entityState?.attributes?.step)) &&
|
||||
Number.isInteger(Number(entityState?.state))
|
||||
) {
|
||||
return { maximumFractionDigits: 0 };
|
||||
}
|
||||
|
52
src/common/translations/entity-state.ts
Normal file
52
src/common/translations/entity-state.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
|
||||
import type { FrontendLocaleData } from "../../data/translation";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import type { LocalizeFunc } from "./localize";
|
||||
|
||||
export type FormatEntityStateFunc = (
|
||||
stateObj: HassEntity,
|
||||
state?: string
|
||||
) => string;
|
||||
export type FormatEntityAttributeValueFunc = (
|
||||
stateObj: HassEntity,
|
||||
attribute: string,
|
||||
value?: any
|
||||
) => string;
|
||||
export type formatEntityAttributeNameFunc = (
|
||||
stateObj: HassEntity,
|
||||
attribute: string
|
||||
) => string;
|
||||
|
||||
export const computeFormatFunctions = async (
|
||||
localize: LocalizeFunc,
|
||||
locale: FrontendLocaleData,
|
||||
config: HassConfig,
|
||||
entities: HomeAssistant["entities"]
|
||||
): Promise<{
|
||||
formatEntityState: FormatEntityStateFunc;
|
||||
formatEntityAttributeValue: FormatEntityAttributeValueFunc;
|
||||
formatEntityAttributeName: formatEntityAttributeNameFunc;
|
||||
}> => {
|
||||
const { computeStateDisplay } = await import(
|
||||
"../entity/compute_state_display"
|
||||
);
|
||||
const { computeAttributeValueDisplay, computeAttributeNameDisplay } =
|
||||
await import("../entity/compute_attribute_display");
|
||||
|
||||
return {
|
||||
formatEntityState: (stateObj, state) =>
|
||||
computeStateDisplay(localize, stateObj, locale, config, entities, state),
|
||||
formatEntityAttributeValue: (stateObj, attribute, value) =>
|
||||
computeAttributeValueDisplay(
|
||||
localize,
|
||||
stateObj,
|
||||
locale,
|
||||
config,
|
||||
entities,
|
||||
attribute,
|
||||
value
|
||||
),
|
||||
formatEntityAttributeName: (stateObj, attribute) =>
|
||||
computeAttributeNameDisplay(localize, stateObj, entities, attribute),
|
||||
};
|
||||
};
|
@@ -11,23 +11,18 @@ export type LocalizeKeys =
|
||||
| `ui.card.alarm_control_panel.${string}`
|
||||
| `ui.card.weather.attributes.${string}`
|
||||
| `ui.card.weather.cardinal_direction.${string}`
|
||||
| `ui.card.lawn_mower.actions.${string}`
|
||||
| `ui.components.calendar.event.rrule.${string}`
|
||||
| `ui.components.logbook.${string}`
|
||||
| `ui.components.selectors.file.${string}`
|
||||
| `ui.dialogs.entity_registry.editor.${string}`
|
||||
| `ui.dialogs.more_info_control.lawn_mower.${string}`
|
||||
| `ui.dialogs.more_info_control.vacuum.${string}`
|
||||
| `ui.dialogs.quick-bar.commands.${string}`
|
||||
| `ui.dialogs.unhealthy.reason.${string}`
|
||||
| `ui.dialogs.unsupported.reason.${string}`
|
||||
| `ui.panel.config.${string}.${"caption" | "description"}`
|
||||
| `ui.panel.config.automation.${string}`
|
||||
| `ui.panel.config.dashboard.${string}`
|
||||
| `ui.panel.config.devices.${string}`
|
||||
| `ui.panel.config.energy.${string}`
|
||||
| `ui.panel.config.info.${string}`
|
||||
| `ui.panel.config.lovelace.${string}`
|
||||
| `ui.panel.config.network.${string}`
|
||||
| `ui.panel.config.scene.${string}`
|
||||
| `ui.panel.config.zha.${string}`
|
||||
| `ui.panel.config.zwave_js.${string}`
|
||||
| `ui.panel.lovelace.card.${string}`
|
||||
|
@@ -1,100 +0,0 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
/* eslint-plugin-disable lit */
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
||||
import { EventsMixin } from "../../mixins/events-mixin";
|
||||
import "./ha-progress-button";
|
||||
|
||||
/*
|
||||
* @appliesMixin EventsMixin
|
||||
*/
|
||||
class HaCallServiceButton extends EventsMixin(PolymerElement) {
|
||||
static get template() {
|
||||
return html`
|
||||
<ha-progress-button
|
||||
id="progress"
|
||||
progress="[[progress]]"
|
||||
disabled="[[disabled]]"
|
||||
on-click="buttonTapped"
|
||||
tabindex="0"
|
||||
><slot></slot
|
||||
></ha-progress-button>
|
||||
`;
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
hass: {
|
||||
type: Object,
|
||||
},
|
||||
|
||||
progress: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
|
||||
domain: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
service: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
serviceData: {
|
||||
type: Object,
|
||||
value: {},
|
||||
},
|
||||
|
||||
confirmation: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
callService() {
|
||||
this.progress = true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const el = this;
|
||||
const eventData = {
|
||||
domain: this.domain,
|
||||
service: this.service,
|
||||
serviceData: this.serviceData,
|
||||
};
|
||||
|
||||
this.hass
|
||||
.callService(this.domain, this.service, this.serviceData)
|
||||
.then(
|
||||
() => {
|
||||
el.progress = false;
|
||||
el.$.progress.actionSuccess();
|
||||
eventData.success = true;
|
||||
},
|
||||
() => {
|
||||
el.progress = false;
|
||||
el.$.progress.actionError();
|
||||
eventData.success = false;
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
el.fire("hass-service-called", eventData);
|
||||
});
|
||||
}
|
||||
|
||||
buttonTapped() {
|
||||
if (this.confirmation) {
|
||||
showConfirmationDialog(this, {
|
||||
text: this.confirmation,
|
||||
confirm: () => this.callService(),
|
||||
});
|
||||
} else {
|
||||
this.callService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("ha-call-service-button", HaCallServiceButton);
|
92
src/components/buttons/ha-call-service-button.ts
Normal file
92
src/components/buttons/ha-call-service-button.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { LitElement, TemplateResult, html } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
||||
import "./ha-progress-button";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
|
||||
@customElement("ha-call-service-button")
|
||||
class HaCallServiceButton extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
@property({ type: Boolean }) public progress = false;
|
||||
|
||||
@property() public domain!: string;
|
||||
|
||||
@property() public service!: string;
|
||||
|
||||
@property({ type: Object }) public serviceData = {};
|
||||
|
||||
@property() public confirmation?;
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
<ha-progress-button
|
||||
.progress=${this.progress}
|
||||
.disabled=${this.disabled}
|
||||
@click=${this._buttonTapped}
|
||||
tabindex="0"
|
||||
>
|
||||
<slot></slot
|
||||
></ha-progress-button>
|
||||
`;
|
||||
}
|
||||
|
||||
private async _callService() {
|
||||
this.progress = true;
|
||||
const eventData = {
|
||||
domain: this.domain,
|
||||
service: this.service,
|
||||
serviceData: this.serviceData,
|
||||
success: false,
|
||||
};
|
||||
|
||||
const progressElement =
|
||||
this.shadowRoot!.querySelector("ha-progress-button")!;
|
||||
|
||||
try {
|
||||
await this.hass.callService(this.domain, this.service, this.serviceData);
|
||||
this.progress = false;
|
||||
progressElement.actionSuccess();
|
||||
eventData.success = true;
|
||||
} catch (e) {
|
||||
this.progress = false;
|
||||
progressElement.actionError();
|
||||
eventData.success = false;
|
||||
return;
|
||||
} finally {
|
||||
fireEvent(this, "hass-service-called", eventData);
|
||||
}
|
||||
}
|
||||
|
||||
private _buttonTapped() {
|
||||
if (this.confirmation) {
|
||||
showConfirmationDialog(this, {
|
||||
text: this.confirmation,
|
||||
confirm: () => this._callService(),
|
||||
});
|
||||
} else {
|
||||
this._callService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-call-service-button": HaCallServiceButton;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
// for fire event
|
||||
interface HASSDomEvents {
|
||||
"hass-service-called": {
|
||||
domain: string;
|
||||
service: string;
|
||||
serviceData: object;
|
||||
success: boolean;
|
||||
};
|
||||
}
|
||||
}
|
@@ -15,13 +15,20 @@ import { HomeAssistant } from "../../types";
|
||||
|
||||
export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000;
|
||||
|
||||
interface Tooltip extends TooltipModel<any> {
|
||||
export interface ChartResizeOptions {
|
||||
aspectRatio?: number;
|
||||
height?: number;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
interface Tooltip
|
||||
extends Omit<TooltipModel<any>, "tooltipPosition" | "hasValue" | "getProps"> {
|
||||
top: string;
|
||||
left: string;
|
||||
}
|
||||
|
||||
@customElement("ha-chart-base")
|
||||
export default class HaChartBase extends LitElement {
|
||||
export class HaChartBase extends LitElement {
|
||||
public chart?: Chart;
|
||||
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@@ -45,14 +52,6 @@ export default class HaChartBase extends LitElement {
|
||||
|
||||
@state() private _hiddenDatasets: Set<number> = new Set();
|
||||
|
||||
private _releaseCanvas() {
|
||||
// release the canvas memory to prevent
|
||||
// safari from running out of memory.
|
||||
if (this.chart) {
|
||||
this.chart.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
this._releaseCanvas();
|
||||
super.disconnectedCallback();
|
||||
@@ -65,6 +64,36 @@ export default class HaChartBase extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
public updateChart = (
|
||||
mode:
|
||||
| "resize"
|
||||
| "reset"
|
||||
| "none"
|
||||
| "hide"
|
||||
| "show"
|
||||
| "default"
|
||||
| "active"
|
||||
| undefined
|
||||
): void => {
|
||||
this.chart?.update(mode);
|
||||
};
|
||||
|
||||
public resize = (options?: ChartResizeOptions): void => {
|
||||
if (options?.aspectRatio && !options.height) {
|
||||
options.height = Math.round(
|
||||
(options.width ?? this.clientWidth) / options.aspectRatio
|
||||
);
|
||||
} else if (options?.aspectRatio && !options.width) {
|
||||
options.width = Math.round(
|
||||
(options.height ?? this.clientHeight) * options.aspectRatio
|
||||
);
|
||||
}
|
||||
this.chart?.resize(
|
||||
options?.width ?? this.clientWidth,
|
||||
options?.height ?? this.clientHeight
|
||||
);
|
||||
};
|
||||
|
||||
protected firstUpdated() {
|
||||
this._setupChart();
|
||||
this.data.datasets.forEach((dataset, index) => {
|
||||
@@ -80,14 +109,11 @@ export default class HaChartBase extends LitElement {
|
||||
if (!this.hasUpdated || !this.chart) {
|
||||
return;
|
||||
}
|
||||
if (changedProps.has("plugins")) {
|
||||
if (changedProps.has("plugins") || changedProps.has("chartType")) {
|
||||
this.chart.destroy();
|
||||
this._setupChart();
|
||||
return;
|
||||
}
|
||||
if (changedProps.has("chartType")) {
|
||||
this.chart.config.type = this.chartType;
|
||||
}
|
||||
if (changedProps.has("data")) {
|
||||
if (this._hiddenDatasets.size) {
|
||||
this.data.datasets.forEach((dataset, index) => {
|
||||
@@ -131,55 +157,70 @@ export default class HaChartBase extends LitElement {
|
||||
</div>`
|
||||
: ""}
|
||||
<div
|
||||
class="chartContainer"
|
||||
class="animationContainer"
|
||||
style=${styleMap({
|
||||
height: `${this.height ?? this._chartHeight}px`,
|
||||
height: `${this.height || this._chartHeight || 0}px`,
|
||||
overflow: this._chartHeight ? "initial" : "hidden",
|
||||
"padding-left": `${computeRTL(this.hass) ? 0 : this.paddingYAxis}px`,
|
||||
"padding-right": `${computeRTL(this.hass) ? this.paddingYAxis : 0}px`,
|
||||
})}
|
||||
>
|
||||
<canvas></canvas>
|
||||
${this._tooltip
|
||||
? html`<div
|
||||
class="chartTooltip ${classMap({ [this._tooltip.yAlign]: true })}"
|
||||
style=${styleMap({
|
||||
top: this._tooltip.top,
|
||||
left: this._tooltip.left,
|
||||
})}
|
||||
>
|
||||
<div class="title">${this._tooltip.title}</div>
|
||||
${this._tooltip.beforeBody
|
||||
? html`<div class="beforeBody">
|
||||
${this._tooltip.beforeBody}
|
||||
</div>`
|
||||
: ""}
|
||||
<div>
|
||||
<ul>
|
||||
${this._tooltip.body.map(
|
||||
(item, i) =>
|
||||
html`<li>
|
||||
<div
|
||||
class="bullet"
|
||||
style=${styleMap({
|
||||
backgroundColor: this._tooltip!.labelColors[i]
|
||||
.backgroundColor as string,
|
||||
borderColor: this._tooltip!.labelColors[i]
|
||||
.borderColor as string,
|
||||
})}
|
||||
></div>
|
||||
${item.lines.join("\n")}
|
||||
</li>`
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
${this._tooltip.footer.length
|
||||
? html`<div class="footer">
|
||||
${this._tooltip.footer.map((item) => html`${item}<br />`)}
|
||||
</div>`
|
||||
: ""}
|
||||
</div>`
|
||||
: ""}
|
||||
<div
|
||||
class="chartContainer"
|
||||
style=${styleMap({
|
||||
height: `${
|
||||
this.height ?? this._chartHeight ?? this.clientWidth / 2
|
||||
}px`,
|
||||
"padding-left": `${
|
||||
computeRTL(this.hass) ? 0 : this.paddingYAxis
|
||||
}px`,
|
||||
"padding-right": `${
|
||||
computeRTL(this.hass) ? this.paddingYAxis : 0
|
||||
}px`,
|
||||
})}
|
||||
>
|
||||
<canvas></canvas>
|
||||
${this._tooltip
|
||||
? html`<div
|
||||
class="chartTooltip ${classMap({
|
||||
[this._tooltip.yAlign]: true,
|
||||
})}"
|
||||
style=${styleMap({
|
||||
top: this._tooltip.top,
|
||||
left: this._tooltip.left,
|
||||
})}
|
||||
>
|
||||
<div class="title">${this._tooltip.title}</div>
|
||||
${this._tooltip.beforeBody
|
||||
? html`<div class="beforeBody">
|
||||
${this._tooltip.beforeBody}
|
||||
</div>`
|
||||
: ""}
|
||||
<div>
|
||||
<ul>
|
||||
${this._tooltip.body.map(
|
||||
(item, i) =>
|
||||
html`<li>
|
||||
<div
|
||||
class="bullet"
|
||||
style=${styleMap({
|
||||
backgroundColor: this._tooltip!.labelColors[i]
|
||||
.backgroundColor as string,
|
||||
borderColor: this._tooltip!.labelColors[i]
|
||||
.borderColor as string,
|
||||
})}
|
||||
></div>
|
||||
${item.lines.join("\n")}
|
||||
</li>`
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
${this._tooltip.footer.length
|
||||
? html`<div class="footer">
|
||||
${this._tooltip.footer.map((item) => html`${item}<br />`)}
|
||||
</div>`
|
||||
: ""}
|
||||
</div>`
|
||||
: ""}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -213,6 +254,7 @@ export default class HaChartBase extends LitElement {
|
||||
|
||||
private _createOptions() {
|
||||
return {
|
||||
maintainAspectRatio: false,
|
||||
...this.options,
|
||||
plugins: {
|
||||
...this.options?.plugins,
|
||||
@@ -233,10 +275,10 @@ export default class HaChartBase extends LitElement {
|
||||
return [
|
||||
...(this.plugins || []),
|
||||
{
|
||||
id: "afterRenderHook",
|
||||
afterRender: (chart) => {
|
||||
id: "resizeHook",
|
||||
resize: (chart) => {
|
||||
const change = chart.height - (this._chartHeight ?? 0);
|
||||
if (!this._chartHeight || change > 0 || change < -12) {
|
||||
if (!this._chartHeight || change > 12 || change < -12) {
|
||||
// hysteresis to prevent infinite render loops
|
||||
this._chartHeight = chart.height;
|
||||
}
|
||||
@@ -288,21 +330,13 @@ export default class HaChartBase extends LitElement {
|
||||
};
|
||||
}
|
||||
|
||||
public updateChart = (
|
||||
mode:
|
||||
| "resize"
|
||||
| "reset"
|
||||
| "none"
|
||||
| "hide"
|
||||
| "show"
|
||||
| "normal"
|
||||
| "active"
|
||||
| undefined
|
||||
): void => {
|
||||
private _releaseCanvas() {
|
||||
// release the canvas memory to prevent
|
||||
// safari from running out of memory.
|
||||
if (this.chart) {
|
||||
this.chart.update(mode);
|
||||
this.chart.destroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
@@ -310,7 +344,7 @@ export default class HaChartBase extends LitElement {
|
||||
display: block;
|
||||
position: var(--chart-base-position, relative);
|
||||
}
|
||||
.chartContainer {
|
||||
.animationContainer {
|
||||
overflow: hidden;
|
||||
height: 0;
|
||||
transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
@@ -1,23 +1,28 @@
|
||||
import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
|
||||
import { html, LitElement, PropertyValues } from "lit";
|
||||
import { property, state } from "lit/decorators";
|
||||
import { property, query, state } from "lit/decorators";
|
||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeRTL } from "../../common/util/compute_rtl";
|
||||
import {
|
||||
formatNumber,
|
||||
numberFormatToLocale,
|
||||
getNumberFormatOptions,
|
||||
} from "../../common/number/format_number";
|
||||
import { LineChartEntity, LineChartState } from "../../data/history";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
||||
import {
|
||||
ChartResizeOptions,
|
||||
HaChartBase,
|
||||
MIN_TIME_BETWEEN_UPDATES,
|
||||
} from "./ha-chart-base";
|
||||
|
||||
const safeParseFloat = (value) => {
|
||||
const parsed = parseFloat(value);
|
||||
return isFinite(parsed) ? parsed : null;
|
||||
};
|
||||
|
||||
class StateHistoryChartLine extends LitElement {
|
||||
export class StateHistoryChartLine extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public data: LineChartEntity[] = [];
|
||||
@@ -46,6 +51,12 @@ class StateHistoryChartLine extends LitElement {
|
||||
|
||||
private _chartTime: Date = new Date();
|
||||
|
||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||
|
||||
public resize = (options?: ChartResizeOptions): void => {
|
||||
this._chart?.resize(options);
|
||||
};
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
<ha-chart-base
|
||||
@@ -125,7 +136,17 @@ class StateHistoryChartLine extends LitElement {
|
||||
label: (context) =>
|
||||
`${context.dataset.label}: ${formatNumber(
|
||||
context.parsed.y,
|
||||
this.hass.locale
|
||||
this.hass.locale,
|
||||
this.data[context.datasetIndex]?.entity_id
|
||||
? getNumberFormatOptions(
|
||||
this.hass.states[
|
||||
this.data[context.datasetIndex].entity_id
|
||||
],
|
||||
this.hass.entities[
|
||||
this.data[context.datasetIndex].entity_id
|
||||
]
|
||||
)
|
||||
: undefined
|
||||
)} ${this.unit}`,
|
||||
},
|
||||
},
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
|
||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
|
||||
import millisecondsToDuration from "../../common/datetime/milliseconds_to_duration";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
@@ -8,7 +8,11 @@ import { numberFormatToLocale } from "../../common/number/format_number";
|
||||
import { computeRTL } from "../../common/util/compute_rtl";
|
||||
import { TimelineEntity } from "../../data/history";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import { MIN_TIME_BETWEEN_UPDATES } from "./ha-chart-base";
|
||||
import {
|
||||
ChartResizeOptions,
|
||||
HaChartBase,
|
||||
MIN_TIME_BETWEEN_UPDATES,
|
||||
} from "./ha-chart-base";
|
||||
import type { TimeLineData } from "./timeline-chart/const";
|
||||
import { computeTimelineColor } from "./timeline-chart/timeline-color";
|
||||
|
||||
@@ -46,6 +50,12 @@ export class StateHistoryChartTimeline extends LitElement {
|
||||
|
||||
private _chartTime: Date = new Date();
|
||||
|
||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||
|
||||
public resize = (options?: ChartResizeOptions): void => {
|
||||
this._chart?.resize(options);
|
||||
};
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
<ha-chart-base
|
||||
|
@@ -6,7 +6,13 @@ import {
|
||||
nothing,
|
||||
PropertyValues,
|
||||
} from "lit";
|
||||
import { customElement, eventOptions, property, state } from "lit/decorators";
|
||||
import {
|
||||
customElement,
|
||||
eventOptions,
|
||||
property,
|
||||
queryAll,
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
||||
import {
|
||||
@@ -18,6 +24,9 @@ import { loadVirtualizer } from "../../resources/virtualizer";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "./state-history-chart-line";
|
||||
import "./state-history-chart-timeline";
|
||||
import type { StateHistoryChartLine } from "./state-history-chart-line";
|
||||
import type { StateHistoryChartTimeline } from "./state-history-chart-timeline";
|
||||
import { ChartResizeOptions } from "./ha-chart-base";
|
||||
|
||||
const CANVAS_TIMELINE_ROWS_CHUNK = 10; // Split up the canvases to avoid hitting the render limit
|
||||
|
||||
@@ -75,6 +84,16 @@ export class StateHistoryCharts extends LitElement {
|
||||
// @ts-ignore
|
||||
@restoreScroll(".container") private _savedScrollPos?: number;
|
||||
|
||||
@queryAll("state-history-chart-line")
|
||||
private _charts?: StateHistoryChartLine[];
|
||||
|
||||
public resize = (options?: ChartResizeOptions): void => {
|
||||
this._charts?.forEach(
|
||||
(chart: StateHistoryChartLine | StateHistoryChartTimeline) =>
|
||||
chart.resize(options)
|
||||
);
|
||||
};
|
||||
|
||||
protected render() {
|
||||
if (!isComponentLoaded(this.hass, "history")) {
|
||||
return html`<div class="info">
|
||||
|
@@ -12,7 +12,7 @@ import {
|
||||
PropertyValues,
|
||||
TemplateResult,
|
||||
} from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, state, query } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { getGraphColorByIndex } from "../../common/color/colors";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
} from "../../data/recorder";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "./ha-chart-base";
|
||||
import type { ChartResizeOptions, HaChartBase } from "./ha-chart-base";
|
||||
|
||||
export const supportedStatTypeMap: Record<StatisticType, StatisticType> = {
|
||||
mean: "mean",
|
||||
@@ -42,7 +43,7 @@ export const supportedStatTypeMap: Record<StatisticType, StatisticType> = {
|
||||
};
|
||||
|
||||
@customElement("statistics-chart")
|
||||
class StatisticsChart extends LitElement {
|
||||
export class StatisticsChart extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public statisticsData?: Statistics;
|
||||
@@ -75,8 +76,14 @@ class StatisticsChart extends LitElement {
|
||||
|
||||
@state() private _chartOptions?: ChartOptions;
|
||||
|
||||
@query("ha-chart-base") private _chart?: HaChartBase;
|
||||
|
||||
private _computedStyle?: CSSStyleDeclaration;
|
||||
|
||||
public resize = (options?: ChartResizeOptions): void => {
|
||||
this._chart?.resize(options);
|
||||
};
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
return changedProps.size > 1 || !changedProps.has("hass");
|
||||
}
|
||||
@@ -329,8 +336,14 @@ class StatisticsChart extends LitElement {
|
||||
|
||||
const statTypes: this["statTypes"] = [];
|
||||
|
||||
const drawBands =
|
||||
const hasMean =
|
||||
this.statTypes.includes("mean") && statisticsHaveType(stats, "mean");
|
||||
const drawBands =
|
||||
hasMean ||
|
||||
(this.statTypes.includes("min") &&
|
||||
statisticsHaveType(stats, "min") &&
|
||||
this.statTypes.includes("max") &&
|
||||
statisticsHaveType(stats, "max"));
|
||||
|
||||
const sortedTypes = drawBands
|
||||
? [...this.statTypes].sort((a, b) => {
|
||||
@@ -358,13 +371,14 @@ class StatisticsChart extends LitElement {
|
||||
`ui.components.statistics_charts.statistic_types.${type}`
|
||||
),
|
||||
fill: drawBands
|
||||
? type === "min"
|
||||
? type === "min" && hasMean
|
||||
? "+1"
|
||||
: type === "max"
|
||||
? "-1"
|
||||
: false
|
||||
: false,
|
||||
borderColor: band ? color + (this.hideLegend ? "00" : "7F") : color,
|
||||
borderColor:
|
||||
band && hasMean ? color + (this.hideLegend ? "00" : "7F") : color,
|
||||
backgroundColor: band ? color + "3F" : color + "7F",
|
||||
pointRadius: 0,
|
||||
data: [],
|
||||
|
@@ -1,3 +1,8 @@
|
||||
import type {
|
||||
BarControllerChartOptions,
|
||||
BarControllerDatasetOptions,
|
||||
} from "chart.js";
|
||||
|
||||
export interface TimeLineData {
|
||||
start: Date;
|
||||
end: Date;
|
||||
|
@@ -16,7 +16,7 @@ export interface TextBaroptions extends BarOptions {
|
||||
export class TextBarElement extends BarElement {
|
||||
static id = "textbar";
|
||||
|
||||
draw(ctx) {
|
||||
draw(ctx: CanvasRenderingContext2D) {
|
||||
super.draw(ctx);
|
||||
const options = this.options as TextBaroptions;
|
||||
const { x, y, base, width, text } = (
|
||||
|
@@ -2,6 +2,95 @@ import { BarController, BarElement } from "chart.js";
|
||||
import { TimeLineData } from "./const";
|
||||
import { TextBarProps } from "./textbar-element";
|
||||
|
||||
function borderProps(properties) {
|
||||
let reverse;
|
||||
let start;
|
||||
let end;
|
||||
let top;
|
||||
let bottom;
|
||||
if (properties.horizontal) {
|
||||
reverse = properties.base > properties.x;
|
||||
start = "left";
|
||||
end = "right";
|
||||
} else {
|
||||
reverse = properties.base < properties.y;
|
||||
start = "bottom";
|
||||
end = "top";
|
||||
}
|
||||
if (reverse) {
|
||||
top = "end";
|
||||
bottom = "start";
|
||||
} else {
|
||||
top = "start";
|
||||
bottom = "end";
|
||||
}
|
||||
return { start, end, reverse, top, bottom };
|
||||
}
|
||||
|
||||
function setBorderSkipped(properties, options, stack, index) {
|
||||
let edge = options.borderSkipped;
|
||||
const res = {};
|
||||
|
||||
if (!edge) {
|
||||
properties.borderSkipped = res;
|
||||
return;
|
||||
}
|
||||
|
||||
if (edge === true) {
|
||||
properties.borderSkipped = {
|
||||
top: true,
|
||||
right: true,
|
||||
bottom: true,
|
||||
left: true,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
const { start, end, reverse, top, bottom } = borderProps(properties);
|
||||
|
||||
if (edge === "middle" && stack) {
|
||||
properties.enableBorderRadius = true;
|
||||
if ((stack._top || 0) === index) {
|
||||
edge = top;
|
||||
} else if ((stack._bottom || 0) === index) {
|
||||
edge = bottom;
|
||||
} else {
|
||||
res[parseEdge(bottom, start, end, reverse)] = true;
|
||||
edge = top;
|
||||
}
|
||||
}
|
||||
|
||||
res[parseEdge(edge, start, end, reverse)] = true;
|
||||
properties.borderSkipped = res;
|
||||
}
|
||||
|
||||
function parseEdge(edge, a, b, reverse) {
|
||||
if (reverse) {
|
||||
edge = swap(edge, a, b);
|
||||
edge = startEnd(edge, b, a);
|
||||
} else {
|
||||
edge = startEnd(edge, a, b);
|
||||
}
|
||||
return edge;
|
||||
}
|
||||
|
||||
function swap(orig, v1, v2) {
|
||||
return orig === v1 ? v2 : orig === v2 ? v1 : orig;
|
||||
}
|
||||
|
||||
function startEnd(v, start, end) {
|
||||
return v === "start" ? start : v === "end" ? end : v;
|
||||
}
|
||||
|
||||
function setInflateAmount(
|
||||
properties,
|
||||
{ inflateAmount }: { inflateAmount?: string | number },
|
||||
ratio
|
||||
) {
|
||||
properties.inflateAmount =
|
||||
inflateAmount === "auto" ? (ratio === 1 ? 0.33 : 0) : inflateAmount;
|
||||
}
|
||||
|
||||
function parseValue(entry, item, vScale, i) {
|
||||
const startValue = vScale.parse(entry.start, i);
|
||||
const endValue = vScale.parse(entry.end, i);
|
||||
@@ -97,7 +186,7 @@ export class TimelineController extends BarController {
|
||||
bars: BarElement[],
|
||||
start: number,
|
||||
count: number,
|
||||
mode: "reset" | "resize" | "none" | "hide" | "show" | "normal" | "active"
|
||||
mode: "reset" | "resize" | "none" | "hide" | "show" | "default" | "active"
|
||||
) {
|
||||
const vScale = this._cachedMeta.vScale!;
|
||||
const iScale = this._cachedMeta.iScale!;
|
||||
@@ -114,15 +203,15 @@ export class TimelineController extends BarController {
|
||||
for (let index = start; index < start + count; index++) {
|
||||
const data = dataset.data[index] as TimeLineData;
|
||||
|
||||
// @ts-ignore
|
||||
const y = vScale.getPixelForValue(this.index);
|
||||
|
||||
// @ts-ignore
|
||||
const xStart = iScale.getPixelForValue(data.start.getTime());
|
||||
// @ts-ignore
|
||||
const xEnd = iScale.getPixelForValue(data.end.getTime());
|
||||
const width = xEnd - xStart;
|
||||
|
||||
const parsed = this.getParsed(index);
|
||||
const stack = (parsed._stacks || {})[vScale.axis];
|
||||
|
||||
const height = 10;
|
||||
|
||||
const properties: TextBarProps = {
|
||||
@@ -145,7 +234,10 @@ export class TimelineController extends BarController {
|
||||
backgroundColor: data.color,
|
||||
};
|
||||
}
|
||||
const options = properties.options || bars[index].options;
|
||||
|
||||
setBorderSkipped(properties, options, stack, index);
|
||||
setInflateAmount(properties, options, 1);
|
||||
this.updateElement(bars[index], index, properties as any, mode);
|
||||
}
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ export interface DataTableColumnData<T = any> extends DataTableSortColumnData {
|
||||
title: TemplateResult | string;
|
||||
label?: TemplateResult | string;
|
||||
type?: "numeric" | "icon" | "icon-button" | "overflow-menu" | "flex";
|
||||
template?: (data: any, row: T) => TemplateResult | string | typeof nothing;
|
||||
template?: (row: T) => TemplateResult | string | typeof nothing;
|
||||
width?: string;
|
||||
maxWidth?: string;
|
||||
grows?: boolean;
|
||||
@@ -431,7 +431,7 @@ export class HaDataTable extends LitElement {
|
||||
})
|
||||
: ""}
|
||||
>
|
||||
${column.template ? column.template(row[key], row) : row[key]}
|
||||
${column.template ? column.template(row) : row[key]}
|
||||
</div>
|
||||
`;
|
||||
})}
|
||||
@@ -458,7 +458,8 @@ export class HaDataTable extends LitElement {
|
||||
filteredData,
|
||||
this._sortColumns[this._sortColumn],
|
||||
this._sortDirection,
|
||||
this._sortColumn
|
||||
this._sortColumn,
|
||||
this.hass.locale.language
|
||||
)
|
||||
: filteredData;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
// To use comlink under ES5
|
||||
import "proxy-polyfill";
|
||||
import { expose } from "comlink";
|
||||
import "proxy-polyfill";
|
||||
import { stringCompare } from "../../common/string/compare";
|
||||
import type {
|
||||
ClonedDataTableColumnData,
|
||||
DataTableRowData,
|
||||
@@ -39,7 +40,8 @@ const sortData = (
|
||||
data: DataTableRowData[],
|
||||
column: ClonedDataTableColumnData,
|
||||
direction: SortingDirection,
|
||||
sortColumn: string
|
||||
sortColumn: string,
|
||||
language?: string
|
||||
) =>
|
||||
data.sort((a, b) => {
|
||||
let sort = 1;
|
||||
@@ -58,13 +60,8 @@ const sortData = (
|
||||
if (column.type === "numeric") {
|
||||
valA = isNaN(valA) ? undefined : Number(valA);
|
||||
valB = isNaN(valB) ? undefined : Number(valB);
|
||||
} else {
|
||||
if (typeof valA === "string") {
|
||||
valA = valA.toUpperCase();
|
||||
}
|
||||
if (typeof valB === "string") {
|
||||
valB = valB.toUpperCase();
|
||||
}
|
||||
} else if (typeof valA === "string" && typeof valB === "string") {
|
||||
return sort * stringCompare(valA, valB, language);
|
||||
}
|
||||
|
||||
// Ensure "undefined" and "null" are always sorted to the bottom
|
||||
|
@@ -27,10 +27,12 @@ export const filterData = (
|
||||
filter: FilterDataParamTypes[2]
|
||||
): Promise<ReturnType<FilterDataType>> =>
|
||||
getWorker().filterData(data, columns, filter);
|
||||
|
||||
export const sortData = (
|
||||
data: SortDataParamTypes[0],
|
||||
columns: SortDataParamTypes[1],
|
||||
direction: SortDataParamTypes[2],
|
||||
sortColumn: SortDataParamTypes[3]
|
||||
sortColumn: SortDataParamTypes[3],
|
||||
language?: SortDataParamTypes[4]
|
||||
): Promise<ReturnType<SortDataType>> =>
|
||||
getWorker().sortData(data, columns, direction, sortColumn);
|
||||
getWorker().sortData(data, columns, direction, sortColumn, language);
|
||||
|
@@ -324,6 +324,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
.renderer=${rowRenderer}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
item-id-path="id"
|
||||
item-value-path="id"
|
||||
item-label-path="name"
|
||||
@opened-changed=${this._openedChanged}
|
||||
|
@@ -1,11 +1,9 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, PropertyValues, nothing } from "lit";
|
||||
import { LitElement, PropertyValues, html, nothing } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeStateDisplay } from "../../common/entity/compute_state_display";
|
||||
import { getStates } from "../../common/entity/get_states";
|
||||
import { computeAttributeValueDisplay } from "../../common/entity/compute_attribute_display";
|
||||
import { ValueChangedEvent, HomeAssistant } from "../../types";
|
||||
import { HomeAssistant, ValueChangedEvent } from "../../types";
|
||||
import "../ha-combo-box";
|
||||
import type { HaComboBox } from "../ha-combo-box";
|
||||
|
||||
@@ -58,20 +56,9 @@ class HaEntityStatePicker extends LitElement {
|
||||
? getStates(state, this.attribute).map((key) => ({
|
||||
value: key,
|
||||
label: !this.attribute
|
||||
? computeStateDisplay(
|
||||
this.hass.localize,
|
||||
? this.hass.formatEntityState(state, key)
|
||||
: this.hass.formatEntityAttributeValue(
|
||||
state,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities,
|
||||
key
|
||||
)
|
||||
: computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
state,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities,
|
||||
this.attribute,
|
||||
key
|
||||
),
|
||||
|
@@ -12,7 +12,6 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { arrayLiteralIncludes } from "../../common/array/literal-includes";
|
||||
import secondsToDuration from "../../common/datetime/seconds_to_duration";
|
||||
import { computeStateDisplay } from "../../common/entity/compute_state_display";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
|
||||
@@ -62,6 +61,8 @@ export class HaStateLabelBadge extends LitElement {
|
||||
|
||||
@property() public image?: string;
|
||||
|
||||
@property() public showName?: boolean;
|
||||
|
||||
@state() private _timerTimeRemaining?: number;
|
||||
|
||||
private _connected?: boolean;
|
||||
@@ -132,7 +133,9 @@ export class HaStateLabelBadge extends LitElement {
|
||||
entityState,
|
||||
this._timerTimeRemaining
|
||||
)}
|
||||
.description=${this.name ?? computeStateName(entityState)}
|
||||
.description=${this.showName === false
|
||||
? undefined
|
||||
: this.name ?? computeStateName(entityState)}
|
||||
>
|
||||
${!image && showIcon
|
||||
? html`<ha-state-icon
|
||||
@@ -188,13 +191,7 @@ export class HaStateLabelBadge extends LitElement {
|
||||
this.hass!.locale,
|
||||
getNumberFormatOptions(entityState, entry)
|
||||
)
|
||||
: computeStateDisplay(
|
||||
this.hass!.localize,
|
||||
entityState,
|
||||
this.hass!.locale,
|
||||
this.hass!.config,
|
||||
this.hass!.entities
|
||||
);
|
||||
: this.hass!.formatEntityState(entityState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||
import { html, LitElement, nothing, PropertyValues, TemplateResult } from "lit";
|
||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
@@ -79,6 +79,14 @@ export class HaStatisticPicker extends LitElement {
|
||||
@property({ type: Boolean, attribute: "entities-only" })
|
||||
public entitiesOnly = false;
|
||||
|
||||
/**
|
||||
* List of statistics to be excluded.
|
||||
* @type {Array}
|
||||
* @attr exclude-statistics
|
||||
*/
|
||||
@property({ type: Array, attribute: "exclude-statistics" })
|
||||
public excludeStatistics?: string[];
|
||||
|
||||
@state() private _opened?: boolean;
|
||||
|
||||
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
||||
@@ -87,6 +95,8 @@ export class HaStatisticPicker extends LitElement {
|
||||
|
||||
private _statistics: StatisticItem[] = [];
|
||||
|
||||
@state() private _filteredItems?: StatisticItem[] = undefined;
|
||||
|
||||
private _rowRenderer: ComboBoxLitRenderer<StatisticItem> = (item) =>
|
||||
html`<mwc-list-item graphic="avatar" twoline>
|
||||
${item.state
|
||||
@@ -116,7 +126,8 @@ export class HaStatisticPicker extends LitElement {
|
||||
includeStatisticsUnitOfMeasurement?: string | string[],
|
||||
includeUnitClass?: string | string[],
|
||||
includeDeviceClass?: string | string[],
|
||||
entitiesOnly?: boolean
|
||||
entitiesOnly?: boolean,
|
||||
excludeStatistics?: string[]
|
||||
): StatisticItem[] => {
|
||||
if (!statisticIds.length) {
|
||||
return [
|
||||
@@ -161,6 +172,12 @@ export class HaStatisticPicker extends LitElement {
|
||||
|
||||
const output: StatisticItem[] = [];
|
||||
statisticIds.forEach((meta) => {
|
||||
if (
|
||||
excludeStatistics &&
|
||||
excludeStatistics.includes(meta.statistic_id)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const entityState = this.hass.states[meta.statistic_id];
|
||||
if (!entityState) {
|
||||
if (!entitiesOnly) {
|
||||
@@ -238,7 +255,8 @@ export class HaStatisticPicker extends LitElement {
|
||||
this.includeStatisticsUnitOfMeasurement,
|
||||
this.includeUnitClass,
|
||||
this.includeDeviceClass,
|
||||
this.entitiesOnly
|
||||
this.entitiesOnly,
|
||||
this.excludeStatistics
|
||||
);
|
||||
} else {
|
||||
this.updateComplete.then(() => {
|
||||
@@ -247,14 +265,19 @@ export class HaStatisticPicker extends LitElement {
|
||||
this.includeStatisticsUnitOfMeasurement,
|
||||
this.includeUnitClass,
|
||||
this.includeDeviceClass,
|
||||
this.entitiesOnly
|
||||
this.entitiesOnly,
|
||||
this.excludeStatistics
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
protected render(): TemplateResult | typeof nothing {
|
||||
if (this._statistics.length === 0) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-combo-box
|
||||
.hass=${this.hass}
|
||||
@@ -265,9 +288,8 @@ export class HaStatisticPicker extends LitElement {
|
||||
.renderer=${this._rowRenderer}
|
||||
.disabled=${this.disabled}
|
||||
.allowCustomValue=${this.allowCustomEntity}
|
||||
.filteredItems=${this.value && this._statistics.length === 0
|
||||
? undefined
|
||||
: this._statistics}
|
||||
.items=${this._statistics}
|
||||
.filteredItems=${this._filteredItems ?? this._statistics}
|
||||
item-value-path="id"
|
||||
item-id-path="id"
|
||||
item-label-path="name"
|
||||
@@ -303,11 +325,10 @@ export class HaStatisticPicker extends LitElement {
|
||||
}
|
||||
|
||||
private _filterChanged(ev: CustomEvent): void {
|
||||
const target = ev.target as HaComboBox;
|
||||
const filterString = ev.detail.value.toLowerCase();
|
||||
target.filteredItems = filterString.length
|
||||
this._filteredItems = filterString.length
|
||||
? fuzzyFilterSort<StatisticItem>(filterString, this._statistics)
|
||||
: this._statistics;
|
||||
: undefined;
|
||||
}
|
||||
|
||||
private _setValue(value: string) {
|
||||
|
@@ -19,7 +19,7 @@ import {
|
||||
} from "../../common/entity/state_color";
|
||||
import { iconColorCSS } from "../../common/style/icon_color_css";
|
||||
import { cameraUrlWithWidthHeight } from "../../data/camera";
|
||||
import { HVAC_ACTION_TO_MODE } from "../../data/climate";
|
||||
import { CLIMATE_HVAC_ACTION_TO_MODE } from "../../data/climate";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "../ha-state-icon";
|
||||
|
||||
@@ -160,10 +160,10 @@ export class StateBadge extends LitElement {
|
||||
}
|
||||
if (stateObj.attributes.hvac_action) {
|
||||
const hvacAction = stateObj.attributes.hvac_action;
|
||||
if (hvacAction in HVAC_ACTION_TO_MODE) {
|
||||
if (hvacAction in CLIMATE_HVAC_ACTION_TO_MODE) {
|
||||
iconStyle.color = stateColorCss(
|
||||
stateObj,
|
||||
HVAC_ACTION_TO_MODE[hvacAction]
|
||||
CLIMATE_HVAC_ACTION_TO_MODE[hvacAction]
|
||||
)!;
|
||||
} else {
|
||||
delete iconStyle.color;
|
||||
|
73
src/components/ha-attribute-value.ts
Normal file
73
src/components/ha-attribute-value.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { until } from "lit/directives/until";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { formatNumber } from "../common/number/format_number";
|
||||
|
||||
let jsYamlPromise: Promise<typeof import("../resources/js-yaml-dump")>;
|
||||
|
||||
@customElement("ha-attribute-value")
|
||||
class HaAttributeValue extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public stateObj?: HassEntity;
|
||||
|
||||
@property() public attribute!: string;
|
||||
|
||||
@property({ type: Boolean, attribute: "hide-unit" })
|
||||
public hideUnit?: boolean;
|
||||
|
||||
protected render() {
|
||||
if (!this.stateObj) {
|
||||
return nothing;
|
||||
}
|
||||
const attributeValue = this.stateObj.attributes[this.attribute];
|
||||
|
||||
if (typeof attributeValue === "number" && this.hideUnit) {
|
||||
return formatNumber(attributeValue, this.hass.locale);
|
||||
}
|
||||
|
||||
if (typeof attributeValue === "string") {
|
||||
// URL handling
|
||||
if (attributeValue.startsWith("http")) {
|
||||
try {
|
||||
// If invalid URL, exception will be raised
|
||||
const url = new URL(attributeValue);
|
||||
if (url.protocol === "http:" || url.protocol === "https:")
|
||||
return html`
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href=${attributeValue}
|
||||
>
|
||||
${attributeValue}
|
||||
</a>
|
||||
`;
|
||||
} catch (_) {
|
||||
// Nothing to do here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(Array.isArray(attributeValue) &&
|
||||
attributeValue.some((val) => val instanceof Object)) ||
|
||||
(!Array.isArray(attributeValue) && attributeValue instanceof Object)
|
||||
) {
|
||||
if (!jsYamlPromise) {
|
||||
jsYamlPromise = import("../resources/js-yaml-dump");
|
||||
}
|
||||
const yaml = jsYamlPromise.then((jsYaml) => jsYaml.dump(attributeValue));
|
||||
return html`<pre>${until(yaml, "")}</pre>`;
|
||||
}
|
||||
|
||||
return this.hass.formatEntityAttributeValue(this.stateObj!, this.attribute);
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-attribute-value": HaAttributeValue;
|
||||
}
|
||||
}
|
@@ -1,14 +1,18 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import {
|
||||
computeAttributeNameDisplay,
|
||||
computeAttributeValueDisplay,
|
||||
} from "../common/entity/compute_attribute_display";
|
||||
css,
|
||||
CSSResultGroup,
|
||||
html,
|
||||
LitElement,
|
||||
nothing,
|
||||
PropertyValues,
|
||||
} from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
|
||||
import { STATE_ATTRIBUTES } from "../data/entity_attributes";
|
||||
import { haStyle } from "../resources/styles";
|
||||
import { HomeAssistant } from "../types";
|
||||
|
||||
import "./ha-attribute-value";
|
||||
import "./ha-expansion-panel";
|
||||
|
||||
@customElement("ha-attributes")
|
||||
@@ -21,16 +25,30 @@ class HaAttributes extends LitElement {
|
||||
|
||||
@state() private _expanded = false;
|
||||
|
||||
private get _filteredAttributes() {
|
||||
return this.computeDisplayAttributes(
|
||||
STATE_ATTRIBUTES.concat(
|
||||
this.extraFilters ? this.extraFilters.split(",") : []
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected willUpdate(changedProperties: PropertyValues): void {
|
||||
if (
|
||||
changedProperties.has("extraFilters") ||
|
||||
changedProperties.has("stateObj")
|
||||
) {
|
||||
this.toggleAttribute("empty", this._filteredAttributes.length === 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.stateObj) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const attributes = this.computeDisplayAttributes(
|
||||
STATE_ATTRIBUTES.concat(
|
||||
this.extraFilters ? this.extraFilters.split(",") : []
|
||||
)
|
||||
);
|
||||
const attributes = this._filteredAttributes;
|
||||
|
||||
if (attributes.length === 0) {
|
||||
return nothing;
|
||||
}
|
||||
@@ -58,14 +76,11 @@ class HaAttributes extends LitElement {
|
||||
)}
|
||||
</div>
|
||||
<div class="value">
|
||||
${computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj!,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities,
|
||||
attribute
|
||||
)}
|
||||
<ha-attribute-value
|
||||
.hass=${this.hass}
|
||||
.attribute=${attribute}
|
||||
.stateObj=${this.stateObj}
|
||||
></ha-attribute-value>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
@@ -1,138 +0,0 @@
|
||||
import { mdiChevronDown, mdiChevronUp } from "@mdi/js";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { conditionalClamp } from "../common/number/clamp";
|
||||
import { HomeAssistant } from "../types";
|
||||
import "./ha-icon";
|
||||
import "./ha-icon-button";
|
||||
|
||||
@customElement("ha-climate-control")
|
||||
class HaClimateControl extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public value!: number;
|
||||
|
||||
@property() public unit = "";
|
||||
|
||||
@property() public min?: number;
|
||||
|
||||
@property() public max?: number;
|
||||
|
||||
@property() public step = 1;
|
||||
|
||||
private _lastChanged?: number;
|
||||
|
||||
@query("#target_temperature") private _targetTemperature!: HTMLElement;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div id="target_temperature">${this.value} ${this.unit}</div>
|
||||
<div class="control-buttons">
|
||||
<div>
|
||||
<ha-icon-button
|
||||
.path=${mdiChevronUp}
|
||||
.label=${this.hass.localize(
|
||||
"ui.components.climate-control.temperature_up"
|
||||
)}
|
||||
@click=${this._incrementValue}
|
||||
>
|
||||
</ha-icon-button>
|
||||
</div>
|
||||
<div>
|
||||
<ha-icon-button
|
||||
.path=${mdiChevronDown}
|
||||
.label=${this.hass.localize(
|
||||
"ui.components.climate-control.temperature_down"
|
||||
)}
|
||||
@click=${this._decrementValue}
|
||||
>
|
||||
</ha-icon-button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
protected updated(changedProperties) {
|
||||
if (changedProperties.has("value")) {
|
||||
this._valueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private _temperatureStateInFlux(inFlux) {
|
||||
this._targetTemperature.classList.toggle("in-flux", inFlux);
|
||||
}
|
||||
|
||||
private _round(value) {
|
||||
// Round value to precision derived from step.
|
||||
// Inspired by https://github.com/soundar24/roundSlider/blob/master/src/roundslider.js
|
||||
const s = this.step.toString().split(".");
|
||||
return s[1] ? parseFloat(value.toFixed(s[1].length)) : Math.round(value);
|
||||
}
|
||||
|
||||
private _incrementValue() {
|
||||
const newValue = this._round(this.value + this.step);
|
||||
this._processNewValue(newValue);
|
||||
}
|
||||
|
||||
private _decrementValue() {
|
||||
const newValue = this._round(this.value - this.step);
|
||||
this._processNewValue(newValue);
|
||||
}
|
||||
|
||||
private _processNewValue(value) {
|
||||
const newValue = conditionalClamp(value, this.min, this.max);
|
||||
|
||||
if (this.value !== newValue) {
|
||||
this.value = newValue;
|
||||
this._lastChanged = Date.now();
|
||||
this._temperatureStateInFlux(true);
|
||||
}
|
||||
}
|
||||
|
||||
private _valueChanged() {
|
||||
// When the last_changed timestamp is changed,
|
||||
// trigger a potential event fire in the future,
|
||||
// as long as last_changed is far enough in the past.
|
||||
if (this._lastChanged) {
|
||||
window.setTimeout(() => {
|
||||
const now = Date.now();
|
||||
if (now - this._lastChanged! >= 2000) {
|
||||
fireEvent(this, "change");
|
||||
this._temperatureStateInFlux(false);
|
||||
this._lastChanged = undefined;
|
||||
}
|
||||
}, 2010);
|
||||
}
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.in-flux {
|
||||
color: var(--error-color);
|
||||
}
|
||||
#target_temperature {
|
||||
align-self: center;
|
||||
font-size: 28px;
|
||||
direction: ltr;
|
||||
}
|
||||
.control-buttons {
|
||||
font-size: 24px;
|
||||
text-align: right;
|
||||
}
|
||||
ha-icon-button {
|
||||
--mdc-icon-size: 32px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-climate-control": HaClimateControl;
|
||||
}
|
||||
}
|
@@ -1,11 +1,14 @@
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
html,
|
||||
LitElement,
|
||||
nothing,
|
||||
TemplateResult,
|
||||
} from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
|
||||
import { computeStateDisplay } from "../common/entity/compute_state_display";
|
||||
import { formatNumber } from "../common/number/format_number";
|
||||
import { blankBeforePercent } from "../common/translations/blank_before_percent";
|
||||
import { ClimateEntity, CLIMATE_PRESET_NONE } from "../data/climate";
|
||||
import { isUnavailableState } from "../data/entity";
|
||||
import { CLIMATE_PRESET_NONE, ClimateEntity } from "../data/climate";
|
||||
import { isUnavailableState, OFF } from "../data/entity";
|
||||
import type { HomeAssistant } from "../types";
|
||||
|
||||
@customElement("ha-climate-state")
|
||||
@@ -24,26 +27,24 @@ class HaClimateState extends LitElement {
|
||||
${this.stateObj.attributes.preset_mode &&
|
||||
this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
|
||||
? html`-
|
||||
${computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities,
|
||||
"preset_mode"
|
||||
)}`
|
||||
: ""}
|
||||
: nothing}
|
||||
</span>
|
||||
<div class="unit">${this._computeTarget()}</div>`
|
||||
: this._localizeState()}
|
||||
</div>
|
||||
|
||||
${currentStatus && !isUnavailableState(this.stateObj.state)
|
||||
? html`<div class="current">
|
||||
${this.hass.localize("ui.card.climate.currently")}:
|
||||
<div class="unit">${currentStatus}</div>
|
||||
</div>`
|
||||
: ""}`;
|
||||
? html`
|
||||
<div class="current">
|
||||
${this.hass.localize("ui.card.climate.currently")}:
|
||||
<div class="unit">${currentStatus}</div>
|
||||
</div>
|
||||
`
|
||||
: nothing}`;
|
||||
}
|
||||
|
||||
private _computeCurrentStatus(): string | undefined {
|
||||
@@ -54,28 +55,28 @@ class HaClimateState extends LitElement {
|
||||
this.stateObj.attributes.current_temperature != null &&
|
||||
this.stateObj.attributes.current_humidity != null
|
||||
) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.current_temperature,
|
||||
this.hass.locale
|
||||
)} ${this.hass.config.unit_system.temperature}/
|
||||
${formatNumber(
|
||||
this.stateObj.attributes.current_humidity,
|
||||
this.hass.locale
|
||||
)}${blankBeforePercent(this.hass.locale)}%`;
|
||||
return `${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"current_temperature"
|
||||
)}/
|
||||
${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"current_humidity"
|
||||
)}`;
|
||||
}
|
||||
|
||||
if (this.stateObj.attributes.current_temperature != null) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.current_temperature,
|
||||
this.hass.locale
|
||||
)} ${this.hass.config.unit_system.temperature}`;
|
||||
return this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"current_temperature"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.stateObj.attributes.current_humidity != null) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.current_humidity,
|
||||
this.hass.locale
|
||||
)}${blankBeforePercent(this.hass.locale)}%`;
|
||||
return this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"current_humidity"
|
||||
);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -90,39 +91,33 @@ class HaClimateState extends LitElement {
|
||||
this.stateObj.attributes.target_temp_low != null &&
|
||||
this.stateObj.attributes.target_temp_high != null
|
||||
) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.target_temp_low,
|
||||
this.hass.locale
|
||||
)}-${formatNumber(
|
||||
this.stateObj.attributes.target_temp_high,
|
||||
this.hass.locale
|
||||
)} ${this.hass.config.unit_system.temperature}`;
|
||||
return `${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"target_temp_low"
|
||||
)}-${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"target_temp_high"
|
||||
)}`;
|
||||
}
|
||||
|
||||
if (this.stateObj.attributes.temperature != null) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.temperature,
|
||||
this.hass.locale
|
||||
)} ${this.hass.config.unit_system.temperature}`;
|
||||
return this.hass.formatEntityAttributeValue(this.stateObj, "temperature");
|
||||
}
|
||||
if (
|
||||
this.stateObj.attributes.target_humidity_low != null &&
|
||||
this.stateObj.attributes.target_humidity_high != null
|
||||
) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.target_humidity_low,
|
||||
this.hass.locale
|
||||
)}-${formatNumber(
|
||||
this.stateObj.attributes.target_humidity_high,
|
||||
this.hass.locale
|
||||
)} %`;
|
||||
return `${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"target_humidity_low"
|
||||
)}-${this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"target_humidity_high"
|
||||
)}`;
|
||||
}
|
||||
|
||||
if (this.stateObj.attributes.humidity != null) {
|
||||
return `${formatNumber(
|
||||
this.stateObj.attributes.humidity,
|
||||
this.hass.locale
|
||||
)} %`;
|
||||
return this.hass.formatEntityAttributeValue(this.stateObj, "humidity");
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -133,24 +128,17 @@ class HaClimateState extends LitElement {
|
||||
return this.hass.localize(`state.default.${this.stateObj.state}`);
|
||||
}
|
||||
|
||||
const stateString = computeStateDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities
|
||||
);
|
||||
const stateString = this.hass.formatEntityState(this.stateObj);
|
||||
|
||||
return this.stateObj.attributes.hvac_action
|
||||
? `${computeAttributeValueDisplay(
|
||||
this.hass.localize,
|
||||
this.stateObj,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
this.hass.entities,
|
||||
"hvac_action"
|
||||
)} (${stateString})`
|
||||
: stateString;
|
||||
if (this.stateObj.attributes.hvac_action && this.stateObj.state !== OFF) {
|
||||
const actionString = this.hass.formatEntityAttributeValue(
|
||||
this.stateObj,
|
||||
"hvac_action"
|
||||
);
|
||||
return `${actionString} (${stateString})`;
|
||||
}
|
||||
|
||||
return stateString;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
|
@@ -4,7 +4,7 @@ import type {
|
||||
CompletionResult,
|
||||
CompletionSource,
|
||||
} from "@codemirror/autocomplete";
|
||||
import type { Extension } from "@codemirror/state";
|
||||
import type { Extension, TransactionSpec } from "@codemirror/state";
|
||||
import type { EditorView, KeyBinding, ViewUpdate } from "@codemirror/view";
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { css, CSSResultGroup, PropertyValues, ReactiveElement } from "lit";
|
||||
@@ -12,7 +12,7 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { stopPropagation } from "../common/dom/stop_propagation";
|
||||
import { loadCodeMirror } from "../resources/codemirror.ondemand";
|
||||
import { CodeMirror, loadCodeMirror } from "../resources/codemirror.ondemand";
|
||||
import { HomeAssistant } from "../types";
|
||||
import "./ha-icon";
|
||||
|
||||
@@ -54,11 +54,11 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
@property({ type: Boolean, attribute: "autocomplete-icons" })
|
||||
public autocompleteIcons = false;
|
||||
|
||||
@property() public error = false;
|
||||
@property({ type: Boolean }) public error = false;
|
||||
|
||||
@state() private _value = "";
|
||||
|
||||
private _loadedCodeMirror?: typeof import("../resources/codemirror");
|
||||
private _loadedCodeMirror?: CodeMirror;
|
||||
|
||||
private _iconList?: Completion[];
|
||||
|
||||
@@ -78,12 +78,19 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
this.codemirror.state,
|
||||
[this._loadedCodeMirror.tags.comment]
|
||||
);
|
||||
return !!this.shadowRoot!.querySelector(`span.${className}`);
|
||||
return !!this.renderRoot.querySelector(`span.${className}`);
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
// Force update on reconnection so editor is recreated
|
||||
if (this.hasUpdated) {
|
||||
this.requestUpdate();
|
||||
}
|
||||
this.addEventListener("keydown", stopPropagation);
|
||||
// This is unreachable as editor will not exist yet,
|
||||
// but focus should not behave like this for good a11y.
|
||||
// (@steverep to fix in autofocus PR)
|
||||
if (!this.codemirror) {
|
||||
return;
|
||||
}
|
||||
@@ -95,31 +102,41 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this.removeEventListener("keydown", stopPropagation);
|
||||
this.updateComplete.then(() => {
|
||||
this.codemirror!.destroy();
|
||||
delete this.codemirror;
|
||||
});
|
||||
}
|
||||
|
||||
// Ensure CodeMirror module is loaded before any update
|
||||
protected override async scheduleUpdate() {
|
||||
this._loadedCodeMirror ??= await loadCodeMirror();
|
||||
super.scheduleUpdate();
|
||||
}
|
||||
|
||||
protected update(changedProps: PropertyValues): void {
|
||||
super.update(changedProps);
|
||||
|
||||
if (!this.codemirror) {
|
||||
this._createCodeMirror();
|
||||
return;
|
||||
}
|
||||
|
||||
const transactions: TransactionSpec[] = [];
|
||||
if (changedProps.has("mode")) {
|
||||
this.codemirror.dispatch({
|
||||
transactions.push({
|
||||
effects: this._loadedCodeMirror!.langCompartment!.reconfigure(
|
||||
this._mode
|
||||
),
|
||||
});
|
||||
}
|
||||
if (changedProps.has("readOnly")) {
|
||||
this.codemirror.dispatch({
|
||||
transactions.push({
|
||||
effects: this._loadedCodeMirror!.readonlyCompartment!.reconfigure(
|
||||
this._loadedCodeMirror!.EditorView!.editable.of(!this.readOnly)
|
||||
),
|
||||
});
|
||||
}
|
||||
if (changedProps.has("_value") && this._value !== this.value) {
|
||||
this.codemirror.dispatch({
|
||||
transactions.push({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: this.codemirror.state.doc.length,
|
||||
@@ -127,46 +144,45 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
},
|
||||
});
|
||||
}
|
||||
if (transactions.length > 0) {
|
||||
this.codemirror.dispatch(...transactions);
|
||||
}
|
||||
if (changedProps.has("error")) {
|
||||
this.classList.toggle("error-state", this.error);
|
||||
}
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues): void {
|
||||
super.firstUpdated(changedProps);
|
||||
this._load();
|
||||
}
|
||||
|
||||
private get _mode() {
|
||||
return this._loadedCodeMirror!.langs[this.mode];
|
||||
}
|
||||
|
||||
private async _load(): Promise<void> {
|
||||
this._loadedCodeMirror = await loadCodeMirror();
|
||||
private _createCodeMirror() {
|
||||
if (!this._loadedCodeMirror) {
|
||||
throw new Error("Cannot create editor before CodeMirror is loaded");
|
||||
}
|
||||
const extensions: Extension[] = [
|
||||
this._loadedCodeMirror.lineNumbers(),
|
||||
this._loadedCodeMirror.EditorState.allowMultipleSelections.of(true),
|
||||
this._loadedCodeMirror.history(),
|
||||
this._loadedCodeMirror.drawSelection(),
|
||||
this._loadedCodeMirror.EditorState.allowMultipleSelections.of(true),
|
||||
this._loadedCodeMirror.rectangularSelection(),
|
||||
this._loadedCodeMirror.crosshairCursor(),
|
||||
this._loadedCodeMirror.highlightSelectionMatches(),
|
||||
this._loadedCodeMirror.highlightActiveLine(),
|
||||
this._loadedCodeMirror.drawSelection(),
|
||||
this._loadedCodeMirror.rectangularSelection(),
|
||||
this._loadedCodeMirror.keymap.of([
|
||||
...this._loadedCodeMirror.defaultKeymap,
|
||||
...this._loadedCodeMirror.searchKeymap,
|
||||
...this._loadedCodeMirror.historyKeymap,
|
||||
...this._loadedCodeMirror.tabKeyBindings,
|
||||
saveKeyBinding,
|
||||
] as KeyBinding[]),
|
||||
]),
|
||||
this._loadedCodeMirror.langCompartment.of(this._mode),
|
||||
this._loadedCodeMirror.haTheme,
|
||||
this._loadedCodeMirror.haSyntaxHighlighting,
|
||||
this._loadedCodeMirror.readonlyCompartment.of(
|
||||
this._loadedCodeMirror.EditorView.editable.of(!this.readOnly)
|
||||
),
|
||||
this._loadedCodeMirror.EditorView.updateListener.of((update) =>
|
||||
this._onUpdate(update)
|
||||
),
|
||||
this._loadedCodeMirror.EditorView.updateListener.of(this._onUpdate),
|
||||
];
|
||||
|
||||
if (!this.readOnly) {
|
||||
@@ -192,8 +208,7 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
doc: this._value,
|
||||
extensions,
|
||||
}),
|
||||
root: this.shadowRoot!,
|
||||
parent: this.shadowRoot!,
|
||||
parent: this.renderRoot,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -277,17 +292,13 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
};
|
||||
}
|
||||
|
||||
private _onUpdate(update: ViewUpdate): void {
|
||||
private _onUpdate = (update: ViewUpdate): void => {
|
||||
if (!update.docChanged) {
|
||||
return;
|
||||
}
|
||||
const newValue = this.value;
|
||||
if (newValue === this._value) {
|
||||
return;
|
||||
}
|
||||
this._value = newValue;
|
||||
this._value = update.state.doc.toString();
|
||||
fireEvent(this, "value-changed", { value: this._value });
|
||||
}
|
||||
};
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
|
@@ -244,7 +244,6 @@ export class HaComboBox extends LitElement {
|
||||
);
|
||||
|
||||
if (overlay) {
|
||||
overlay.setAttribute("required-vertical-space", "0");
|
||||
this._removeInert(overlay);
|
||||
}
|
||||
this._observeBody();
|
||||
@@ -312,6 +311,10 @@ export class HaComboBox extends LitElement {
|
||||
|
||||
private _valueChanged(ev: ComboBoxLightValueChangedEvent) {
|
||||
ev.stopPropagation();
|
||||
if (!this.allowCustomValue) {
|
||||
// @ts-ignore
|
||||
this._comboBox._closeOnBlurIsPrevented = true;
|
||||
}
|
||||
const newValue = ev.detail.value;
|
||||
|
||||
if (newValue !== this.value) {
|
||||
@@ -327,7 +330,7 @@ export class HaComboBox extends LitElement {
|
||||
}
|
||||
vaadin-combo-box-light {
|
||||
position: relative;
|
||||
--vaadin-combo-box-overlay-max-height: calc(45vh);
|
||||
--vaadin-combo-box-overlay-max-height: calc(45vh - 56px);
|
||||
}
|
||||
ha-textfield {
|
||||
width: 100%;
|
||||
|
@@ -18,10 +18,9 @@ import {
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { clamp } from "../common/number/clamp";
|
||||
import { arc } from "../resources/svg-arc";
|
||||
import { svgArc } from "../resources/svg-arc";
|
||||
|
||||
const MAX_ANGLE = 270;
|
||||
const ROTATE_ANGLE = 360 - MAX_ANGLE / 2 - 90;
|
||||
@@ -60,6 +59,8 @@ const A11Y_KEY_CODES = new Set([
|
||||
"End",
|
||||
]);
|
||||
|
||||
export type ControlCircularSliderMode = "start" | "end" | "full";
|
||||
|
||||
@customElement("ha-control-circular-slider")
|
||||
export class HaControlCircularSlider extends LitElement {
|
||||
@property({ type: Boolean, reflect: true })
|
||||
@@ -68,8 +69,11 @@ export class HaControlCircularSlider extends LitElement {
|
||||
@property({ type: Boolean })
|
||||
public dual?: boolean;
|
||||
|
||||
@property({ type: Boolean, reflect: true })
|
||||
public inverted?: boolean;
|
||||
@property({ type: String })
|
||||
public mode?: ControlCircularSliderMode;
|
||||
|
||||
@property({ type: Boolean })
|
||||
public inactive?: boolean;
|
||||
|
||||
@property({ type: String })
|
||||
public label?: string;
|
||||
@@ -388,44 +392,151 @@ export class HaControlCircularSlider extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _strokeDashArc(
|
||||
percentage: number,
|
||||
inverted?: boolean
|
||||
): [string, string] {
|
||||
const maxRatio = MAX_ANGLE / 360;
|
||||
const f = RADIUS * 2 * Math.PI;
|
||||
if (inverted) {
|
||||
const arcLength = (1 - percentage) * f * maxRatio;
|
||||
const strokeDasharray = `${arcLength} ${f - arcLength}`;
|
||||
const strokeDashOffset = `${arcLength + f * (1 - maxRatio)}`;
|
||||
return [strokeDasharray, strokeDashOffset];
|
||||
}
|
||||
const arcLength = percentage * f * maxRatio;
|
||||
const strokeDasharray = `${arcLength} ${f - arcLength}`;
|
||||
const strokeDashOffset = "0";
|
||||
private _strokeCircleDashArc(value: number): [string, string] {
|
||||
return this._strokeDashArc(value, value);
|
||||
}
|
||||
|
||||
private _strokeDashArc(from: number, to: number): [string, string] {
|
||||
const start = this._valueToPercentage(from);
|
||||
const end = this._valueToPercentage(to);
|
||||
|
||||
const track = (RADIUS * 2 * Math.PI * MAX_ANGLE) / 360;
|
||||
const arc = Math.max((end - start) * track, 0);
|
||||
const arcOffset = start * track - 0.5;
|
||||
|
||||
const strokeDasharray = `${arc} ${track - arc}`;
|
||||
const strokeDashOffset = `-${arcOffset}`;
|
||||
return [strokeDasharray, strokeDashOffset];
|
||||
}
|
||||
|
||||
protected renderArc(
|
||||
id: string,
|
||||
value: number | undefined,
|
||||
mode: ControlCircularSliderMode
|
||||
) {
|
||||
if (this.disabled) return nothing;
|
||||
|
||||
const path = svgArc({
|
||||
x: 0,
|
||||
y: 0,
|
||||
start: 0,
|
||||
end: MAX_ANGLE,
|
||||
r: RADIUS,
|
||||
});
|
||||
|
||||
const limit = mode === "end" ? this.max : this.min;
|
||||
|
||||
const current = this.current ?? limit;
|
||||
const target = value ?? limit;
|
||||
|
||||
const showActive =
|
||||
mode === "end"
|
||||
? target <= current
|
||||
: mode === "start"
|
||||
? current <= target
|
||||
: false;
|
||||
|
||||
const activeArc = showActive
|
||||
? mode === "end"
|
||||
? this._strokeDashArc(target, current)
|
||||
: this._strokeDashArc(current, target)
|
||||
: this._strokeCircleDashArc(target);
|
||||
|
||||
const coloredArc =
|
||||
mode === "full"
|
||||
? this._strokeDashArc(this.min, this.max)
|
||||
: mode === "end"
|
||||
? this._strokeDashArc(target, limit)
|
||||
: this._strokeDashArc(limit, target);
|
||||
|
||||
const targetCircle = this._strokeCircleDashArc(target);
|
||||
|
||||
const currentCircle =
|
||||
this.current != null &&
|
||||
this.current <= this.max &&
|
||||
this.current >= this.min &&
|
||||
(showActive || this.mode === "full")
|
||||
? this._strokeCircleDashArc(this.current)
|
||||
: undefined;
|
||||
|
||||
return svg`
|
||||
<g class=${classMap({ inactive: Boolean(this.inactive) })}>
|
||||
<path
|
||||
class="arc arc-clear"
|
||||
d=${path}
|
||||
stroke-dasharray=${coloredArc[0]}
|
||||
stroke-dashoffset=${coloredArc[1]}
|
||||
/>
|
||||
<path
|
||||
class="arc arc-colored ${classMap({ [id]: true })}"
|
||||
d=${path}
|
||||
stroke-dasharray=${coloredArc[0]}
|
||||
stroke-dashoffset=${coloredArc[1]}
|
||||
/>
|
||||
<path
|
||||
.id=${id}
|
||||
d=${path}
|
||||
class="arc arc-active ${classMap({ [id]: true })}"
|
||||
stroke-dasharray=${activeArc[0]}
|
||||
stroke-dashoffset=${activeArc[1]}
|
||||
role="slider"
|
||||
tabindex="0"
|
||||
aria-valuemin=${this.min}
|
||||
aria-valuemax=${this.max}
|
||||
aria-valuenow=${
|
||||
this._localValue != null
|
||||
? this._steppedValue(this._localValue)
|
||||
: undefined
|
||||
}
|
||||
aria-disabled=${this.disabled}
|
||||
aria-label=${ifDefined(this.lowLabel ?? this.label)}
|
||||
@keydown=${this._handleKeyDown}
|
||||
@keyup=${this._handleKeyUp}
|
||||
/>
|
||||
${
|
||||
currentCircle
|
||||
? svg`
|
||||
<path
|
||||
class="current arc-current"
|
||||
d=${path}
|
||||
stroke-dasharray=${currentCircle[0]}
|
||||
stroke-dashoffset=${currentCircle[1]}
|
||||
/>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
<path
|
||||
class="target-border ${classMap({ [id]: true })}"
|
||||
d=${path}
|
||||
stroke-dasharray=${targetCircle[0]}
|
||||
stroke-dashoffset=${targetCircle[1]}
|
||||
/>
|
||||
<path
|
||||
class="target"
|
||||
d=${path}
|
||||
stroke-dasharray=${targetCircle[0]}
|
||||
stroke-dashoffset=${targetCircle[1]}
|
||||
/>
|
||||
</g>
|
||||
`;
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const trackPath = arc({ x: 0, y: 0, start: 0, end: MAX_ANGLE, r: RADIUS });
|
||||
const trackPath = svgArc({
|
||||
x: 0,
|
||||
y: 0,
|
||||
start: 0,
|
||||
end: MAX_ANGLE,
|
||||
r: RADIUS,
|
||||
});
|
||||
|
||||
const lowValue = this.dual ? this._localLow : this._localValue;
|
||||
const highValue = this._localHigh;
|
||||
const lowPercentage = this._valueToPercentage(lowValue ?? this.min);
|
||||
const highPercentage = this._valueToPercentage(highValue ?? this.max);
|
||||
const current = this.current;
|
||||
|
||||
const [lowStrokeDasharray, lowStrokeDashOffset] = this._strokeDashArc(
|
||||
lowPercentage,
|
||||
this.inverted
|
||||
);
|
||||
|
||||
const [highStrokeDasharray, highStrokeDashOffset] = this._strokeDashArc(
|
||||
highPercentage,
|
||||
true
|
||||
);
|
||||
|
||||
const currentPercentage = this._valueToPercentage(this.current ?? 0);
|
||||
const currentAngle = currentPercentage * MAX_ANGLE;
|
||||
const currentStroke = current
|
||||
? this._strokeCircleDashArc(current)
|
||||
: undefined;
|
||||
|
||||
return html`
|
||||
<svg
|
||||
@@ -447,79 +558,25 @@ export class HaControlCircularSlider extends LitElement {
|
||||
</g>
|
||||
<g id="display">
|
||||
<path class="background" d=${trackPath} />
|
||||
${lowValue != null
|
||||
${currentStroke
|
||||
? svg`
|
||||
<circle
|
||||
.id=${this.dual ? "low" : "value"}
|
||||
class="track"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r=${RADIUS}
|
||||
stroke-dasharray=${lowStrokeDasharray}
|
||||
stroke-dashoffset=${lowStrokeDashOffset}
|
||||
role="slider"
|
||||
tabindex="0"
|
||||
aria-valuemin=${this.min}
|
||||
aria-valuemax=${this.max}
|
||||
aria-valuenow=${
|
||||
lowValue != null ? this._steppedValue(lowValue) : undefined
|
||||
}
|
||||
aria-disabled=${this.disabled}
|
||||
aria-label=${ifDefined(this.lowLabel ?? this.label)}
|
||||
@keydown=${this._handleKeyDown}
|
||||
@keyup=${this._handleKeyUp}
|
||||
/>
|
||||
`
|
||||
<path
|
||||
class="current"
|
||||
d=${trackPath}
|
||||
stroke-dasharray=${currentStroke[0]}
|
||||
stroke-dashoffset=${currentStroke[1]}
|
||||
/>
|
||||
`
|
||||
: nothing}
|
||||
${lowValue != null
|
||||
? this.renderArc(
|
||||
this.dual ? "low" : "value",
|
||||
lowValue,
|
||||
(!this.dual && this.mode) || "start"
|
||||
)
|
||||
: nothing}
|
||||
${this.dual && highValue != null
|
||||
? svg`
|
||||
<circle
|
||||
id="high"
|
||||
class="track"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r=${RADIUS}
|
||||
stroke-dasharray=${highStrokeDasharray}
|
||||
stroke-dashoffset=${highStrokeDashOffset}
|
||||
role="slider"
|
||||
tabindex="0"
|
||||
aria-valuemin=${this.min}
|
||||
aria-valuemax=${this.max}
|
||||
aria-valuenow=${
|
||||
highValue != null
|
||||
? this._steppedValue(highValue)
|
||||
: undefined
|
||||
}
|
||||
aria-disabled=${this.disabled}
|
||||
aria-label=${ifDefined(this.highLabel)}
|
||||
@keydown=${this._handleKeyDown}
|
||||
@keyup=${this._handleKeyUp}
|
||||
/>
|
||||
`
|
||||
: nothing}
|
||||
${this.current != null
|
||||
? svg`
|
||||
<g
|
||||
style=${styleMap({ "--current-angle": `${currentAngle}deg` })}
|
||||
class="current"
|
||||
>
|
||||
<line
|
||||
x1=${RADIUS - 12}
|
||||
y1="0"
|
||||
x2=${RADIUS - 15}
|
||||
y2="0"
|
||||
stroke-width="4"
|
||||
/>
|
||||
<line
|
||||
x1=${RADIUS - 15}
|
||||
y1="0"
|
||||
x2=${RADIUS - 20}
|
||||
y2="0"
|
||||
stroke-linecap="round"
|
||||
stroke-width="4"
|
||||
/>
|
||||
</g>
|
||||
`
|
||||
? this.renderArc("high", highValue, "end")
|
||||
: nothing}
|
||||
</g>
|
||||
</g>
|
||||
@@ -531,7 +588,7 @@ export class HaControlCircularSlider extends LitElement {
|
||||
return css`
|
||||
:host {
|
||||
--control-circular-slider-color: var(--primary-color);
|
||||
--control-circular-slider-background: #8b97a3;
|
||||
--control-circular-slider-background: var(--disabled-color);
|
||||
--control-circular-slider-background-opacity: 0.3;
|
||||
--control-circular-slider-low-color: var(
|
||||
--control-circular-slider-color
|
||||
@@ -573,8 +630,7 @@ export class HaControlCircularSlider extends LitElement {
|
||||
stroke-width: 24px;
|
||||
}
|
||||
|
||||
.track {
|
||||
outline: none;
|
||||
.arc {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke-width: 24px;
|
||||
@@ -586,29 +642,87 @@ export class HaControlCircularSlider extends LitElement {
|
||||
opacity 180ms ease-in-out;
|
||||
}
|
||||
|
||||
.track:focus-visible {
|
||||
stroke-width: 28px;
|
||||
.target {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke-width: 18px;
|
||||
stroke: white;
|
||||
transition:
|
||||
stroke-width 300ms ease-in-out,
|
||||
stroke-dasharray 300ms ease-in-out,
|
||||
stroke-dashoffset 300ms ease-in-out,
|
||||
stroke 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
}
|
||||
|
||||
.pressed .track {
|
||||
transition: stroke-width 300ms ease-in-out;
|
||||
.target-border {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke-width: 24px;
|
||||
stroke: white;
|
||||
transition:
|
||||
stroke-width 300ms ease-in-out,
|
||||
stroke-dasharray 300ms ease-in-out,
|
||||
stroke-dashoffset 300ms ease-in-out,
|
||||
stroke 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
}
|
||||
|
||||
.current {
|
||||
fill: none;
|
||||
stroke-linecap: round;
|
||||
stroke-width: 8px;
|
||||
stroke: var(--primary-text-color);
|
||||
transform: rotate(var(--current-angle, 0));
|
||||
transition: transform 300ms ease-in-out;
|
||||
opacity: 0.5;
|
||||
transition:
|
||||
stroke-width 300ms ease-in-out,
|
||||
stroke-dasharray 300ms ease-in-out,
|
||||
stroke-dashoffset 300ms ease-in-out,
|
||||
stroke 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
}
|
||||
|
||||
#value {
|
||||
.arc-current {
|
||||
stroke: var(--clear-background-color);
|
||||
}
|
||||
|
||||
.arc-clear {
|
||||
stroke: var(--clear-background-color);
|
||||
}
|
||||
.arc-colored {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.arc-active {
|
||||
outline: none;
|
||||
}
|
||||
.arc-active:focus-visible {
|
||||
stroke-width: 28px;
|
||||
}
|
||||
|
||||
.pressed .arc,
|
||||
.pressed .target,
|
||||
.pressed .target-border,
|
||||
.pressed .current {
|
||||
transition:
|
||||
stroke-width 300ms ease-in-out,
|
||||
stroke 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
}
|
||||
|
||||
.inactive .arc,
|
||||
.inactive .arc-current {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.value {
|
||||
stroke: var(--control-circular-slider-color);
|
||||
}
|
||||
|
||||
#low {
|
||||
.low {
|
||||
stroke: var(--control-circular-slider-low-color);
|
||||
}
|
||||
|
||||
#high {
|
||||
.high {
|
||||
stroke: var(--control-circular-slider-high-color);
|
||||
}
|
||||
`;
|
||||
|
260
src/components/ha-control-number-buttons.ts
Normal file
260
src/components/ha-control-number-buttons.ts
Normal file
@@ -0,0 +1,260 @@
|
||||
import { mdiMinus, mdiPlus } from "@mdi/js";
|
||||
import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { conditionalClamp } from "../common/number/clamp";
|
||||
import { formatNumber } from "../common/number/format_number";
|
||||
import { FrontendLocaleData } from "../data/translation";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
|
||||
const A11Y_KEY_CODES = new Set([
|
||||
"ArrowRight",
|
||||
"ArrowUp",
|
||||
"ArrowLeft",
|
||||
"ArrowDown",
|
||||
"PageUp",
|
||||
"PageDown",
|
||||
"Home",
|
||||
"End",
|
||||
]);
|
||||
|
||||
@customElement("ha-control-number-buttons")
|
||||
export class HaControlNumberButton extends LitElement {
|
||||
@property({ attribute: false }) public locale?: FrontendLocaleData;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) disabled = false;
|
||||
|
||||
@property() public label?: string;
|
||||
|
||||
@property({ type: Number }) public step?: number;
|
||||
|
||||
@property({ type: Number }) public value?: number;
|
||||
|
||||
@property({ type: Number }) public min?: number;
|
||||
|
||||
@property({ type: Number }) public max?: number;
|
||||
|
||||
@property({ attribute: "false" })
|
||||
public formatOptions: Intl.NumberFormatOptions = {};
|
||||
|
||||
@query("#input") _input!: HTMLDivElement;
|
||||
|
||||
private boundedValue(value: number) {
|
||||
const clamped = conditionalClamp(value, this.min, this.max);
|
||||
return Math.round(clamped / this._step) * this._step;
|
||||
}
|
||||
|
||||
private get _step() {
|
||||
return this.step ?? 1;
|
||||
}
|
||||
|
||||
private get _value() {
|
||||
return this.value ?? 0;
|
||||
}
|
||||
|
||||
private get _tenPercentStep() {
|
||||
if (this.max == null || this.min == null) return this._step;
|
||||
const range = this.max - this.min / 10;
|
||||
|
||||
if (range <= this._step) return this._step;
|
||||
return Math.max(range / 10);
|
||||
}
|
||||
|
||||
private _handlePlusButton() {
|
||||
this._increment();
|
||||
fireEvent(this, "value-changed", { value: this.value });
|
||||
this._input.focus();
|
||||
}
|
||||
|
||||
private _handleMinusButton() {
|
||||
this._decrement();
|
||||
fireEvent(this, "value-changed", { value: this.value });
|
||||
this._input.focus();
|
||||
}
|
||||
|
||||
private _increment() {
|
||||
this.value = this.boundedValue(this._value + this._step);
|
||||
}
|
||||
|
||||
private _decrement() {
|
||||
this.value = this.boundedValue(this._value - this._step);
|
||||
}
|
||||
|
||||
_handleKeyDown(e: KeyboardEvent) {
|
||||
if (this.disabled) return;
|
||||
if (!A11Y_KEY_CODES.has(e.code)) return;
|
||||
e.preventDefault();
|
||||
switch (e.code) {
|
||||
case "ArrowRight":
|
||||
case "ArrowUp":
|
||||
this._increment();
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
case "ArrowDown":
|
||||
this._decrement();
|
||||
break;
|
||||
case "PageUp":
|
||||
this.value = this.boundedValue(this._value + this._tenPercentStep);
|
||||
break;
|
||||
case "PageDown":
|
||||
this.value = this.boundedValue(this._value - this._tenPercentStep);
|
||||
break;
|
||||
case "Home":
|
||||
if (this.min != null) {
|
||||
this.value = this.min;
|
||||
}
|
||||
break;
|
||||
case "End":
|
||||
if (this.max != null) {
|
||||
this.value = this.max;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fireEvent(this, "value-changed", { value: this.value });
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const displayedValue =
|
||||
this.value != null
|
||||
? formatNumber(this.value, this.locale, this.formatOptions)
|
||||
: "";
|
||||
|
||||
return html`
|
||||
<div class="container">
|
||||
<div
|
||||
id="input"
|
||||
class="value"
|
||||
role="number-button"
|
||||
.tabIndex=${this.disabled ? "-1" : "0"}
|
||||
aria-valuenow=${this.value}
|
||||
aria-valuemin=${this.min}
|
||||
aria-valuemax=${this.max}
|
||||
aria-label=${ifDefined(this.label)}
|
||||
?disabled=${this.disabled}
|
||||
@keydown=${this._handleKeyDown}
|
||||
>
|
||||
${displayedValue}
|
||||
</div>
|
||||
<button
|
||||
class="button minus"
|
||||
type="button"
|
||||
tabindex="-1"
|
||||
aria-label="decrement"
|
||||
@click=${this._handleMinusButton}
|
||||
.disabled=${this.disabled ||
|
||||
(this.min != null && this._value <= this.min)}
|
||||
>
|
||||
<ha-svg-icon aria-hidden .path=${mdiMinus}></ha-svg-icon>
|
||||
</button>
|
||||
<button
|
||||
class="button plus"
|
||||
type="button"
|
||||
tabindex="-1"
|
||||
aria-label="increment"
|
||||
@click=${this._handlePlusButton}
|
||||
.disabled=${this.disabled ||
|
||||
(this.max != null && this._value >= this.max)}
|
||||
>
|
||||
<ha-svg-icon aria-hidden .path=${mdiPlus}></ha-svg-icon>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host {
|
||||
display: block;
|
||||
--control-number-buttons-focus-color: var(--primary-color);
|
||||
--control-number-buttons-background-color: var(--disabled-color);
|
||||
--control-number-buttons-background-opacity: 0.2;
|
||||
--control-number-buttons-border-radius: 10px;
|
||||
--mdc-icon-size: 16px;
|
||||
height: 40px;
|
||||
width: 200px;
|
||||
color: var(--primary-text-color);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
transition: color 180ms ease-in-out;
|
||||
}
|
||||
:host([disabled]) {
|
||||
color: var(--disabled-color);
|
||||
}
|
||||
.container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0 44px;
|
||||
border-radius: var(--control-number-buttons-border-radius);
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
line-height: 0;
|
||||
overflow: hidden;
|
||||
/* For safari border-radius overflow */
|
||||
z-index: 0;
|
||||
font-size: inherit;
|
||||
color: inherit;
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
outline: none;
|
||||
}
|
||||
.value::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: var(--control-number-buttons-background-color);
|
||||
transition:
|
||||
background-color 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
opacity: var(--control-number-buttons-background-opacity);
|
||||
}
|
||||
.value:focus-visible {
|
||||
box-shadow: 0 0 0 2px var(--control-number-buttons-focus-color);
|
||||
}
|
||||
.button {
|
||||
color: inherit;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
padding: 0;
|
||||
width: 35px;
|
||||
height: 40px;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
}
|
||||
.button[disabled] {
|
||||
opacity: 0.4;
|
||||
pointer-events: none;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.button.minus {
|
||||
left: 0;
|
||||
}
|
||||
.button.plus {
|
||||
right: 0;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-control-number-buttons": HaControlNumberButton;
|
||||
}
|
||||
}
|
300
src/components/ha-control-select-menu.ts
Normal file
300
src/components/ha-control-select-menu.ts
Normal file
@@ -0,0 +1,300 @@
|
||||
import { Ripple } from "@material/mwc-ripple";
|
||||
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
|
||||
import { SelectBase } from "@material/mwc-select/mwc-select-base";
|
||||
import { mdiMenuDown } from "@mdi/js";
|
||||
import { css, html, nothing } from "lit";
|
||||
import {
|
||||
customElement,
|
||||
eventOptions,
|
||||
property,
|
||||
query,
|
||||
queryAsync,
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { debounce } from "../common/util/debounce";
|
||||
import { nextRender } from "../common/util/render-status";
|
||||
import "./ha-icon";
|
||||
import type { HaIcon } from "./ha-icon";
|
||||
import "./ha-svg-icon";
|
||||
import type { HaSvgIcon } from "./ha-svg-icon";
|
||||
|
||||
@customElement("ha-control-select-menu")
|
||||
export class HaControlSelectMenu extends SelectBase {
|
||||
@query(".select") protected mdcRoot!: HTMLElement;
|
||||
|
||||
@query(".select-anchor") protected anchorElement!: HTMLDivElement | null;
|
||||
|
||||
@property({ type: Boolean, attribute: "show-arrow" })
|
||||
public showArrow?: boolean;
|
||||
|
||||
@property({ type: Boolean, attribute: "hide-label" })
|
||||
public hideLabel?: boolean;
|
||||
|
||||
@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;
|
||||
|
||||
@state() private _shouldRenderRipple = false;
|
||||
|
||||
public override render() {
|
||||
const classes = {
|
||||
"select-disabled": this.disabled,
|
||||
"select-required": this.required,
|
||||
"select-invalid": !this.isUiValid,
|
||||
"select-no-value": !this.selectedText,
|
||||
};
|
||||
|
||||
const labelledby = this.label && !this.hideLabel ? "label" : undefined;
|
||||
const labelAttribute =
|
||||
this.label && this.hideLabel ? this.label : undefined;
|
||||
|
||||
return html`
|
||||
<div class="select ${classMap(classes)}">
|
||||
<input
|
||||
class="formElement"
|
||||
.name=${this.name}
|
||||
.value=${this.value}
|
||||
hidden
|
||||
?disabled=${this.disabled}
|
||||
?required=${this.required}
|
||||
/>
|
||||
<!-- @ts-ignore -->
|
||||
<div
|
||||
class="select-anchor"
|
||||
aria-autocomplete="none"
|
||||
role="combobox"
|
||||
aria-expanded=${this.menuOpen}
|
||||
aria-invalid=${!this.isUiValid}
|
||||
aria-haspopup="listbox"
|
||||
aria-labelledby=${ifDefined(labelledby)}
|
||||
aria-label=${ifDefined(labelAttribute)}
|
||||
aria-required=${this.required}
|
||||
@click=${this.onClick}
|
||||
@focus=${this.onFocus}
|
||||
@blur=${this.onBlur}
|
||||
@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()}
|
||||
<div class="content">
|
||||
${this.hideLabel
|
||||
? nothing
|
||||
: html`<p id="label" class="label">${this.label}</p>`}
|
||||
${this.selectedText
|
||||
? html`<p class="value">${this.selectedText}</p>`
|
||||
: nothing}
|
||||
</div>
|
||||
${this.renderArrow()}
|
||||
${this._shouldRenderRipple && !this.disabled
|
||||
? html` <mwc-ripple></mwc-ripple> `
|
||||
: nothing}
|
||||
</div>
|
||||
${this.renderMenu()}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private renderArrow() {
|
||||
if (!this.showArrow) return nothing;
|
||||
|
||||
return html`
|
||||
<div class="icon">
|
||||
<ha-svg-icon .path=${mdiMenuDown}></ha-svg-icon>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private renderIcon() {
|
||||
const index = this.mdcFoundation?.getSelectedIndex();
|
||||
const items = this.menuElement?.items ?? [];
|
||||
const item = index != null ? items[index] : undefined;
|
||||
const defaultIcon = this.querySelector("[slot='icon']");
|
||||
const icon = (item?.querySelector("[slot='graphic']") ?? null) as
|
||||
| HaSvgIcon
|
||||
| HaIcon
|
||||
| null;
|
||||
|
||||
if (!defaultIcon && !icon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="icon">
|
||||
${icon && "path" in icon
|
||||
? html`<ha-svg-icon .path=${icon.path}></ha-svg-icon>`
|
||||
: icon && "icon" in icon
|
||||
? html`<ha-icon .path=${icon.icon}></ha-icon>`
|
||||
: html`<slot name="icon"></slot>`}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
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() {
|
||||
super.connectedCallback();
|
||||
window.addEventListener("translations-updated", this._translationsUpdated);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
window.removeEventListener(
|
||||
"translations-updated",
|
||||
this._translationsUpdated
|
||||
);
|
||||
}
|
||||
|
||||
private _translationsUpdated = debounce(async () => {
|
||||
await nextRender();
|
||||
this.layoutOptions();
|
||||
}, 500);
|
||||
|
||||
static override styles = [
|
||||
css`
|
||||
:host {
|
||||
display: inline-block;
|
||||
--control-select-menu-text-color: var(--primary-text-color);
|
||||
--control-select-menu-background-color: var(--disabled-color);
|
||||
--control-select-menu-background-opacity: 0.2;
|
||||
--control-select-menu-border-radius: 14px;
|
||||
--control-select-menu-height: 48px;
|
||||
--control-select-menu-padding: 6px 10px;
|
||||
--mdc-icon-size: 20px;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
width: auto;
|
||||
color: var(--primary-text-color);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.select-anchor {
|
||||
height: var(--control-select-menu-height);
|
||||
padding: var(--control-select-menu-padding);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
border-radius: var(--control-select-menu-border-radius);
|
||||
box-sizing: border-box;
|
||||
outline: none;
|
||||
overflow: hidden;
|
||||
background: none;
|
||||
--mdc-ripple-color: var(--control-select-menu-background-color);
|
||||
/* For safari border-radius overflow */
|
||||
z-index: 0;
|
||||
transition: color 180ms ease-in-out;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
user-select: none;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.25px;
|
||||
}
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content p {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 0.85em;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
|
||||
.select-no-value .label {
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
letter-spacing: inherit;
|
||||
}
|
||||
|
||||
.select-anchor::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: var(--control-select-menu-background-color);
|
||||
transition:
|
||||
background-color 180ms ease-in-out,
|
||||
opacity 180ms ease-in-out;
|
||||
opacity: var(--control-select-menu-background-opacity);
|
||||
}
|
||||
|
||||
.select-disabled .select-anchor {
|
||||
cursor: not-allowed;
|
||||
color: var(--disabled-color);
|
||||
}
|
||||
|
||||
mwc-menu {
|
||||
--mdc-shape-medium: 8px;
|
||||
}
|
||||
mwc-list {
|
||||
--mdc-list-vertical-padding: 0;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-control-select-menu": HaControlSelectMenu;
|
||||
}
|
||||
}
|
@@ -217,6 +217,7 @@ export class HaControlSelect extends LitElement {
|
||||
transition: box-shadow 180ms ease-in-out;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
color: var(--primary-text-color);
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
@@ -267,7 +268,6 @@ export class HaControlSelect extends LitElement {
|
||||
justify-content: center;
|
||||
border-radius: var(--control-select-button-border-radius);
|
||||
overflow: hidden;
|
||||
color: var(--primary-text-color);
|
||||
/* For safari border-radius overflow */
|
||||
z-index: 0;
|
||||
}
|
||||
@@ -331,6 +331,7 @@ export class HaControlSelect extends LitElement {
|
||||
:host([disabled]) {
|
||||
--control-select-color: var(--disabled-color);
|
||||
--control-select-focused-opacity: 0;
|
||||
color: var(--disabled-color);
|
||||
}
|
||||
:host([disabled]) .option {
|
||||
cursor: not-allowed;
|
||||
|
@@ -43,6 +43,9 @@ export class HaControlSlider extends LitElement {
|
||||
@property({ type: Boolean, attribute: "show-handle" })
|
||||
public showHandle = false;
|
||||
|
||||
@property({ type: Boolean, attribute: "inverted" })
|
||||
public inverted = false;
|
||||
|
||||
@property({ type: Number })
|
||||
public value?: number;
|
||||
|
||||
@@ -61,11 +64,16 @@ export class HaControlSlider extends LitElement {
|
||||
public pressed = false;
|
||||
|
||||
valueToPercentage(value: number) {
|
||||
return (this.boundedValue(value) - this.min) / (this.max - this.min);
|
||||
const percentage =
|
||||
(this.boundedValue(value) - this.min) / (this.max - this.min);
|
||||
return this.inverted ? 1 - percentage : percentage;
|
||||
}
|
||||
|
||||
percentageToValue(value: number) {
|
||||
return (this.max - this.min) * value + this.min;
|
||||
percentageToValue(percentage: number) {
|
||||
return (
|
||||
(this.max - this.min) * (this.inverted ? 1 - percentage : percentage) +
|
||||
this.min
|
||||
);
|
||||
}
|
||||
|
||||
steppedValue(value: number) {
|
||||
|
@@ -155,11 +155,12 @@ export class HaConversationAgentPicker extends LitElement {
|
||||
if (!this._configEntry) {
|
||||
return;
|
||||
}
|
||||
showOptionsFlowDialog(
|
||||
this,
|
||||
this._configEntry,
|
||||
await fetchIntegrationManifest(this.hass, this._configEntry.domain)
|
||||
);
|
||||
showOptionsFlowDialog(this, this._configEntry, {
|
||||
manifest: await fetchIntegrationManifest(
|
||||
this.hass,
|
||||
this._configEntry.domain
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user