Compare commits

..

106 Commits

Author SHA1 Message Date
Bram Kragten
c0a5c6fa61 fix typing 2023-08-30 12:54:03 +02:00
Bram Kragten
fe91dbb139 Start updating styling of onboarding (#17698)
Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2023-08-30 12:45:03 +02:00
Bram Kragten
a8e17da9f3 Add language picker to onboarding (#17668) 2023-08-30 12:45:03 +02:00
Bram Kragten
e8f1a86005 Remove name and core config steps from onboarding (#17670) 2023-08-30 12:45:03 +02:00
Bram Kragten
45b04a6188 Simplify onboarding integrations page (#17684) 2023-08-30 12:45:03 +02:00
karwosts
034ce56da5 Updates to alarm panel card configuration (#17598)
* Updates to alarm panel card configuration

* changes from feedback
2023-08-30 11:42:51 +02:00
karwosts
ae9fcebfd5 Add sortable options to input_select settings menu (#17706)
* Sortable options in input_select settings menu

* fix lint

* no ripple, default cursor

* Update src/panels/config/helpers/forms/ha-input_select-form.ts

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>

* sortableStyles

* Use ha-list-item and mwc-list

---------

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2023-08-30 07:59:06 +00:00
renovate[bot]
6197b55da8 Update dependency luxon to v3.4.2 (#17710)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-30 09:54:39 +02:00
Bram Kragten
4e5d57b5f3 Ask user to logout all devices when changing password (#17523)
* Ask user to logout all devices when changing password

* missing import

* use core command
2023-08-29 17:09:17 +02:00
Paul Bottein
7040c6d469 Add target temperature tile feature for climate and water heater (#17697) 2023-08-29 16:36:07 +02:00
Paul Bottein
6f99a39b55 Adapt more info button layout depending of number of items and screen (#17691) 2023-08-29 15:13:08 +02:00
Paul Bottein
7483833dcd Use active color for position cover tile feature even if it's closed (#17685) 2023-08-29 15:11:30 +02:00
Sam Reed
38fb48b231 Add trailing full stop to visit_addon_page message (#17719) 2023-08-29 14:38:15 +02:00
karwosts
166acee1c6 Fix language picker in profile displaying wrong language (#17725)
* fix language picker when changing language sort order #16642

* alternative fix
2023-08-29 09:45:54 +02:00
renovate[bot]
916a6df39b Update vaadinWebComponents monorepo to v24.1.6 (#17724)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-28 18:03:02 +02:00
renovate[bot]
70f37158fb Update dependency @material/web to v1.0.0-pre.16 (#17703)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-28 18:01:28 +02:00
renovate[bot]
5011bba20e Update dependency typescript to v5.2.2 (#17720)
* Update dependency typescript to v5.2.2

* Remove expect error for URL.canParse

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
2023-08-27 17:43:49 +00:00
renovate[bot]
8897bc703d Update babel monorepo to v7.22.11 (#17717)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-27 13:15:40 -04:00
renovate[bot]
ea6e7d441a Update dependency chai to v4.3.8 (#17718)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-27 13:10:52 -04:00
renovate[bot]
f91396c986 Update Yarn to v3.6.3 (#17715)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-27 13:09:28 -04:00
renovate[bot]
4598b530af Update dependency @lit-labs/virtualizer to v2.0.6 (#17702)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-26 13:14:25 -04:00
renovate[bot]
dfabb4bc36 Update dependency @rollup/plugin-node-resolve to v15.2.1 (#17704) 2023-08-25 21:18:32 -04:00
Bram Kragten
66e0100c95 Fix combobox picking first item with label on blur (#17701) 2023-08-24 16:22:26 -04:00
renovate[bot]
a08a989ef5 Update dependency lint-staged to v14.0.1 (#17694)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-24 15:18:37 -04:00
renovate[bot]
000c28abf9 Update dependency magic-string to v0.30.3 (#17695)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-24 15:16:40 -04:00
renovate[bot]
6b67397c83 Update typescript-eslint monorepo to v6.4.1 (#17700)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-24 15:15:50 -04:00
karwosts
f68823a09e Add for_each to repeat action UI. Convert repeat to ha-form (#17688)
* Add for_each to repeat action UI. Convert repeat to ha-form

* reordermode as a selector option

* css styling
2023-08-24 18:13:10 +02:00
Bram Kragten
fc1782e676 Use 1 element for all group previews (#17693) 2023-08-24 10:14:30 +00:00
Simon Lamon
b4975344a1 Don't show a battery if the entity domain is Number (#17631) 2023-08-24 11:56:03 +02:00
Joakim Sørensen
2dc08d782f Hide STT and TTS entities from generated dashboard (#17689) 2023-08-24 08:59:41 +02:00
Erik Montnemery
ed92958735 Add preview support to binary sensor group (#17682) 2023-08-23 14:52:45 +02:00
Paul Bottein
5ce31f3177 Adapt circular slider style for climate, water_heater and humidifier (#17677)
* Add more rendering mode for circular slider

* Improve transitions
2023-08-23 14:35:54 +02:00
Bram Kragten
370ec9cd98 Revert "Simplify onboarding integrations page (#17671)" (#17683) 2023-08-23 14:28:34 +02:00
Bram Kragten
52c12b5659 Simplify onboarding integrations page (#17671) 2023-08-23 10:52:44 +02:00
renovate[bot]
3de4cfbc00 Update dependency marked to v7.0.4 (#17680)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-23 10:14:39 +02:00
renovate[bot]
4215854414 Update dependency eslint-import-resolver-webpack to v0.13.7 (#17675)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-23 10:14:12 +02:00
Simon Lamon
88eba92f57 Migrate ha-service-call-button to LitElement (#17666) 2023-08-22 19:49:30 +02:00
Matthias Alphart
f773c968f9 Clear input element value of ha-file-upload (#17663) 2023-08-22 17:21:06 +02:00
Simon Lamon
bbb6fccaec Clean system health subscription after data is collected (#17665) 2023-08-22 17:20:13 +02:00
karwosts
aa2b2b0d16 Typo: lates -> latest (#17673) 2023-08-22 17:14:10 +02:00
Simon Lamon
5cc06ebf0b Migrate gallery pages to LitElement (#17667) 2023-08-22 17:10:26 +02:00
Paul Bottein
85977e505b Add cover tilt position to tile card (#17619)
Add cover tilt to tile card
2023-08-22 16:55:12 +02:00
Bram Kragten
3249a5225f Keep user signed in during onboarding (#17669) 2023-08-22 15:26:46 +02:00
Paul Bottein
7e7205627a Update return home and dock icon (#17672)
Update return home and docker icon
2023-08-22 15:24:30 +02:00
Paul Bottein
d33430e53f Reduce ha-icon-button-group height (#17664) 2023-08-22 11:09:18 +02:00
Bram Kragten
e3f53e90e2 Fix not showing multi day events on mobile (#17660) 2023-08-22 11:07:46 +02:00
Bram Kragten
811edfcc0f Add support for previews in data flows (#17533) 2023-08-22 10:30:31 +02:00
renovate[bot]
2483249b5f Update dependency eslint-plugin-import to v2.28.1 (#17661)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-21 18:57:19 -04:00
Bram Kragten
3534617f81 Fix initial data for select selector without labels (#17659) 2023-08-21 21:46:08 +02:00
renovate[bot]
216a3c4c7e Update dependency core-js to v3.32.1 (#17658)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-21 20:08:43 +02:00
Paul Bottein
567bd9831f Reduce control select menu component size (#17657) 2023-08-21 16:15:29 +02:00
Bram Kragten
98d1a55d35 fix tabindex for glance card (#17656) 2023-08-21 16:15:08 +02:00
karwosts
92358b4859 Don't show pointer for glance entity when there is no action (#17625) 2023-08-21 15:51:33 +02:00
Paul Bottein
eca3ec7f98 Tile feature lawn mower (#17655)
* Add lawn mower commands to tile card

* Rename state to action button
2023-08-21 15:49:33 +02:00
Simon Lamon
bfcdbbd70b Form fields should not init in the error state (#17615) 2023-08-21 15:49:27 +02:00
karwosts
e764076b1a Fix blueprint editor behavior for number and text with defaults (#17646) 2023-08-21 15:48:10 +02:00
Virenbar
693c77ce1c Fix AND condition description (#17630) 2023-08-21 13:41:26 +00:00
Simon Lamon
a725b6c9de Clear entityId before duplicate script (#17624) 2023-08-21 15:27:54 +02:00
ildar170975
014bbf12ce Update ha-config-person.ts: fix misaligned text (#17637) 2023-08-21 15:12:58 +02:00
ildar170975
07dceb8e6d Update ha-sidebar.ts: fix notification badge clipped (#17638) 2023-08-21 15:12:13 +02:00
karwosts
53f18bec53 Respect sensor precision setting when rendering line chart tooltips (#17648) 2023-08-21 15:04:23 +02:00
renovate[bot]
ac3e858738 Update dependency eslint-plugin-lit to v1.9.1 (#17556)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-21 13:46:07 +02:00
Erik Montnemery
c76b2fb357 Fix reselecting forecast type in weather forecast card editor (#17652)
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2023-08-21 11:22:01 +00:00
Paul Bottein
5f015ac9af Add basic more info for lawn mower (#17601)
* Add basic more info for lawn mower

* Change buttons layout
2023-08-21 13:17:11 +02:00
renovate[bot]
ac7c354bfc Update dependency @lrnwebcomponents/simple-tooltip to v7.0.16 (#17651)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-21 13:12:02 +02:00
Paul Bottein
dddee87de3 Use gradient based on min/max color temp for tile card feature (#17612) 2023-08-21 13:03:20 +02:00
Paul Bottein
e8bd77a84e Add water heater more info to gallery (#17621) 2023-08-21 13:02:36 +02:00
Steve Repsher
46a036ddbe Improve frontend error messages written to system log (#17616) 2023-08-21 13:01:42 +02:00
Steve Repsher
bf912f7bd3 Add missing super calls to disconnectedCallback (#17641) 2023-08-21 12:57:38 +02:00
Michael Arthur
196c15ff3e Add lawn mower entity state, icon and color (#17558)
* start of lawn mower entity in the frontend

* added colours for states

* remove schedule states as no longer needed

* change mowing to teal

* remove docking as not included in architecture discussion and was missed
2023-08-21 12:19:15 +02:00
dependabot[bot]
d0a6e727f2 Bump actions/setup-node from 3.7.0 to 3.8.1 (#17650)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-21 10:58:07 +02:00
renovate[bot]
09697148cf Update Yarn to v3.6.2 (#17647)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-20 21:46:00 -04:00
Franck Nijhof
76093d898d Fix template selector usage in config flows (#17643) 2023-08-20 12:45:39 -04:00
renovate[bot]
00c69c0fc3 Lock file maintenance (#17634)
* Lock file maintenance

* Limit time period for lock file maintenance

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
2023-08-20 02:11:09 +00:00
renovate[bot]
93dd119ce5 Update dependency @rollup/plugin-node-resolve to v15.2.0 (#17640)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-20 02:10:29 +00:00
renovate[bot]
e4f3211e9f Update dependency prettier to v3.0.2 (#17623)
* Update dependency prettier to v3.0.2

* Reformat

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
2023-08-19 20:41:39 +00:00
renovate[bot]
c6ecdc9d5d Lock file maintenance (#17627)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-19 16:06:31 -04:00
renovate[bot]
6bdd2d234d Update dependency @codemirror/language to v6.9.0 (#17632)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-19 15:39:44 -04:00
renovate[bot]
9d169bcbeb Update dependency systemjs to v6.14.2 (#17629)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-19 15:36:45 -04:00
renovate[bot]
5c06ec1084 Update dependency eslint-import-resolver-webpack to v0.13.6 (#17628)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-19 15:35:05 -04:00
RoboMagus
38a317b7e7 Fix ha-tabs chevrons bug (#17620) 2023-08-18 13:01:13 +00:00
renovate[bot]
cd19894ab0 Update dependency @lit-labs/context to v0.4.0 (#17613)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-18 11:11:25 +02:00
Tomasz
705b6aeb4b Cover position tile feature (#16110)
* wip

* css + transtations

* Update types.ts

rollback changes done by VS Code

* fix

* Inverted slider

---------

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2023-08-18 08:40:41 +00:00
Paul Bottein
6e27fbe10f Add unit when formatting attribute for display (#17607) 2023-08-18 10:28:27 +02:00
renovate[bot]
bbb99a6eee Update typescript-eslint monorepo to v6.4.0 (#17611)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 17:53:39 -04:00
renovate[bot]
8411efc1c3 Update dependency marked to v7.0.3 (#17539)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 16:09:16 +00:00
Bram Kragten
88721df637 Bump marked (#17609) 2023-08-17 15:56:31 +00:00
renovate[bot]
265faddfa9 Update dependency @lit-labs/virtualizer to v2.0.5 (#17499)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 15:51:59 +00:00
PaoloTK
6584dc70b7 Added support for color temperature tile feature (#16515)
* Added support for color temperature tile feature

* Update src/panels/lovelace/tile-features/hui-light-color-temp-tile-feature.ts

---------

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2023-08-17 17:45:42 +02:00
renovate[bot]
d6b4dbe6a2 Update dependency @lit-labs/motion to v1.0.4 (#17498)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 15:37:03 +00:00
ildar170975
d579f93aa7 Update developer-tools-state.js: widen "Set state" controls (#17500) 2023-08-17 15:30:18 +00:00
renovate[bot]
b91261a789 Update dependency @lrnwebcomponents/simple-tooltip to v7.0.15 (#17324)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 17:27:22 +02:00
renovate[bot]
872128d9a8 Update dependency luxon to v3.4.0 (#17559)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 17:26:30 +02:00
renovate[bot]
4972db4648 Update dependency lint-staged to v14 (#17604)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-17 17:26:03 +02:00
Paul Bottein
821cd7fe05 Add operation modes to tile card (#17597) 2023-08-17 17:19:46 +02:00
Paul Bottein
8c24ffa710 Add water heater state colors to gallery (#17606) 2023-08-17 15:51:49 +02:00
karwosts
d50a130345 Add show_name to state label badge (#17603) 2023-08-17 08:56:51 +02:00
renovate[bot]
ee8997fbd2 Update dependency lint-staged to v13.3.0 (#17602) 2023-08-16 17:01:00 -04:00
Bram Kragten
613cf932b5 Delay showing connection message (#17595) 2023-08-16 12:56:44 +00:00
Paul Bottein
12b61aea2f Add hvac modes to tile card (#17592) 2023-08-16 14:56:24 +02:00
Bram Kragten
51d9271c83 Change wording and icon for default thread router (#17593) 2023-08-16 14:25:29 +02:00
Paul Bottein
bd5264308f Sync selected icon with selected value in new select component (#17573) 2023-08-16 12:47:35 +02:00
Bram Kragten
2c17d2fead Allow to set default router for thread network (#17584)
* Allow to set default router for thread network

* Update thread-config-panel.ts
2023-08-16 11:52:42 +02:00
Bram Kragten
9f0b9782a0 Round altitude from GPS result (#17591) 2023-08-16 11:49:53 +02:00
Steve Repsher
88ff4c2fa8 Fix synchronous loading for ES5 build (#17174) 2023-08-15 19:48:51 +02:00
Steve Repsher
cba246fc7f Fix source URLs in source maps (#17585) 2023-08-15 15:10:12 +00:00
214 changed files with 13951 additions and 3510 deletions

View File

@@ -26,7 +26,7 @@ jobs:
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
@@ -62,7 +62,7 @@ jobs:
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

View File

@@ -26,7 +26,7 @@ jobs:
- name: Check out files from GitHub
uses: actions/checkout@v3.5.3
- 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,7 +57,7 @@ jobs:
- name: Check out files from GitHub
uses: actions/checkout@v3.5.3
- name: Setup Node
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v3.8.1
with:
node-version-file: ".nvmrc"
cache: yarn
@@ -75,7 +75,7 @@ jobs:
- name: Check out files from GitHub
uses: actions/checkout@v3.5.3
- name: Setup Node
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v3.8.1
with:
node-version-file: ".nvmrc"
cache: yarn
@@ -93,7 +93,7 @@ jobs:
- name: Check out files from GitHub
uses: actions/checkout@v3.5.3
- name: Setup Node
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v3.8.1
with:
node-version-file: ".nvmrc"
cache: yarn

View File

@@ -27,7 +27,7 @@ jobs:
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
@@ -63,7 +63,7 @@ jobs:
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

View File

@@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v3.5.3
- name: Setup Node
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v3.8.1
with:
node-version-file: ".nvmrc"
cache: yarn

View File

@@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v3.5.3
- name: Setup Node
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v3.8.1
with:
node-version-file: ".nvmrc"
cache: yarn

View File

@@ -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

View File

@@ -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

File diff suppressed because one or more lines are too long

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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);

View 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;
}
}

View File

@@ -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);

View 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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,3 @@
---
title: Control Number Buttons
---

View 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;
}
}

View File

@@ -0,0 +1,3 @@
---
title: Control Select Menu
---

View 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;
}
}

View File

@@ -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

View File

@@ -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: `

View File

@@ -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(

View File

@@ -43,6 +43,28 @@ const ENTITIES = [
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"],

View File

@@ -0,0 +1,3 @@
---
title: Water Heater
---

View 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;
}
}

View File

@@ -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),

View File

@@ -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;

View File

@@ -25,11 +25,11 @@
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@babel/runtime": "7.22.10",
"@babel/runtime": "7.22.11",
"@braintree/sanitize-url": "6.0.4",
"@codemirror/autocomplete": "6.9.0",
"@codemirror/commands": "6.2.4",
"@codemirror/language": "6.8.0",
"@codemirror/language": "6.9.0",
"@codemirror/legacy-modes": "6.3.3",
"@codemirror/search": "6.5.1",
"@codemirror/state": "6.2.1",
@@ -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.0",
"@lit-labs/motion": "1.0.4",
"@lit-labs/virtualizer": "2.0.6",
"@lrnwebcomponents/simple-tooltip": "7.0.16",
"@material/chips": "=14.0.0-canary.53b3cad2f.0",
"@material/data-table": "=14.0.0-canary.53b3cad2f.0",
"@material/mwc-button": "0.27.0",
@@ -79,7 +79,7 @@
"@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.15",
"@material/web": "=1.0.0-pre.16",
"@mdi/js": "7.2.96",
"@mdi/svg": "7.2.96",
"@polymer/app-layout": "3.1.0",
@@ -94,8 +94,8 @@
"@polymer/paper-toast": "3.0.1",
"@polymer/polymer": "3.5.1",
"@thomasloven/round-slider": "0.6.0",
"@vaadin/combo-box": "24.1.5",
"@vaadin/vaadin-themable-mixin": "24.1.5",
"@vaadin/combo-box": "24.1.6",
"@vaadin/vaadin-themable-mixin": "24.1.6",
"@vibrant/color": "3.2.1-alpha.1",
"@vibrant/core": "3.2.1-alpha.1",
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
@@ -105,7 +105,7 @@
"app-datepicker": "5.1.1",
"chart.js": "3.3.2",
"comlink": "4.4.1",
"core-js": "3.32.0",
"core-js": "3.32.1",
"cropperjs": "1.5.13",
"date-fns": "2.30.0",
"date-fns-tz": "2.0.0",
@@ -121,8 +121,8 @@
"leaflet": "1.9.4",
"leaflet-draw": "1.0.4",
"lit": "2.8.0",
"luxon": "3.3.0",
"marked": "4.3.0",
"luxon": "3.4.2",
"marked": "7.0.4",
"memoize-one": "6.0.0",
"node-vibrant": "3.2.1-alpha.1",
"proxy-polyfill": "0.3.2",
@@ -133,10 +133,12 @@
"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.12.0",
"tsparticles-preset-links": "2.12.0",
"ua-parser-js": "1.0.35",
"unfetch": "5.0.0",
"vis-data": "7.1.6",
"vis-network": "9.1.6",
@@ -152,11 +154,11 @@
"xss": "1.0.14"
},
"devDependencies": {
"@babel/core": "7.22.10",
"@babel/core": "7.22.11",
"@babel/plugin-proposal-decorators": "7.22.10",
"@babel/plugin-transform-runtime": "7.22.10",
"@babel/preset-env": "7.22.10",
"@babel/preset-typescript": "7.22.5",
"@babel/preset-typescript": "7.22.11",
"@koa/cors": "4.0.0",
"@octokit/auth-oauth-device": "6.0.0",
"@octokit/plugin-retry": "6.0.0",
@@ -165,7 +167,7 @@
"@rollup/plugin-babel": "6.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",
@@ -177,29 +179,29 @@
"@types/leaflet": "1.9.3",
"@types/leaflet-draw": "1.0.7",
"@types/luxon": "3.3.1",
"@types/marked": "4.3.1",
"@types/mocha": "10.0.1",
"@types/qrcode": "1.5.1",
"@types/serve-handler": "6.1.1",
"@types/sortablejs": "1.15.1",
"@types/tar": "6.1.5",
"@types/ua-parser-js": "0.7.36",
"@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "6.3.0",
"@typescript-eslint/parser": "6.3.0",
"@typescript-eslint/eslint-plugin": "6.4.1",
"@typescript-eslint/parser": "6.4.1",
"@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",
"chai": "4.3.8",
"del": "7.0.0",
"eslint": "8.47.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-webpack": "0.13.4",
"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",
@@ -217,16 +219,16 @@
"husky": "8.0.3",
"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.2",
"magic-string": "0.30.3",
"map-stream": "0.0.7",
"mocha": "10.2.0",
"object-hash": "3.0.0",
"open": "9.1.0",
"pinst": "3.0.0",
"prettier": "3.0.1",
"prettier": "3.0.2",
"rollup": "2.79.1",
"rollup-plugin-string": "3.0.0",
"rollup-plugin-terser": "7.0.2",
@@ -234,11 +236,11 @@
"serve-handler": "6.1.5",
"sinon": "15.2.0",
"source-map-url": "0.4.1",
"systemjs": "6.14.1",
"systemjs": "6.14.2",
"tar": "6.1.15",
"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",
@@ -255,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"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -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": [
{

View File

@@ -1,3 +1,4 @@
import punycode from "punycode";
import {
css,
CSSResultGroup,
@@ -7,7 +8,6 @@ import {
PropertyValues,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import punycode from "punycode";
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
import { extractSearchParamsObject } from "../common/url/search-params";
import "../components/ha-alert";
@@ -35,6 +35,8 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
@property() public oauth2State?: string;
@property() public translationFragment = "page-authorize";
@state() private _authProvider?: AuthProvider;
@state() private _authProviders?: AuthProvider[];
@@ -45,7 +47,6 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
constructor() {
super();
this.translationFragment = "page-authorize";
const query = extractSearchParamsObject() as AuthUrlSearchParams;
if (query.client_id) {
this.clientId = query.client_id;
@@ -102,7 +103,6 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
: nothing}
<ha-auth-flow
.resources=${this.resources}
.clientId=${this.clientId}
.redirectUri=${this.redirectUri}
.oauth2State=${this.oauth2State}

View File

@@ -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

View File

@@ -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,
@@ -187,6 +189,7 @@ export const DOMAINS_WITH_CARD = [
"input_number",
"input_text",
"humidifier",
"lawn_mower",
"lock",
"media_player",
"number",

View File

@@ -1,6 +1,11 @@
import { HassConfig, HassEntity } from "home-assistant-js-websocket";
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";
@@ -9,8 +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 { computeStateDomain } from "./compute_state_domain";
export const computeAttributeValueDisplay = (
localize: LocalizeFunc,
@@ -31,7 +38,40 @@ 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

View File

@@ -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: [

View File

@@ -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":

View File

@@ -22,6 +22,7 @@ const STATE_COLORED_DOMAIN = new Set([
"group",
"humidifier",
"input_boolean",
"lawn_mower",
"light",
"lock",
"media_player",

View File

@@ -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;
};

View File

@@ -3,25 +3,30 @@ import type { FrontendLocaleData } from "../../data/translation";
import type { HomeAssistant } from "../../types";
import type { LocalizeFunc } from "./localize";
export type FormatEntityStateFunc = {
formatEntityState: (stateObj: HassEntity, state?: string) => string;
formatEntityAttributeValue: (
stateObj: HassEntity,
attribute: string,
value?: any
) => string;
formatEntityAttributeName: (
stateObj: HassEntity,
attribute: string
) => string;
};
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<FormatEntityStateFunc> => {
): Promise<{
formatEntityState: FormatEntityStateFunc;
formatEntityAttributeValue: FormatEntityAttributeValueFunc;
formatEntityAttributeName: formatEntityAttributeNameFunc;
}> => {
const { computeStateDisplay } = await import(
"../entity/compute_state_display"
);

View File

@@ -11,10 +11,12 @@ 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}`

View File

@@ -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);

View 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;
};
}
}

View File

@@ -7,6 +7,7 @@ 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";
@@ -125,7 +126,13 @@ class StateHistoryChartLine extends LitElement {
label: (context) =>
`${context.dataset.label}: ${formatNumber(
context.parsed.y,
this.hass.locale
this.hass.locale,
getNumberFormatOptions(
this.hass.states[this.data[context.datasetIndex].entity_id],
this.hass.entities[
this.data[context.datasetIndex].entity_id
]
)
)} ${this.unit}`,
},
},

View File

@@ -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}

View File

@@ -62,6 +62,8 @@ export class HaStateLabelBadge extends LitElement {
@property() public image?: string;
@property() public showName?: boolean;
@state() private _timerTimeRemaining?: number;
private _connected?: boolean;
@@ -132,7 +134,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

View File

@@ -3,6 +3,7 @@ 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")>;
@@ -14,11 +15,19 @@ class HaAttributeValue extends LitElement {
@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")) {

View File

@@ -2,9 +2,7 @@ import { css, CSSResultGroup, html, LitElement, 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 { CLIMATE_PRESET_NONE, ClimateEntity } from "../data/climate";
import { isUnavailableState } from "../data/entity";
import type { HomeAssistant } from "../types";
@@ -54,28 +52,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 +88,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 "";

View File

@@ -312,6 +312,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) {

View File

@@ -59,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 })
@@ -67,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;
@@ -407,12 +412,10 @@ export class HaControlCircularSlider extends LitElement {
protected renderArc(
id: string,
value: number | undefined,
inverted: boolean | undefined
mode: ControlCircularSliderMode
) {
if (this.disabled) return nothing;
const limit = inverted ? this.max : this.min;
const path = svgArc({
x: 0,
y: 0,
@@ -421,82 +424,100 @@ export class HaControlCircularSlider extends LitElement {
r: RADIUS,
});
const limit = mode === "end" ? this.max : this.min;
const current = this.current ?? limit;
const target = value ?? limit;
const showActive = inverted ? target <= current : current <= target;
const showActive =
mode === "end"
? target <= current
: mode === "start"
? current <= target
: false;
const activeArcDashArray = showActive
? inverted
const activeArc = showActive
? mode === "end"
? this._strokeDashArc(target, current)
: this._strokeDashArc(current, target)
: this._strokeCircleDashArc(target);
const arcDashArray = inverted
? this._strokeDashArc(target, limit)
: this._strokeDashArc(limit, target);
const coloredArc =
mode === "full"
? this._strokeDashArc(this.min, this.max)
: mode === "end"
? this._strokeDashArc(target, limit)
: this._strokeDashArc(limit, target);
const targetCircleDashArray = this._strokeCircleDashArc(target);
const targetCircle = this._strokeCircleDashArc(target);
const currentCircleDashArray =
const currentCircle =
this.current != null &&
showActive &&
current <= this.max &&
current >= this.min
this.current <= this.max &&
this.current >= this.min &&
(showActive || this.mode === "full")
? this._strokeCircleDashArc(this.current)
: undefined;
return svg`
<path
class="arc arc-clear"
d=${path}
stroke-dasharray=${arcDashArray[0]}
stroke-dashoffset=${arcDashArray[1]}
/>
<path
class="arc arc-background ${classMap({ [id]: true })}"
d=${path}
stroke-dasharray=${arcDashArray[0]}
stroke-dashoffset=${arcDashArray[1]}
/>
<path
.id=${id}
d=${path}
class="arc arc-active ${classMap({ [id]: true })}"
stroke-dasharray=${activeArcDashArray[0]}
stroke-dashoffset=${activeArcDashArray[1]}
role="slider"
tabindex="0"
aria-valuemin=${this.min}
aria-valuemax=${this.max}
aria-valuenow=${
this._localValue != null
? this._steppedValue(this._localValue)
: undefined
<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
}
aria-disabled=${this.disabled}
aria-label=${ifDefined(this.lowLabel ?? this.label)}
@keydown=${this._handleKeyDown}
@keyup=${this._handleKeyUp}
/>
${
currentCircleDashArray
? svg`
<path
class="current arc-current"
d=${path}
stroke-dasharray=${currentCircleDashArray[0]}
stroke-dashoffset=${currentCircleDashArray[1]}
/>
`
: nothing
}
<path
class="target"
d=${path}
stroke-dasharray=${targetCircleDashArray[0]}
stroke-dashoffset=${targetCircleDashArray[1]}
/>
<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>
`;
}
@@ -551,11 +572,11 @@ export class HaControlCircularSlider extends LitElement {
? this.renderArc(
this.dual ? "low" : "value",
lowValue,
this.inverted
(!this.dual && this.mode) || "start"
)
: nothing}
${this.dual && highValue != null
? this.renderArc("high", highValue, true)
? this.renderArc("high", highValue, "end")
: nothing}
</g>
</g>
@@ -634,6 +655,19 @@ export class HaControlCircularSlider extends LitElement {
opacity 180ms 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;
@@ -655,7 +689,7 @@ export class HaControlCircularSlider extends LitElement {
.arc-clear {
stroke: var(--clear-background-color);
}
.arc-background {
.arc-colored {
opacity: 0.5;
}
.arc-active {
@@ -667,6 +701,7 @@ export class HaControlCircularSlider extends LitElement {
.pressed .arc,
.pressed .target,
.pressed .target-border,
.pressed .current {
transition:
stroke-width 300ms ease-in-out,
@@ -674,6 +709,11 @@ export class HaControlCircularSlider extends LitElement {
opacity 180ms ease-in-out;
}
.inactive .arc,
.inactive .arc-current {
opacity: 0;
}
.value {
stroke: var(--control-circular-slider-color);
}

View File

@@ -0,0 +1,258 @@
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 (!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="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;
}
.button.minus {
left: 0;
}
.button.plus {
right: 0;
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-control-number-buttons": HaControlNumberButton;
}
}

View File

@@ -13,6 +13,10 @@ 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 {
@@ -66,9 +70,7 @@ export class HaControlSelectMenu extends SelectBase {
@touchend=${this.handleRippleDeactivate}
@touchcancel=${this.handleRippleDeactivate}
>
<div class="icon">
<slot name="icon"></slot>
</div>
${this.renderIcon()}
<div class="content">
<p id="label" class="label">${this.label}</p>
${this.selectedText
@@ -84,6 +86,25 @@ export class HaControlSelectMenu extends SelectBase {
`;
}
private renderIcon() {
const index = this.mdcFoundation?.getSelectedIndex();
const items = this.menuElement?.items ?? [];
const item = index != null ? items[index] : undefined;
const icon =
item?.querySelector("[slot='graphic']") ??
(null as HaSvgIcon | HaIcon | 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();
@@ -149,18 +170,15 @@ export class HaControlSelectMenu extends SelectBase {
--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: 16px;
--control-select-menu-min-width: 120px;
--control-select-menu-max-width: 200px;
--control-select-menu-width: 100%;
--mdc-icon-size: 24px;
--control-select-menu-border-radius: 14px;
--mdc-icon-size: 20px;
width: auto;
color: var(--primary-text-color);
-webkit-tap-highlight-color: transparent;
}
.select-anchor {
color: var(--control-select-menu-text-color);
height: 56px;
padding: 8px 12px;
height: 48px;
padding: 6px 10px;
overflow: hidden;
position: relative;
cursor: pointer;
@@ -177,12 +195,14 @@ export class HaControlSelectMenu extends SelectBase {
z-index: 0;
font-size: inherit;
transition: color 180ms ease-in-out;
color: var(--control-text-icon-color);
gap: 12px;
min-width: var(--control-select-menu-min-width);
max-width: var(--control-select-menu-max-width);
width: var(--control-select-menu-width);
gap: 10px;
width: 100%;
user-select: none;
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 20px;
letter-spacing: 0.25px;
}
.content {
display: flex;
@@ -204,24 +224,14 @@ export class HaControlSelectMenu extends SelectBase {
.label {
font-size: 12px;
font-style: normal;
font-weight: 400;
line-height: 16px;
letter-spacing: 0.4px;
}
.select-no-value .label {
font-size: 16px;
line-height: 24px;
letter-spacing: 0.5px;
}
.value {
font-size: 16px;
font-style: normal;
font-weight: 400;
line-height: 24px;
letter-spacing: 0.5px;
font-size: inherit;
line-height: inherit;
letter-spacing: inherit;
}
.select-anchor::before {

View File

@@ -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) {

View File

@@ -10,12 +10,12 @@ import "./ha-icon-button";
const SUPPRESS_DEFAULT_PRESS_SELECTOR = ["button", "ha-list-item"];
export const createCloseHeading = (
hass: HomeAssistant,
hass: HomeAssistant | undefined,
title: string | TemplateResult
) => html`
<div class="header_title">${title}</div>
<ha-icon-button
.label=${hass.localize("ui.dialogs.generic.close")}
.label=${hass?.localize("ui.dialogs.generic.close") ?? "Close"}
.path=${mdiClose}
dialogAction="close"
class="header_button"

View File

@@ -146,6 +146,7 @@ export class HaFileUpload extends LitElement {
private _clearValue(ev: Event) {
ev.preventDefault();
this.value = null;
this._input!.value = "";
fireEvent(this, "change");
}

View File

@@ -47,11 +47,12 @@ export const computeInitialHaFormData = (
} else if ("boolean" in selector) {
data[field.name] = false;
} else if (
"text" in selector ||
"addon" in selector ||
"attribute" in selector ||
"file" in selector ||
"icon" in selector ||
"template" in selector ||
"text" in selector ||
"theme" in selector
) {
data[field.name] = "";
@@ -59,7 +60,8 @@ export const computeInitialHaFormData = (
data[field.name] = selector.number?.min ?? 0;
} else if ("select" in selector) {
if (selector.select?.options.length) {
data[field.name] = selector.select.options[0][0];
const val = selector.select.options[0];
data[field.name] = Array.isArray(val) ? val[0] : val;
}
} else if ("duration" in selector) {
data[field.name] = {

View File

@@ -2,8 +2,6 @@ import { css, CSSResultGroup, html, LitElement, 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 { isUnavailableState, OFF } from "../data/entity";
import { HumidifierEntity } from "../data/humidifier";
import type { HomeAssistant } from "../types";
@@ -51,10 +49,10 @@ class HaHumidifierState extends LitElement {
}
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;
@@ -66,10 +64,10 @@ class HaHumidifierState extends LitElement {
}
if (this.stateObj.attributes.humidity != null) {
return `${formatNumber(
this.stateObj.attributes.humidity,
this.hass.locale
)}${blankBeforePercent(this.hass.locale)}%`;
return `${this.hass.formatEntityAttributeValue(
this.stateObj,
"humidity"
)}`;
}
return "";

View File

@@ -14,17 +14,17 @@ export class HaIconButtonGroup extends LitElement {
display: flex;
flex-direction: row;
align-items: center;
height: 56px;
height: 48px;
border-radius: 28px;
background-color: rgba(139, 145, 151, 0.1);
box-sizing: border-box;
width: auto;
padding: 4px;
gap: 4px;
padding: 0;
}
::slotted(.separator) {
background-color: rgba(var(--rgb-primary-text-color), 0.15);
width: 1px;
margin: 0 1px;
height: 40px;
}
`;

View File

@@ -7,6 +7,7 @@ import { formatLanguageCode } from "../common/language/format_language";
import { caseInsensitiveStringCompare } from "../common/string/compare";
import { FrontendLocaleData } from "../data/translation";
import "../resources/intl-polyfill";
import { translationMetadata } from "../resources/translations-metadata";
import { HomeAssistant } from "../types";
import "./ha-list-item";
import "./ha-select";
@@ -20,7 +21,7 @@ export class HaLanguagePicker extends LitElement {
@property() public languages?: string[];
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public hass?: HomeAssistant;
@property({ type: Boolean, reflect: true }) public disabled = false;
@@ -41,7 +42,18 @@ export class HaLanguagePicker extends LitElement {
protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
if (changedProperties.has("languages") || changedProperties.has("value")) {
const localeChanged =
changedProperties.has("hass") &&
this.hass &&
changedProperties.get("hass") &&
changedProperties.get("hass").locale.language !==
this.hass.locale.language;
if (
changedProperties.has("languages") ||
changedProperties.has("value") ||
localeChanged
) {
this._select.layoutOptions();
if (this._select.value !== this.value) {
fireEvent(this, "value-changed", { value: this._select.value });
@@ -51,24 +63,27 @@ export class HaLanguagePicker extends LitElement {
}
const languageOptions = this._getLanguagesOptions(
this.languages ?? this._defaultLanguages,
this.hass.locale,
this.nativeName
this.nativeName,
this.hass?.locale
);
const selectedItem = languageOptions.find(
const selectedItemIndex = languageOptions.findIndex(
(option) => option.value === this.value
);
if (!selectedItem) {
if (selectedItemIndex === -1) {
this.value = undefined;
}
if (localeChanged) {
this._select.select(selectedItemIndex);
}
}
}
private _getLanguagesOptions = memoizeOne(
(languages: string[], locale: FrontendLocaleData, nativeName: boolean) => {
(languages: string[], nativeName: boolean, locale?: FrontendLocaleData) => {
let options: { label: string; value: string }[] = [];
if (nativeName) {
const translations = this.hass.translationMetadata.translations;
const translations = translationMetadata.translations;
options = languages.map((lang) => {
let label = translations[lang]?.nativeName;
if (!label) {
@@ -87,14 +102,14 @@ export class HaLanguagePicker extends LitElement {
label,
};
});
} else {
} else if (locale) {
options = languages.map((lang) => ({
value: lang,
label: formatLanguageCode(lang, locale),
}));
}
if (!this.noSort) {
if (!this.noSort && locale) {
options.sort((a, b) =>
caseInsensitiveStringCompare(a.label, b.label, locale.language)
);
@@ -104,20 +119,14 @@ export class HaLanguagePicker extends LitElement {
);
private _computeDefaultLanguageOptions() {
if (!this.hass.translationMetadata?.translations) {
return;
}
this._defaultLanguages = Object.keys(
this.hass.translationMetadata.translations
);
this._defaultLanguages = Object.keys(translationMetadata.translations);
}
protected render() {
const languageOptions = this._getLanguagesOptions(
this.languages ?? this._defaultLanguages,
this.hass.locale,
this.nativeName
this.nativeName,
this.hass?.locale
);
const value =
@@ -125,9 +134,10 @@ export class HaLanguagePicker extends LitElement {
return html`
<ha-select
.label=${this.label ||
this.hass.localize("ui.components.language-picker.language")}
.value=${value}
.label=${this.label ??
(this.hass?.localize("ui.components.language-picker.language") ||
"Language")}
.value=${value || ""}
.required=${this.required}
.disabled=${this.disabled}
@selected=${this._changed}
@@ -137,9 +147,9 @@ export class HaLanguagePicker extends LitElement {
>
${languageOptions.length === 0
? html`<ha-list-item value=""
>${this.hass.localize(
>${this.hass?.localize(
"ui.components.language-picker.no_languages"
)}</ha-list-item
) || "No languages"}</ha-list-item
>`
: languageOptions.map(
(option) => html`
@@ -162,7 +172,7 @@ export class HaLanguagePicker extends LitElement {
private _changed(ev): void {
const target = ev.target as HaSelect;
if (!this.hass || target.value === "" || target.value === this.value) {
if (target.value === "" || target.value === this.value) {
return;
}
this.value = target.value;

View File

@@ -0,0 +1,91 @@
import "@material/mwc-button";
import { CSSResultGroup, LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators";
import { supportsFeature } from "../common/entity/supports-feature";
import {
LawnMowerEntity,
LawnMowerEntityFeature,
LawnMowerEntityState,
} from "../data/lawn_mower";
import { HomeAssistant } from "../types";
type LawnMowerAction = {
action: string;
service: string;
feature: LawnMowerEntityFeature;
};
const LAWN_MOWER_ACTIONS: Partial<
Record<LawnMowerEntityState, LawnMowerAction>
> = {
mowing: {
action: "dock",
service: "dock",
feature: LawnMowerEntityFeature.DOCK,
},
docked: {
action: "start_mowing",
service: "start_mowing",
feature: LawnMowerEntityFeature.START_MOWING,
},
paused: {
action: "resume_mowing",
service: "start_mowing",
feature: LawnMowerEntityFeature.START_MOWING,
},
};
@customElement("ha-lawn_mower-action-button")
class HaLawnMowerActionButton extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public stateObj!: LawnMowerEntity;
public render() {
const state = this.stateObj.state;
const action = LAWN_MOWER_ACTIONS[state];
if (action && supportsFeature(this.stateObj, action.feature)) {
return html`
<mwc-button @click=${this.callService} .service=${action.service}>
${this.hass.localize(`ui.card.lawn_mower.actions.${action.action}`)}
</mwc-button>
`;
}
return html`
<mwc-button disabled>
${this.hass.formatEntityState(this.stateObj)}
</mwc-button>
`;
}
callService(ev) {
ev.stopPropagation();
const stateObj = this.stateObj;
const service = ev.target.service;
this.hass.callService("lawn_mower", service, {
entity_id: stateObj.entity_id,
});
}
static get styles(): CSSResultGroup {
return css`
mwc-button {
top: 3px;
height: 37px;
margin-right: -0.57em;
}
mwc-button[disabled] {
background-color: transparent;
color: var(--secondary-text-color);
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-lawn_mower-action-button": HaLawnMowerActionButton;
}
}

View File

@@ -47,6 +47,9 @@ export class HaSelect extends SelectBase {
.mdc-select__anchor {
width: var(--ha-select-min-width, 200px);
}
.mdc-select--filled .mdc-select__anchor {
height: var(--ha-select-height, 56px);
}
.mdc-select--filled .mdc-floating-label {
inset-inline-start: 12px;
inset-inline-end: initial;

View File

@@ -1,4 +1,4 @@
import { css, CSSResultGroup, html, LitElement } from "lit";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { Action } from "../../data/script";
import { ActionSelector } from "../../data/selector";
@@ -19,10 +19,13 @@ export class HaActionSelector extends LitElement {
protected render() {
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
<ha-automation-action
.disabled=${this.disabled}
.actions=${this.value || []}
.hass=${this.hass}
.nested=${this.selector.action?.nested}
.reOrderMode=${this.selector.action?.reorder_mode}
></ha-automation-action>
`;
}
@@ -37,6 +40,11 @@ export class HaActionSelector extends LitElement {
opacity: var(--light-disabled-opacity);
pointer-events: none;
}
label {
display: block;
margin-bottom: 4px;
font-weight: 500;
}
`;
}
}

View File

@@ -1,4 +1,4 @@
import { css, CSSResultGroup, html, LitElement } from "lit";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { Condition } from "../../data/automation";
import { ConditionSelector } from "../../data/selector";
@@ -19,10 +19,13 @@ export class HaConditionSelector extends LitElement {
protected render() {
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
<ha-automation-condition
.disabled=${this.disabled}
.conditions=${this.value || []}
.hass=${this.hass}
.nested=${this.selector.condition?.nested}
.reOrderMode=${this.selector.condition?.reorder_mode}
></ha-automation-condition>
`;
}
@@ -37,6 +40,11 @@ export class HaConditionSelector extends LitElement {
opacity: var(--light-disabled-opacity);
pointer-events: none;
}
label {
display: block;
margin-bottom: 4px;
font-weight: 500;
}
`;
}
}

View File

@@ -1075,7 +1075,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
background-color: var(--accent-color);
line-height: 20px;
text-align: center;
padding: 0px 6px;
padding: 0px 2px;
color: var(--text-accent-color, var(--text-primary-color));
}
ha-svg-icon + .notification-badge,

View File

@@ -65,6 +65,7 @@ export class HaTabs extends PaperTabs {
const selected = this.querySelector(".iron-selected");
if (selected) {
selected.scrollIntoView();
this._affectScroll(0); // Ensure scroll arrows match scroll position
}
}

View File

@@ -1,10 +1,14 @@
import { DIRECTION_ALL, Manager, Pan, Tap } from "@egjs/hammerjs";
import { css, html, LitElement, PropertyValues, svg } from "lit";
import { LitElement, PropertyValues, css, html, svg } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
import { rgb2hex } from "../common/color/convert-color";
import { temperature2rgb } from "../common/color/convert-light-color";
import {
DEFAULT_MAX_KELVIN,
DEFAULT_MIN_KELVIN,
temperature2rgb,
} from "../common/color/convert-light-color";
import { fireEvent } from "../common/dom/fire_event";
const SAFE_ZONE_FACTOR = 0.9;
@@ -79,10 +83,10 @@ class HaTempColorPicker extends LitElement {
public value?: number;
@property({ type: Number })
public min = 2000;
public min = DEFAULT_MIN_KELVIN;
@property({ type: Number })
public max = 10000;
public max = DEFAULT_MAX_KELVIN;
@query("#canvas") private _canvas!: HTMLCanvasElement;

View File

@@ -102,9 +102,8 @@ class HaWebRtcPlayer extends LitElement {
offerToReceiveAudio: true,
offerToReceiveVideo: true,
};
const offer: RTCSessionDescriptionInit = await peerConnection.createOffer(
offerOptions
);
const offer: RTCSessionDescriptionInit =
await peerConnection.createOffer(offerOptions);
await peerConnection.setLocalDescription(offer);
let candidates = ""; // Build an Offer SDP string with ice candidates

View File

@@ -1,15 +0,0 @@
import { HomeAssistant } from "../types";
export const createLanguageListEl = (hass: HomeAssistant) => {
const list = document.createElement("datalist");
list.id = "languages";
for (const [language, metadata] of Object.entries(
hass.translationMetadata.translations
)) {
const option = document.createElement("option");
option.value = language;
option.innerText = metadata.nativeName;
list.appendChild(option);
}
return list;
};

View File

@@ -122,6 +122,7 @@ export class HaMediaPlayerBrowse extends LitElement {
}
public disconnectedCallback(): void {
super.disconnectedCallback();
if (this._resizeObserver) {
this._resizeObserver.disconnect();
}

View File

@@ -61,7 +61,18 @@ export const createAuthForUser = async (
password,
});
export const adminChangePassword = async (
export const changePassword = (
hass: HomeAssistant,
current_password: string,
new_password: string
) =>
hass.callWS({
type: "config/auth_provider/homeassistant/change_password",
current_password,
new_password,
});
export const adminChangePassword = (
hass: HomeAssistant,
userId: string,
password: string
@@ -71,3 +82,8 @@ export const adminChangePassword = async (
user_id: userId,
password,
});
export const deleteAllRefreshTokens = (hass: HomeAssistant) =>
hass.callWS({
type: "auth/delete_all_refresh_tokens",
});

View File

@@ -34,14 +34,17 @@ import {
import { haOscillatingOff } from "./icons/haOscillatingOff";
import { haOscillating } from "./icons/haOscillating";
export type HvacMode =
| "off"
| "heat"
| "cool"
| "heat_cool"
| "auto"
| "dry"
| "fan_only";
export const HVAC_MODES = [
"auto",
"heat_cool",
"heat",
"cool",
"dry",
"fan_only",
"off",
] as const;
export type HvacMode = (typeof HVAC_MODES)[number];
export const CLIMATE_PRESET_NONE = "none";
@@ -92,15 +95,13 @@ export const enum ClimateEntityFeature {
AUX_HEAT = 64,
}
const hvacModeOrdering: { [key in HvacMode]: number } = {
auto: 1,
heat_cool: 2,
heat: 3,
cool: 4,
dry: 5,
fan_only: 6,
off: 7,
};
const hvacModeOrdering = HVAC_MODES.reduce(
(order, mode, index) => {
order[mode] = index;
return order;
},
{} as Record<HvacMode, number>
);
export const compareClimateHvacModes = (mode1: HvacMode, mode2: HvacMode) =>
hvacModeOrdering[mode1] - hvacModeOrdering[mode2];

View File

@@ -4,9 +4,8 @@ import {
} from "home-assistant-js-websocket";
import { stateActive } from "../common/entity/state_active";
import { supportsFeature } from "../common/entity/supports-feature";
import { blankBeforePercent } from "../common/translations/blank_before_percent";
import type { HomeAssistant } from "../types";
import { UNAVAILABLE } from "./entity";
import { FrontendLocaleData } from "./translation";
export const enum CoverEntityFeature {
OPEN = 1,
@@ -112,7 +111,7 @@ export interface CoverEntity extends HassEntityBase {
export function computeCoverPositionStateDisplay(
stateObj: CoverEntity,
locale: FrontendLocaleData,
hass: HomeAssistant,
position?: number
) {
const statePosition = stateActive(stateObj)
@@ -123,6 +122,11 @@ export function computeCoverPositionStateDisplay(
const currentPosition = position ?? statePosition;
return currentPosition && currentPosition !== 100
? `${Math.round(currentPosition)}${blankBeforePercent(locale)}%`
? hass.formatEntityAttributeValue(
stateObj,
// Always use position as it's the same formatting as tilt position
"current_position",
Math.round(currentPosition)
)
: "";
}

View File

@@ -2,6 +2,8 @@ import { Connection } from "home-assistant-js-websocket";
import type { HaFormSchema } from "../components/ha-form/types";
import { ConfigEntry } from "./config_entries";
export type FlowType = "config_flow" | "options_flow" | "repair_flow";
export interface DataEntryFlowProgressedEvent {
type: "data_entry_flow_progressed";
data: {
@@ -30,6 +32,7 @@ export interface DataEntryFlowStepForm {
errors: Record<string, string>;
description_placeholders?: Record<string, string>;
last_step: boolean | null;
preview?: string;
}
export interface DataEntryFlowStepExternal {

View File

@@ -21,3 +21,53 @@ export const STATE_ATTRIBUTES = [
"supported_features",
"unit_of_measurement",
];
export const TEMPERATURE_ATTRIBUTES = new Set([
"temperature",
"current_temperature",
"target_temperature",
"target_temp_temp",
"target_temp_high",
"target_temp_step",
"min_temp",
"max_temp",
]);
export const DOMAIN_ATTRIBUTES_UNITS: Record<string, Record<string, string>> = {
climate: {
humidity: "%",
current_humidity: "%",
target_humidity_low: "%",
target_humidity_high: "%",
target_humidity_step: "%",
min_humidity: "%",
max_humidity: "%",
},
cover: {
current_position: "%",
current_tilt_position: "%",
},
fan: {
percentage: "%",
},
humidifier: {
humidity: "%",
current_humidity: "%",
min_humidity: "%",
max_humidity: "%",
},
light: {
color_temp: "mired",
max_mireds: "mired",
min_mireds: "mired",
color_temp_kelvin: "K",
min_color_temp_kelvin: "K",
max_color_temp_kelvin: "K",
},
sun: {
elevation: "°",
},
vacuum: {
battery_level: "%",
},
};

View File

@@ -6,6 +6,7 @@ import { caseInsensitiveStringCompare } from "../common/string/compare";
import { debounce } from "../common/util/debounce";
import { HomeAssistant } from "../types";
import { LightColor } from "./light";
import { computeDomain } from "../common/entity/compute_domain";
type entityCategory = "config" | "diagnostic";
@@ -129,15 +130,29 @@ export interface EntityRegistryEntryUpdateParams {
aliases?: string[];
}
const batteryPriorities = ["sensor", "binary_sensor"];
export const findBatteryEntity = <T extends { entity_id: string }>(
hass: HomeAssistant,
entities: T[]
): T | undefined =>
entities.find(
(entity) =>
hass.states[entity.entity_id] &&
hass.states[entity.entity_id].attributes.device_class === "battery"
);
): T | undefined => {
const batteryEntities = entities
.filter(
(entity) =>
hass.states[entity.entity_id] &&
hass.states[entity.entity_id].attributes.device_class === "battery" &&
batteryPriorities.includes(computeDomain(entity.entity_id))
)
.sort(
(a, b) =>
batteryPriorities.indexOf(computeDomain(a.entity_id)) -
batteryPriorities.indexOf(computeDomain(b.entity_id))
);
if (batteryEntities.length > 0) {
return batteryEntities[0];
}
return undefined;
};
export const findBatteryChargingEntity = <T extends { entity_id: string }>(
hass: HomeAssistant,

View File

@@ -10,8 +10,7 @@ import {
HassEntityBase,
} from "home-assistant-js-websocket";
import { stateActive } from "../common/entity/state_active";
import { blankBeforePercent } from "../common/translations/blank_before_percent";
import { FrontendLocaleData } from "./translation";
import type { HomeAssistant } from "../types";
export const enum FanEntityFeature {
SET_SPEED = 1,
@@ -97,7 +96,7 @@ export const FAN_SPEED_COUNT_MAX_FOR_BUTTONS = 4;
export function computeFanSpeedStateDisplay(
stateObj: FanEntity,
locale: FrontendLocaleData,
hass: HomeAssistant,
speed?: number
) {
const percentage = stateActive(stateObj)
@@ -106,6 +105,10 @@ export function computeFanSpeedStateDisplay(
const currentSpeed = speed ?? percentage;
return currentSpeed
? `${Math.floor(currentSpeed)}${blankBeforePercent(locale)}%`
? hass.formatEntityAttributeValue(
stateObj,
"percentage",
Math.round(currentSpeed)
)
: "";
}

View File

@@ -1,8 +1,10 @@
import {
HassEntityAttributeBase,
HassEntityBase,
UnsubscribeFunc,
} from "home-assistant-js-websocket";
import { computeDomain } from "../common/entity/compute_domain";
import { HomeAssistant } from "../types";
interface GroupEntityAttributes extends HassEntityAttributeBase {
entity_id: string[];
@@ -15,6 +17,11 @@ export interface GroupEntity extends HassEntityBase {
attributes: GroupEntityAttributes;
}
export interface GroupPreview {
state: string;
attributes: Record<string, any>;
}
export const computeGroupDomain = (
stateObj: GroupEntity
): string | undefined => {
@@ -24,3 +31,17 @@ export const computeGroupDomain = (
];
return uniqueDomains.length === 1 ? uniqueDomains[0] : undefined;
};
export const subscribePreviewGroup = (
hass: HomeAssistant,
flow_id: string,
flow_type: "config_flow" | "options_flow",
user_input: Record<string, any>,
callback: (preview: GroupPreview) => void
): Promise<UnsubscribeFunc> =>
hass.connection.subscribeMessage(callback, {
type: "group/start_preview",
flow_id,
flow_type,
user_input,
});

42
src/data/lawn_mower.ts Normal file
View File

@@ -0,0 +1,42 @@
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { UNAVAILABLE } from "./entity";
export type LawnMowerEntityState = "paused" | "mowing" | "docked" | "error";
export const enum LawnMowerEntityFeature {
START_MOWING = 1,
PAUSE = 2,
DOCK = 4,
}
interface LawnMowerEntityAttributes extends HassEntityAttributeBase {
[key: string]: any;
}
export interface LawnMowerEntity extends HassEntityBase {
attributes: LawnMowerEntityAttributes;
}
export function canStartMowing(stateObj: LawnMowerEntity): boolean {
if (stateObj.state === UNAVAILABLE) {
return false;
}
return stateObj.state !== "mowing";
}
export function canPause(stateObj: LawnMowerEntity): boolean {
if (stateObj.state === UNAVAILABLE) {
return false;
}
return stateObj.state !== "paused";
}
export function canDock(stateObj: LawnMowerEntity): boolean {
if (stateObj.state === UNAVAILABLE) {
return false;
}
return stateObj.state !== "docked";
}

View File

@@ -54,8 +54,10 @@ export type Selector =
| UiColorSelector;
export interface ActionSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
action: {} | null;
action: {
reorder_mode?: boolean;
nested?: boolean;
} | null;
}
export interface AddonSelector {
@@ -98,8 +100,10 @@ export interface ColorTempSelector {
}
export interface ConditionSelector {
// eslint-disable-next-line @typescript-eslint/ban-types
condition: {} | null;
condition: {
reorder_mode?: boolean;
nested?: boolean;
} | null;
}
export interface ConversationAgentSelector {

View File

@@ -69,7 +69,7 @@ type SystemHealthEvent =
export const subscribeSystemHealthInfo = (
hass: HomeAssistant,
callback: (info: SystemHealthInfo) => void
callback: (info: SystemHealthInfo | undefined) => void
) => {
let data = {};
@@ -82,6 +82,7 @@ export const subscribeSystemHealthInfo = (
}
if (updateEvent.type === "finish") {
unsubProm.then((unsub) => unsub());
callback(undefined);
return;
}

View File

@@ -1,15 +1,21 @@
import { HomeAssistant, TranslationDict } from "../types";
import { HomeAssistant } from "../types";
export type SystemLogLevel =
| "critical"
| "error"
| "warning"
| "info"
| "debug";
export interface LoggedError {
name: string;
message: [string];
level: keyof TranslationDict["ui"]["panel"]["config"]["logs"]["level"];
level: SystemLogLevel;
source: [string, number];
// unix timestamp in seconds
timestamp: number;
exception: string;
count: number;
// unix timestamp in seconds
// unix timestamps in seconds
timestamp: number;
first_occurred: number;
}

View File

@@ -18,14 +18,17 @@ export const enum WaterHeaterEntityFeature {
AWAY_MODE = 4,
}
export type OperationMode =
| "eco"
| "electric"
| "performance"
| "high_demand"
| "heat_pump"
| "gas"
| "off";
export const OPERATION_MODES = [
"electric",
"gas",
"heat_pump",
"eco",
"performance",
"high_demand",
"off",
] as const;
export type OperationMode = (typeof OPERATION_MODES)[number];
export type WaterHeaterEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
@@ -40,20 +43,20 @@ export type WaterHeaterEntity = HassEntityBase & {
};
};
const hvacModeOrdering: { [key in OperationMode]: number } = {
eco: 1,
electric: 2,
performance: 3,
high_demand: 4,
heat_pump: 5,
gas: 6,
off: 7,
};
const waterHeaterOperationModeOrdering = OPERATION_MODES.reduce(
(order, mode, index) => {
order[mode] = index;
return order;
},
{} as Record<OperationMode, number>
);
export const compareWaterHeaterOperationMode = (
mode1: OperationMode,
mode2: OperationMode
) => hvacModeOrdering[mode1] - hvacModeOrdering[mode2];
) =>
waterHeaterOperationModeOrdering[mode1] -
waterHeaterOperationModeOrdering[mode2];
export const WATER_HEATER_OPERATION_MODE_ICONS: Record<OperationMode, string> =
{

View File

@@ -19,13 +19,14 @@ import {
mdiWeatherWindyVariant,
} from "@mdi/js";
import {
HassConfig,
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { css, html, svg, SVGTemplateResult, TemplateResult } from "lit";
import { SVGTemplateResult, TemplateResult, css, html, svg } from "lit";
import { styleMap } from "lit/directives/style-map";
import { supportsFeature } from "../common/entity/supports-feature";
import { formatNumber } from "../common/number/format_number";
import { round } from "../common/number/round";
import "../components/ha-svg-icon";
import type { HomeAssistant } from "../types";
@@ -187,11 +188,7 @@ export const getWind = (
): string => {
const speedText =
speed !== undefined && speed !== null
? `${formatNumber(speed, hass.locale)} ${getWeatherUnit(
hass!,
stateObj,
"wind_speed"
)}`
? hass.formatEntityAttributeValue(stateObj, "wind_speed", speed)
: "-";
if (bearing !== undefined && bearing !== null) {
const cardinalDirection = getWindBearing(bearing);
@@ -205,11 +202,11 @@ export const getWind = (
};
export const getWeatherUnit = (
hass: HomeAssistant,
config: HassConfig,
stateObj: WeatherEntity,
measure: string
): string => {
const lengthUnit = hass.config.unit_system.length || "";
const lengthUnit = config.unit_system.length || "";
switch (measure) {
case "visibility":
return stateObj.attributes.visibility_unit || lengthUnit;
@@ -224,9 +221,9 @@ export const getWeatherUnit = (
(lengthUnit === "km" ? "hPa" : "inHg")
);
case "temperature":
case "templow":
return (
stateObj.attributes.temperature_unit ||
hass.config.unit_system.temperature
stateObj.attributes.temperature_unit || config.unit_system.temperature
);
case "wind_speed":
return stateObj.attributes.wind_speed_unit || `${lengthUnit}/h`;
@@ -234,7 +231,7 @@ export const getWeatherUnit = (
case "precipitation_probability":
return "%";
default:
return hass.config.unit_system[measure] || "";
return config.unit_system[measure] || "";
}
};
@@ -268,14 +265,15 @@ export const getSecondaryWeatherAttribute = (
const weatherAttrIcon = weatherAttrIcons[attribute];
const roundedValue = round(value, 1);
return html`
${weatherAttrIcon
? html`
<ha-svg-icon class="attr-icon" .path=${weatherAttrIcon}></ha-svg-icon>
`
: hass!.localize(`ui.card.weather.attributes.${attribute}`)}
${formatNumber(value, hass.locale, { maximumFractionDigits: 1 })}
${getWeatherUnit(hass!, stateObj, attribute)}
${hass.formatEntityAttributeValue(stateObj, attribute, roundedValue)}
`;
};
@@ -311,12 +309,14 @@ const getWeatherExtrema = (
return undefined;
}
const unit = getWeatherUnit(hass!, stateObj, "temperature");
return html`
${tempHigh ? `${formatNumber(tempHigh, hass.locale)} ${unit}` : ""}
${tempHigh
? hass.formatEntityAttributeValue(stateObj, "temperature", tempHigh)
: ""}
${tempLow && tempHigh ? " / " : ""}
${tempLow ? `${formatNumber(tempLow, hass.locale)} ${unit}` : ""}
${tempLow
? hass.formatEntityAttributeValue(stateObj, "temperature", tempLow)
: ""}
`;
};

View File

@@ -0,0 +1,71 @@
import { HassEntity } from "home-assistant-js-websocket";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { isUnavailableState } from "../../../data/entity";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
import { HomeAssistant } from "../../../types";
@customElement("entity-preview-row")
class EntityPreviewRow extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@state() private stateObj?: HassEntity;
protected render() {
if (!this.stateObj) {
return nothing;
}
const stateObj = this.stateObj;
return html`<state-badge
.hass=${this.hass}
.stateObj=${stateObj}
></state-badge>
<div class="name" .title=${computeStateName(stateObj)}>
${computeStateName(stateObj)}
</div>
<div class="value">
${stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
!isUnavailableState(stateObj.state)
? html`
<hui-timestamp-display
.hass=${this.hass}
.ts=${new Date(stateObj.state)}
capitalize
></hui-timestamp-display>
`
: computeStateDisplay(
this.hass!.localize,
stateObj,
this.hass.locale,
this.hass.config,
this.hass.entities
)}
</div>`;
}
static get styles(): CSSResultGroup {
return css`
:host {
display: flex;
align-items: center;
flex-direction: row;
}
.name {
margin-left: 16px;
margin-right: 8px;
flex: 1 1 30%;
}
.value {
direction: ltr;
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"entity-preview-row": EntityPreviewRow;
}
}

View File

@@ -0,0 +1,90 @@
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
import { LitElement, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { FlowType } from "../../../data/data_entry_flow";
import { GroupPreview, subscribePreviewGroup } from "../../../data/group";
import { HomeAssistant } from "../../../types";
import "./entity-preview-row";
import { debounce } from "../../../common/util/debounce";
@customElement("flow-preview-group")
class FlowPreviewGroup extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public flowType!: FlowType;
public handler!: string;
@property() public stepId!: string;
@property() public flowId!: string;
@property() public stepData!: Record<string, any>;
@state() private _preview?: HassEntity;
private _unsub?: Promise<UnsubscribeFunc>;
disconnectedCallback(): void {
super.disconnectedCallback();
if (this._unsub) {
this._unsub.then((unsub) => unsub());
this._unsub = undefined;
}
}
willUpdate(changedProps) {
if (changedProps.has("stepData")) {
this._debouncedSubscribePreview();
}
}
protected render() {
return html`<entity-preview-row
.hass=${this.hass}
.stateObj=${this._preview}
></entity-preview-row>`;
}
private _setPreview = (preview: GroupPreview) => {
const now = new Date().toISOString();
this._preview = {
entity_id: `${this.stepId}.flow_preview`,
last_changed: now,
last_updated: now,
context: { id: "", parent_id: null, user_id: null },
...preview,
};
};
private _debouncedSubscribePreview = debounce(() => {
this._subscribePreview();
}, 250);
private async _subscribePreview() {
if (this._unsub) {
(await this._unsub)();
this._unsub = undefined;
}
if (this.flowType === "repair_flow") {
return;
}
try {
this._unsub = subscribePreviewGroup(
this.hass,
this.flowId,
this.flowType,
this.stepData,
this._setPreview
);
} catch (err) {
this._preview = undefined;
}
}
}
declare global {
interface HTMLElementTagNameMap {
"flow-preview-group": FlowPreviewGroup;
}
}

View File

@@ -19,6 +19,7 @@ export const showConfigFlowDialog = (
dialogParams: Omit<DataEntryFlowDialogParams, "flowConfig">
): void =>
showFlowDialog(element, dialogParams, {
flowType: "config_flow",
loadDevicesAndAreas: true,
createFlow: async (hass, handler) => {
const [step] = await Promise.all([

View File

@@ -9,11 +9,14 @@ import {
DataEntryFlowStepForm,
DataEntryFlowStepMenu,
DataEntryFlowStepProgress,
FlowType,
} from "../../data/data_entry_flow";
import type { IntegrationManifest } from "../../data/integration";
import type { HomeAssistant } from "../../types";
export interface FlowConfig {
flowType: FlowType;
loadDevicesAndAreas: boolean;
createFlow(hass: HomeAssistant, handler: string): Promise<DataEntryFlowStep>;

View File

@@ -27,6 +27,7 @@ export const showOptionsFlowDialog = (
manifest,
},
{
flowType: "options_flow",
loadDevicesAndAreas: false,
createFlow: async (hass, handler) => {
const [step] = await Promise.all([

View File

@@ -1,15 +1,18 @@
import "@material/mwc-button";
import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
import "@material/mwc-button";
import {
css,
CSSResultGroup,
html,
LitElement,
nothing,
PropertyValues,
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
import { fireEvent } from "../../common/dom/fire_event";
import { isNavigationClick } from "../../common/dom/is-navigation-click";
import "../../components/ha-alert";
import "../../components/ha-circular-progress";
import { computeInitialHaFormData } from "../../components/ha-form/compute-initial-ha-form-data";
@@ -21,7 +24,7 @@ import type { DataEntryFlowStepForm } from "../../data/data_entry_flow";
import type { HomeAssistant } from "../../types";
import type { FlowConfig } from "./show-dialog-data-entry-flow";
import { configFlowContentStyles } from "./styles";
import { isNavigationClick } from "../../common/dom/is-navigation-click";
import { haStyle } from "../../resources/styles";
@customElement("step-flow-form")
class StepFlowForm extends LitElement {
@@ -66,6 +69,23 @@ class StepFlowForm extends LitElement {
.localizeValue=${this._localizeValueCallback}
></ha-form>
</div>
${step.preview
? html`<div class="preview">
<h3>
${this.hass.localize(
"ui.panel.config.integrations.config_flow.preview"
)}:
</h3>
${dynamicElement(`flow-preview-${this.step.preview}`, {
hass: this.hass,
flowType: this.flowConfig.flowType,
handler: step.handler,
stepId: step.step_id,
flowId: step.flow_id,
stepData,
})}
</div>`
: nothing}
<div class="buttons">
${this._loading
? html`
@@ -93,6 +113,13 @@ class StepFlowForm extends LitElement {
this.addEventListener("keydown", this._handleKeyDown);
}
protected willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps);
if (changedProps.has("step") && this.step?.preview) {
import(`./previews/flow-preview-${this.step.preview}`);
}
}
private _clickHandler(ev: MouseEvent) {
if (isNavigationClick(ev, false)) {
fireEvent(this, "flow-update", {
@@ -199,6 +226,7 @@ class StepFlowForm extends LitElement {
static get styles(): CSSResultGroup {
return [
haStyle,
configFlowContentStyles,
css`
.error {

View File

@@ -23,7 +23,8 @@ export const configFlowContentStyles = css`
box-sizing: border-box;
}
.content {
.content,
.preview {
margin-top: 20px;
padding: 0 24px;
}

View File

@@ -6,8 +6,6 @@ import { stateActive } from "../../../../common/entity/state_active";
import { domainStateColorProperties } from "../../../../common/entity/state_color";
import { supportsFeature } from "../../../../common/entity/supports-feature";
import { clamp } from "../../../../common/number/clamp";
import { formatNumber } from "../../../../common/number/format_number";
import { blankBeforePercent } from "../../../../common/translations/blank_before_percent";
import { debounce } from "../../../../common/util/debounce";
import "../../../../components/ha-control-circular-slider";
import "../../../../components/ha-outlined-icon-button";
@@ -116,18 +114,19 @@ export class HaMoreInfoClimateHumidity extends LitElement {
}
private _renderTarget(humidity: number) {
const formatted = formatNumber(humidity, this.hass.locale, {
maximumFractionDigits: 0,
});
const rounded = Math.round(humidity);
const formatted = this.hass.formatEntityAttributeValue(
this.stateObj,
"humidity",
rounded
);
return html`
<div class="target">
<p class="value" aria-hidden="true">
${formatted}<span class="unit">%</span>
</p>
<p class="visually-hidden">
${formatted}${blankBeforePercent(this.hass.locale)}%
${rounded}<span class="unit">%</span>
</p>
<p class="visually-hidden">${formatted}</p>
</div>
`;
}
@@ -164,6 +163,7 @@ export class HaMoreInfoClimateHumidity extends LitElement {
})}
>
<ha-control-circular-slider
.inactive=${!active}
.value=${this._targetHumidity}
.min=${this._min}
.max=${this._max}

View File

@@ -10,6 +10,7 @@ import {
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
import { UNIT_F } from "../../../../common/const";
import { computeAttributeValueDisplay } from "../../../../common/entity/compute_attribute_display";
import { stateActive } from "../../../../common/entity/state_active";
import { stateColorCss } from "../../../../common/entity/state_color";
@@ -18,12 +19,14 @@ import { clamp } from "../../../../common/number/clamp";
import { formatNumber } from "../../../../common/number/format_number";
import { debounce } from "../../../../common/util/debounce";
import "../../../../components/ha-control-circular-slider";
import type { ControlCircularSliderMode } from "../../../../components/ha-control-circular-slider";
import "../../../../components/ha-outlined-icon-button";
import "../../../../components/ha-svg-icon";
import {
CLIMATE_HVAC_ACTION_TO_MODE,
ClimateEntity,
ClimateEntityFeature,
HvacMode,
} from "../../../../data/climate";
import { UNAVAILABLE } from "../../../../data/entity";
import { HomeAssistant } from "../../../../types";
@@ -31,6 +34,16 @@ import { moreInfoControlCircularSliderStyle } from "../ha-more-info-control-circ
type Target = "value" | "low" | "high";
const SLIDER_MODES: Record<HvacMode, ControlCircularSliderMode> = {
auto: "full",
cool: "end",
dry: "full",
fan_only: "full",
heat: "start",
heat_cool: "full",
off: "full",
};
@customElement("ha-more-info-climate-temperature")
export class HaMoreInfoClimateTemperature extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@@ -55,7 +68,7 @@ export class HaMoreInfoClimateTemperature extends LitElement {
private get _step() {
return (
this.stateObj.attributes.target_temp_step ||
(this.hass.config.unit_system.temperature.indexOf("F") === -1 ? 0.5 : 1)
(this.hass.config.unit_system.temperature === UNIT_F ? 1 : 0.5)
);
}
@@ -267,17 +280,15 @@ export class HaMoreInfoClimateTemperature extends LitElement {
);
}
const hvacModes = this.stateObj.attributes.hvac_modes;
const activeModes = this.stateObj.attributes.hvac_modes.filter(
(m) => m !== "off"
);
if (
supportsTargetTemperature &&
this._targetTemperature.value != null &&
this.stateObj.state !== UNAVAILABLE
) {
const hasOnlyCoolMode =
hvacModes.length === 2 &&
hvacModes.includes("cool") &&
hvacModes.includes("off");
return html`
<div
class="container"
@@ -287,7 +298,10 @@ export class HaMoreInfoClimateTemperature extends LitElement {
})}
>
<ha-control-circular-slider
.inverted=${mode === "cool" || hasOnlyCoolMode}
.inactive=${!active}
.mode=${mode === "off" && activeModes.length === 1
? SLIDER_MODES[activeModes[0]]
: SLIDER_MODES[mode]}
.value=${this._targetTemperature.value}
.min=${this._min}
.max=${this._max}
@@ -324,6 +338,7 @@ export class HaMoreInfoClimateTemperature extends LitElement {
})}
>
<ha-control-circular-slider
.inactive=${!active}
dual
.low=${this._targetTemperature.low}
.high=${this._targetTemperature.high}
@@ -416,11 +431,12 @@ export class HaMoreInfoClimateTemperature extends LitElement {
font-size: 20px;
line-height: 24px;
align-self: flex-start;
margin-left: -20px;
width: 20px;
margin-top: 4px;
}
.decimal + .unit {
margin-left: -20px;
}
.dual {
display: flex;
flex-direction: row;

View File

@@ -35,7 +35,9 @@ export class HaMoreInfoCoverPosition extends LitElement {
}
protected render(): TemplateResult {
const color = stateColorCss(this.stateObj);
const forcedState = this.stateObj.state === "closed" ? "open" : undefined;
const color = stateColorCss(this.stateObj, forcedState);
return html`
<ha-control-slider
@@ -50,7 +52,7 @@ export class HaMoreInfoCoverPosition extends LitElement {
this.hass.localize,
this.stateObj,
this.hass.entities,
"position"
"current_position"
)}
style=${styleMap({
"--control-slider-color": color,
@@ -68,8 +70,6 @@ export class HaMoreInfoCoverPosition extends LitElement {
height: 45vh;
max-height: 320px;
min-height: 200px;
/* Force inactive state to be colored for the slider */
--state-cover-inactive-color: var(--state-cover-active-color);
--control-slider-thickness: 100px;
--control-slider-border-radius: 24px;
--control-slider-color: var(--primary-color);

View File

@@ -15,7 +15,7 @@ import { CoverEntity } from "../../../../data/cover";
import { UNAVAILABLE } from "../../../../data/entity";
import { HomeAssistant } from "../../../../types";
function generateTiltSliderTrackBackgroundGradient() {
export function generateTiltSliderTrackBackgroundGradient() {
const count = 24;
const minStrokeWidth = 0.2;
const gradient: [number, string][] = [];
@@ -72,8 +72,9 @@ export class HaMoreInfoCoverTiltPosition extends LitElement {
}
protected render(): TemplateResult {
const color = stateColorCss(this.stateObj);
const isUnavailable = this.stateObj.state === UNAVAILABLE;
const forcedState = this.stateObj.state === "closed" ? "open" : undefined;
const color = stateColorCss(this.stateObj, forcedState);
return html`
<ha-control-slider
@@ -87,13 +88,13 @@ export class HaMoreInfoCoverTiltPosition extends LitElement {
this.hass.localize,
this.stateObj,
this.hass.entities,
"tilt_position"
"current_tilt_position"
)}
style=${styleMap({
"--control-slider-color": color,
"--control-slider-background": color,
})}
.disabled=${isUnavailable}
.disabled=${this.stateObj.state === UNAVAILABLE}
>
<div slot="background" class="gradient"></div>
</ha-control-slider>
@@ -106,8 +107,6 @@ export class HaMoreInfoCoverTiltPosition extends LitElement {
height: 45vh;
max-height: 320px;
min-height: 200px;
/* Force inactive state to be colored for the slider */
--state-cover-inactive-color: var(--state-cover-active-color);
--control-slider-thickness: 100px;
--control-slider-border-radius: 24px;
--control-slider-color: var(--primary-color);

View File

@@ -0,0 +1,79 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@customElement("ha-more-info-control-select-container")
export class HaMoreInfoControlSelectContainer extends LitElement {
protected render(): TemplateResult {
const classname = `items-${this.childElementCount}`;
return html`
<div class="controls">
<div
class="controls-scroll ${classMap({
[classname]: true,
multiline: this.childElementCount >= 4,
})}"
>
<slot></slot>
</div>
</div>
`;
}
static get styles(): CSSResultGroup {
return css`
.controls {
display: flex;
flex-direction: row;
justify-content: center;
}
.controls-scroll {
display: flex;
flex-direction: row;
justify-content: flex-start;
gap: 12px;
margin: auto;
overflow: auto;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
margin: 0 -24px;
padding: 0 24px;
}
.controls-scroll::-webkit-scrollbar {
display: none;
}
::slotted(*) {
min-width: 120px;
max-width: 160px;
flex: none;
}
@media all and (hover: hover),
all and (min-width: 600px) and (min-height: 501px) {
.controls-scroll {
justify-content: center;
flex-wrap: wrap;
width: 100%;
max-width: 450px;
}
.controls-scroll.items-4 {
max-width: 300px;
}
.controls-scroll.items-3 ::slotted(*) {
max-width: 140px;
}
.multiline ::slotted(*) {
width: 140px;
}
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-more-info-control-select-container": HaMoreInfoControlSelectContainer;
}
}

View File

@@ -22,35 +22,6 @@ export const moreInfoControlStyle = css`
margin-bottom: 24px;
}
.secondary-controls {
display: flex;
flex-direction: row;
justify-content: center;
}
.secondary-controls-scroll {
display: flex;
flex-direction: row;
justify-content: flex-start;
gap: 12px;
margin: auto;
overflow: auto;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
margin: 0 -24px;
padding: 0 24px;
}
.secondary-controls-scroll::-webkit-scrollbar {
display: none;
}
/* Don't use scroll on device without touch support */
@media (hover: hover) {
.secondary-controls-scroll {
justify-content: center;
flex-wrap: wrap;
}
}
.buttons {
display: flex;
align-items: center;

View File

@@ -184,7 +184,8 @@ export class HaMoreInfoHumidifierHumidity extends LitElement {
})}
>
<ha-control-circular-slider
.inverted=${inverted}
.inactive=${!active}
.mode=${inverted ? "end" : "start"}
.value=${targetHumidity}
.min=${this._min}
.max=${this._max}

View File

@@ -16,6 +16,10 @@ import {
LightEntity,
} from "../../../../data/light";
import { HomeAssistant } from "../../../../types";
import {
DEFAULT_MAX_KELVIN,
DEFAULT_MIN_KELVIN,
} from "../../../../common/color/convert-light-color";
declare global {
interface HASSDomEvents {
@@ -37,12 +41,17 @@ class LightColorTempPicker extends LitElement {
return nothing;
}
const minKelvin =
this.stateObj.attributes.min_color_temp_kelvin ?? DEFAULT_MIN_KELVIN;
const maxKelvin =
this.stateObj.attributes.max_color_temp_kelvin ?? DEFAULT_MAX_KELVIN;
return html`
<ha-temp-color-picker
@value-changed=${this._ctColorChanged}
@cursor-moved=${this._ctColorCursorMoved}
.min=${this.stateObj.attributes.min_color_temp_kelvin!}
.max=${this.stateObj.attributes.max_color_temp_kelvin!}
.min=${minKelvin}
.max=${maxKelvin}
.value=${this._ctPickerValue}
>
</ha-temp-color-picker>

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