Compare commits

...

136 Commits

Author SHA1 Message Date
Bram Kragten
64f54d9aaa 20240424.1 (#20609) 2024-04-24 14:45:22 +02:00
Bram Kragten
fbda9ca418 Bumped version to 20240424.1 2024-04-24 14:30:36 +02:00
Paul Bottein
4e97e3763e Use theme mode property for ha-map (#20606)
* Use theme mode property for ha-map

* Use theme mode in ha-location-editor

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-24 14:28:33 +02:00
Bram Kragten
4c9c52d27d Add filter for domains to entity settings (#20605) 2024-04-24 13:53:14 +02:00
Bram Kragten
87bcd3e471 Add multiselect area to automation/scene/script (#20604) 2024-04-24 10:10:43 +00:00
Paul Bottein
7e9b01b56d Fix text alignment for open lock card feature (#20603)
Fix text aligment for open lock card feature
2024-04-24 09:36:17 +00:00
karwosts
713763fc21 Fix visual map issues (#20541)
* Fix visual map issues (#15587)

- hover background color of zoom control in dark mode
- map light mode when dark theme is used
- background color of zoom control with map dark mode when light theme is used

* Fix breaking change (#15587)

* Change theme mode selection to use dropdown (#15587)

- Additionally fixed unpleasant horizontal scrollbar in map editor

* Add yaml migration, fix force light/dark options

---------

Co-authored-by: Christoph Wen <wen.christoph@gmail.com>
2024-04-24 11:35:37 +02:00
renovate[bot]
5b7ab1bfcb Update dependency cropperjs to v1.6.2 (#20600)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-24 11:28:58 +02:00
Bram Kragten
8712adbf8d 20240424.0 (#20602) 2024-04-24 11:21:24 +02:00
Bram Kragten
4b0d19b615 Fix duplicate imports from merge 2024-04-24 11:14:55 +02:00
Bram Kragten
90e5d259af Merge branch 'master' into dev 2024-04-24 11:13:34 +02:00
Bram Kragten
af3a331f57 Bumped version to 20240424.0 2024-04-24 11:09:48 +02:00
Bram Kragten
67c60a4aa8 Add strict connection cloud settings (#20585)
* Add strict connection cloud settings

* Change static page to guard page

* saving files helps...

* Add create link button

* use correct service
2024-04-24 11:06:15 +02:00
Bram Kragten
62de16bb8e Implement storing sorting and grouping for all tables (#20594) 2024-04-24 11:06:00 +02:00
Marc Geurts
d9b71e754d Add lock features for tile card (#20539)
* Added lock features for tile card

* Change success label
2024-04-24 10:30:34 +02:00
Matthias Alphart
5fc950f09f Fix ha-filter-states clear filter behaviour (#20599)
Fix ha-filter-states clear filter behaviour
2024-04-24 10:28:17 +02:00
J. Nick Koston
0725c7b160 Restore getHassTranslationsPre109 (#20597)
* Revert "Remove legacy state translations (#20536)"

This reverts commit e376efc579.

* keep
2024-04-24 10:26:24 +02:00
Steve Repsher
469dbbcccc Rollback gulp to version 4 (#20598) 2024-04-24 10:25:52 +02:00
Bram Kragten
ffdd661b1f Make fallback translations work (#20596) 2024-04-24 07:31:29 +02:00
Bram Kragten
81922f5a3e Save and restore collapsed groups (#20591) 2024-04-23 21:00:17 +02:00
renovate[bot]
7e25366897 Update dependency @types/chromecast-caf-receiver to v6.0.14 (#20589)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-23 18:04:44 +02:00
Bram Kragten
8ab61b5468 Add title when text in datatable doesnt fit (#20590) 2024-04-23 13:50:44 +02:00
Bram Kragten
8239f6dd60 Update hass-tabs-subpage-data-table.ts 2024-04-22 20:28:21 +02:00
Bram Kragten
45dce18e4d typo 2024-04-22 20:15:52 +02:00
Bram Kragten
a428ad0655 Add bulk area assignment to device dashboard (#20581)
* Add bulk area assignment to device dashboard

* Update ha-config-devices-dashboard.ts
2024-04-22 18:35:58 +02:00
Bram Kragten
1b54d51e4a Add option for custom group order to data table (#20582) 2024-04-22 18:28:50 +02:00
Bram Kragten
eb1354d229 Allow groups in data table to be collapsed (#20579) 2024-04-22 18:27:46 +02:00
Bram Kragten
4d21f9e80c Allow to group entities by domain (#20580)
Allow group entities by domain
2024-04-22 18:27:13 +02:00
Paul Bottein
62f46baacf Fix more info slider in iOS (#20586) 2024-04-22 18:26:50 +02:00
Bram Kragten
a3090796d2 Store grouping and sorting for device table (#20583) 2024-04-22 18:13:44 +02:00
renovate[bot]
c34c5d64f9 Update dependency @codemirror/commands to v6.5.0 (#20587)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 18:09:46 +02:00
Bram Kragten
66228f5858 Add new timestamp state domains (#20584) 2024-04-22 16:33:32 +02:00
Bram Kragten
ac378cfe6d Update external barcode scanning API (#20470) 2024-04-22 12:52:59 +02:00
Nicooow
7ecf8b755e Add css var for meta theme-color attribute (#20558)
* add app-theme-color var

* Fix Prettier format
2024-04-22 09:51:21 +02:00
Matthias Alphart
141107f1f3 Apply initial values to forms of device trigger extra fields (#20555)
* Apply default values of device trigger extra fields

* use computeInitialHaFormData
2024-04-22 09:48:50 +02:00
karwosts
b5277dee53 When munging statistics to history, assume always numeric (#20544) 2024-04-22 09:41:12 +02:00
Steve Repsher
4b593c1c96 Enhance webpack transform async plugin to use babel runtime (#20543) 2024-04-22 09:40:20 +02:00
dependabot[bot]
50ce1b94c8 Bump actions/upload-artifact from 4.3.1 to 4.3.2 (#20575)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-22 09:22:38 +02:00
dependabot[bot]
8bf27a83ec Bump actions/checkout from 4.1.2 to 4.1.3 (#20576)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-22 09:21:14 +02:00
renovate[bot]
389f0d3d23 Update dependency marked to v12.0.2 (#20577)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 09:19:52 +02:00
karwosts
b966601e6a Hide beta toggle when unsupervised (#20573) 2024-04-21 09:50:14 +02:00
renovate[bot]
f2a0881821 Update dependency @types/tar to v6.1.13 (#20572)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-21 09:36:09 +02:00
renovate[bot]
50a49eae43 Update dependency date-fns-tz to v3.1.3 (#20552)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 14:23:57 -04:00
renovate[bot]
1c04561004 Update dependency @codemirror/commands to v6.4.0 (#20569)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 19:39:54 +02:00
renovate[bot]
b80d94d260 Update dependency magic-string to v0.30.10 (#20568)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 19:39:42 +02:00
karwosts
87012e23e7 Wrap unbreakable area names in ha-card header (#20566) 2024-04-20 19:39:24 +02:00
Simon Lamon
f39758b103 Only create sortable when not disabled (#20565) 2024-04-20 14:32:40 +02:00
G Johansson
697bbf428e Add translation to integration setup failures (#19128) 2024-04-20 09:16:36 +02:00
renovate[bot]
c7444a2605 Update dependency @octokit/auth-oauth-device to v7.1.1 (#20560)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 09:03:01 +02:00
karwosts
3a5f4d33d2 Fix stopped_unknown_reason localization message (#20557)
* Fix stopped_unknown_reason localization message
2024-04-20 08:45:05 +02:00
renovate[bot]
c3dc62523b Update dependency core-js to v3.37.0 (#20559) 2024-04-19 20:45:00 -04:00
renovate[bot]
424622061a Lock file maintenance (#20553) 2024-04-19 00:47:42 -04:00
renovate[bot]
a3b021b11d Update dependency @material/web to v1.4.1 (#20551) 2024-04-19 00:12:18 -04:00
renovate[bot]
b60ad8b143 Update typescript-eslint monorepo to v7.7.0 (#20549) 2024-04-18 18:55:17 -04:00
J. Nick Koston
e376efc579 Remove legacy state translations (#20536)
* Remove legacy state translations

https://github.com/home-assistant/core/pull/112023
2024-04-18 06:33:07 +02:00
renovate[bot]
382035a1d4 Update dependency @types/color-name to v1.1.4 (#20546)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-17 18:55:59 -04:00
renovate[bot]
542e22fe0e Update dependency tar to v7.0.1 (#20547)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-17 22:54:57 +00:00
karwosts
af37d57779 Fix entity picker delete entity (#20542) 2024-04-17 19:48:25 +02:00
renovate[bot]
fbef0b0186 Update dependency gulp to v5 (#20305)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-17 12:31:10 -04:00
renovate[bot]
9e67d6add8 Update dependency @types/leaflet to v1.9.11 (#20538)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-17 18:21:59 +02:00
Simon Lamon
25c702ad2b Don't display keyboard shortcut hints in quickbar if keyboard shortcuts are disabled (#20527)
Fix forgotten hint shortcut tip
2024-04-15 20:20:45 +02:00
Bram Kragten
6516597c93 Fix zones on mobile, align mobile and non mobile view (#20525)
* Fix zones on mobile, align mobile and non mobile view

* Fix CI

---------

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
2024-04-15 20:20:14 +02:00
renovate[bot]
1df9c38a8c Update dependency tar to v7 (#20513)
* Update dependency tar to v7

* Update fetch-nightly-translations.js

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-15 13:40:38 +00:00
renovate[bot]
bd7217145a Update dependency element-internals-polyfill to v1.3.11 (#20512)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-15 15:07:09 +02:00
renovate[bot]
569fef38a4 Update vaadinWebComponents monorepo to v24.3.11 (#20523)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-15 15:03:46 +02:00
Thomas Steiner
f21c89cf1a Make allow attribute configurable in iframe panel (#19087)
* Make allow attribute configurable in iframe panel

* Delete .vscode/settings.json

* Update ha-panel-iframe.ts

* Don't quote

* Update src/panels/iframe/ha-panel-iframe.ts

Co-authored-by: Quentame <polletquentin74@me.com>

* Make `allow` configurable for `hui-iframe-card`

* Update src/panels/iframe/ha-panel-iframe.ts

Co-authored-by: Quentame <polletquentin74@me.com>

* Update src/panels/lovelace/cards/hui-iframe-card.ts

Co-authored-by: Quentame <polletquentin74@me.com>

* Update src/panels/iframe/ha-panel-iframe.ts

Co-authored-by: Quentame <polletquentin74@me.com>

* Update src/panels/lovelace/cards/hui-iframe-card.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

* Delete src/panels/iframe/ha-panel-iframe.ts

* Restore dev

* Update ha-panel-iframe.ts

* Prettier

---------

Co-authored-by: Quentame <polletquentin74@me.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-15 14:48:57 +02:00
renovate[bot]
02cc418969 Update CodeMirror (#20520)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-15 09:21:07 +00:00
Cougar
4faba159c0 ZHA (Zigbee) visualization enhancement (#20511) 2024-04-15 11:09:16 +02:00
Adam Kapos
29816e6c5e Fix malformed CSS in dialog surface (#20519) 2024-04-15 11:06:07 +02:00
karwosts
5317a11c39 Sort custom cards in card picker (#20517) 2024-04-14 22:32:35 +02:00
Simon Lamon
27c53b3241 Replace paper-listbox in zone area (#19955)
* ha-config-zone

* Fixes

* add selected event back

* Fixes

* remove leftover paper-item css rule

* Fixup merge conflict
2024-04-14 13:46:38 +02:00
renovate[bot]
919befa961 Update dependency typescript to v5.4.5 (#20510) 2024-04-13 20:43:27 -04:00
renovate[bot]
f9c02ed099 Update dependency date-fns-tz to v3.0.1 (#20509) 2024-04-13 20:38:12 -04:00
karwosts
b35c325f43 Rebuild stack card when a child card rebuilds (#19861) 2024-04-12 20:53:04 +02:00
karwosts
b82f1128fe Location/zone editor updates (#19994) 2024-04-12 20:51:23 +02:00
karwosts
178feb7330 Create helpers from automation editor (#19287)
* Create helpers from automation editor

* support multiple createDomains

* localization

* fix lint

* Move multi domain to entity picker

* Update dialog-helper-detail.ts

* Update ha-config-helpers.ts

* optimize a little

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-12 18:38:39 +00:00
karwosts
0118a5bf4c Allow customizing display name for energy device (#20033)
* Allow customizing display name for energy device

* use display name in device settings list
2024-04-12 20:31:59 +02:00
renovate[bot]
e0087bd142 Update dependency @material/web to v1.4.0 (#20177)
* Update dependency @material/web to v1.4.0

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
2024-04-12 15:15:33 +00:00
renovate[bot]
c2d3e7900e Update date-fns to v3 (major) (#20504)
* Update date-fns to v3

* update imports

* breaking changes

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-12 17:03:30 +02:00
Charles Garwood
fb8312110b Add support for setting label description (#20421)
* Add support for setting label description
2024-04-12 15:49:07 +02:00
renovate[bot]
16de57342e Update dependency eslint-plugin-wc to v2.1.0 (#20500)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-12 08:23:48 -04:00
renovate[bot]
ad6e041c04 Update dependency @codemirror/view to v6.26.2 (#20505)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-12 13:10:15 +02:00
Steve Repsher
e22e3e88a0 Speed up and simplify translations build (#19988)
* Speed up and simplify translations build

- Remove use of gulp-flatmap for merges (wasted input) and just loop over translation files.
- Parse and buffer master only once for all merges.
- Remove lokalise key reference transform from non-English files. This is already done by Lokalise when they are downloaded.
- Remove tabs from merged output to minimize buffer sizes.
- Pipe merges to a hashing stream, removing extra tasks and intermediate file I/O.
- Pipe hashed files to a single custom asynchronous transform stream to fragmentize the files. It expands the stream to push a new file for each fragment.
- Incorporate flattening into fragmentization.
- Delete entire ui.panel key for base translation (instead of leaving an empty object).
- Optimize flatten method to stop copying output over and over.
- Convert empty and test filters to JSON.parse() revivers for simplicity and better performance.
- Incorporate supervisor builds into main tasks using a simple toggle (i.e. remove duplicate code).
- Funcify local tasks and simplify exported tasks.
- Incorporate test metadata task into a simplified metadata task.

* Fix Lokalise key reference link

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>

---------

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
2024-04-12 12:49:18 +02:00
Steve Repsher
dc8a50965c Group date-fns packages (#20499) 2024-04-12 12:22:18 +02:00
Bram Kragten
1914de7ddf Bumped version to 20240404.2 2024-04-12 11:21:05 +02:00
Simon Lamon
2e505cfb1f Add spacing between icon and name in entity button bar (#20492)
* Fix width between icon and name

* Remove no-text
2024-04-12 11:20:15 +02:00
Bram Kragten
ab49aca815 Handle errors in multi select (#20494) 2024-04-12 11:19:57 +02:00
Bram Kragten
c96968e476 Fix issues with application credentials (#20495) 2024-04-12 11:19:31 +02:00
Simon Lamon
8f050516ec Fix missing argument in voice assistant expose search label (#20491) 2024-04-12 11:18:47 +02:00
Simon Lamon
27d2b244a4 Add spacing between icon and name in entity button bar (#20492)
* Fix width between icon and name

* Remove no-text
2024-04-12 11:17:51 +02:00
Bram Kragten
be2f2c6271 Handle errors in multi select (#20494) 2024-04-12 11:15:15 +02:00
Bram Kragten
8dc2797b16 Fix issues with application credentials (#20495) 2024-04-12 11:10:23 +02:00
renovate[bot]
7ca8dabc44 Update typescript-eslint monorepo to v7.6.0 (#20497)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-11 16:32:52 -04:00
Bram Kragten
baeb55e217 Merge branch 'master' into dev 2024-04-11 11:16:42 +02:00
Simon Lamon
a8502fcc11 Fix missing argument in voice assistant expose search label (#20491) 2024-04-11 11:10:02 +02:00
Paulus Schoutsen
9f5bc5b196 Match on correct entity ID of HA conversation agent (#20484) 2024-04-10 11:41:12 +02:00
Bruno Pantaleão Gonçalves
7556ab9506 Add css var for header webkit backdrop filter (#20473)
* Add CSS var for header -webkit-backdrop-filter

* Add backdrop to energy and developer tools
2024-04-10 11:40:44 +02:00
Adam Kapos
bf176ac314 Make it possible for themes to blur backgrounds (#20447)
* Make it possible for themes to blur card backgrounds

* Make it possible for themes to blur dialog backgrounds

* Add ha prefix

Co-authored-by: Bram Kragten <mail@bramkragten.nl>

* Rename dialog-backdrop-filter to ha-dialog-scrim-backdrop-filter

With backwards compatibility

* Run prettier

---------

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2024-04-10 11:37:35 +02:00
Adam Kapos
9903e22eaa Change tile to display "last triggered" in relative time (#20463) 2024-04-09 14:11:58 +02:00
Simon Lamon
1e0f7d9629 Don't display keyboard shortcut hints if keyboard shortcuts are disabled (#20456)
* Shortcut hints

* Prettier
2024-04-09 14:10:59 +02:00
Charles Garwood
e8a140af44 Don't duplicate the label as the description in Z-Wave Config (#20454)
Don'tduplicate the label as the description
2024-04-09 14:09:21 +02:00
Bram Kragten
b091d4f298 Write log on translation error (#20430)
* Write log on translation error

* Update ha-config-devices-dashboard.ts

---------

Co-authored-by: Franck Nijhof <git@frenck.dev>
2024-04-09 13:25:27 +02:00
renovate[bot]
35cf3063cb Update dependency @lokalise/node-api to v12.4.0 (#20252) 2024-04-08 20:49:48 -04:00
renovate[bot]
7141ef17be Update dependency @codemirror/legacy-modes to v6.4.0 (#20475) 2024-04-08 20:36:26 -04:00
renovate[bot]
be2c68c0bb Update octokit monorepo (#20453) 2024-04-08 20:32:57 -04:00
renovate[bot]
7c944d3767 Update dependency mocha to v10.4.0 (#20279) 2024-04-08 20:29:48 -04:00
renovate[bot]
1d4f02df2e Update dependency glob to v10.3.12 (#20298) 2024-04-08 20:28:30 -04:00
renovate[bot]
2007a74a20 Update babel monorepo to v7.24.4 (#20451) 2024-04-08 20:23:53 -04:00
renovate[bot]
8c0839ad57 Update dependency @types/tar to v6.1.12 (#20457) 2024-04-08 20:22:31 -04:00
renovate[bot]
516b9a54c4 Update dependency typescript to v5.4.4 (#20468) 2024-04-08 20:21:33 -04:00
renovate[bot]
0d3e730c9c Update dependency magic-string to v0.30.9 (#20465)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-08 09:33:26 +02:00
renovate[bot]
c7a87d02b2 Update dependency @types/leaflet to v1.9.9 (#20452) 2024-04-07 20:37:42 +02:00
Bram Kragten
dd082c204b Remove unused type (#20429) 2024-04-05 12:22:47 +02:00
renovate[bot]
c4af3d1579 Update typescript-eslint monorepo to v7.5.0 (#20426)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-05 11:36:28 +02:00
Bram Kragten
10eadbcbbb Merge branch 'dev' 2024-04-04 21:31:51 +02:00
Bram Kragten
17141824f7 Bumped version to 20240404.1 2024-04-04 21:31:30 +02:00
Bram Kragten
4cfd6c010f Fix overflow on submenus (#20415) 2024-04-04 19:54:36 +02:00
Bram Kragten
daa9024bff Make pages full height 2024-04-04 17:16:36 +02:00
Bram Kragten
e96aca90fe 20240404.0 (#20414) 2024-04-04 16:23:24 +02:00
Bram Kragten
0580a31961 Bumped version to 20240404.0 2024-04-04 16:16:30 +02:00
Bram Kragten
5c42c5130c Add count of items (#20410)
* Add count of items

* Adjust layout, correct filter count
2024-04-04 16:15:13 +02:00
Bram Kragten
72d1e37a23 Fix integration filter search (#20408) 2024-04-04 13:26:26 +02:00
Bram Kragten
61c9072a08 Fix icons in entity settings (#20405) 2024-04-04 13:00:14 +02:00
Bram Kragten
08b25f9c2a Add floor and label support to describe action (#20403) 2024-04-04 13:00:05 +02:00
Samuel Schultze
1a03b49700 Fix calendar range selection (#20394)
fix: calendar range selector
2024-04-04 12:59:54 +02:00
Paul Bottein
2d4a8e2e45 Fix search input outlined background color and margin (#20407) 2024-04-04 12:53:03 +02:00
Bram Kragten
8486377604 Fix z-index create category dialog (#20406) 2024-04-04 10:51:04 +00:00
Bram Kragten
4326519a3f 20240403.1 (#20380) 2024-04-03 16:58:47 +02:00
Bram Kragten
962b30adb9 20240403.0 (#20370) 2024-04-03 14:50:16 +02:00
Bram Kragten
29eb73176a 20240402.2 (#20348) 2024-04-02 23:34:17 +02:00
Bram Kragten
4f1cf1110f 20240402.1 (#20326) 2024-04-02 16:41:12 +02:00
Bram Kragten
d3bf0da289 20240402.0 (#20314) 2024-04-02 11:44:05 +02:00
Paul Bottein
fd06d434f2 20240329.1 (#20280) 2024-03-29 21:25:10 +01:00
Paul Bottein
d24d29e42f 20240329.0 (#20277) 2024-03-29 19:10:34 +01:00
Paul Bottein
e02a47a16a 20240328.0 (#20250) 2024-03-28 16:49:01 +01:00
Bram Kragten
795c16a941 20240327.0 (#20210) 2024-03-27 17:52:08 +01:00
158 changed files with 4630 additions and 2192 deletions

View File

@@ -21,7 +21,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }} url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
with: with:
ref: dev ref: dev
@@ -57,7 +57,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }} url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
with: with:
ref: master ref: master

View File

@@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2
with: with:
@@ -58,7 +58,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2
with: with:
@@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2
with: with:
@@ -89,7 +89,7 @@ jobs:
env: env:
IS_TEST: "true" IS_TEST: "true"
- name: Upload bundle stats - name: Upload bundle stats
uses: actions/upload-artifact@v4.3.1 uses: actions/upload-artifact@v4.3.2
with: with:
name: frontend-bundle-stats name: frontend-bundle-stats
path: build/stats/*.json path: build/stats/*.json
@@ -100,7 +100,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2
with: with:
@@ -113,7 +113,7 @@ jobs:
env: env:
IS_TEST: "true" IS_TEST: "true"
- name: Upload bundle stats - name: Upload bundle stats
uses: actions/upload-artifact@v4.3.1 uses: actions/upload-artifact@v4.3.2
with: with:
name: supervisor-bundle-stats name: supervisor-bundle-stats
path: build/stats/*.json path: build/stats/*.json

View File

@@ -23,7 +23,7 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
with: with:
# We must fetch at least the immediate parents so that if this is # We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head. # a pull request then we can checkout the head.

View File

@@ -22,7 +22,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }} url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
with: with:
ref: dev ref: dev
@@ -58,7 +58,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }} url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
with: with:
ref: master ref: master

View File

@@ -16,7 +16,7 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }} url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2

View File

@@ -21,7 +21,7 @@ jobs:
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview') if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
steps: steps:
- name: Check out files from GitHub - name: Check out files from GitHub
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4.0.2 uses: actions/setup-node@v4.0.2

View File

@@ -20,7 +20,7 @@ jobs:
contents: write contents: write
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Set up Python ${{ env.PYTHON_VERSION }} - name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5 uses: actions/setup-python@v5
@@ -57,14 +57,14 @@ jobs:
run: tar -czvf translations.tar.gz translations run: tar -czvf translations.tar.gz translations
- name: Upload build artifacts - name: Upload build artifacts
uses: actions/upload-artifact@v4.3.1 uses: actions/upload-artifact@v4.3.2
with: with:
name: wheels name: wheels
path: dist/home_assistant_frontend*.whl path: dist/home_assistant_frontend*.whl
if-no-files-found: error if-no-files-found: error
- name: Upload translations - name: Upload translations
uses: actions/upload-artifact@v4.3.1 uses: actions/upload-artifact@v4.3.2
with: with:
name: translations name: translations
path: translations.tar.gz path: translations.tar.gz

View File

@@ -23,7 +23,7 @@ jobs:
contents: write # Required to upload release assets contents: write # Required to upload release assets
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Verify version - name: Verify version
uses: home-assistant/actions/helpers/verify-version@master uses: home-assistant/actions/helpers/verify-version@master

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@v4.1.2 uses: actions/checkout@v4.1.3
- name: Upload Translations - name: Upload Translations
run: | run: |

View File

@@ -9,7 +9,7 @@ import gulp from "gulp";
import jszip from "jszip"; import jszip from "jszip";
import path from "path"; import path from "path";
import process from "process"; import process from "process";
import tar from "tar"; import { extract } from "tar";
const MAX_AGE = 24; // hours const MAX_AGE = 24; // hours
const OWNER = "home-assistant"; const OWNER = "home-assistant";
@@ -156,7 +156,7 @@ gulp.task("fetch-nightly-translations", async function () {
console.log("Unpacking downloaded translations..."); console.log("Unpacking downloaded translations...");
const zip = await jszip.loadAsync(downloadResponse.data); const zip = await jszip.loadAsync(downloadResponse.data);
await deleteCurrent; await deleteCurrent;
const extractStream = zip.file(/.*/)[0].nodeStream().pipe(tar.extract()); const extractStream = zip.file(/.*/)[0].nodeStream().pipe(extract());
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
extractStream.on("close", resolve).on("error", reject); extractStream.on("close", resolve).on("error", reject);
}); });

View File

@@ -1,92 +1,76 @@
import { createHash } from "crypto"; import { deleteAsync } from "del";
import { deleteSync } from "del"; import { glob } from "glob";
import { mkdirSync, readdirSync, readFileSync, renameSync } from "fs";
import { writeFile } from "node:fs/promises";
import gulp from "gulp"; import gulp from "gulp";
import flatmap from "gulp-flatmap";
import transform from "gulp-json-transform";
import merge from "gulp-merge-json"; import merge from "gulp-merge-json";
import rename from "gulp-rename"; import rename from "gulp-rename";
import path from "path"; import { createHash } from "node:crypto";
import vinylBuffer from "vinyl-buffer"; import { mkdir, readFile } from "node:fs/promises";
import source from "vinyl-source-stream"; import { basename, join } from "node:path";
import { Transform } from "node:stream";
import { finished } from "node:stream/promises";
import env from "../env.cjs"; import env from "../env.cjs";
import paths from "../paths.cjs"; import paths from "../paths.cjs";
import { mapFiles } from "../util.cjs";
import "./fetch-nightly-translations.js"; import "./fetch-nightly-translations.js";
const inFrontendDir = "translations/frontend"; const inFrontendDir = "translations/frontend";
const inBackendDir = "translations/backend"; const inBackendDir = "translations/backend";
const workDir = "build/translations"; const workDir = "build/translations";
const fullDir = workDir + "/full"; const outDir = join(workDir, "output");
const coreDir = workDir + "/core"; const EN_SRC = join(paths.translations_src, "en.json");
const outDir = workDir + "/output";
let mergeBackend = false; let mergeBackend = false;
gulp.task( gulp.task(
"translations-enable-merge-backend", "translations-enable-merge-backend",
gulp.parallel((done) => { gulp.parallel(async () => {
mergeBackend = true; mergeBackend = true;
done();
}, "allow-setup-fetch-nightly-translations") }, "allow-setup-fetch-nightly-translations")
); );
// Panel translations which should be split from the core translations. // Transform stream to apply a function on Vinyl JSON files (buffer mode only).
const TRANSLATION_FRAGMENTS = Object.keys( // The provided function can either return a new object, or an array of
JSON.parse( // [object, subdirectory] pairs for fragmentizing the JSON.
readFileSync( class CustomJSON extends Transform {
path.resolve(paths.polymer_dir, "src/translations/en.json"), constructor(func, reviver = null) {
"utf-8" super({ objectMode: true });
) this._func = func;
).ui.panel this._reviver = reviver;
); }
function recursiveFlatten(prefix, data) { async _transform(file, _, callback) {
let output = {}; try {
Object.keys(data).forEach((key) => { let obj = JSON.parse(file.contents.toString(), this._reviver);
if (typeof data[key] === "object") { if (this._func) obj = this._func(obj, file.path);
output = { for (const [outObj, dir] of Array.isArray(obj) ? obj : [[obj, ""]]) {
...output, const outFile = file.clone({ contents: false });
...recursiveFlatten(prefix + key + ".", data[key]), outFile.contents = Buffer.from(JSON.stringify(outObj));
}; outFile.dirname += `/${dir}`;
this.push(outFile);
}
callback(null);
} catch (err) {
callback(err);
}
}
}
// Utility to flatten object keys to single level using separator
const flatten = (data, prefix = "", sep = ".") => {
const output = {};
for (const [key, value] of Object.entries(data)) {
if (typeof value === "object") {
Object.assign(output, flatten(value, prefix + key + sep, sep));
} else { } else {
output[prefix + key] = data[key]; output[prefix + key] = value;
} }
}); }
return output; return output;
} };
function flatten(data) { // Filter functions that can be passed directly to JSON.parse()
return recursiveFlatten("", data); const emptyReviver = (_key, value) => value || undefined;
} const testReviver = (_key, value) =>
value && typeof value === "string" ? "TRANSLATED" : value;
function emptyFilter(data) {
const newData = {};
Object.keys(data).forEach((key) => {
if (data[key]) {
if (typeof data[key] === "object") {
newData[key] = emptyFilter(data[key]);
} else {
newData[key] = data[key];
}
}
});
return newData;
}
function recursiveEmpty(data) {
const newData = {};
Object.keys(data).forEach((key) => {
if (data[key]) {
if (typeof data[key] === "object") {
newData[key] = recursiveEmpty(data[key]);
} else {
newData[key] = "TRANSLATED";
}
}
});
return newData;
}
/** /**
* Replace Lokalise key placeholders with their actual values. * Replace Lokalise key placeholders with their actual values.
@@ -95,60 +79,44 @@ function recursiveEmpty(data) {
* be included in src/translations/en.json, but still be usable while * be included in src/translations/en.json, but still be usable while
* developing locally. * developing locally.
* *
* @link https://docs.lokalise.co/article/KO5SZWLLsy-key-referencing * @link https://docs.lokalise.com/en/articles/1400528-key-referencing
*/ */
const re_key_reference = /\[%key:([^%]+)%\]/; const KEY_REFERENCE = /\[%key:([^%]+)%\]/;
function lokaliseTransform(data, original, file) { const lokaliseTransform = (data, path, original = data) => {
const output = {}; const output = {};
Object.entries(data).forEach(([key, value]) => { for (const [key, value] of Object.entries(data)) {
if (value instanceof Object) { if (typeof value === "object") {
output[key] = lokaliseTransform(value, original, file); output[key] = lokaliseTransform(value, path, original);
} else { } else {
output[key] = value.replace(re_key_reference, (_match, lokalise_key) => { output[key] = value.replace(KEY_REFERENCE, (_match, lokalise_key) => {
const replace = lokalise_key.split("::").reduce((tr, k) => { const replace = lokalise_key.split("::").reduce((tr, k) => {
if (!tr) { if (!tr) {
throw Error( throw Error(`Invalid key placeholder ${lokalise_key} in ${path}`);
`Invalid key placeholder ${lokalise_key} in ${file.path}`
);
} }
return tr[k]; return tr[k];
}, original); }, original);
if (typeof replace !== "string") { if (typeof replace !== "string") {
throw Error( throw Error(`Invalid key placeholder ${lokalise_key} in ${path}`);
`Invalid key placeholder ${lokalise_key} in ${file.path}`
);
} }
return replace; return replace;
}); });
} }
}); }
return output; return output;
} };
gulp.task("clean-translations", async () => deleteSync([workDir])); gulp.task("clean-translations", () => deleteAsync([workDir]));
gulp.task("ensure-translations-build-dir", async () => { const makeWorkDir = () => mkdir(workDir, { recursive: true });
mkdirSync(workDir, { recursive: true });
});
gulp.task("create-test-metadata", () => const createTestTranslation = () =>
env.isProdBuild()
? Promise.resolve()
: writeFile(
workDir + "/testMetadata.json",
JSON.stringify({ test: { nativeName: "Test" } })
)
);
gulp.task("create-test-translation", () =>
env.isProdBuild() env.isProdBuild()
? Promise.resolve() ? Promise.resolve()
: gulp : gulp
.src(path.join(paths.translations_src, "en.json")) .src(EN_SRC)
.pipe(transform((data, _file) => recursiveEmpty(data))) .pipe(new CustomJSON(null, testReviver))
.pipe(rename("test.json")) .pipe(rename("test.json"))
.pipe(gulp.dest(workDir)) .pipe(gulp.dest(workDir));
);
/** /**
* This task will build a master translation file, to be used as the base for * This task will build a master translation file, to be used as the base for
@@ -159,279 +127,171 @@ gulp.task("create-test-translation", () =>
* project is buildable immediately after merging new translation keys, since * project is buildable immediately after merging new translation keys, since
* the Lokalise update to translations/en.json will not happen immediately. * the Lokalise update to translations/en.json will not happen immediately.
*/ */
gulp.task("build-master-translation", () => { const createMasterTranslation = () =>
const src = [path.join(paths.translations_src, "en.json")]; gulp
.src([EN_SRC, ...(mergeBackend ? [`${inBackendDir}/en.json`] : [])])
if (mergeBackend) { .pipe(new CustomJSON(lokaliseTransform))
src.push(path.join(inBackendDir, "en.json"));
}
return gulp
.src(src)
.pipe(transform((data, file) => lokaliseTransform(data, data, file)))
.pipe( .pipe(
merge({ merge({
fileName: "en.json", fileName: "en.json",
jsonSpace: undefined,
}) })
) )
.pipe(gulp.dest(fullDir)); .pipe(gulp.dest(workDir));
});
gulp.task("build-merged-translations", () => const FRAGMENTS = ["base"];
gulp
.src([
inFrontendDir + "/*.json",
"!" + inFrontendDir + "/en.json",
...(env.isProdBuild() ? [] : [workDir + "/test.json"]),
])
.pipe(transform((data, file) => lokaliseTransform(data, data, file)))
.pipe(
flatmap((stream, file) => {
// For each language generate a merged json file. It begins with the master
// translation as a failsafe for untranslated strings, and merges all parent
// tags into one file for each specific subtag
//
// TODO: This is a naive interpretation of BCP47 that should be improved.
// Will be OK for now as long as we don't have anything more complicated
// than a base translation + region.
const tr = path.basename(file.history[0], ".json");
const subtags = tr.split("-");
const src = [fullDir + "/en.json"];
for (let i = 1; i <= subtags.length; i++) {
const lang = subtags.slice(0, i).join("-");
if (lang === "test") {
src.push(workDir + "/test.json");
} else if (lang !== "en") {
src.push(inFrontendDir + "/" + lang + ".json");
if (mergeBackend) {
src.push(inBackendDir + "/" + lang + ".json");
}
}
}
return gulp
.src(src, { allowEmpty: true })
.pipe(transform((data) => emptyFilter(data)))
.pipe(
merge({
fileName: tr + ".json",
})
)
.pipe(gulp.dest(fullDir));
})
)
);
let taskName; const toggleSupervisorFragment = async () => {
FRAGMENTS[0] = "supervisor";
};
const splitTasks = []; const panelFragment = (fragment) =>
TRANSLATION_FRAGMENTS.forEach((fragment) => { fragment !== "base" && fragment !== "supervisor";
taskName = "build-translation-fragment-" + fragment;
gulp.task(taskName, () =>
// Return only the translations for this fragment.
gulp
.src(fullDir + "/*.json")
.pipe(
transform((data) => ({
ui: {
panel: {
[fragment]: data.ui.panel[fragment],
},
},
}))
)
.pipe(gulp.dest(workDir + "/" + fragment))
);
splitTasks.push(taskName);
});
taskName = "build-translation-core"; const HASHES = new Map();
gulp.task(taskName, () =>
// Remove the fragment translations from the core translation.
gulp
.src(fullDir + "/*.json")
.pipe(
transform((data, _file) => {
TRANSLATION_FRAGMENTS.forEach((fragment) => {
delete data.ui.panel[fragment];
});
delete data.supervisor;
return data;
})
)
.pipe(gulp.dest(coreDir))
);
splitTasks.push(taskName); const createTranslations = async () => {
// Parse and store the master to avoid repeating this for each locale, then
gulp.task("build-flattened-translations", () => // add the panel fragments when processing the app.
// Flatten the split versions of our translations, and move them into outDir const enMaster = JSON.parse(await readFile(`${workDir}/en.json`, "utf-8"));
gulp if (FRAGMENTS[0] === "base") {
.src( FRAGMENTS.push(...Object.keys(enMaster.ui.panel));
TRANSLATION_FRAGMENTS.map(
(fragment) => workDir + "/" + fragment + "/*.json"
).concat(coreDir + "/*.json"),
{ base: workDir }
)
.pipe(
transform((data) =>
// Polymer.AppLocalizeBehavior requires flattened json
flatten(data)
)
)
.pipe(
rename((filePath) => {
if (filePath.dirname === "core") {
filePath.dirname = "";
}
// In dev we create the file with the fake hash in the filename
if (!env.isProdBuild()) {
filePath.basename += "-dev";
}
})
)
.pipe(gulp.dest(outDir))
);
const fingerprints = {};
gulp.task("build-translation-fingerprints", () => {
// Fingerprint full file of each language
const files = readdirSync(fullDir);
for (let i = 0; i < files.length; i++) {
fingerprints[files[i].split(".")[0]] = {
// In dev we create fake hashes
hash: env.isProdBuild()
? createHash("md5")
.update(readFileSync(path.join(fullDir, files[i]), "utf-8"))
.digest("hex")
: "dev",
};
} }
// In dev we create the file with the fake hash in the filename // The downstream pipeline is setup first. It hashes the merged data for
if (env.isProdBuild()) { // each locale, then fragmentizes and flattens the data for final output.
mapFiles(outDir, ".json", (filename) => { const translationFiles = await glob([
const parsed = path.parse(filename); `${inFrontendDir}/!(en).json`,
...(env.isProdBuild() ? [] : [`${workDir}/test.json`]),
]);
const hashStream = new Transform({
objectMode: true,
transform: async (file, _, callback) => {
const hash = env.isProdBuild()
? createHash("md5").update(file.contents).digest("hex")
: "dev";
HASHES.set(file.stem, hash);
file.stem += `-${hash}`;
callback(null, file);
},
}).setMaxListeners(translationFiles.length + 1);
const fragmentsStream = hashStream
.pipe(
new CustomJSON((data) =>
FRAGMENTS.map((fragment) => {
switch (fragment) {
case "base":
// Remove the panels and supervisor to create the base translations
return [
flatten({
...data,
ui: { ...data.ui, panel: undefined },
supervisor: undefined,
}),
"",
];
case "supervisor":
// Supervisor key is at the top level
return [flatten(data.supervisor), ""];
default:
// Create a fragment with only the given panel
return [
flatten(data.ui.panel[fragment], `ui.panel.${fragment}.`),
fragment,
];
}
})
)
)
.pipe(gulp.dest(outDir));
// nl.json -> nl-<hash>.json // Send the English master downstream first, then for each other locale
if (!(parsed.name in fingerprints)) { // generate merged JSON data to continue piping. It begins with the master
throw new Error(`Unable to find hash for ${filename}`); // translation as a failsafe for untranslated strings, and merges all parent
// tags into one file for each specific subtag
//
// TODO: This is a naive interpretation of BCP47 that should be improved.
// Will be OK for now as long as we don't have anything more complicated
// than a base translation + region.
gulp.src(`${workDir}/en.json`).pipe(hashStream, { end: false });
const mergesFinished = [];
for (const translationFile of translationFiles) {
const locale = basename(translationFile, ".json");
const subtags = locale.split("-");
const mergeFiles = [];
for (let i = 1; i <= subtags.length; i++) {
const lang = subtags.slice(0, i).join("-");
if (lang === "test") {
mergeFiles.push(`${workDir}/test.json`);
} else if (lang !== "en") {
mergeFiles.push(`${inFrontendDir}/${lang}.json`);
if (mergeBackend) {
mergeFiles.push(`${inBackendDir}/${lang}.json`);
}
} }
}
renameSync( const mergeStream = gulp.src(mergeFiles, { allowEmpty: true }).pipe(
filename, merge({
`${parsed.dir}/${parsed.name}-${fingerprints[parsed.name].hash}${ fileName: `${locale}.json`,
parsed.ext startObj: enMaster,
}` jsonReviver: emptyReviver,
); jsonSpace: undefined,
}); })
);
mergesFinished.push(finished(mergeStream));
mergeStream.pipe(hashStream, { end: false });
} }
const stream = source("translationFingerprints.json"); // Wait for all merges to finish, then it's safe to end writing to the
stream.write(JSON.stringify(fingerprints)); // downstream pipeline and wait for all fragments to finish writing.
process.nextTick(() => stream.end()); await Promise.all(mergesFinished);
return stream.pipe(vinylBuffer()).pipe(gulp.dest(workDir)); hashStream.end();
}); await finished(fragmentsStream);
};
gulp.task("build-translation-fragment-supervisor", () => const writeTranslationMetaData = () =>
gulp gulp
.src(fullDir + "/*.json") .src([`${paths.translations_src}/translationMetadata.json`])
.pipe(transform((data) => data.supervisor))
.pipe( .pipe(
rename((filePath) => { new CustomJSON((meta) => {
// In dev we create the file with the fake hash in the filename // Add the test translation in development.
if (!env.isProdBuild()) { if (!env.isProdBuild()) {
filePath.basename += "-dev"; meta.test = { nativeName: "Test" };
} }
}) // Filter out locales without a native name, and add the hashes.
) for (const locale of Object.keys(meta)) {
.pipe(gulp.dest(workDir + "/supervisor")) if (!meta[locale].nativeName) {
); meta[locale] = undefined;
gulp.task("build-translation-flatten-supervisor", () =>
gulp
.src(workDir + "/supervisor/*.json")
.pipe(
transform((data) =>
// Polymer.AppLocalizeBehavior requires flattened json
flatten(data)
)
)
.pipe(gulp.dest(outDir))
);
gulp.task("build-translation-write-metadata", () =>
gulp
.src([
path.join(paths.translations_src, "translationMetadata.json"),
...(env.isProdBuild() ? [] : [workDir + "/testMetadata.json"]),
workDir + "/translationFingerprints.json",
])
.pipe(merge({}))
.pipe(
transform((data) => {
const newData = {};
Object.entries(data).forEach(([key, value]) => {
// Filter out translations without native name.
if (value.nativeName) {
newData[key] = value;
} else {
console.warn( console.warn(
`Skipping language ${key}. Native name was not translated.` `Skipping locale ${locale} because native name is not translated.`
); );
} else {
meta[locale].hash = HASHES.get(locale);
} }
}); }
return newData; return {
fragments: FRAGMENTS.filter(panelFragment),
translations: meta,
};
}) })
) )
.pipe( .pipe(gulp.dest(workDir));
transform((data) => ({
fragments: TRANSLATION_FRAGMENTS,
translations: data,
}))
)
.pipe(rename("translationMetadata.json"))
.pipe(gulp.dest(workDir))
);
gulp.task(
"create-translations",
gulp.series(
gulp.parallel("create-test-metadata", "create-test-translation"),
"build-master-translation",
"build-merged-translations",
gulp.parallel(...splitTasks),
"build-flattened-translations"
)
);
gulp.task( gulp.task(
"build-translations", "build-translations",
gulp.series( gulp.series(
gulp.parallel( gulp.parallel(
"fetch-nightly-translations", "fetch-nightly-translations",
gulp.series("clean-translations", "ensure-translations-build-dir") gulp.series("clean-translations", makeWorkDir)
), ),
"create-translations", createTestTranslation,
"build-translation-fingerprints", createMasterTranslation,
"build-translation-write-metadata" createTranslations,
writeTranslationMetaData
) )
); );
gulp.task( gulp.task(
"build-supervisor-translations", "build-supervisor-translations",
gulp.series( gulp.series(toggleSupervisorFragment, "build-translations")
gulp.parallel(
"fetch-nightly-translations",
gulp.series("clean-translations", "ensure-translations-build-dir")
),
gulp.parallel("create-test-metadata", "create-test-translation"),
"build-master-translation",
"build-merged-translations",
"build-translation-fragment-supervisor",
"build-translation-flatten-supervisor",
"build-translation-fingerprints",
"build-translation-write-metadata"
)
); );

View File

@@ -99,7 +99,7 @@ gulp.task("webpack-watch-app", () => {
).watch({ poll: isWsl }, doneHandler()); ).watch({ poll: isWsl }, doneHandler());
gulp.watch( gulp.watch(
path.join(paths.translations_src, "en.json"), path.join(paths.translations_src, "en.json"),
gulp.series("create-translations", "copy-translations-app") gulp.series("build-translations", "copy-translations-app")
); );
}); });

View File

@@ -1,16 +0,0 @@
const path = require("path");
const fs = require("fs");
// Helper function to map recursively over files in a folder and it's subfolders
module.exports.mapFiles = function mapFiles(startPath, filter, mapFunc) {
const files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename = path.join(startPath, files[i]);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
mapFiles(filename, filter, mapFunc);
} else if (filename.indexOf(filter) >= 0) {
mapFunc(filename);
}
}
};

View File

@@ -10,6 +10,7 @@ const WebpackBar = require("webpackbar");
const { const {
TransformAsyncModulesPlugin, TransformAsyncModulesPlugin,
} = require("transform-async-modules-webpack-plugin"); } = require("transform-async-modules-webpack-plugin");
const { dependencies } = require("../package.json");
const paths = require("./paths.cjs"); const paths = require("./paths.cjs");
const bundle = require("./bundle.cjs"); const bundle = require("./bundle.cjs");
@@ -156,11 +157,15 @@ const createWebpackConfig = ({
transform: (stats) => JSON.stringify(filterStats(stats)), transform: (stats) => JSON.stringify(filterStats(stats)),
}), }),
!latestBuild && !latestBuild &&
new TransformAsyncModulesPlugin({ browserslistEnv: "legacy" }), new TransformAsyncModulesPlugin({
browserslistEnv: "legacy",
runtime: { version: dependencies["@babel/runtime"] },
}),
].filter(Boolean), ].filter(Boolean),
resolve: { resolve: {
extensions: [".ts", ".js", ".json"], extensions: [".ts", ".js", ".json"],
alias: { alias: {
"lit/static-html$": "lit/static-html.js",
"lit/decorators$": "lit/decorators.js", "lit/decorators$": "lit/decorators.js",
"lit/directive$": "lit/directive.js", "lit/directive$": "lit/directive.js",
"lit/directives/until$": "lit/directives/until.js", "lit/directives/until$": "lit/directives/until.js",

View File

@@ -1,4 +1,4 @@
import { format, startOfToday, startOfTomorrow } from "date-fns/esm"; import { format, startOfToday, startOfTomorrow } from "date-fns";
import { import {
EnergyInfo, EnergyInfo,
EnergyPreferences, EnergyPreferences,

View File

@@ -136,7 +136,7 @@ export class DemoAutomationDescribeAction extends LitElement {
<div class="action"> <div class="action">
<span> <span>
${this._action ${this._action
? describeAction(this.hass, [], this._action) ? describeAction(this.hass, [], [], [], this._action)
: "<invalid YAML>"} : "<invalid YAML>"}
</span> </span>
<ha-yaml-editor <ha-yaml-editor
@@ -149,7 +149,7 @@ export class DemoAutomationDescribeAction extends LitElement {
${ACTIONS.map( ${ACTIONS.map(
(conf) => html` (conf) => html`
<div class="action"> <div class="action">
<span>${describeAction(this.hass, [], conf as any)}</span> <span>${describeAction(this.hass, [], [], [], conf as any)}</span>
<pre>${dump(conf)}</pre> <pre>${dump(conf)}</pre>
</div> </div>
` `

View File

@@ -161,12 +161,14 @@ const LABELS: LabelRegistryEntry[] = [
name: "Energy", name: "Energy",
icon: null, icon: null,
color: "yellow", color: "yellow",
description: null,
}, },
{ {
label_id: "entertainment", label_id: "entertainment",
name: "Entertainment", name: "Entertainment",
icon: "mdi:popcorn", icon: "mdi:popcorn",
color: "blue", color: "blue",
description: null,
}, },
]; ];

View File

@@ -2,6 +2,7 @@ import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, query } from "lit/decorators"; import { customElement, query } from "lit/decorators";
import { CoverEntityFeature } from "../../../../src/data/cover"; import { CoverEntityFeature } from "../../../../src/data/cover";
import { LightColorMode } from "../../../../src/data/light"; import { LightColorMode } from "../../../../src/data/light";
import { LockEntityFeature } from "../../../../src/data/lock";
import { VacuumEntityFeature } from "../../../../src/data/vacuum"; import { VacuumEntityFeature } from "../../../../src/data/vacuum";
import { getEntity } from "../../../../src/fake_data/entity"; import { getEntity } from "../../../../src/fake_data/entity";
import { provideHass } from "../../../../src/fake_data/provide_hass"; import { provideHass } from "../../../../src/fake_data/provide_hass";
@@ -20,6 +21,11 @@ const ENTITIES = [
getEntity("light", "unavailable", "unavailable", { getEntity("light", "unavailable", "unavailable", {
friendly_name: "Unavailable entity", friendly_name: "Unavailable entity",
}), }),
getEntity("lock", "front_door", "locked", {
friendly_name: "Front Door Lock",
device_class: "lock",
supported_features: LockEntityFeature.OPEN,
}),
getEntity("climate", "thermostat", "heat", { getEntity("climate", "thermostat", "heat", {
current_temperature: 73, current_temperature: 73,
min_temp: 45, min_temp: 45,
@@ -138,6 +144,24 @@ const CONFIGS = [
- type: "color-temp" - type: "color-temp"
`, `,
}, },
{
heading: "Lock commands feature",
config: `
- type: tile
entity: lock.front_door
features:
- type: "lock-commands"
`,
},
{
heading: "Lock open door feature",
config: `
- type: tile
entity: lock.front_door
features:
- type: "lock-open-door"
`,
},
{ {
heading: "Vacuum commands feature", heading: "Vacuum commands feature",
config: ` config: `

View File

@@ -36,6 +36,8 @@ const createConfigEntry = (
pref_disable_new_entities: false, pref_disable_new_entities: false,
pref_disable_polling: false, pref_disable_polling: false,
reason: null, reason: null,
error_reason_translation_key: null,
error_reason_translation_placeholders: null,
...override, ...override,
}); });

View File

@@ -1,4 +1,7 @@
import { globIterate } from "glob"; import { globIterate } from "glob";
import { availableParallelism } from "node:os";
process.env.UV_THREADPOOL_SIZE = availableParallelism();
const gulpImports = []; const gulpImports = [];

View File

@@ -25,15 +25,15 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@babel/runtime": "7.24.1", "@babel/runtime": "7.24.4",
"@braintree/sanitize-url": "7.0.1", "@braintree/sanitize-url": "7.0.1",
"@codemirror/autocomplete": "6.15.0", "@codemirror/autocomplete": "6.16.0",
"@codemirror/commands": "6.3.3", "@codemirror/commands": "6.5.0",
"@codemirror/language": "6.10.1", "@codemirror/language": "6.10.1",
"@codemirror/legacy-modes": "6.3.3", "@codemirror/legacy-modes": "6.4.0",
"@codemirror/search": "6.5.6", "@codemirror/search": "6.5.6",
"@codemirror/state": "6.4.1", "@codemirror/state": "6.4.1",
"@codemirror/view": "6.26.1", "@codemirror/view": "6.26.3",
"@egjs/hammerjs": "2.0.17", "@egjs/hammerjs": "2.0.17",
"@formatjs/intl-datetimeformat": "6.12.3", "@formatjs/intl-datetimeformat": "6.12.3",
"@formatjs/intl-displaynames": "6.6.6", "@formatjs/intl-displaynames": "6.6.6",
@@ -81,7 +81,7 @@
"@material/mwc-top-app-bar": "0.27.0", "@material/mwc-top-app-bar": "0.27.0",
"@material/mwc-top-app-bar-fixed": "0.27.0", "@material/mwc-top-app-bar-fixed": "0.27.0",
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0", "@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
"@material/web": "=1.3.0", "@material/web": "1.4.1",
"@mdi/js": "7.4.47", "@mdi/js": "7.4.47",
"@mdi/svg": "7.4.47", "@mdi/svg": "7.4.47",
"@polymer/paper-item": "3.0.1", "@polymer/paper-item": "3.0.1",
@@ -89,8 +89,8 @@
"@polymer/paper-tabs": "3.1.0", "@polymer/paper-tabs": "3.1.0",
"@polymer/polymer": "3.5.1", "@polymer/polymer": "3.5.1",
"@thomasloven/round-slider": "0.6.0", "@thomasloven/round-slider": "0.6.0",
"@vaadin/combo-box": "24.3.10", "@vaadin/combo-box": "24.3.11",
"@vaadin/vaadin-themable-mixin": "24.3.10", "@vaadin/vaadin-themable-mixin": "24.3.11",
"@vibrant/color": "3.2.1-alpha.1", "@vibrant/color": "3.2.1-alpha.1",
"@vibrant/core": "3.2.1-alpha.1", "@vibrant/core": "3.2.1-alpha.1",
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1", "@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
@@ -101,17 +101,17 @@
"chart.js": "4.4.2", "chart.js": "4.4.2",
"color-name": "2.0.0", "color-name": "2.0.0",
"comlink": "4.4.1", "comlink": "4.4.1",
"core-js": "3.36.1", "core-js": "3.37.0",
"cropperjs": "1.6.1", "cropperjs": "1.6.2",
"date-fns": "2.30.0", "date-fns": "3.6.0",
"date-fns-tz": "2.0.1", "date-fns-tz": "3.1.3",
"deep-clone-simple": "1.1.1", "deep-clone-simple": "1.1.1",
"deep-freeze": "0.0.1", "deep-freeze": "0.0.1",
"element-internals-polyfill": "1.3.10", "element-internals-polyfill": "1.3.11",
"fuse.js": "7.0.0", "fuse.js": "7.0.0",
"google-timezones-json": "1.2.0", "google-timezones-json": "1.2.0",
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch", "hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
"home-assistant-js-websocket": "9.2.1", "home-assistant-js-websocket": "9.3.0",
"idb-keyval": "6.2.1", "idb-keyval": "6.2.1",
"intl-messageformat": "10.5.11", "intl-messageformat": "10.5.11",
"js-yaml": "4.1.0", "js-yaml": "4.1.0",
@@ -119,7 +119,7 @@
"leaflet-draw": "1.0.4", "leaflet-draw": "1.0.4",
"lit": "2.8.0", "lit": "2.8.0",
"luxon": "3.4.4", "luxon": "3.4.4",
"marked": "12.0.1", "marked": "12.0.2",
"memoize-one": "6.0.0", "memoize-one": "6.0.0",
"node-vibrant": "3.2.1-alpha.1", "node-vibrant": "3.2.1-alpha.1",
"proxy-polyfill": "0.3.2", "proxy-polyfill": "0.3.2",
@@ -150,18 +150,18 @@
"xss": "1.0.15" "xss": "1.0.15"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "7.24.3", "@babel/core": "7.24.4",
"@babel/helper-define-polyfill-provider": "0.6.1", "@babel/helper-define-polyfill-provider": "0.6.1",
"@babel/plugin-proposal-decorators": "7.24.1", "@babel/plugin-proposal-decorators": "7.24.1",
"@babel/plugin-transform-runtime": "7.24.3", "@babel/plugin-transform-runtime": "7.24.3",
"@babel/preset-env": "7.24.3", "@babel/preset-env": "7.24.4",
"@babel/preset-typescript": "7.24.1", "@babel/preset-typescript": "7.24.1",
"@bundle-stats/plugin-webpack-filter": "4.12.2", "@bundle-stats/plugin-webpack-filter": "4.12.2",
"@koa/cors": "5.0.0", "@koa/cors": "5.0.0",
"@lokalise/node-api": "12.3.0", "@lokalise/node-api": "12.4.0",
"@octokit/auth-oauth-device": "7.0.1", "@octokit/auth-oauth-device": "7.1.1",
"@octokit/plugin-retry": "7.0.3", "@octokit/plugin-retry": "7.1.0",
"@octokit/rest": "20.0.2", "@octokit/rest": "20.1.0",
"@open-wc/dev-server-hmr": "0.1.4", "@open-wc/dev-server-hmr": "0.1.4",
"@rollup/plugin-babel": "6.0.4", "@rollup/plugin-babel": "6.0.4",
"@rollup/plugin-commonjs": "25.0.7", "@rollup/plugin-commonjs": "25.0.7",
@@ -169,24 +169,24 @@
"@rollup/plugin-node-resolve": "15.2.3", "@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-replace": "5.0.5", "@rollup/plugin-replace": "5.0.5",
"@types/babel__plugin-transform-runtime": "7.9.5", "@types/babel__plugin-transform-runtime": "7.9.5",
"@types/chromecast-caf-receiver": "6.0.13", "@types/chromecast-caf-receiver": "6.0.14",
"@types/chromecast-caf-sender": "1.0.9", "@types/chromecast-caf-sender": "1.0.9",
"@types/color-name": "1.1.3", "@types/color-name": "1.1.4",
"@types/glob": "8.1.0", "@types/glob": "8.1.0",
"@types/html-minifier-terser": "7.0.2", "@types/html-minifier-terser": "7.0.2",
"@types/js-yaml": "4.0.9", "@types/js-yaml": "4.0.9",
"@types/leaflet": "1.9.8", "@types/leaflet": "1.9.11",
"@types/leaflet-draw": "1.0.11", "@types/leaflet-draw": "1.0.11",
"@types/luxon": "3.4.2", "@types/luxon": "3.4.2",
"@types/mocha": "10.0.6", "@types/mocha": "10.0.6",
"@types/qrcode": "1.5.5", "@types/qrcode": "1.5.5",
"@types/serve-handler": "6.1.4", "@types/serve-handler": "6.1.4",
"@types/sortablejs": "1.15.8", "@types/sortablejs": "1.15.8",
"@types/tar": "6.1.11", "@types/tar": "6.1.13",
"@types/ua-parser-js": "0.7.39", "@types/ua-parser-js": "0.7.39",
"@types/webspeechapi": "0.0.29", "@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "7.4.0", "@typescript-eslint/eslint-plugin": "7.7.0",
"@typescript-eslint/parser": "7.4.0", "@typescript-eslint/parser": "7.7.0",
"@web/dev-server": "0.1.38", "@web/dev-server": "0.1.38",
"@web/dev-server-rollup": "0.4.1", "@web/dev-server-rollup": "0.4.1",
"babel-loader": "9.1.3", "babel-loader": "9.1.3",
@@ -203,12 +203,11 @@
"eslint-plugin-lit": "1.11.0", "eslint-plugin-lit": "1.11.0",
"eslint-plugin-lit-a11y": "4.1.2", "eslint-plugin-lit-a11y": "4.1.2",
"eslint-plugin-unused-imports": "3.1.0", "eslint-plugin-unused-imports": "3.1.0",
"eslint-plugin-wc": "2.0.4", "eslint-plugin-wc": "2.1.0",
"fancy-log": "2.0.0", "fancy-log": "2.0.0",
"fs-extra": "11.2.0", "fs-extra": "11.2.0",
"glob": "10.3.10", "glob": "10.3.12",
"gulp": "4.0.2", "gulp": "4.0.2",
"gulp-flatmap": "1.0.2",
"gulp-json-transform": "0.5.0", "gulp-json-transform": "0.5.0",
"gulp-merge-json": "2.2.1", "gulp-merge-json": "2.2.1",
"gulp-rename": "2.0.0", "gulp-rename": "2.0.0",
@@ -220,9 +219,9 @@
"lint-staged": "15.2.2", "lint-staged": "15.2.2",
"lit-analyzer": "2.0.3", "lit-analyzer": "2.0.3",
"lodash.template": "4.5.0", "lodash.template": "4.5.0",
"magic-string": "0.30.8", "magic-string": "0.30.10",
"map-stream": "0.0.7", "map-stream": "0.0.7",
"mocha": "10.3.0", "mocha": "10.4.0",
"object-hash": "3.0.0", "object-hash": "3.0.0",
"open": "10.1.0", "open": "10.1.0",
"pinst": "3.0.0", "pinst": "3.0.0",
@@ -235,13 +234,11 @@
"sinon": "17.0.1", "sinon": "17.0.1",
"source-map-url": "0.4.1", "source-map-url": "0.4.1",
"systemjs": "6.14.3", "systemjs": "6.14.3",
"tar": "6.2.1", "tar": "7.0.1",
"terser-webpack-plugin": "5.3.10", "terser-webpack-plugin": "5.3.10",
"transform-async-modules-webpack-plugin": "1.0.4", "transform-async-modules-webpack-plugin": "1.1.0",
"ts-lit-plugin": "2.0.2", "ts-lit-plugin": "2.0.2",
"typescript": "5.4.3", "typescript": "5.4.5",
"vinyl-buffer": "1.0.1",
"vinyl-source-stream": "2.0.0",
"webpack": "5.91.0", "webpack": "5.91.0",
"webpack-cli": "5.1.4", "webpack-cli": "5.1.4",
"webpack-dev-server": "5.0.4", "webpack-dev-server": "5.0.4",

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "home-assistant-frontend" name = "home-assistant-frontend"
version = "20240403.1" version = "20240424.1"
license = {text = "Apache-2.0"} license = {text = "Apache-2.0"}
description = "The Home Assistant frontend" description = "The Home Assistant frontend"
readme = "README.md" readme = "README.md"

View File

@@ -40,6 +40,11 @@
"matchPackageNames": ["tsparticles-engine"], "matchPackageNames": ["tsparticles-engine"],
"matchPackagePrefixes": ["tsparticles-preset-"] "matchPackagePrefixes": ["tsparticles-preset-"]
}, },
{
"description": "Group date-fns with dependent timezone package",
"groupName": "date-fns",
"matchPackageNames": ["date-fns", "date-fns-tz"]
},
{ {
"description": "Group and temporarily disable WDS packages", "description": "Group and temporarily disable WDS packages",
"groupName": "Web Dev Server", "groupName": "Web Dev Server",

View File

@@ -1,4 +1,4 @@
import { utcToZonedTime, zonedTimeToUtc } from "date-fns-tz"; import { toZonedTime, fromZonedTime } from "date-fns-tz";
import { HassConfig } from "home-assistant-js-websocket"; import { HassConfig } from "home-assistant-js-websocket";
import { FrontendLocaleData, TimeZone } from "../../data/translation"; import { FrontendLocaleData, TimeZone } from "../../data/translation";
@@ -8,10 +8,10 @@ const calcZonedDate = (
fn: (date: Date, options?: any) => Date | number | boolean, fn: (date: Date, options?: any) => Date | number | boolean,
options? options?
) => { ) => {
const inputZoned = utcToZonedTime(date, tz); const inputZoned = toZonedTime(date, tz);
const fnZoned = fn(inputZoned, options); const fnZoned = fn(inputZoned, options);
if (fnZoned instanceof Date) { if (fnZoned instanceof Date) {
return zonedTimeToUtc(fnZoned, tz) as Date; return fromZonedTime(fnZoned, tz) as Date;
} }
return fnZoned; return fnZoned;
}; };
@@ -51,6 +51,6 @@ export const calcDateDifferenceProperty = (
locale, locale,
config, config,
locale.time_zone === TimeZone.server locale.time_zone === TimeZone.server
? utcToZonedTime(startDate, config.time_zone) ? toZonedTime(startDate, config.time_zone)
: startDate : startDate
); );

View File

@@ -187,11 +187,14 @@ export const computeStateDisplayFromEntityAttributes = (
if ( if (
[ [
"button", "button",
"conversation",
"event", "event",
"image", "image",
"input_button", "input_button",
"notify",
"scene", "scene",
"stt", "stt",
"tag",
"tts", "tts",
"wake_word", "wake_word",
].includes(domain) || ].includes(domain) ||

View File

@@ -2,6 +2,7 @@ import IntlMessageFormat from "intl-messageformat";
import type { HTMLTemplateResult } from "lit"; import type { HTMLTemplateResult } from "lit";
import { polyfillLocaleData } from "../../resources/locale-data-polyfill"; import { polyfillLocaleData } from "../../resources/locale-data-polyfill";
import { Resources, TranslationDict } from "../../types"; import { Resources, TranslationDict } from "../../types";
import { fireEvent } from "../dom/fire_event";
// Exclude some patterns from key type checking for now // Exclude some patterns from key type checking for now
// These are intended to be removed as errors are fixed // These are intended to be removed as errors are fixed
@@ -81,7 +82,9 @@ export interface FormatsType {
*/ */
export const computeLocalize = async <Keys extends string = LocalizeKeys>( export const computeLocalize = async <Keys extends string = LocalizeKeys>(
cache: any, cache: HTMLElement & {
_localizationCache?: Record<string, IntlMessageFormat>;
},
language: string, language: string,
resources: Resources, resources: Resources,
formats?: FormatsType formats?: FormatsType
@@ -107,7 +110,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
} }
const messageKey = key + translatedValue; const messageKey = key + translatedValue;
let translatedMessage = cache._localizationCache[messageKey] as let translatedMessage = cache._localizationCache![messageKey] as
| IntlMessageFormat | IntlMessageFormat
| undefined; | undefined;
@@ -121,7 +124,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
} catch (err: any) { } catch (err: any) {
return "Translation error: " + err.message; return "Translation error: " + err.message;
} }
cache._localizationCache[messageKey] = translatedMessage; cache._localizationCache![messageKey] = translatedMessage;
} }
let argObject = {}; let argObject = {};
@@ -137,6 +140,12 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
try { try {
return translatedMessage.format<string>(argObject) as string; return translatedMessage.format<string>(argObject) as string;
} catch (err: any) { } catch (err: any) {
// eslint-disable-next-line no-console
console.error("Translation error", key, language, err);
fireEvent(cache, "write_log", {
level: "error",
message: `Failed to format translation for key '${key}' in language '${language}'. ${err}`,
});
return "Translation " + err; return "Translation " + err;
} }
}; };

View File

@@ -0,0 +1,9 @@
export const hasRejectedItems = <T = any>(results: PromiseSettledResult<T>[]) =>
results.some((result) => result.status === "rejected");
export const rejectedItems = <T = any>(
results: PromiseSettledResult<T>[]
): PromiseRejectedResult[] =>
results.filter(
(result) => result.status === "rejected"
) as PromiseRejectedResult[];

View File

@@ -1,4 +1,4 @@
import { differenceInDays, differenceInWeeks, startOfWeek } from "date-fns/esm"; import { differenceInDays, differenceInWeeks, startOfWeek } from "date-fns";
import { FrontendLocaleData } from "../../data/translation"; import { FrontendLocaleData } from "../../data/translation";
import { firstWeekdayIndex } from "../datetime/first_weekday"; import { firstWeekdayIndex } from "../datetime/first_weekday";

View File

@@ -34,7 +34,7 @@ import {
endOfMonth, endOfMonth,
endOfQuarter, endOfQuarter,
endOfYear, endOfYear,
} from "date-fns/esm"; } from "date-fns";
import { import {
formatDate, formatDate,
formatDateMonth, formatDateMonth,

View File

@@ -1,13 +1,13 @@
import { mdiArrowDown, mdiArrowUp } from "@mdi/js"; import { mdiArrowDown, mdiArrowUp, mdiChevronDown } from "@mdi/js";
import deepClone from "deep-clone-simple"; import deepClone from "deep-clone-simple";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
nothing,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
css,
html,
nothing,
} from "lit"; } from "lit";
import { import {
customElement, customElement,
@@ -22,7 +22,9 @@ import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { restoreScroll } from "../../common/decorators/restore-scroll"; import { restoreScroll } from "../../common/decorators/restore-scroll";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { stringCompare } from "../../common/string/compare";
import { debounce } from "../../common/util/debounce"; import { debounce } from "../../common/util/debounce";
import { groupBy } from "../../common/util/group-by";
import { nextRender } from "../../common/util/render-status"; import { nextRender } from "../../common/util/render-status";
import { haStyleScrollbar } from "../../resources/styles"; import { haStyleScrollbar } from "../../resources/styles";
import { loadVirtualizer } from "../../resources/virtualizer"; import { loadVirtualizer } from "../../resources/virtualizer";
@@ -32,17 +34,6 @@ import type { HaCheckbox } from "../ha-checkbox";
import "../ha-svg-icon"; import "../ha-svg-icon";
import "../search-input"; import "../search-input";
import { filterData, sortData } from "./sort-filter"; import { filterData, sortData } from "./sort-filter";
import { groupBy } from "../../common/util/group-by";
import { stringCompare } from "../../common/string/compare";
declare global {
// for fire event
interface HASSDomEvents {
"selection-changed": SelectionChangedEvent;
"row-click": RowClickedEvent;
"sorting-changed": SortingChangedEvent;
}
}
export interface RowClickedEvent { export interface RowClickedEvent {
id: string; id: string;
@@ -52,6 +43,10 @@ export interface SelectionChangedEvent {
value: string[]; value: string[];
} }
export interface CollapsedChangedEvent {
value: string[];
}
export interface SortingChangedEvent { export interface SortingChangedEvent {
column: string; column: string;
direction: SortingDirection; direction: SortingDirection;
@@ -142,10 +137,14 @@ export class HaDataTable extends LitElement {
@property() public groupColumn?: string; @property() public groupColumn?: string;
@property({ attribute: false }) public groupOrder?: string[];
@property() public sortColumn?: string; @property() public sortColumn?: string;
@property() public sortDirection: SortingDirection = null; @property() public sortDirection: SortingDirection = null;
@property({ attribute: false }) public initialCollapsedGroups?: string[];
@state() private _filterable = false; @state() private _filterable = false;
@state() private _filter = ""; @state() private _filter = "";
@@ -158,6 +157,8 @@ export class HaDataTable extends LitElement {
@state() private _items: DataTableRowData[] = []; @state() private _items: DataTableRowData[] = [];
@state() private _collapsedGroups: string[] = [];
private _checkableRowsCount?: number; private _checkableRowsCount?: number;
private _checkedRows: string[] = []; private _checkedRows: string[] = [];
@@ -213,17 +214,19 @@ export class HaDataTable extends LitElement {
(column) => column.filterable (column) => column.filterable
); );
for (const columnId in this.columns) { if (!this.sortColumn) {
if (this.columns[columnId].direction) { for (const columnId in this.columns) {
this.sortDirection = this.columns[columnId].direction!; if (this.columns[columnId].direction) {
this.sortColumn = columnId; this.sortDirection = this.columns[columnId].direction!;
this.sortColumn = columnId;
fireEvent(this, "sorting-changed", { fireEvent(this, "sorting-changed", {
column: columnId, column: columnId,
direction: this.sortDirection, direction: this.sortDirection,
}); });
break; break;
}
} }
} }
@@ -248,13 +251,23 @@ export class HaDataTable extends LitElement {
).length; ).length;
} }
if (!this.hasUpdated && this.initialCollapsedGroups) {
this._collapsedGroups = this.initialCollapsedGroups;
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
} else if (properties.has("groupColumn")) {
this._collapsedGroups = [];
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
}
if ( if (
properties.has("data") || properties.has("data") ||
properties.has("columns") || properties.has("columns") ||
properties.has("_filter") || properties.has("_filter") ||
properties.has("sortColumn") || properties.has("sortColumn") ||
properties.has("sortDirection") || properties.has("sortDirection") ||
properties.has("groupColumn") properties.has("groupColumn") ||
properties.has("groupOrder") ||
properties.has("_collapsedGroups")
) { ) {
this._sortFilterData(); this._sortFilterData();
} }
@@ -447,6 +460,8 @@ export class HaDataTable extends LitElement {
} }
return html` return html`
<div <div
@mouseover=${this._setTitle}
@focus=${this._setTitle}
role=${column.main ? "rowheader" : "cell"} role=${column.main ? "rowheader" : "cell"}
class="mdc-data-table__cell ${classMap({ class="mdc-data-table__cell ${classMap({
"mdc-data-table__cell--flex": column.type === "flex", "mdc-data-table__cell--flex": column.type === "flex",
@@ -514,11 +529,7 @@ export class HaDataTable extends LitElement {
} }
if (this.appendRow || this.hasFab || this.groupColumn) { if (this.appendRow || this.hasFab || this.groupColumn) {
const items = [...data]; let items = [...data];
if (this.appendRow) {
items.push({ append: true, content: this.appendRow });
}
if (this.groupColumn) { if (this.groupColumn) {
const grouped = groupBy(items, (item) => item[this.groupColumn!]); const grouped = groupBy(items, (item) => item[this.groupColumn!]);
@@ -530,13 +541,24 @@ export class HaDataTable extends LitElement {
const sorted: { const sorted: {
[key: string]: DataTableRowData[]; [key: string]: DataTableRowData[];
} = Object.keys(grouped) } = Object.keys(grouped)
.sort((a, b) => .sort((a, b) => {
stringCompare( const orderA = this.groupOrder?.indexOf(a) ?? -1;
const orderB = this.groupOrder?.indexOf(b) ?? -1;
if (orderA !== orderB) {
if (orderA === -1) {
return 1;
}
if (orderB === -1) {
return -1;
}
return orderA - orderB;
}
return stringCompare(
["", "-", "—"].includes(a) ? "zzz" : a, ["", "-", "—"].includes(a) ? "zzz" : a,
["", "-", "—"].includes(b) ? "zzz" : b, ["", "-", "—"].includes(b) ? "zzz" : b,
this.hass.locale.language this.hass.locale.language
) );
) })
.reduce((obj, key) => { .reduce((obj, key) => {
obj[key] = grouped[key]; obj[key] = grouped[key];
return obj; return obj;
@@ -552,23 +574,39 @@ export class HaDataTable extends LitElement {
content: html`<div content: html`<div
class="mdc-data-table__cell group-header" class="mdc-data-table__cell group-header"
role="cell" role="cell"
.group=${groupName}
@click=${this._collapseGroup}
> >
${groupName === UNDEFINED_GROUP_KEY ? "" : groupName || ""} <ha-icon-button
.path=${mdiChevronDown}
class=${this._collapsedGroups.includes(groupName)
? "collapsed"
: ""}
>
</ha-icon-button>
${groupName === UNDEFINED_GROUP_KEY
? this.hass.localize("ui.components.data-table.ungrouped")
: groupName || ""}
</div>`, </div>`,
}); });
} }
if (!this._collapsedGroups.includes(groupName)) {
groupedItems.push(...rows); groupedItems.push(...rows);
}
}); });
this._items = groupedItems; items = groupedItems;
} else { }
this._items = items;
if (this.appendRow) {
items.push({ append: true, content: this.appendRow });
} }
if (this.hasFab) { if (this.hasFab) {
this._items = [...this._items, { empty: true }]; items.push({ empty: true });
} }
this._items = items;
} else { } else {
this._items = data; this._items = data;
} }
@@ -649,6 +687,13 @@ export class HaDataTable extends LitElement {
fireEvent(this, "row-click", { id: rowId }, { bubbles: false }); fireEvent(this, "row-click", { id: rowId }, { bubbles: false });
}; };
private _setTitle(ev: Event) {
const target = ev.currentTarget as HTMLElement;
if (target.scrollWidth > target.offsetWidth) {
target.setAttribute("title", target.innerText);
}
}
private _checkedRowsChanged() { private _checkedRowsChanged() {
// force scroller to update, change it's items // force scroller to update, change it's items
if (this._items.length) { if (this._items.length) {
@@ -679,6 +724,18 @@ export class HaDataTable extends LitElement {
this._savedScrollPos = (e.target as HTMLDivElement).scrollTop; this._savedScrollPos = (e.target as HTMLDivElement).scrollTop;
} }
private _collapseGroup = (ev: Event) => {
const groupName = (ev.currentTarget as any).group;
if (this._collapsedGroups.includes(groupName)) {
this._collapsedGroups = this._collapsedGroups.filter(
(grp) => grp !== groupName
);
} else {
this._collapsedGroups = [...this._collapsedGroups, groupName];
}
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
};
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyleScrollbar, haStyleScrollbar,
@@ -931,8 +988,21 @@ export class HaDataTable extends LitElement {
.group-header { .group-header {
padding-top: 12px; padding-top: 12px;
padding-left: 12px;
padding-inline-start: 12px;
width: 100%; width: 100%;
font-weight: 500; font-weight: 500;
display: flex;
align-items: center;
cursor: pointer;
}
.group-header ha-icon-button {
transition: transform 0.2s ease;
}
.group-header ha-icon-button.collapsed {
transform: rotate(180deg);
} }
:host { :host {
@@ -1031,4 +1101,12 @@ declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"ha-data-table": HaDataTable; "ha-data-table": HaDataTable;
} }
// for fire event
interface HASSDomEvents {
"selection-changed": SelectionChangedEvent;
"row-click": RowClickedEvent;
"sorting-changed": SortingChangedEvent;
"collapsed-changed": CollapsedChangedEvent;
}
} }

View File

@@ -11,10 +11,10 @@ import {
} from "../common/datetime/localize_date"; } from "../common/datetime/localize_date";
import { mainWindow } from "../common/dom/get_main_window"; import { mainWindow } from "../common/dom/get_main_window";
// Set the current date to the left picker instead of the right picker because the right is hidden
const CustomDateRangePicker = Vue.extend({ const CustomDateRangePicker = Vue.extend({
mixins: [DateRangePicker], mixins: [DateRangePicker],
methods: { methods: {
// Set the current date to the left picker instead of the right picker because the right is hidden
selectMonthDate() { selectMonthDate() {
const dt: Date = this.end || new Date(); const dt: Date = this.end || new Date();
// @ts-ignore // @ts-ignore
@@ -23,6 +23,33 @@ const CustomDateRangePicker = Vue.extend({
month: dt.getMonth() + 1, month: dt.getMonth() + 1,
}); });
}, },
// Fix the start/end date calculation when selecting a date range. The
// original code keeps track of the first clicked date (in_selection) but it
// never sets it to either the start or end date variables, so if the
// in_selection date is between the start and end date that were set by the
// hover the selection will enter a broken state that's counter-intuitive
// when hovering between weeks and leads to a random date when selecting a
// range across months. This bug doesn't seem to be present on v0.6.7 of the
// lib
hoverDate(value: Date) {
if (this.readonly) return;
if (this.in_selection) {
const pickA = this.in_selection as Date;
const pickB = value;
this.start = this.normalizeDatetime(
Math.min(pickA.valueOf(), pickB.valueOf()),
this.start
);
this.end = this.normalizeDatetime(
Math.max(pickA.valueOf(), pickB.valueOf()),
this.end
);
}
this.$emit("hover-date", value);
},
}, },
}); });

View File

@@ -18,6 +18,12 @@ import "../ha-icon-button";
import "../ha-svg-icon"; import "../ha-svg-icon";
import "./state-badge"; import "./state-badge";
import { caseInsensitiveStringCompare } from "../../common/string/compare"; import { caseInsensitiveStringCompare } from "../../common/string/compare";
import { showHelperDetailDialog } from "../../panels/config/helpers/show-dialog-helper-detail";
import { domainToName } from "../../data/integration";
import {
isHelperDomain,
HelperDomain,
} from "../../panels/config/helpers/const";
interface HassEntityWithCachedName extends HassEntity, ScorableTextItem { interface HassEntityWithCachedName extends HassEntity, ScorableTextItem {
friendly_name: string; friendly_name: string;
@@ -25,6 +31,8 @@ interface HassEntityWithCachedName extends HassEntity, ScorableTextItem {
export type HaEntityPickerEntityFilterFunc = (entity: HassEntity) => boolean; export type HaEntityPickerEntityFilterFunc = (entity: HassEntity) => boolean;
const CREATE_ID = "___create-new-entity___";
@customElement("ha-entity-picker") @customElement("ha-entity-picker")
export class HaEntityPicker extends LitElement { export class HaEntityPicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@@ -44,6 +52,8 @@ export class HaEntityPicker extends LitElement {
@property() public helper?: string; @property() public helper?: string;
@property({ type: Array }) public createDomains?: string[];
/** /**
* Show entities from specific domains. * Show entities from specific domains.
* @type {Array} * @type {Array}
@@ -130,7 +140,11 @@ export class HaEntityPicker extends LitElement {
></state-badge>` ></state-badge>`
: ""} : ""}
<span>${item.friendly_name}</span> <span>${item.friendly_name}</span>
<span slot="secondary">${item.entity_id}</span> <span slot="secondary"
>${item.entity_id.startsWith(CREATE_ID)
? this.hass.localize("ui.components.entity.entity-picker.new_entity")
: item.entity_id}</span
>
</ha-list-item>`; </ha-list-item>`;
private _getStates = memoizeOne( private _getStates = memoizeOne(
@@ -143,7 +157,8 @@ export class HaEntityPicker extends LitElement {
includeDeviceClasses: this["includeDeviceClasses"], includeDeviceClasses: this["includeDeviceClasses"],
includeUnitOfMeasurement: this["includeUnitOfMeasurement"], includeUnitOfMeasurement: this["includeUnitOfMeasurement"],
includeEntities: this["includeEntities"], includeEntities: this["includeEntities"],
excludeEntities: this["excludeEntities"] excludeEntities: this["excludeEntities"],
createDomains: this["createDomains"]
): HassEntityWithCachedName[] => { ): HassEntityWithCachedName[] => {
let states: HassEntityWithCachedName[] = []; let states: HassEntityWithCachedName[] = [];
@@ -152,6 +167,34 @@ export class HaEntityPicker extends LitElement {
} }
let entityIds = Object.keys(hass.states); let entityIds = Object.keys(hass.states);
const createItems = createDomains?.length
? createDomains.map((domain) => {
const newFriendlyName = hass.localize(
"ui.components.entity.entity-picker.create_helper",
{
domain: isHelperDomain(domain)
? hass.localize(
`ui.panel.config.helpers.types.${domain as HelperDomain}`
)
: domainToName(hass.localize, domain),
}
);
return {
entity_id: CREATE_ID + domain,
state: "on",
last_changed: "",
last_updated: "",
context: { id: "", user_id: null, parent_id: null },
friendly_name: newFriendlyName,
attributes: {
icon: "mdi:plus",
},
strings: [domain, newFriendlyName],
};
})
: [];
if (!entityIds.length) { if (!entityIds.length) {
return [ return [
{ {
@@ -171,6 +214,7 @@ export class HaEntityPicker extends LitElement {
}, },
strings: [], strings: [],
}, },
...createItems,
]; ];
} }
@@ -281,9 +325,14 @@ export class HaEntityPicker extends LitElement {
}, },
strings: [], strings: [],
}, },
...createItems,
]; ];
} }
if (createItems?.length) {
states.push(...createItems);
}
return states; return states;
} }
); );
@@ -310,13 +359,18 @@ export class HaEntityPicker extends LitElement {
this.includeDeviceClasses, this.includeDeviceClasses,
this.includeUnitOfMeasurement, this.includeUnitOfMeasurement,
this.includeEntities, this.includeEntities,
this.excludeEntities this.excludeEntities,
this.createDomains
); );
if (this._initedStates) { if (this._initedStates) {
this.comboBox.filteredItems = this._states; this.comboBox.filteredItems = this._states;
} }
this._initedStates = true; this._initedStates = true;
} }
if (changedProps.has("createDomains") && this.createDomains?.length) {
this.hass.loadFragmentTranslation("config");
}
} }
protected render(): TemplateResult { protected render(): TemplateResult {
@@ -354,6 +408,18 @@ export class HaEntityPicker extends LitElement {
private _valueChanged(ev: ValueChangedEvent<string>) { private _valueChanged(ev: ValueChangedEvent<string>) {
ev.stopPropagation(); ev.stopPropagation();
const newValue = ev.detail.value; const newValue = ev.detail.value;
if (newValue && newValue.startsWith(CREATE_ID)) {
const domain = newValue.substring(CREATE_ID.length);
showHelperDetailDialog(this, {
domain,
dialogClosedCallback: (item) => {
if (item.entityId) this._setValue(item.entityId);
},
});
return;
}
if (newValue !== this._value) { if (newValue !== this._value) {
this._setValue(newValue); this._setValue(newValue);
} }

View File

@@ -14,6 +14,8 @@ export class HaCard extends LitElement {
--ha-card-background, --ha-card-background,
var(--card-background-color, white) var(--card-background-color, white)
); );
-webkit-backdrop-filter: var(--ha-card-backdrop-filter, none);
backdrop-filter: var(--ha-card-backdrop-filter, none);
box-shadow: var(--ha-card-box-shadow, none); box-shadow: var(--ha-card-box-shadow, none);
box-sizing: border-box; box-sizing: border-box;
border-radius: var(--ha-card-border-radius, 12px); border-radius: var(--ha-card-border-radius, 12px);

View File

@@ -1,6 +1,6 @@
import "element-internals-polyfill"; import "element-internals-polyfill";
import { MdCircularProgress } from "@material/web/progress/circular-progress"; import { MdCircularProgress } from "@material/web/progress/circular-progress";
import { CSSResult, PropertyValues, css } from "lit"; import { PropertyValues, css } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
@customElement("ha-circular-progress") @customElement("ha-circular-progress")
@@ -32,17 +32,15 @@ export class HaCircularProgress extends MdCircularProgress {
} }
} }
static get styles(): CSSResult[] { static override styles = [
return [ ...super.styles,
...super.styles, css`
css` :host {
:host { --md-sys-color-primary: var(--primary-color);
--md-sys-color-primary: var(--primary-color); --md-circular-progress-size: 48px;
--md-circular-progress-size: 48px; }
} `,
`, ];
];
}
} }
declare global { declare global {

View File

@@ -67,6 +67,9 @@ export class HaControlSlider extends LitElement {
@property({ attribute: "tooltip-mode" }) @property({ attribute: "tooltip-mode" })
public tooltipMode: TooltipMode = "interaction"; public tooltipMode: TooltipMode = "interaction";
@property({ attribute: "touch-action" })
public touchAction?: string;
@property({ type: Number }) @property({ type: Number })
public value?: number; public value?: number;
@@ -152,7 +155,7 @@ export class HaControlSlider extends LitElement {
setupListeners() { setupListeners() {
if (this.slider && !this._mc) { if (this.slider && !this._mc) {
this._mc = new Manager(this.slider, { this._mc = new Manager(this.slider, {
touchAction: this.vertical ? "pan-x" : "pan-y", touchAction: this.touchAction ?? (this.vertical ? "pan-x" : "pan-y"),
}); });
this._mc.add( this._mc.add(
new Pan({ new Pan({

View File

@@ -33,6 +33,9 @@ export class HaControlSwitch extends LitElement {
// SVG icon path (if you need a non SVG icon instead, use the provided off icon slot to pass an <ha-icon slot="icon-off"> in) // SVG icon path (if you need a non SVG icon instead, use the provided off icon slot to pass an <ha-icon slot="icon-off"> in)
@property({ type: String }) pathOff?: string; @property({ type: String }) pathOff?: string;
@property({ attribute: "touch-action" })
public touchAction?: string;
private _mc?: HammerManager; private _mc?: HammerManager;
protected firstUpdated(changedProperties: PropertyValues): void { protected firstUpdated(changedProperties: PropertyValues): void {
@@ -73,7 +76,7 @@ export class HaControlSwitch extends LitElement {
setupListeners() { setupListeners() {
if (this.switch && !this._mc) { if (this.switch && !this._mc) {
this._mc = new Manager(this.switch, { this._mc = new Manager(this.switch, {
touchAction: this.vertical ? "pan-x" : "pan-y", touchAction: this.touchAction ?? (this.vertical ? "pan-x" : "pan-y"),
}); });
this._mc.add( this._mc.add(
new Swipe({ new Swipe({

View File

@@ -75,8 +75,14 @@ export class HaDialog extends DialogBase {
var(--divider-color) var(--divider-color)
); );
z-index: var(--dialog-z-index, 8); z-index: var(--dialog-z-index, 8);
-webkit-backdrop-filter: var(--dialog-backdrop-filter, none); -webkit-backdrop-filter: var(
backdrop-filter: var(--dialog-backdrop-filter, none); --ha-dialog-scrim-backdrop-filter,
var(--dialog-backdrop-filter, none)
);
backdrop-filter: var(
--ha-dialog-scrim-backdrop-filter,
var(--dialog-backdrop-filter, none)
);
--mdc-dialog-box-shadow: var(--dialog-box-shadow, none); --mdc-dialog-box-shadow: var(--dialog-box-shadow, none);
--mdc-typography-headline6-font-weight: 400; --mdc-typography-headline6-font-weight: 400;
--mdc-typography-headline6-font-size: 1.574rem; --mdc-typography-headline6-font-size: 1.574rem;
@@ -119,6 +125,8 @@ export class HaDialog extends DialogBase {
margin-top: var(--dialog-surface-margin-top); margin-top: var(--dialog-surface-margin-top);
min-height: var(--mdc-dialog-min-height, auto); min-height: var(--mdc-dialog-min-height, auto);
border-radius: var(--ha-dialog-border-radius, 28px); border-radius: var(--ha-dialog-border-radius, 28px);
-webkit-backdrop-filter: var(--ha-dialog-surface-backdrop-filter, none);
backdrop-filter: var(--ha-dialog-surface-backdrop-filter, none);
} }
:host([flexContent]) .mdc-dialog .mdc-dialog__content { :host([flexContent]) .mdc-dialog .mdc-dialog__content {
display: flex; display: flex;

View File

@@ -69,7 +69,7 @@ export class HaFilterDevices extends LitElement {
@value-changed=${this._handleSearchChange} @value-changed=${this._handleSearchChange}
> >
</search-input-outlined> </search-input-outlined>
<mwc-list class="ha-scrollbar"> <mwc-list class="ha-scrollbar" multi>
<lit-virtualizer <lit-virtualizer
.items=${this._devices( .items=${this._devices(
this.hass.devices, this.hass.devices,
@@ -94,7 +94,7 @@ export class HaFilterDevices extends LitElement {
? nothing ? nothing
: html`<ha-check-list-item : html`<ha-check-list-item
.value=${device.id} .value=${device.id}
.selected=${this.value?.includes(device.id)} .selected=${this.value?.includes(device.id) ?? false}
> >
${computeDeviceName(device, this.hass)} ${computeDeviceName(device, this.hass)}
</ha-check-list-item>`; </ha-check-list-item>`;

View File

@@ -0,0 +1,198 @@
import { mdiFilterVariantRemove } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import memoizeOne from "memoize-one";
import { fireEvent } from "../common/dom/fire_event";
import { stringCompare } from "../common/string/compare";
import { domainToName } from "../data/integration";
import { haStyleScrollbar } from "../resources/styles";
import type { HomeAssistant } from "../types";
import "./ha-domain-icon";
import "./search-input-outlined";
import { computeDomain } from "../common/entity/compute_domain";
@customElement("ha-filter-domains")
export class HaFilterDomains extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public value?: string[];
@property({ type: Boolean }) public narrow = false;
@property({ type: Boolean, reflect: true }) public expanded = false;
@state() private _shouldRender = false;
@state() private _filter?: string;
protected render() {
return html`
<ha-expansion-panel
leftChevron
.expanded=${this.expanded}
@expanded-will-change=${this._expandedWillChange}
@expanded-changed=${this._expandedChanged}
>
<div slot="header" class="header">
${this.hass.localize(
"ui.panel.config.entities.picker.headers.domain"
)}
${this.value?.length
? html`<div class="badge">${this.value?.length}</div>
<ha-icon-button
.path=${mdiFilterVariantRemove}
@click=${this._clearFilter}
></ha-icon-button>`
: nothing}
</div>
${this._shouldRender
? html`<search-input-outlined
.hass=${this.hass}
.filter=${this._filter}
@value-changed=${this._handleSearchChange}
>
</search-input-outlined>
<mwc-list
class="ha-scrollbar"
@click=${this._handleItemClick}
multi
>
${repeat(
this._domains(this.hass.states, this._filter),
(i) => i,
(domain) =>
html`<ha-check-list-item
.value=${domain}
.selected=${(this.value || []).includes(domain)}
graphic="icon"
>
<ha-domain-icon
slot="graphic"
.hass=${this.hass}
.domain=${domain}
brandFallback
></ha-domain-icon>
${domainToName(this.hass.localize, domain)}
</ha-check-list-item>`
)}
</mwc-list> `
: nothing}
</ha-expansion-panel>
`;
}
private _domains = memoizeOne((states, filter) => {
const domains = new Set<string>();
Object.keys(states).forEach((entityId) => {
domains.add(computeDomain(entityId));
});
return Array.from(domains)
.filter((domain) => !filter || domain.toLowerCase().includes(filter))
.sort((a, b) => stringCompare(a, b, this.hass.locale.language));
});
protected updated(changed) {
if (changed.has("expanded") && this.expanded) {
setTimeout(() => {
if (!this.expanded) return;
this.renderRoot.querySelector("mwc-list")!.style.height =
`${this.clientHeight - 49 - 32}px`; // 32px is the height of the search input
}, 300);
}
}
private _expandedWillChange(ev) {
this._shouldRender = ev.detail.expanded;
}
private _expandedChanged(ev) {
this.expanded = ev.detail.expanded;
}
private _handleItemClick(ev) {
const listItem = ev.target.closest("ha-check-list-item");
const value = listItem?.value;
if (!value) {
return;
}
if (this.value?.includes(value)) {
this.value = this.value?.filter((val) => val !== value);
} else {
this.value = [...(this.value || []), value];
}
listItem.selected = this.value.includes(value);
fireEvent(this, "data-table-filter-changed", {
value: this.value,
items: undefined,
});
}
private _clearFilter(ev) {
ev.preventDefault();
this.value = undefined;
fireEvent(this, "data-table-filter-changed", {
value: undefined,
items: undefined,
});
}
private _handleSearchChange(ev: CustomEvent) {
this._filter = ev.detail.value.toLowerCase();
}
static get styles(): CSSResultGroup {
return [
haStyleScrollbar,
css`
:host {
border-bottom: 1px solid var(--divider-color);
}
:host([expanded]) {
flex: 1;
height: 0;
}
ha-expansion-panel {
--ha-card-border-radius: 0;
--expansion-panel-content-padding: 0;
}
.header {
display: flex;
align-items: center;
}
.header ha-icon-button {
margin-inline-start: auto;
margin-inline-end: 8px;
}
.badge {
display: inline-block;
margin-left: 8px;
margin-inline-start: 8px;
margin-inline-end: 0;
min-width: 16px;
box-sizing: border-box;
border-radius: 50%;
font-weight: 400;
font-size: 11px;
background-color: var(--primary-color);
line-height: 16px;
text-align: center;
padding: 0px 2px;
color: var(--text-primary-color);
}
search-input-outlined {
display: block;
padding: 0 8px;
}
`,
];
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-filter-domains": HaFilterDomains;
}
}

View File

@@ -71,7 +71,7 @@ export class HaFilterEntities extends LitElement {
@value-changed=${this._handleSearchChange} @value-changed=${this._handleSearchChange}
> >
</search-input-outlined> </search-input-outlined>
<mwc-list class="ha-scrollbar"> <mwc-list class="ha-scrollbar" multi>
<lit-virtualizer <lit-virtualizer
.items=${this._entities( .items=${this._entities(
this.hass.states, this.hass.states,
@@ -108,7 +108,7 @@ export class HaFilterEntities extends LitElement {
? nothing ? nothing
: html`<ha-check-list-item : html`<ha-check-list-item
.value=${entity.entity_id} .value=${entity.entity_id}
.selected=${this.value?.includes(entity.entity_id)} .selected=${this.value?.includes(entity.entity_id) ?? false}
graphic="icon" graphic="icon"
> >
<ha-state-icon <ha-state-icon

View File

@@ -1,4 +1,3 @@
import { SelectedDetail } from "@material/mwc-list";
import { mdiFilterVariantRemove } from "@mdi/js"; import { mdiFilterVariantRemove } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
@@ -57,9 +56,9 @@ export class HaFilterIntegrations extends LitElement {
> >
</search-input-outlined> </search-input-outlined>
<mwc-list <mwc-list
@selected=${this._integrationsSelected}
multi
class="ha-scrollbar" class="ha-scrollbar"
@click=${this._handleItemClick}
multi
> >
${repeat( ${repeat(
this._integrations(this._manifests, this._filter, this.value), this._integrations(this._manifests, this._filter, this.value),
@@ -131,34 +130,21 @@ export class HaFilterIntegrations extends LitElement {
) )
); );
private async _integrationsSelected( private _handleItemClick(ev) {
ev: CustomEvent<SelectedDetail<Set<number>>> const listItem = ev.target.closest("ha-check-list-item");
) { const value = listItem?.value;
const integrations = this._integrations( if (!value) {
this._manifests!,
this._filter,
this.value
);
if (!ev.detail.index.size) {
fireEvent(this, "data-table-filter-changed", {
value: [],
items: undefined,
});
this.value = [];
return; return;
} }
if (this.value?.includes(value)) {
const value: string[] = []; this.value = this.value?.filter((val) => val !== value);
} else {
for (const index of ev.detail.index) { this.value = [...(this.value || []), value];
const domain = integrations[index].domain;
value.push(domain);
} }
this.value = value; listItem.selected = this.value?.includes(value);
fireEvent(this, "data-table-filter-changed", { fireEvent(this, "data-table-filter-changed", {
value, value: this.value,
items: undefined, items: undefined,
}); });
} }

View File

@@ -62,8 +62,8 @@ export class HaFilterStates extends LitElement {
(item) => (item) =>
html`<ha-check-list-item html`<ha-check-list-item
.value=${item.value} .value=${item.value}
.selected=${this.value?.includes(item.value)} .selected=${this.value?.includes(item.value) ?? false}
.graphic=${hasIcon ? "icon" : undefined} .graphic=${hasIcon ? "icon" : null}
> >
${item.icon ${item.icon
? html`<ha-icon ? html`<ha-icon

View File

@@ -302,6 +302,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
name: this.hass.localize("ui.components.label-picker.no_match"), name: this.hass.localize("ui.components.label-picker.no_match"),
icon: null, icon: null,
color: null, color: null,
description: null,
}, },
]; ];
} }
@@ -315,6 +316,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
name: this.hass.localize("ui.components.label-picker.add_new"), name: this.hass.localize("ui.components.label-picker.add_new"),
icon: "mdi:plus", icon: "mdi:plus",
color: null, color: null,
description: null,
}, },
]; ];
} }

View File

@@ -1,25 +1,23 @@
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { MdListItem } from "@material/web/list/list-item"; import { MdListItem } from "@material/web/list/list-item";
import { CSSResult, css } from "lit"; import { css } from "lit";
@customElement("ha-list-item-new") @customElement("ha-list-item-new")
export class HaListItemNew extends MdListItem { export class HaListItemNew extends MdListItem {
static get styles(): CSSResult[] { static override styles = [
return [ ...super.styles,
...MdListItem.styles, css`
css` :host {
:host { --ha-icon-display: block;
--ha-icon-display: block; --md-sys-color-primary: var(--primary-text-color);
--md-sys-color-primary: var(--primary-text-color); --md-sys-color-secondary: var(--secondary-text-color);
--md-sys-color-secondary: var(--secondary-text-color); --md-sys-color-surface: var(--card-background-color);
--md-sys-color-surface: var(--card-background-color); --md-sys-color-on-surface: var(--primary-text-color);
--md-sys-color-on-surface: var(--primary-text-color); --md-sys-color-on-surface-variant: var(--secondary-text-color);
--md-sys-color-on-surface-variant: var(--secondary-text-color); }
} `,
`, ];
];
}
} }
declare global { declare global {

View File

@@ -1,20 +1,18 @@
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { MdList } from "@material/web/list/list"; import { MdList } from "@material/web/list/list";
import { CSSResult, css } from "lit"; import { css } from "lit";
@customElement("ha-list-new") @customElement("ha-list-new")
export class HaListNew extends MdList { export class HaListNew extends MdList {
static get styles(): CSSResult[] { static override styles = [
return [ ...super.styles,
...MdList.styles, css`
css` :host {
:host { --md-sys-color-surface: var(--card-background-color);
--md-sys-color-surface: var(--card-background-color); }
} `,
`, ];
];
}
} }
declare global { declare global {

View File

@@ -1,12 +1,12 @@
import { MdMenuItem } from "@material/web/menu/menu-item"; import { MdMenuItem } from "@material/web/menu/menu-item";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { CSSResult, css } from "lit"; import { css } from "lit";
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
@customElement("ha-menu-item") @customElement("ha-menu-item")
export class HaMenuItem extends MdMenuItem { export class HaMenuItem extends MdMenuItem {
static override styles: CSSResult[] = [ static override styles = [
...MdMenuItem.styles, ...super.styles,
css` css`
:host { :host {
--ha-icon-display: block; --ha-icon-display: block;

View File

@@ -1,12 +1,12 @@
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { CSSResult, css } from "lit"; import { css } from "lit";
import { MdMenu } from "@material/web/menu/menu"; import { MdMenu } from "@material/web/menu/menu";
@customElement("ha-menu") @customElement("ha-menu")
export class HaMenu extends MdMenu { export class HaMenu extends MdMenu {
static override styles: CSSResult[] = [ static override styles = [
...MdMenu.styles, ...super.styles,
css` css`
:host { :host {
--md-sys-color-surface-container: var(--card-background-color); --md-sys-color-surface-container: var(--card-background-color);

View File

@@ -0,0 +1,40 @@
import { MdOutlinedField } from "@material/web/field/outlined-field";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";
import { literal } from "lit/static-html";
@customElement("ha-outlined-field")
export class HaOutlinedField extends MdOutlinedField {
protected readonly fieldTag = literal`ha-outlined-field`;
static override styles = [
...super.styles,
css`
.container::before {
display: block;
content: "";
position: absolute;
inset: 0;
background-color: var(--ha-outlined-field-container-color, transparent);
opacity: var(--ha-outlined-field-container-opacity, 1);
border-start-start-radius: var(--_container-shape-start-start);
border-start-end-radius: var(--_container-shape-start-end);
border-end-start-radius: var(--_container-shape-end-start);
border-end-end-radius: var(--_container-shape-end-end);
}
.with-start .start {
margin-inline-end: var(--ha-outlined-field-start-margin, 4px);
}
.with-end .end {
margin-inline-start: var(--ha-outlined-field-end-margin, 4px);
}
`,
];
}
declare global {
interface HTMLElementTagNameMap {
"ha-outlined-field": HaOutlinedField;
}
}

View File

@@ -2,9 +2,13 @@ import { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field
import "element-internals-polyfill"; import "element-internals-polyfill";
import { css } from "lit"; import { css } from "lit";
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import { literal } from "lit/static-html";
import "./ha-outlined-field";
@customElement("ha-outlined-text-field") @customElement("ha-outlined-text-field")
export class HaOutlinedTextField extends MdOutlinedTextField { export class HaOutlinedTextField extends MdOutlinedTextField {
protected readonly fieldTag = literal`ha-outlined-field`;
static override styles = [ static override styles = [
...super.styles, ...super.styles,
css` css`
@@ -25,12 +29,10 @@ export class HaOutlinedTextField extends MdOutlinedTextField {
--md-outlined-field-container-shape-end-end: 10px; --md-outlined-field-container-shape-end-end: 10px;
--md-outlined-field-container-shape-end-start: 10px; --md-outlined-field-container-shape-end-start: 10px;
--md-outlined-field-focus-outline-width: 1px; --md-outlined-field-focus-outline-width: 1px;
--ha-outlined-field-start-margin: -4px;
--ha-outlined-field-end-margin: -4px;
--mdc-icon-size: var(--md-input-chip-icon-size, 18px); --mdc-icon-size: var(--md-input-chip-icon-size, 18px);
} }
md-outlined-field {
background: var(--ha-outlined-text-field-container-color, transparent);
opacity: var(--ha-outlined-text-field-container-opacity, 1);
}
.input { .input {
font-family: Roboto, sans-serif; font-family: Roboto, sans-serif;
} }

View File

@@ -7,8 +7,10 @@ import type {
LocationSelectorValue, LocationSelectorValue,
} from "../../data/selector"; } from "../../data/selector";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import type { SchemaUnion } from "../ha-form/types";
import type { MarkerLocation } from "../map/ha-locations-editor"; import type { MarkerLocation } from "../map/ha-locations-editor";
import "../map/ha-locations-editor"; import "../map/ha-locations-editor";
import "../ha-form/ha-form";
@customElement("ha-selector-location") @customElement("ha-selector-location")
export class HaLocationSelector extends LitElement { export class HaLocationSelector extends LitElement {
@@ -24,6 +26,49 @@ export class HaLocationSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false; @property({ type: Boolean, reflect: true }) public disabled = false;
private _schema = memoizeOne(
(radius?: boolean, radius_readonly?: boolean) =>
[
{
name: "",
type: "grid",
schema: [
{
name: "latitude",
required: true,
selector: { number: { step: "any" } },
},
{
name: "longitude",
required: true,
selector: { number: { step: "any" } },
},
],
},
...(radius
? [
{
name: "radius",
required: true,
default: 1000,
disabled: !!radius_readonly,
selector: { number: { min: 0, step: 1, mode: "box" } as const },
} as const,
]
: []),
] as const
);
protected willUpdate() {
if (!this.value) {
this.value = {
latitude: this.hass.config.latitude,
longitude: this.hass.config.longitude,
radius: this.selector.location?.radius ? 1000 : undefined,
};
}
}
protected render() { protected render() {
return html` return html`
<p>${this.label ? this.label : ""}</p> <p>${this.label ? this.label : ""}</p>
@@ -35,6 +80,17 @@ export class HaLocationSelector extends LitElement {
@location-updated=${this._locationChanged} @location-updated=${this._locationChanged}
@radius-updated=${this._radiusChanged} @radius-updated=${this._radiusChanged}
></ha-locations-editor> ></ha-locations-editor>
<ha-form
.hass=${this.hass}
.schema=${this._schema(
this.selector.location?.radius,
this.selector.location?.radius_readonly
)}
.data=${this.value}
.computeLabel=${this._computeLabel}
.disabled=${this.disabled}
@value-changed=${this._valueChanged}
></ha-form>
`; `;
} }
@@ -66,7 +122,8 @@ export class HaLocationSelector extends LitElement {
? "mdi:map-marker-radius" ? "mdi:map-marker-radius"
: "mdi:map-marker", : "mdi:map-marker",
location_editable: true, location_editable: true,
radius_editable: true, radius_editable:
!!selector.location?.radius && !selector.location?.radius_readonly,
}, },
]; ];
} }
@@ -80,14 +137,39 @@ export class HaLocationSelector extends LitElement {
} }
private _radiusChanged(ev: CustomEvent) { private _radiusChanged(ev: CustomEvent) {
const radius = ev.detail.radius; const radius = Math.round(ev.detail.radius);
fireEvent(this, "value-changed", { value: { ...this.value, radius } }); fireEvent(this, "value-changed", { value: { ...this.value, radius } });
} }
private _valueChanged(ev: CustomEvent) {
ev.stopPropagation();
const value = ev.detail.value;
const radius = Math.round(ev.detail.value.radius);
fireEvent(this, "value-changed", {
value: {
latitude: value.latitude,
longitude: value.longitude,
...(this.selector.location?.radius &&
!this.selector.location?.radius_readonly
? {
radius,
}
: {}),
},
});
}
private _computeLabel = (
entry: SchemaUnion<ReturnType<typeof this._schema>>
): string =>
this.hass.localize(`ui.components.selectors.location.${entry.name}`);
static styles = css` static styles = css`
ha-locations-editor { ha-locations-editor {
display: block; display: block;
height: 400px; height: 400px;
margin-bottom: 16px;
} }
p { p {
margin-top: 0; margin-top: 0;

View File

@@ -82,6 +82,7 @@ export class HaTargetSelector extends LitElement {
.deviceFilter=${this._filterDevices} .deviceFilter=${this._filterDevices}
.entityFilter=${this._filterEntities} .entityFilter=${this._filterEntities}
.disabled=${this.disabled} .disabled=${this.disabled}
.createDomains=${this.selector.target?.create_domains}
></ha-target-picker>`; ></ha-target-picker>`;
} }

View File

@@ -33,6 +33,7 @@ import {
expandFloorTarget, expandFloorTarget,
expandLabelTarget, expandLabelTarget,
Selector, Selector,
TargetSelector,
} from "../data/selector"; } from "../data/selector";
import { HomeAssistant, ValueChangedEvent } from "../types"; import { HomeAssistant, ValueChangedEvent } from "../types";
import { documentationUrl } from "../util/documentation-url"; import { documentationUrl } from "../util/documentation-url";
@@ -43,6 +44,7 @@ import "./ha-service-picker";
import "./ha-settings-row"; import "./ha-settings-row";
import "./ha-yaml-editor"; import "./ha-yaml-editor";
import type { HaYamlEditor } from "./ha-yaml-editor"; import type { HaYamlEditor } from "./ha-yaml-editor";
import { isHelperDomain } from "../panels/config/helpers/const";
const attributeFilter = (values: any[], attribute: any) => { const attributeFilter = (values: any[], attribute: any) => {
if (typeof attribute === "object") { if (typeof attribute === "object") {
@@ -363,6 +365,15 @@ export class HaServiceControl extends LitElement {
return false; return false;
} }
private _targetSelector = memoizeOne(
(targetSelector: TargetSelector | null | undefined, domain?: string) => {
const create_domains = isHelperDomain(domain) ? [domain] : undefined;
return targetSelector
? { target: { ...targetSelector, create_domains } }
: { target: { create_domains } };
}
);
protected render() { protected render() {
const serviceData = this._getServiceInfo( const serviceData = this._getServiceInfo(
this._value?.service, this._value?.service,
@@ -401,157 +412,152 @@ export class HaServiceControl extends LitElement {
)) || )) ||
serviceData?.description; serviceData?.description;
return html` return html`${this.hidePicker
${this.hidePicker ? nothing
? nothing : html`<ha-service-picker
: html`<ha-service-picker .hass=${this.hass}
.value=${this._value?.service}
.disabled=${this.disabled}
@value-changed=${this._serviceChanged}
></ha-service-picker>`}
${this.hideDescription
? nothing
: html`
<div class="description">
${description ? html`<p>${description}</p>` : ""}
${this._manifest
? html` <a
href=${this._manifest.is_built_in
? documentationUrl(
this.hass,
`/integrations/${this._manifest.domain}`
)
: this._manifest.documentation}
title=${this.hass.localize(
"ui.components.service-control.integration_doc"
)}
target="_blank"
rel="noreferrer"
>
<ha-icon-button
.path=${mdiHelpCircle}
class="help-icon"
></ha-icon-button>
</a>`
: nothing}
</div>
`}
${serviceData && "target" in serviceData
? html`<ha-settings-row .narrow=${this.narrow}>
${hasOptional
? html`<div slot="prefix" class="checkbox-spacer"></div>`
: ""}
<span slot="heading"
>${this.hass.localize("ui.components.service-control.target")}</span
>
<span slot="description"
>${this.hass.localize(
"ui.components.service-control.target_description"
)}</span
><ha-selector
.hass=${this.hass} .hass=${this.hass}
.value=${this._value?.service} .selector=${this._targetSelector(
serviceData.target as TargetSelector,
domain
)}
.disabled=${this.disabled} .disabled=${this.disabled}
@value-changed=${this._serviceChanged} @value-changed=${this._targetChanged}
></ha-service-picker>`} .value=${this._value?.target}
${this.hideDescription ></ha-selector
? nothing ></ha-settings-row>`
: html` : entityId
<div class="description"> ? html`<ha-entity-picker
${description ? html`<p>${description}</p>` : ""}
${this._manifest
? html` <a
href=${this._manifest.is_built_in
? documentationUrl(
this.hass,
`/integrations/${this._manifest.domain}`
)
: this._manifest.documentation}
title=${this.hass.localize(
"ui.components.service-control.integration_doc"
)}
target="_blank"
rel="noreferrer"
>
<ha-icon-button
.path=${mdiHelpCircle}
class="help-icon"
></ha-icon-button>
</a>`
: nothing}
</div>
`}
${serviceData && "target" in serviceData
? html`<ha-settings-row .narrow=${this.narrow}>
${hasOptional
? html`<div slot="prefix" class="checkbox-spacer"></div>`
: ""}
<span slot="heading"
>${this.hass.localize(
"ui.components.service-control.target"
)}</span
>
<span slot="description"
>${this.hass.localize(
"ui.components.service-control.target_description"
)}</span
><ha-selector
.hass=${this.hass}
.selector=${serviceData.target
? { target: serviceData.target }
: { target: {} }}
.disabled=${this.disabled}
@value-changed=${this._targetChanged}
.value=${this._value?.target}
></ha-selector
></ha-settings-row>`
: entityId
? html`<ha-entity-picker
.hass=${this.hass}
.disabled=${this.disabled}
.value=${this._value?.data?.entity_id}
.label=${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.entity_id.description`
) || entityId.description}
@value-changed=${this._entityPicked}
allow-custom-entity
></ha-entity-picker>`
: ""}
${shouldRenderServiceDataYaml
? html`<ha-yaml-editor
.hass=${this.hass} .hass=${this.hass}
.label=${this.hass.localize("ui.components.service-control.data")} .disabled=${this.disabled}
.name=${"data"} .value=${this._value?.data?.entity_id}
.readOnly=${this.disabled} .label=${this.hass.localize(
.defaultValue=${this._value?.data} `component.${domain}.services.${serviceName}.fields.entity_id.description`
@value-changed=${this._dataChanged} ) || entityId.description}
></ha-yaml-editor>` @value-changed=${this._entityPicked}
: filteredFields?.map((dataField) => { allow-custom-entity
const selector = dataField?.selector ?? { text: undefined }; ></ha-entity-picker>`
const type = Object.keys(selector)[0]; : ""}
const enhancedSelector = [ ${shouldRenderServiceDataYaml
"action", ? html`<ha-yaml-editor
"condition", .hass=${this.hass}
"trigger", .label=${this.hass.localize("ui.components.service-control.data")}
].includes(type) .name=${"data"}
? { .readOnly=${this.disabled}
[type]: { .defaultValue=${this._value?.data}
...selector[type], @value-changed=${this._dataChanged}
path: [dataField.key], ></ha-yaml-editor>`
}, : filteredFields?.map((dataField) => {
} const selector = dataField?.selector ?? { text: undefined };
: selector; const type = Object.keys(selector)[0];
const enhancedSelector = ["action", "condition", "trigger"].includes(
type
)
? {
[type]: {
...selector[type],
path: [dataField.key],
},
}
: selector;
const showOptional = showOptionalToggle(dataField); const showOptional = showOptionalToggle(dataField);
return dataField.selector && return dataField.selector &&
(!dataField.advanced || (!dataField.advanced ||
this.showAdvanced || this.showAdvanced ||
(this._value?.data && (this._value?.data &&
this._value.data[dataField.key] !== undefined)) this._value.data[dataField.key] !== undefined))
? html`<ha-settings-row .narrow=${this.narrow}> ? html`<ha-settings-row .narrow=${this.narrow}>
${!showOptional ${!showOptional
? hasOptional ? hasOptional
? html`<div slot="prefix" class="checkbox-spacer"></div>` ? html`<div slot="prefix" class="checkbox-spacer"></div>`
: "" : ""
: html`<ha-checkbox : html`<ha-checkbox
.key=${dataField.key} .key=${dataField.key}
.checked=${this._checkedKeys.has(dataField.key) || .checked=${this._checkedKeys.has(dataField.key) ||
(this._value?.data && (this._value?.data &&
this._value.data[dataField.key] !== undefined)} this._value.data[dataField.key] !== undefined)}
.disabled=${this.disabled} .disabled=${this.disabled}
@change=${this._checkboxChanged} @change=${this._checkboxChanged}
slot="prefix" slot="prefix"
></ha-checkbox>`} ></ha-checkbox>`}
<span slot="heading" <span slot="heading"
>${this.hass.localize( >${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${dataField.key}.name` `component.${domain}.services.${serviceName}.fields.${dataField.key}.name`
) || ) ||
dataField.name || dataField.name ||
dataField.key}</span dataField.key}</span
> >
<span slot="description" <span slot="description"
>${this.hass.localize( >${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description` `component.${domain}.services.${serviceName}.fields.${dataField.key}.description`
) || dataField?.description}</span ) || dataField?.description}</span
> >
<ha-selector <ha-selector
.disabled=${this.disabled || .disabled=${this.disabled ||
(showOptional && (showOptional &&
!this._checkedKeys.has(dataField.key) && !this._checkedKeys.has(dataField.key) &&
(!this._value?.data || (!this._value?.data ||
this._value.data[dataField.key] === undefined))} this._value.data[dataField.key] === undefined))}
.hass=${this.hass} .hass=${this.hass}
.selector=${enhancedSelector} .selector=${enhancedSelector}
.key=${dataField.key} .key=${dataField.key}
@value-changed=${this._serviceDataChanged} @value-changed=${this._serviceDataChanged}
.value=${this._value?.data .value=${this._value?.data
? this._value.data[dataField.key] ? this._value.data[dataField.key]
: undefined} : undefined}
.placeholder=${dataField.default} .placeholder=${dataField.default}
.localizeValue=${this._localizeValueCallback} .localizeValue=${this._localizeValueCallback}
@item-moved=${this._itemMoved} @item-moved=${this._itemMoved}
></ha-selector> ></ha-selector>
</ha-settings-row>` </ha-settings-row>`
: ""; : "";
})} })} `;
`;
} }
private _localizeValueCallback = (key: string) => { private _localizeValueCallback = (key: string) => {

View File

@@ -1,7 +1,7 @@
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { MdSlider } from "@material/web/slider/slider"; import { MdSlider } from "@material/web/slider/slider";
import { CSSResult, css } from "lit"; import { css } from "lit";
import { mainWindow } from "../common/dom/get_main_window"; import { mainWindow } from "../common/dom/get_main_window";
@customElement("ha-slider") @customElement("ha-slider")
@@ -11,8 +11,8 @@ export class HaSlider extends MdSlider {
this.dir = mainWindow.document.dir; this.dir = mainWindow.document.dir;
} }
static override styles: CSSResult[] = [ static override styles = [
...MdSlider.styles, ...super.styles,
css` css`
:host { :host {
--md-sys-color-primary: var(--primary-color); --md-sys-color-primary: var(--primary-color);

View File

@@ -82,7 +82,7 @@ export class HaSortable extends LitElement {
public connectedCallback() { public connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this._shouldBeDestroy = false; this._shouldBeDestroy = false;
if (this.hasUpdated) { if (this.hasUpdated && !this.disabled) {
this._createSortable(); this._createSortable();
} }
} }

View File

@@ -1,13 +1,17 @@
import { customElement } from "lit/decorators"; import { customElement } from "lit/decorators";
import "element-internals-polyfill"; import "element-internals-polyfill";
import { CSSResult, css } from "lit"; import { css } from "lit";
import { MdSubMenu } from "@material/web/menu/sub-menu"; import { MdSubMenu } from "@material/web/menu/sub-menu";
@customElement("ha-sub-menu") @customElement("ha-sub-menu")
// @ts-expect-error
export class HaSubMenu extends MdSubMenu { export class HaSubMenu extends MdSubMenu {
static override styles: CSSResult[] = [ async show() {
MdSubMenu.styles, super.show();
this.menu.hasOverflow = false;
}
static override styles = [
...super.styles,
css` css`
:host { :host {
--ha-icon-display: block; --ha-icon-display: block;

View File

@@ -65,6 +65,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
@property() public helper?: string; @property() public helper?: string;
@property({ type: Array }) public createDomains?: string[];
/** /**
* Show only targets with entities from specific domains. * Show only targets with entities from specific domains.
* @type {Array} * @type {Array}
@@ -468,6 +470,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
.includeDeviceClasses=${this.includeDeviceClasses} .includeDeviceClasses=${this.includeDeviceClasses}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeEntities=${ensureArray(this.value?.entity_id)} .excludeEntities=${ensureArray(this.value?.entity_id)}
.createDomains=${this.createDomains}
@value-changed=${this._targetPicked} @value-changed=${this._targetPicked}
@click=${this._preventDefault} @click=${this._preventDefault}
allow-custom-entity allow-custom-entity

View File

@@ -19,7 +19,7 @@ import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import type { LeafletModuleType } from "../../common/dom/setup-leaflet-map"; import type { LeafletModuleType } from "../../common/dom/setup-leaflet-map";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant, ThemeMode } from "../../types";
import "../ha-input-helper-text"; import "../ha-input-helper-text";
import "./ha-map"; import "./ha-map";
import type { HaMap } from "./ha-map"; import type { HaMap } from "./ha-map";
@@ -61,7 +61,8 @@ export class HaLocationsEditor extends LitElement {
@property({ type: Number }) public zoom = 16; @property({ type: Number }) public zoom = 16;
@property({ type: Boolean }) public darkMode = false; @property({ attribute: "theme-mode", type: String })
public themeMode: ThemeMode = "auto";
@state() private _locationMarkers?: Record<string, Marker | Circle>; @state() private _locationMarkers?: Record<string, Marker | Circle>;
@@ -133,7 +134,7 @@ export class HaLocationsEditor extends LitElement {
.layers=${this._getLayers(this._circles, this._locationMarkers)} .layers=${this._getLayers(this._circles, this._locationMarkers)}
.zoom=${this.zoom} .zoom=${this.zoom}
.autoFit=${this.autoFit} .autoFit=${this.autoFit}
?darkMode=${this.darkMode} .themeMode=${this.themeMode}
></ha-map> ></ha-map>
${this.helper ${this.helper
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>` ? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`

View File

@@ -1,32 +1,32 @@
import { isToday } from "date-fns";
import type { import type {
Circle, Circle,
CircleMarker, CircleMarker,
LatLngTuple,
LatLngExpression, LatLngExpression,
LatLngTuple,
Layer, Layer,
Map, Map,
Marker, Marker,
Polyline, Polyline,
} from "leaflet"; } from "leaflet";
import { isToday } from "date-fns"; import { CSSResultGroup, PropertyValues, ReactiveElement, css } from "lit";
import { css, CSSResultGroup, PropertyValues, ReactiveElement } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { formatDateTime } from "../../common/datetime/format_date_time";
import {
formatTimeWeekday,
formatTimeWithSeconds,
} from "../../common/datetime/format_time";
import { import {
LeafletModuleType, LeafletModuleType,
setupLeafletMap, setupLeafletMap,
} from "../../common/dom/setup-leaflet-map"; } from "../../common/dom/setup-leaflet-map";
import {
formatTimeWithSeconds,
formatTimeWeekday,
} from "../../common/datetime/format_time";
import { formatDateTime } from "../../common/datetime/format_date_time";
import { computeStateDomain } from "../../common/entity/compute_state_domain"; import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name"; import { computeStateName } from "../../common/entity/compute_state_name";
import { loadPolyfillIfNeeded } from "../../resources/resize-observer.polyfill"; import { loadPolyfillIfNeeded } from "../../resources/resize-observer.polyfill";
import { HomeAssistant } from "../../types"; import { HomeAssistant, ThemeMode } from "../../types";
import { isTouch } from "../../util/is_touch";
import "../ha-icon-button"; import "../ha-icon-button";
import "./ha-entity-marker"; import "./ha-entity-marker";
import { isTouch } from "../../util/is_touch";
const getEntityId = (entity: string | HaMapEntity): string => const getEntityId = (entity: string | HaMapEntity): string =>
typeof entity === "string" ? entity : entity.entity_id; typeof entity === "string" ? entity : entity.entity_id;
@@ -69,7 +69,8 @@ export class HaMap extends ReactiveElement {
@property({ type: Boolean }) public fitZones = false; @property({ type: Boolean }) public fitZones = false;
@property({ type: Boolean }) public darkMode = false; @property({ attribute: "theme-mode", type: String })
public themeMode: ThemeMode = "auto";
@property({ type: Number }) public zoom = 14; @property({ type: Number }) public zoom = 14;
@@ -154,7 +155,7 @@ export class HaMap extends ReactiveElement {
} }
if ( if (
!changedProps.has("darkMode") && !changedProps.has("themeMode") &&
(!changedProps.has("hass") || (!changedProps.has("hass") ||
(oldHass && oldHass.themes?.darkMode === this.hass.themes?.darkMode)) (oldHass && oldHass.themes?.darkMode === this.hass.themes?.darkMode))
) { ) {
@@ -163,12 +164,18 @@ export class HaMap extends ReactiveElement {
this._updateMapStyle(); this._updateMapStyle();
} }
private get _darkMode() {
return (
this.themeMode === "dark" ||
(this.themeMode === "auto" && Boolean(this.hass.themes.darkMode))
);
}
private _updateMapStyle(): void { private _updateMapStyle(): void {
const darkMode = this.darkMode || (this.hass.themes.darkMode ?? false);
const forcedDark = this.darkMode;
const map = this.renderRoot.querySelector("#map"); const map = this.renderRoot.querySelector("#map");
map!.classList.toggle("dark", darkMode); map!.classList.toggle("dark", this._darkMode);
map!.classList.toggle("forced-dark", forcedDark); map!.classList.toggle("forced-dark", this.themeMode === "dark");
map!.classList.toggle("forced-light", this.themeMode === "light");
} }
private async _loadMap(): Promise<void> { private async _loadMap(): Promise<void> {
@@ -398,8 +405,7 @@ export class HaMap extends ReactiveElement {
"--dark-primary-color" "--dark-primary-color"
); );
const className = const className = this._darkMode ? "dark" : "light";
this.darkMode || this.hass.themes.darkMode ? "dark" : "light";
for (const entity of this.entities) { for (const entity of this.entities) {
const stateObj = hass.states[getEntityId(entity)]; const stateObj = hass.states[getEntityId(entity)];
@@ -543,27 +549,30 @@ export class HaMap extends ReactiveElement {
background: #090909; background: #090909;
} }
#map.forced-dark { #map.forced-dark {
color: #ffffff;
--map-filter: invert(0.9) hue-rotate(170deg) brightness(1.5) --map-filter: invert(0.9) hue-rotate(170deg) brightness(1.5)
contrast(1.2) saturate(0.3); contrast(1.2) saturate(0.3);
} }
#map.forced-light {
background: #ffffff;
color: #000000;
--map-filter: invert(0);
}
#map:active { #map:active {
cursor: grabbing; cursor: grabbing;
cursor: -moz-grabbing; cursor: -moz-grabbing;
cursor: -webkit-grabbing; cursor: -webkit-grabbing;
} }
.light {
color: #000000;
}
.dark {
color: #ffffff;
}
.leaflet-tile-pane { .leaflet-tile-pane {
filter: var(--map-filter); filter: var(--map-filter);
} }
.dark .leaflet-bar a { .dark .leaflet-bar a {
background-color: var(--card-background-color, #1c1c1c); background-color: #1c1c1c;
color: #ffffff; color: #ffffff;
} }
.dark .leaflet-bar a:hover {
background-color: #313131;
}
.leaflet-marker-draggable { .leaflet-marker-draggable {
cursor: move !important; cursor: move !important;
} }

View File

@@ -97,7 +97,7 @@ class SearchInputOutlined extends LitElement {
ha-outlined-text-field { ha-outlined-text-field {
display: block; display: block;
width: 100%; width: 100%;
--ha-outlined-text-field-container-color: var(--card-background-color); --ha-outlined-field-container-color: var(--card-background-color);
} }
ha-svg-icon, ha-svg-icon,
ha-icon-button { ha-icon-button {

View File

@@ -1,3 +1,4 @@
import { consume } from "@lit-labs/context";
import { import {
mdiAlertCircle, mdiAlertCircle,
mdiCircle, mdiCircle,
@@ -6,14 +7,13 @@ import {
mdiProgressWrench, mdiProgressWrench,
mdiRecordCircleOutline, mdiRecordCircleOutline,
} from "@mdi/js"; } from "@mdi/js";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
TemplateResult, TemplateResult,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
@@ -23,27 +23,31 @@ import { relativeTime } from "../../common/datetime/relative_time";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { toggleAttribute } from "../../common/dom/toggle_attribute"; import { toggleAttribute } from "../../common/dom/toggle_attribute";
import { import {
EntityRegistryEntry, floorsContext,
subscribeEntityRegistry, fullEntitiesContext,
} from "../../data/entity_registry"; labelsContext,
} from "../../data/context";
import { EntityRegistryEntry } from "../../data/entity_registry";
import { FloorRegistryEntry } from "../../data/floor_registry";
import { LabelRegistryEntry } from "../../data/label_registry";
import { LogbookEntry } from "../../data/logbook"; import { LogbookEntry } from "../../data/logbook";
import { import {
ChooseAction, ChooseAction,
ChooseActionChoice, ChooseActionChoice,
getActionType,
IfAction, IfAction,
ParallelAction, ParallelAction,
RepeatAction, RepeatAction,
getActionType,
} from "../../data/script"; } from "../../data/script";
import { describeAction } from "../../data/script_i18n"; import { describeAction } from "../../data/script_i18n";
import { import {
ActionTraceStep, ActionTraceStep,
AutomationTraceExtended, AutomationTraceExtended,
ChooseActionTraceStep, ChooseActionTraceStep,
getDataFromPath,
IfActionTraceStep, IfActionTraceStep,
isTriggerPath,
TriggerTraceStep, TriggerTraceStep,
getDataFromPath,
isTriggerPath,
} from "../../data/trace"; } from "../../data/trace";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "./ha-timeline"; import "./ha-timeline";
@@ -200,6 +204,8 @@ class ActionRenderer {
constructor( constructor(
private hass: HomeAssistant, private hass: HomeAssistant,
private entityReg: EntityRegistryEntry[], private entityReg: EntityRegistryEntry[],
private labelReg: LabelRegistryEntry[],
private floorReg: FloorRegistryEntry[],
private entries: TemplateResult[], private entries: TemplateResult[],
private trace: AutomationTraceExtended, private trace: AutomationTraceExtended,
private logbookRenderer: LogbookRenderer, private logbookRenderer: LogbookRenderer,
@@ -310,7 +316,14 @@ class ActionRenderer {
this._renderEntry( this._renderEntry(
path, path,
describeAction(this.hass, this.entityReg, data, actionType), describeAction(
this.hass,
this.entityReg,
this.labelReg,
this.floorReg,
data,
actionType
),
undefined, undefined,
data.enabled === false data.enabled === false
); );
@@ -475,7 +488,13 @@ class ActionRenderer {
const name = const name =
repeatConfig.alias || repeatConfig.alias ||
describeAction(this.hass, this.entityReg, repeatConfig); describeAction(
this.hass,
this.entityReg,
this.labelReg,
this.floorReg,
repeatConfig
);
this._renderEntry(repeatPath, name, undefined, disabled); this._renderEntry(repeatPath, name, undefined, disabled);
@@ -631,15 +650,17 @@ export class HaAutomationTracer extends LitElement {
@property({ type: Boolean }) public allowPick = false; @property({ type: Boolean }) public allowPick = false;
@state() private _entityReg: EntityRegistryEntry[] = []; @state()
@consume({ context: fullEntitiesContext, subscribe: true })
_entityReg!: EntityRegistryEntry[];
public hassSubscribe(): UnsubscribeFunc[] { @state()
return [ @consume({ context: labelsContext, subscribe: true })
subscribeEntityRegistry(this.hass.connection!, (entities) => { _labelReg!: LabelRegistryEntry[];
this._entityReg = entities;
}), @state()
]; @consume({ context: floorsContext, subscribe: true })
} _floorReg!: FloorRegistryEntry[];
protected render() { protected render() {
if (!this.trace) { if (!this.trace) {
@@ -657,6 +678,8 @@ export class HaAutomationTracer extends LitElement {
const actionRenderer = new ActionRenderer( const actionRenderer = new ActionRenderer(
this.hass, this.hass,
this._entityReg, this._entityReg,
this._labelReg,
this._floorReg,
entries, entries,
this.trace, this.trace,
logbookRenderer, logbookRenderer,
@@ -774,6 +797,7 @@ export class HaAutomationTracer extends LitElement {
description: html`${this.hass.localize( description: html`${this.hass.localize(
`ui.panel.config.automation.trace.messages.${message}`, `ui.panel.config.automation.trace.messages.${message}`,
{ {
reason: this.trace.script_execution,
time: renderFinishedAt(), time: renderFinishedAt(),
executiontime: renderRuntime(), executiontime: renderRuntime(),
} }

View File

@@ -1,6 +1,8 @@
import { EntityFilter } from "../common/entity/entity_filter"; import { EntityFilter } from "../common/entity/entity_filter";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
type StrictConnectionMode = "disabled" | "guard_page" | "drop_connection";
interface CloudStatusNotLoggedIn { interface CloudStatusNotLoggedIn {
logged_in: false; logged_in: false;
cloud: "disconnected" | "connecting" | "connected"; cloud: "disconnected" | "connecting" | "connected";
@@ -19,6 +21,7 @@ export interface CloudPreferences {
alexa_enabled: boolean; alexa_enabled: boolean;
remote_enabled: boolean; remote_enabled: boolean;
remote_allow_remote_enable: boolean; remote_allow_remote_enable: boolean;
strict_connection: StrictConnectionMode;
google_secure_devices_pin: string | undefined; google_secure_devices_pin: string | undefined;
cloudhooks: { [webhookId: string]: CloudWebhook }; cloudhooks: { [webhookId: string]: CloudWebhook };
alexa_report_state: boolean; alexa_report_state: boolean;
@@ -141,6 +144,7 @@ export const updateCloudPref = (
google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"]; google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"];
tts_default_voice?: CloudPreferences["tts_default_voice"]; tts_default_voice?: CloudPreferences["tts_default_voice"];
remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"]; remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"];
strict_connection?: CloudPreferences["strict_connection"];
} }
) => ) =>
hass.callWS({ hass.callWS({

View File

@@ -23,6 +23,8 @@ export interface ConfigEntry {
pref_disable_polling: boolean; pref_disable_polling: boolean;
disabled_by: "user" | null; disabled_by: "user" | null;
reason: string | null; reason: string | null;
error_reason_translation_key: string | null;
error_reason_translation_placeholders: Record<string, string> | null;
} }
export type ConfigEntryMutableParams = Partial< export type ConfigEntryMutableParams = Partial<

View File

@@ -2,6 +2,8 @@ import { createContext } from "@lit-labs/context";
import { HassConfig } from "home-assistant-js-websocket"; import { HassConfig } from "home-assistant-js-websocket";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { EntityRegistryEntry } from "./entity_registry"; import { EntityRegistryEntry } from "./entity_registry";
import { FloorRegistryEntry } from "./floor_registry";
import { LabelRegistryEntry } from "./label_registry";
export const connectionContext = export const connectionContext =
createContext<HomeAssistant["connection"]>("connection"); createContext<HomeAssistant["connection"]>("connection");
@@ -25,3 +27,7 @@ export const panelsContext = createContext<HomeAssistant["panels"]>("panels");
export const fullEntitiesContext = export const fullEntitiesContext =
createContext<EntityRegistryEntry[]>("extendedEntities"); createContext<EntityRegistryEntry[]>("extendedEntities");
export const floorsContext = createContext<FloorRegistryEntry[]>("floors");
export const labelsContext = createContext<LabelRegistryEntry[]>("labels");

View File

@@ -9,7 +9,7 @@ import {
startOfDay, startOfDay,
isFirstDayOfMonth, isFirstDayOfMonth,
isLastDayOfMonth, isLastDayOfMonth,
} from "date-fns/esm"; } from "date-fns";
import { Collection, getCollection } from "home-assistant-js-websocket"; import { Collection, getCollection } from "home-assistant-js-websocket";
import { import {
calcDate, calcDate,
@@ -95,6 +95,7 @@ export type EnergySolarForecasts = {
export interface DeviceConsumptionEnergyPreference { export interface DeviceConsumptionEnergyPreference {
// This is an ever increasing value // This is an ever increasing value
stat_consumption: string; stat_consumption: string;
name?: string;
} }
export interface FlowFromGridSourceEnergyPreference { export interface FlowFromGridSourceEnergyPreference {

View File

@@ -422,7 +422,8 @@ export const computeHistory = (
entityIds: string[], entityIds: string[],
localize: LocalizeFunc, localize: LocalizeFunc,
sensorNumericalDeviceClasses: string[], sensorNumericalDeviceClasses: string[],
splitDeviceClasses = false splitDeviceClasses = false,
forceNumeric = false
): HistoryResult => { ): HistoryResult => {
const lineChartDevices: { [unit: string]: HistoryStates } = {}; const lineChartDevices: { [unit: string]: HistoryStates } = {};
const timelineDevices: TimelineEntity[] = []; const timelineDevices: TimelineEntity[] = [];
@@ -468,6 +469,7 @@ export const computeHistory = (
let unit: string | undefined; let unit: string | undefined;
const isNumeric = const isNumeric =
forceNumeric ||
isNumericFromDomain(domain) || isNumericFromDomain(domain) ||
(currentState != null && (currentState != null &&
isNumericFromAttributes(currentState.attributes)) || isNumericFromAttributes(currentState.attributes)) ||

View File

@@ -9,12 +9,14 @@ export interface LabelRegistryEntry {
name: string; name: string;
icon: string | null; icon: string | null;
color: string | null; color: string | null;
description: string | null;
} }
export interface LabelRegistryEntryMutableParams { export interface LabelRegistryEntryMutableParams {
name: string; name: string;
icon?: string | null; icon?: string | null;
color?: string | null; color?: string | null;
description?: string | null;
} }
export const fetchLabelRegistry = (conn: Connection) => export const fetchLabelRegistry = (conn: Connection) =>

View File

@@ -5,9 +5,7 @@ import {
import { getExtendedEntityRegistryEntry } from "./entity_registry"; import { getExtendedEntityRegistryEntry } from "./entity_registry";
import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog"; import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
import { UNAVAILABLE } from "./entity";
export const FORMAT_TEXT = "text";
export const FORMAT_NUMBER = "number";
export const enum LockEntityFeature { export const enum LockEntityFeature {
OPEN = 1, OPEN = 1,
@@ -24,6 +22,33 @@ export interface LockEntity extends HassEntityBase {
type ProtectedLockService = "lock" | "unlock" | "open"; type ProtectedLockService = "lock" | "unlock" | "open";
export function isLocked(stateObj: LockEntity) {
return stateObj.state === "locked";
}
export function isUnlocking(stateObj: LockEntity) {
return stateObj.state === "unlocking";
}
export function isLocking(stateObj: LockEntity) {
return stateObj.state === "locking";
}
export function isJammed(stateObj: LockEntity) {
return stateObj.state === "jammed";
}
export function isAvailable(stateObj: LockEntity) {
if (stateObj.state === UNAVAILABLE) {
return false;
}
const assumedState = stateObj.attributes.assumed_state === true;
return (
assumedState ||
(!isLocking(stateObj) && !isUnlocking(stateObj) && !isJammed(stateObj))
);
}
export const callProtectedLockService = async ( export const callProtectedLockService = async (
element: HTMLElement, element: HTMLElement,
hass: HomeAssistant, hass: HomeAssistant,

View File

@@ -14,7 +14,9 @@ import {
computeEntityRegistryName, computeEntityRegistryName,
entityRegistryById, entityRegistryById,
} from "./entity_registry"; } from "./entity_registry";
import { FloorRegistryEntry } from "./floor_registry";
import { domainToName } from "./integration"; import { domainToName } from "./integration";
import { LabelRegistryEntry } from "./label_registry";
import { import {
ActionType, ActionType,
ActionTypes, ActionTypes,
@@ -40,6 +42,8 @@ const actionTranslationBaseKey =
export const describeAction = <T extends ActionType>( export const describeAction = <T extends ActionType>(
hass: HomeAssistant, hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[], entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[],
floorRegistry: FloorRegistryEntry[],
action: ActionTypes[T], action: ActionTypes[T],
actionType?: T, actionType?: T,
ignoreAlias = false ignoreAlias = false
@@ -48,6 +52,8 @@ export const describeAction = <T extends ActionType>(
return tryDescribeAction( return tryDescribeAction(
hass, hass,
entityRegistry, entityRegistry,
labelRegistry,
floorRegistry,
action, action,
actionType, actionType,
ignoreAlias ignoreAlias
@@ -66,6 +72,8 @@ export const describeAction = <T extends ActionType>(
const tryDescribeAction = <T extends ActionType>( const tryDescribeAction = <T extends ActionType>(
hass: HomeAssistant, hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[], entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[],
floorRegistry: FloorRegistryEntry[],
action: ActionTypes[T], action: ActionTypes[T],
actionType?: T, actionType?: T,
ignoreAlias = false ignoreAlias = false
@@ -82,10 +90,12 @@ const tryDescribeAction = <T extends ActionType>(
const targets: string[] = []; const targets: string[] = [];
if (config.target) { if (config.target) {
for (const [key, label] of Object.entries({ for (const [key, name] of Object.entries({
area_id: "areas", area_id: "areas",
device_id: "devices", device_id: "devices",
entity_id: "entities", entity_id: "entities",
floor_id: "floors",
label_id: "labels",
})) { })) {
if (!(key in config.target)) { if (!(key in config.target)) {
continue; continue;
@@ -99,7 +109,7 @@ const tryDescribeAction = <T extends ActionType>(
targets.push( targets.push(
hass.localize( hass.localize(
`${actionTranslationBaseKey}.service.description.target_template`, `${actionTranslationBaseKey}.service.description.target_template`,
{ name: label } { name }
) )
); );
break; break;
@@ -147,6 +157,32 @@ const tryDescribeAction = <T extends ActionType>(
) )
); );
} }
} else if (key === "floor_id") {
const floor = floorRegistry.find(
(flr) => flr.floor_id === targetThing
);
if (floor?.name) {
targets.push(floor.name);
} else {
targets.push(
hass.localize(
`${actionTranslationBaseKey}.service.description.target_unknown_floor`
)
);
}
} else if (key === "label_id") {
const label = labelRegistry.find(
(lbl) => lbl.label_id === targetThing
);
if (label?.name) {
targets.push(label.name);
} else {
targets.push(
hass.localize(
`${actionTranslationBaseKey}.service.description.target_unknown_label`
)
);
}
} else { } else {
targets.push(targetThing); targets.push(targetThing);
} }

View File

@@ -270,7 +270,11 @@ export interface LanguageSelector {
} }
export interface LocationSelector { export interface LocationSelector {
location: { radius?: boolean; icon?: string } | null; location: {
radius?: boolean;
radius_readonly?: boolean;
icon?: string;
} | null;
} }
export interface LocationSelectorValue { export interface LocationSelectorValue {
@@ -401,6 +405,7 @@ export interface TargetSelector {
target: { target: {
entity?: EntitySelectorFilter | readonly EntitySelectorFilter[]; entity?: EntitySelectorFilter | readonly EntitySelectorFilter[];
device?: DeviceSelectorFilter | readonly DeviceSelectorFilter[]; device?: DeviceSelectorFilter | readonly DeviceSelectorFilter[];
create_domains?: string[];
} | null; } | null;
} }

View File

@@ -11,6 +11,11 @@ export interface Zone {
radius?: number; radius?: number;
} }
export interface HomeZoneMutableParams {
latitude: number;
longitude: number;
}
export interface ZoneMutableParams { export interface ZoneMutableParams {
name: string; name: string;
icon?: string; icon?: string;

View File

@@ -78,6 +78,7 @@ class LightColorTempPicker extends LitElement {
return html` return html`
<ha-control-slider <ha-control-slider
touch-action="none"
inverted inverted
vertical vertical
.value=${this._ctPickerValue} .value=${this._ctPickerValue}

View File

@@ -9,11 +9,12 @@ import "../../../components/ha-control-button";
import "../../../components/ha-control-button-group"; import "../../../components/ha-control-button-group";
import "../../../components/ha-outlined-icon-button"; import "../../../components/ha-outlined-icon-button";
import "../../../components/ha-state-icon"; import "../../../components/ha-state-icon";
import { UNAVAILABLE } from "../../../data/entity";
import { import {
LockEntity, LockEntity,
LockEntityFeature, LockEntityFeature,
callProtectedLockService, callProtectedLockService,
isAvailable,
isJammed,
} from "../../../data/lock"; } from "../../../data/lock";
import "../../../state-control/lock/ha-state-control-lock-toggle"; import "../../../state-control/lock/ha-state-control-lock-toggle";
import type { HomeAssistant } from "../../../types"; import type { HomeAssistant } from "../../../types";
@@ -85,15 +86,13 @@ class MoreInfoLock extends LitElement {
"--state-color": color, "--state-color": color,
}; };
const isJammed = this.stateObj.state === "jammed";
return html` return html`
<ha-more-info-state-header <ha-more-info-state-header
.hass=${this.hass} .hass=${this.hass}
.stateObj=${this.stateObj} .stateObj=${this.stateObj}
></ha-more-info-state-header> ></ha-more-info-state-header>
<div class="controls" style=${styleMap(style)}> <div class="controls" style=${styleMap(style)}>
${this.stateObj.state === "jammed" ${isJammed(this.stateObj)
? html` ? html`
<div class="status"> <div class="status">
<span></span> <span></span>
@@ -125,7 +124,7 @@ class MoreInfoLock extends LitElement {
` `
: html` : html`
<ha-control-button <ha-control-button
.disabled=${this.stateObj.state === UNAVAILABLE} .disabled=${!isAvailable(this.stateObj)}
class="open-button ${this._buttonState}" class="open-button ${this._buttonState}"
@click=${this._open} @click=${this._open}
> >
@@ -139,7 +138,7 @@ class MoreInfoLock extends LitElement {
: nothing} : nothing}
</div> </div>
<div> <div>
${isJammed ${isJammed(this.stateObj)
? html` ? html`
<ha-control-button-group class="jammed"> <ha-control-button-group class="jammed">
<ha-control-button @click=${this._unlock}> <ha-control-button @click=${this._unlock}>

View File

@@ -1,4 +1,4 @@
import { startOfYesterday, subHours } from "date-fns/esm"; import { startOfYesterday, subHours } from "date-fns";
import { LitElement, PropertyValues, css, html, nothing } from "lit"; import { LitElement, PropertyValues, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../common/config/is_component_loaded";

View File

@@ -1,4 +1,4 @@
import { startOfYesterday } from "date-fns/esm"; import { startOfYesterday } from "date-fns";
import { css, html, LitElement, PropertyValues, nothing } from "lit"; import { css, html, LitElement, PropertyValues, nothing } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";

View File

@@ -9,7 +9,19 @@ import { fireEvent } from "../common/dom/fire_event";
import { mainWindow } from "../common/dom/get_main_window"; import { mainWindow } from "../common/dom/get_main_window";
import { showAutomationEditor } from "../data/automation"; import { showAutomationEditor } from "../data/automation";
import { HomeAssistantMain } from "../layouts/home-assistant-main"; import { HomeAssistantMain } from "../layouts/home-assistant-main";
import type { EMIncomingMessageCommands } from "./external_messaging"; import type {
EMIncomingMessageBarCodeScanAborted,
EMIncomingMessageBarCodeScanResult,
EMIncomingMessageCommands,
} from "./external_messaging";
const barCodeListeners = new Set<
(
msg:
| EMIncomingMessageBarCodeScanResult
| EMIncomingMessageBarCodeScanAborted
) => boolean
>();
export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => { export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
window.addEventListener("haptic", (ev) => window.addEventListener("haptic", (ev) =>
@@ -24,6 +36,19 @@ export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
); );
}; };
export const addExternalBarCodeListener = (
listener: (
msg:
| EMIncomingMessageBarCodeScanResult
| EMIncomingMessageBarCodeScanAborted
) => boolean
) => {
barCodeListeners.add(listener);
return () => {
barCodeListeners.delete(listener);
};
};
const handleExternalMessage = ( const handleExternalMessage = (
hassMainEl: HomeAssistantMain, hassMainEl: HomeAssistantMain,
msg: EMIncomingMessageCommands msg: EMIncomingMessageCommands
@@ -88,6 +113,22 @@ const handleExternalMessage = (
success: true, success: true,
result: null, result: null,
}); });
} else if (msg.command === "bar_code/scan_result") {
barCodeListeners.forEach((listener) => listener(msg));
bus.fireMessage({
id: msg.id,
type: "result",
success: true,
result: null,
});
} else if (msg.command === "bar_code/aborted") {
barCodeListeners.forEach((listener) => listener(msg));
bus.fireMessage({
id: msg.id,
type: "result",
success: true,
result: null,
});
} else { } else {
return false; return false;
} }

View File

@@ -37,9 +37,11 @@ interface EMOutgoingMessageConfigGet extends EMMessage {
interface EMOutgoingMessageBarCodeScan extends EMMessage { interface EMOutgoingMessageBarCodeScan extends EMMessage {
type: "bar_code/scan"; type: "bar_code/scan";
title: string; payload: {
description: string; title: string;
alternative_option_label?: string; description: string;
alternative_option_label?: string;
};
} }
interface EMOutgoingMessageBarCodeClose extends EMMessage { interface EMOutgoingMessageBarCodeClose extends EMMessage {
@@ -48,7 +50,9 @@ interface EMOutgoingMessageBarCodeClose extends EMMessage {
interface EMOutgoingMessageBarCodeNotify extends EMMessage { interface EMOutgoingMessageBarCodeNotify extends EMMessage {
type: "bar_code/notify"; type: "bar_code/notify";
message: string; payload: {
message: string;
};
} }
interface EMOutgoingMessageMatterCommission extends EMMessage { interface EMOutgoingMessageMatterCommission extends EMMessage {

View File

@@ -41,14 +41,6 @@ import type { HomeAssistant, Route } from "../types";
import "./hass-tabs-subpage"; import "./hass-tabs-subpage";
import type { PageNavigation } from "./hass-tabs-subpage"; import type { PageNavigation } from "./hass-tabs-subpage";
declare global {
// for fire event
interface HASSDomEvents {
"search-changed": { value: string };
"clear-filter": undefined;
}
}
@customElement("hass-tabs-subpage-data-table") @customElement("hass-tabs-subpage-data-table")
export class HaTabsSubpageDataTable extends LitElement { export class HaTabsSubpageDataTable extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@@ -63,6 +55,8 @@ export class HaTabsSubpageDataTable extends LitElement {
@property({ type: Boolean, attribute: "main-page" }) public mainPage = false; @property({ type: Boolean, attribute: "main-page" }) public mainPage = false;
@property({ attribute: false }) public initialCollapsedGroups: string[] = [];
/** /**
* Object with the columns. * Object with the columns.
* @type {Object} * @type {Object}
@@ -166,8 +160,15 @@ export class HaTabsSubpageDataTable extends LitElement {
@property({ type: Boolean }) public showFilters = false; @property({ type: Boolean }) public showFilters = false;
@property({ attribute: false }) public initialSorting?: {
column: string;
direction: SortingDirection;
};
@property() public initialGroupColumn?: string; @property() public initialGroupColumn?: string;
@property({ attribute: false }) public groupOrder?: string[];
@state() private _sortColumn?: string; @state() private _sortColumn?: string;
@state() private _sortDirection: SortingDirection = null; @state() private _sortDirection: SortingDirection = null;
@@ -190,9 +191,16 @@ export class HaTabsSubpageDataTable extends LitElement {
this._dataTable.clearSelection(); this._dataTable.clearSelection();
} }
protected firstUpdated() { protected willUpdate() {
if (this.hasUpdated) {
return;
}
if (this.initialGroupColumn) { if (this.initialGroupColumn) {
this._groupColumn = this.initialGroupColumn; this._setGroupColumn(this.initialGroupColumn);
}
if (this.initialSorting) {
this._sortColumn = this.initialSorting.column;
this._sortDirection = this.initialSorting.direction;
} }
} }
@@ -418,6 +426,8 @@ export class HaTabsSubpageDataTable extends LitElement {
.sortColumn=${this._sortColumn} .sortColumn=${this._sortColumn}
.sortDirection=${this._sortDirection} .sortDirection=${this._sortDirection}
.groupColumn=${this._groupColumn} .groupColumn=${this._groupColumn}
.groupOrder=${this.groupOrder}
.initialCollapsedGroups=${this.initialCollapsedGroups}
> >
${!this.narrow ${!this.narrow
? html` ? html`
@@ -496,7 +506,6 @@ export class HaTabsSubpageDataTable extends LitElement {
${this.showFilters && !showPane ${this.showFilters && !showPane
? html`<ha-dialog ? html`<ha-dialog
open open
hideActions
.heading=${localize("ui.components.subpage-data-table.filters")} .heading=${localize("ui.components.subpage-data-table.filters")}
> >
<ha-dialog-header slot="heading"> <ha-dialog-header slot="heading">
@@ -523,8 +532,17 @@ export class HaTabsSubpageDataTable extends LitElement {
: nothing} : nothing}
</ha-dialog-header> </ha-dialog-header>
<div class="filter-dialog-content"> <div class="filter-dialog-content">
<slot name="filter-pane"></slot></div <slot name="filter-pane"></slot>
></ha-dialog>` </div>
<div slot="primaryAction">
<ha-button @click=${this._toggleFilters}>
${this.hass.localize(
"ui.components.subpage-data-table.show_results",
{ number: this.data.length }
)}
</ha-button>
</div>
</ha-dialog>`
: nothing} : nothing}
`; `;
} }
@@ -552,10 +570,20 @@ export class HaTabsSubpageDataTable extends LitElement {
this._sortDirection = null; this._sortDirection = null;
} }
this._sortColumn = this._sortDirection === null ? undefined : columnId; this._sortColumn = this._sortDirection === null ? undefined : columnId;
fireEvent(this, "sorting-changed", {
column: columnId,
direction: this._sortDirection,
});
} }
private _handleGroupBy(ev) { private _handleGroupBy(ev) {
this._groupColumn = ev.currentTarget.value; this._setGroupColumn(ev.currentTarget.value);
}
private _setGroupColumn(columnId: string) {
this._groupColumn = columnId;
fireEvent(this, "grouping-changed", { value: columnId });
} }
private _enableSelectMode() { private _enableSelectMode() {
@@ -779,7 +807,6 @@ export class HaTabsSubpageDataTable extends LitElement {
} }
ha-dialog { ha-dialog {
--dialog-z-index: 100;
--mdc-dialog-min-width: calc( --mdc-dialog-min-width: calc(
100vw - env(safe-area-inset-right) - env(safe-area-inset-left) 100vw - env(safe-area-inset-right) - env(safe-area-inset-left)
); );
@@ -794,7 +821,7 @@ export class HaTabsSubpageDataTable extends LitElement {
} }
.filter-dialog-content { .filter-dialog-content {
height: calc(100vh - 1px - var(--header-height)); height: calc(100vh - 1px - 61px - var(--header-height));
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
@@ -812,4 +839,11 @@ declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"hass-tabs-subpage-data-table": HaTabsSubpageDataTable; "hass-tabs-subpage-data-table": HaTabsSubpageDataTable;
} }
// for fire event
interface HASSDomEvents {
"search-changed": { value: string };
"grouping-changed": { value: string };
"clear-filter": undefined;
}
} }

View File

@@ -169,10 +169,6 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
// @ts-ignore // @ts-ignore
this._loadHassTranslations(this.hass!.language, "entity"); this._loadHassTranslations(this.hass!.language, "entity");
// Backwards compatibility for custom integrations
// @ts-ignore
this._loadHassTranslations(this.hass!.language, "state");
document.addEventListener( document.addEventListener(
"visibilitychange", "visibilitychange",
() => this._checkVisibility(), () => this._checkVisibility(),

View File

@@ -41,7 +41,7 @@ import type { HomeAssistant } from "../types";
import { onBoardingStyles } from "./styles"; import { onBoardingStyles } from "./styles";
const AMSTERDAM: [number, number] = [52.3731339, 4.8903147]; const AMSTERDAM: [number, number] = [52.3731339, 4.8903147];
const mql = matchMedia("(prefers-color-scheme: dark)"); const darkMql = matchMedia("(prefers-color-scheme: dark)");
const LOCATION_MARKER_ID = "location"; const LOCATION_MARKER_ID = "location";
@customElement("onboarding-location") @customElement("onboarding-location")
@@ -199,7 +199,7 @@ class OnboardingLocation extends LitElement {
this._highlightedMarker this._highlightedMarker
)} )}
zoom="14" zoom="14"
.darkMode=${mql.matches} .themeMode=${darkMql.matches ? "dark" : "light"}
.disabled=${this._working} .disabled=${this._working}
@location-updated=${this._locationChanged} @location-updated=${this._locationChanged}
@marker-clicked=${this._markerClicked} @marker-clicked=${this._markerClicked}

View File

@@ -1,7 +1,7 @@
import "@material/mwc-button"; import "@material/mwc-button";
import { mdiCalendarClock } from "@mdi/js"; import { mdiCalendarClock } from "@mdi/js";
import { toDate } from "date-fns-tz"; import { toDate } from "date-fns-tz";
import { addDays, isSameDay } from "date-fns/esm"; import { addDays, isSameDay } from "date-fns";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { property, state } from "lit/decorators"; import { property, state } from "lit/decorators";
import { formatDate } from "../../common/datetime/format_date"; import { formatDate } from "../../common/datetime/format_date";

View File

@@ -6,7 +6,7 @@ import {
addMilliseconds, addMilliseconds,
differenceInMilliseconds, differenceInMilliseconds,
startOfHour, startOfHour,
} from "date-fns/esm"; } from "date-fns";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";

View File

@@ -1,14 +1,6 @@
import { mdiDelete, mdiPlus } from "@mdi/js"; import { mdiDelete, mdiPlus } from "@mdi/js";
import { import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
nothing,
} from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import type { HASSDomEvent } from "../../../common/dom/fire_event"; import type { HASSDomEvent } from "../../../common/dom/fire_event";
import { LocalizeFunc } from "../../../common/translations/localize"; import { LocalizeFunc } from "../../../common/translations/localize";
@@ -59,27 +51,24 @@ export class HaConfigApplicationCredentials extends LitElement {
title: localize( title: localize(
"ui.panel.config.application_credentials.picker.headers.name" "ui.panel.config.application_credentials.picker.headers.name"
), ),
sortable: true,
direction: "asc", direction: "asc",
grows: true, grows: true,
template: (entry) => html`${entry.name}`,
}, },
client_id: { client_id: {
title: localize( title: localize(
"ui.panel.config.application_credentials.picker.headers.client_id" "ui.panel.config.application_credentials.picker.headers.client_id"
), ),
width: "30%", width: "30%",
direction: "asc",
hidden: narrow, hidden: narrow,
template: (entry) => html`${entry.client_id}`,
}, },
application: { localizedDomain: {
title: localize( title: localize(
"ui.panel.config.application_credentials.picker.headers.application" "ui.panel.config.application_credentials.picker.headers.application"
), ),
sortable: true, sortable: true,
width: "30%", width: "30%",
direction: "asc", direction: "asc",
template: (entry) => html`${domainToName(localize, entry.domain)}`,
}, },
}; };
@@ -87,6 +76,14 @@ export class HaConfigApplicationCredentials extends LitElement {
} }
); );
private _getApplicationCredentials = memoizeOne(
(applicationCredentials: ApplicationCredential[], localize: LocalizeFunc) =>
applicationCredentials.map((credential) => ({
...credential,
localizedDomain: domainToName(localize, credential.domain),
}))
);
protected firstUpdated(changedProperties: PropertyValues) { protected firstUpdated(changedProperties: PropertyValues) {
super.firstUpdated(changedProperties); super.firstUpdated(changedProperties);
this._loadTranslations(); this._loadTranslations();
@@ -102,56 +99,40 @@ export class HaConfigApplicationCredentials extends LitElement {
backPath="/config" backPath="/config"
.tabs=${configSections.devices} .tabs=${configSections.devices}
.columns=${this._columns(this.narrow, this.hass.localize)} .columns=${this._columns(this.narrow, this.hass.localize)}
.data=${this._applicationCredentials} .data=${this._getApplicationCredentials(
this._applicationCredentials,
this.hass.localize
)}
hasFab hasFab
selectable selectable
.selected=${this._selected.length}
@selection-changed=${this._handleSelectionChanged} @selection-changed=${this._handleSelectionChanged}
> >
${this._selected.length <div class="header-btns" slot="selection-bar">
? html` ${!this.narrow
<div ? html`
class=${classMap({ <mwc-button @click=${this._removeSelected} class="warning"
"header-toolbar": this.narrow, >${this.hass.localize(
"table-header": !this.narrow, "ui.panel.config.application_credentials.picker.remove_selected.button"
})} )}</mwc-button
slot="header" >
> `
<p class="selected-txt"> : html`
${this.hass.localize( <ha-icon-button
"ui.panel.config.application_credentials.picker.selected", class="warning"
{ number: this._selected.length } id="remove-btn"
@click=${this._removeSelected}
.path=${mdiDelete}
.label=${this.hass.localize("ui.common.remove")}
></ha-icon-button>
<ha-help-tooltip
.label=${this.hass.localize(
"ui.panel.config.application_credentials.picker.remove_selected.button"
)} )}
</p> >
<div class="header-btns"> </ha-help-tooltip>
${!this.narrow `}
? html` </div>
<mwc-button
@click=${this._removeSelected}
class="warning"
>${this.hass.localize(
"ui.panel.config.application_credentials.picker.remove_selected.button"
)}</mwc-button
>
`
: html`
<ha-icon-button
class="warning"
id="remove-btn"
@click=${this._removeSelected}
.path=${mdiDelete}
.label=${this.hass.localize("ui.common.remove")}
></ha-icon-button>
<ha-help-tooltip
.label=${this.hass.localize(
"ui.panel.config.application_credentials.picker.remove_selected.button"
)}
>
</ha-help-tooltip>
`}
</div>
</div>
`
: nothing}
<ha-fab <ha-fab
slot="fab" slot="fab"
.label=${this.hass.localize( .label=${this.hass.localize(

View File

@@ -511,6 +511,7 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
overflow-wrap: anywhere;
} }
.warning { .warning {
color: var(--error-color); color: var(--error-color);

View File

@@ -42,8 +42,14 @@ import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
import { ACTION_ICONS, YAML_ONLY_ACTION_TYPES } from "../../../../data/action"; import { ACTION_ICONS, YAML_ONLY_ACTION_TYPES } from "../../../../data/action";
import { AutomationClipboard } from "../../../../data/automation"; import { AutomationClipboard } from "../../../../data/automation";
import { validateConfig } from "../../../../data/config"; import { validateConfig } from "../../../../data/config";
import { fullEntitiesContext } from "../../../../data/context"; import {
floorsContext,
fullEntitiesContext,
labelsContext,
} from "../../../../data/context";
import { EntityRegistryEntry } from "../../../../data/entity_registry"; import { EntityRegistryEntry } from "../../../../data/entity_registry";
import { FloorRegistryEntry } from "../../../../data/floor_registry";
import { LabelRegistryEntry } from "../../../../data/label_registry";
import { import {
Action, Action,
NonConditionAction, NonConditionAction,
@@ -146,6 +152,14 @@ export default class HaAutomationActionRow extends LitElement {
@consume({ context: fullEntitiesContext, subscribe: true }) @consume({ context: fullEntitiesContext, subscribe: true })
_entityReg!: EntityRegistryEntry[]; _entityReg!: EntityRegistryEntry[];
@state()
@consume({ context: labelsContext, subscribe: true })
_labelReg!: LabelRegistryEntry[];
@state()
@consume({ context: floorsContext, subscribe: true })
_floorReg!: FloorRegistryEntry[];
@state() private _warnings?: string[]; @state() private _warnings?: string[];
@state() private _uiModeAvailable = true; @state() private _uiModeAvailable = true;
@@ -210,7 +224,13 @@ export default class HaAutomationActionRow extends LitElement {
.path=${ACTION_ICONS[type!]} .path=${ACTION_ICONS[type!]}
></ha-svg-icon>`} ></ha-svg-icon>`}
${capitalizeFirstLetter( ${capitalizeFirstLetter(
describeAction(this.hass, this._entityReg, this.action) describeAction(
this.hass,
this._entityReg,
this._labelReg,
this._floorReg,
this.action
)
)} )}
</h3> </h3>
@@ -573,7 +593,15 @@ export default class HaAutomationActionRow extends LitElement {
), ),
inputType: "string", inputType: "string",
placeholder: capitalizeFirstLetter( placeholder: capitalizeFirstLetter(
describeAction(this.hass, this._entityReg, this.action, undefined, true) describeAction(
this.hass,
this._entityReg,
this._labelReg,
this._floorReg,
this.action,
undefined,
true
)
), ),
defaultValue: this.action.alias, defaultValue: this.action.alias,
confirmText: this.hass.localize("ui.common.submit"), confirmText: this.hass.localize("ui.common.submit"),

View File

@@ -15,11 +15,12 @@ import {
mdiPlus, mdiPlus,
mdiRobotHappy, mdiRobotHappy,
mdiTag, mdiTag,
mdiTextureBox,
mdiToggleSwitch, mdiToggleSwitch,
mdiToggleSwitchOffOutline, mdiToggleSwitchOffOutline,
mdiTransitConnection, mdiTransitConnection,
} from "@mdi/js"; } from "@mdi/js";
import { differenceInDays } from "date-fns/esm"; import { differenceInDays } from "date-fns";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { import {
CSSResultGroup, CSSResultGroup,
@@ -37,15 +38,21 @@ import { computeCssColor } from "../../../common/color/compute-color";
import { isComponentLoaded } from "../../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { formatShortDateTime } from "../../../common/datetime/format_date_time"; import { formatShortDateTime } from "../../../common/datetime/format_date_time";
import { relativeTime } from "../../../common/datetime/relative_time"; import { relativeTime } from "../../../common/datetime/relative_time";
import { storage } from "../../../common/decorators/storage";
import { HASSDomEvent, fireEvent } from "../../../common/dom/fire_event"; import { HASSDomEvent, fireEvent } from "../../../common/dom/fire_event";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import { navigate } from "../../../common/navigate"; import { navigate } from "../../../common/navigate";
import { LocalizeFunc } from "../../../common/translations/localize"; import { LocalizeFunc } from "../../../common/translations/localize";
import {
hasRejectedItems,
rejectedItems,
} from "../../../common/util/promise-all-settled-results";
import "../../../components/chips/ha-assist-chip"; import "../../../components/chips/ha-assist-chip";
import type { import type {
DataTableColumnContainer, DataTableColumnContainer,
RowClickedEvent, RowClickedEvent,
SelectionChangedEvent, SelectionChangedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/data-table/ha-data-table-labels"; import "../../../components/data-table/ha-data-table-labels";
import "../../../components/entity/ha-entity-toggle"; import "../../../components/entity/ha-entity-toggle";
@@ -63,6 +70,7 @@ import type { HaMenu } from "../../../components/ha-menu";
import "../../../components/ha-menu-item"; import "../../../components/ha-menu-item";
import "../../../components/ha-sub-menu"; import "../../../components/ha-sub-menu";
import "../../../components/ha-svg-icon"; import "../../../components/ha-svg-icon";
import { createAreaRegistryEntry } from "../../../data/area_registry";
import { import {
AutomationEntity, AutomationEntity,
deleteAutomation, deleteAutomation,
@@ -100,6 +108,7 @@ import { haStyle } from "../../../resources/styles";
import { HomeAssistant, Route, ServiceCallResponse } from "../../../types"; import { HomeAssistant, Route, ServiceCallResponse } from "../../../types";
import { documentationUrl } from "../../../util/documentation-url"; import { documentationUrl } from "../../../util/documentation-url";
import { turnOnOffEntity } from "../../lovelace/common/entity/turn-on-off-entity"; import { turnOnOffEntity } from "../../lovelace/common/entity/turn-on-off-entity";
import { showAreaRegistryDetailDialog } from "../areas/show-dialog-area-registry-detail";
import { showAssignCategoryDialog } from "../category/show-dialog-assign-category"; import { showAssignCategoryDialog } from "../category/show-dialog-assign-category";
import { showCategoryRegistryDetailDialog } from "../category/show-dialog-category-registry-detail"; import { showCategoryRegistryDetailDialog } from "../category/show-dialog-category-registry-detail";
import { configSections } from "../ha-panel-config"; import { configSections } from "../ha-panel-config";
@@ -152,6 +161,19 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
@state() private _overflowAutomation?: AutomationItem; @state() private _overflowAutomation?: AutomationItem;
@storage({ key: "automation-table-sort", state: false, subscribe: false })
private _activeSorting?: SortingChangedEvent;
@storage({ key: "automation-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;
@storage({
key: "automation-table-collapsed",
state: false,
subscribe: false,
})
private _activeCollapsed?: string;
@query("#overflow-menu") private _overflowMenu!: HaMenu; @query("#overflow-menu") private _overflowMenu!: HaMenu;
private _sizeController = new ResizeController(this, { private _sizeController = new ResizeController(this, {
@@ -196,6 +218,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
labels: (labels || []).map( labels: (labels || []).map(
(lbl) => labelReg!.find((label) => label.label_id === lbl)! (lbl) => labelReg!.find((label) => label.label_id === lbl)!
), ),
selectable: entityRegEntry !== undefined,
}; };
}); });
} }
@@ -383,6 +406,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
${this.hass.localize("ui.panel.config.category.editor.add")} ${this.hass.localize("ui.panel.config.category.editor.add")}
</div> </div>
</ha-menu-item>`; </ha-menu-item>`;
const labelItems = html`${this._labels?.map((label) => { const labelItems = html`${this._labels?.map((label) => {
const color = label.color ? computeCssColor(label.color) : undefined; const color = label.color ? computeCssColor(label.color) : undefined;
const selected = this._selected.every((entityId) => const selected = this._selected.every((entityId) =>
@@ -419,9 +443,54 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
${this.hass.localize("ui.panel.config.labels.add_label")} ${this.hass.localize("ui.panel.config.labels.add_label")}
</div></ha-menu-item </div></ha-menu-item
>`; >`;
const labelsInOverflow =
(this._sizeController.value && this._sizeController.value < 700) || const areaItems = html`${Object.values(this.hass.areas).map(
(area) =>
html`<ha-menu-item
.value=${area.area_id}
@click=${this._handleBulkArea}
>
${area.icon
? html`<ha-icon slot="start" .icon=${area.icon}></ha-icon>`
: html`<ha-svg-icon
slot="start"
.path=${mdiTextureBox}
></ha-svg-icon>`}
<div slot="headline">${area.name}</div>
</ha-menu-item>`
)}
<ha-menu-item .value=${null} @click=${this._handleBulkArea}>
<div slot="headline">
${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.no_area"
)}
</div>
</ha-menu-item>
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._bulkCreateArea}>
<div slot="headline">
${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.add_area"
)}
</div>
</ha-menu-item>`;
const areasInOverflow =
(this._sizeController.value && this._sizeController.value < 900) ||
(!this._sizeController.value && this.hass.dockedSidebar === "docked"); (!this._sizeController.value && this.hass.dockedSidebar === "docked");
const labelsInOverflow =
areasInOverflow &&
(!this._sizeController.value || this._sizeController.value < 700);
const automations = this._automations(
this.automations,
this._entityReg,
this.hass.areas,
this._categories,
this._labels,
this._filteredAutomations
);
return html` return html`
<hass-tabs-subpage-data-table <hass-tabs-subpage-data-table
.hass=${this.hass} .hass=${this.hass}
@@ -432,28 +501,36 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
id="entity_id" id="entity_id"
.route=${this.route} .route=${this.route}
.tabs=${configSections.automations} .tabs=${configSections.automations}
.searchLabel=${this.hass.localize(
"ui.panel.config.automation.picker.search",
{ number: automations.length }
)}
selectable selectable
.selected=${this._selected.length} .selected=${this._selected.length}
@selection-changed=${this._handleSelectionChanged} @selection-changed=${this._handleSelectionChanged}
hasFilters hasFilters
.filters=${ .filters=${
Object.values(this._filters).filter((filter) => filter.value?.length) Object.values(this._filters).filter((filter) =>
.length Array.isArray(filter.value)
? filter.value.length
: filter.value &&
Object.values(filter.value).some((val) =>
Array.isArray(val) ? val.length : val
)
).length
} }
.columns=${this._columns( .columns=${this._columns(
this.narrow, this.narrow,
this.hass.localize, this.hass.localize,
this.hass.locale this.hass.locale
)} )}
initialGroupColumn="category" .initialGroupColumn=${this._activeGrouping || "category"}
.data=${this._automations( .initialCollapsedGroups=${this._activeCollapsed}
this.automations, .initialSorting=${this._activeSorting}
this._entityReg, @sorting-changed=${this._handleSortingChanged}
this.hass.areas, @grouping-changed=${this._handleGroupingChanged}
this._categories, @collapsed-changed=${this._handleCollapseChanged}
this._labels, .data=${automations}
this._filteredAutomations
)}
.empty=${!this.automations.length} .empty=${!this.automations.length}
@row-click=${this._handleRowClicked} @row-click=${this._handleRowClicked}
.noDataText=${this.hass.localize( .noDataText=${this.hass.localize(
@@ -560,6 +637,22 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
></ha-svg-icon> ></ha-svg-icon>
</ha-assist-chip> </ha-assist-chip>
${labelItems} ${labelItems}
</ha-button-menu-new>`}
${areasInOverflow
? nothing
: html`<ha-button-menu-new slot="selection-bar">
<ha-assist-chip
slot="trigger"
.label=${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.move_area"
)}
>
<ha-svg-icon
slot="trailing-icon"
.path=${mdiMenuDown}
></ha-svg-icon>
</ha-assist-chip>
${areaItems}
</ha-button-menu-new>`}` </ha-button-menu-new>`}`
: nothing : nothing
} }
@@ -624,6 +717,24 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
</ha-sub-menu>` </ha-sub-menu>`
: nothing : nothing
} }
${
this.narrow || areasInOverflow
? html`<ha-sub-menu>
<ha-menu-item slot="item">
<div slot="headline">
${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.move_area"
)}
</div>
<ha-svg-icon
slot="end"
.path=${mdiChevronRight}
></ha-svg-icon>
</ha-menu-item>
<ha-menu slot="menu">${areaItems}</ha-menu>
</ha-sub-menu>`
: nothing
}
<ha-menu-item @click=${this._handleBulkEnable}> <ha-menu-item @click=${this._handleBulkEnable}>
<ha-svg-icon slot="start" .path=${mdiToggleSwitch}></ha-svg-icon> <ha-svg-icon slot="start" .path=${mdiToggleSwitch}></ha-svg-icon>
<div slot="headline"> <div slot="headline">
@@ -1101,7 +1212,20 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private async _handleBulkLabel(ev) { private async _handleBulkLabel(ev) {
@@ -1124,7 +1248,60 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
}
private async _handleBulkArea(ev) {
const area = ev.currentTarget.value;
this._bulkAddArea(area);
}
private async _bulkAddArea(area: string) {
const promises: Promise<UpdateEntityRegistryEntryResult>[] = [];
this._selected.forEach((entityId) => {
promises.push(
updateEntityRegistryEntry(this.hass, entityId, {
area_id: area,
})
);
});
const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
}
private async _bulkCreateArea() {
showAreaRegistryDetailDialog(this, {
createEntry: async (values) => {
const area = await createAreaRegistryEntry(this.hass, values);
this._bulkAddArea(area.area_id);
return area;
},
});
} }
private async _handleBulkEnable() { private async _handleBulkEnable() {
@@ -1132,7 +1309,20 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
this._selected.forEach((entityId) => { this._selected.forEach((entityId) => {
promises.push(turnOnOffEntity(this.hass, entityId, true)); promises.push(turnOnOffEntity(this.hass, entityId, true));
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private async _handleBulkDisable() { private async _handleBulkDisable() {
@@ -1140,7 +1330,20 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
this._selected.forEach((entityId) => { this._selected.forEach((entityId) => {
promises.push(turnOnOffEntity(this.hass, entityId, false)); promises.push(turnOnOffEntity(this.hass, entityId, false));
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private async _bulkCreateCategory() { private async _bulkCreateCategory() {
@@ -1168,12 +1371,25 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
}); });
} }
private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,
css` css`
:host { :host {
display: block; display: block;
height: 100%;
} }
hass-tabs-subpage-data-table { hass-tabs-subpage-data-table {
--data-table-row-height: 60px; --data-table-row-height: 60px;

View File

@@ -6,6 +6,7 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/device/ha-device-picker"; import "../../../../../components/device/ha-device-picker";
import "../../../../../components/device/ha-device-trigger-picker"; import "../../../../../components/device/ha-device-trigger-picker";
import "../../../../../components/ha-form/ha-form"; import "../../../../../components/ha-form/ha-form";
import { computeInitialHaFormData } from "../../../../../components/ha-form/compute-initial-ha-form-data";
import { fullEntitiesContext } from "../../../../../data/context"; import { fullEntitiesContext } from "../../../../../data/context";
import { import {
deviceAutomationsEqual, deviceAutomationsEqual,
@@ -44,7 +45,9 @@ export class HaDeviceTrigger extends LitElement {
private _extraFieldsData = memoizeOne( private _extraFieldsData = memoizeOne(
(trigger: DeviceTrigger, capabilities: DeviceCapabilities) => { (trigger: DeviceTrigger, capabilities: DeviceCapabilities) => {
const extraFieldsData: Record<string, any> = {}; const extraFieldsData = computeInitialHaFormData(
capabilities.extra_fields
);
capabilities.extra_fields.forEach((item) => { capabilities.extra_fields.forEach((item) => {
if (trigger[item.name] !== undefined) { if (trigger[item.name] !== undefined) {
extraFieldsData![item.name] = trigger[item.name]; extraFieldsData![item.name] = trigger[item.name];

View File

@@ -24,6 +24,7 @@ import { extractSearchParam } from "../../../common/url/search-params";
import { import {
DataTableColumnContainer, DataTableColumnContainer,
RowClickedEvent, RowClickedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/entity/ha-entity-toggle"; import "../../../components/entity/ha-entity-toggle";
import "../../../components/ha-button"; import "../../../components/ha-button";
@@ -54,6 +55,7 @@ import { documentationUrl } from "../../../util/documentation-url";
import { showToast } from "../../../util/toast"; import { showToast } from "../../../util/toast";
import { configSections } from "../ha-panel-config"; import { configSections } from "../ha-panel-config";
import { showAddBlueprintDialog } from "./show-dialog-import-blueprint"; import { showAddBlueprintDialog } from "./show-dialog-import-blueprint";
import { storage } from "../../../common/decorators/storage";
type BlueprintMetaDataPath = BlueprintMetaData & { type BlueprintMetaDataPath = BlueprintMetaData & {
path: string; path: string;
@@ -92,8 +94,24 @@ class HaBlueprintOverview extends LitElement {
Blueprints Blueprints
>; >;
@storage({ key: "blueprint-table-sort", state: false, subscribe: false })
private _activeSorting?: SortingChangedEvent;
@storage({ key: "blueprint-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;
@storage({
key: "blueprint-table-collapsed",
state: false,
subscribe: false,
})
private _activeCollapsed?: string;
private _processedBlueprints = memoizeOne( private _processedBlueprints = memoizeOne(
(blueprints: Record<string, Blueprints>): BlueprintMetaDataPath[] => { (
blueprints: Record<string, Blueprints>,
localize: LocalizeFunc
): BlueprintMetaDataPath[] => {
const result: any[] = []; const result: any[] = [];
Object.entries(blueprints).forEach(([type, typeBlueprints]) => Object.entries(blueprints).forEach(([type, typeBlueprints]) =>
Object.entries(typeBlueprints).forEach(([path, blueprint]) => { Object.entries(typeBlueprints).forEach(([path, blueprint]) => {
@@ -101,6 +119,9 @@ class HaBlueprintOverview extends LitElement {
result.push({ result.push({
name: blueprint.error, name: blueprint.error,
type, type,
translated_type: localize(
`ui.panel.config.blueprint.overview.types.${type as "automation" | "script"}`
),
error: true, error: true,
path, path,
fullpath: `${type}/${path}`, fullpath: `${type}/${path}`,
@@ -109,6 +130,9 @@ class HaBlueprintOverview extends LitElement {
result.push({ result.push({
...blueprint.metadata, ...blueprint.metadata,
type, type,
translated_type: localize(
`ui.panel.config.blueprint.overview.types.${type as "automation" | "script"}`
),
error: false, error: false,
path, path,
fullpath: `${type}/${path}`, fullpath: `${type}/${path}`,
@@ -140,14 +164,11 @@ class HaBlueprintOverview extends LitElement {
` `
: undefined, : undefined,
}, },
type: { translated_type: {
title: localize("ui.panel.config.blueprint.overview.headers.type"), title: localize("ui.panel.config.blueprint.overview.headers.type"),
template: (blueprint) =>
html`${this.hass.localize(
`ui.panel.config.blueprint.overview.types.${blueprint.type}`
)}`,
sortable: true, sortable: true,
filterable: true, filterable: true,
groupable: true,
hidden: narrow, hidden: narrow,
direction: "asc", direction: "asc",
width: "10%", width: "10%",
@@ -256,7 +277,7 @@ class HaBlueprintOverview extends LitElement {
this.hass.language, this.hass.language,
this.hass.localize this.hass.localize
)} )}
.data=${this._processedBlueprints(this.blueprints)} .data=${this._processedBlueprints(this.blueprints, this.hass.localize)}
id="fullpath" id="fullpath"
.noDataText=${this.hass.localize( .noDataText=${this.hass.localize(
"ui.panel.config.blueprint.overview.no_blueprints" "ui.panel.config.blueprint.overview.no_blueprints"
@@ -281,6 +302,12 @@ class HaBlueprintOverview extends LitElement {
> >
</a> </a>
</div>`} </div>`}
.initialGroupColumn=${this._activeGrouping}
.initialCollapsedGroups=${this._activeCollapsed}
.initialSorting=${this._activeSorting}
@sorting-changed=${this._handleSortingChanged}
@grouping-changed=${this._handleGroupingChanged}
@collapsed-changed=${this._handleCollapseChanged}
> >
<ha-icon-button <ha-icon-button
slot="toolbar-icon" slot="toolbar-icon"
@@ -341,9 +368,10 @@ class HaBlueprintOverview extends LitElement {
} }
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) { private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const blueprint = this._processedBlueprints(this.blueprints).find( const blueprint = this._processedBlueprints(
(b) => b.fullpath === ev.detail.id this.blueprints,
)!; this.hass.localize
).find((b) => b.fullpath === ev.detail.id)!;
if (blueprint.error) { if (blueprint.error) {
showAlertDialog(this, { showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.blueprint.overview.error", { title: this.hass.localize("ui.panel.config.blueprint.overview.error", {
@@ -502,6 +530,18 @@ class HaBlueprintOverview extends LitElement {
fireEvent(this, "reload-blueprints"); fireEvent(this, "reload-blueprints");
}; };
private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return haStyle; return haStyle;
} }

View File

@@ -21,6 +21,7 @@ import {
import type { HomeAssistant } from "../../../../types"; import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast"; import { showToast } from "../../../../util/toast";
import { showCloudCertificateDialog } from "../dialog-cloud-certificate/show-dialog-cloud-certificate"; import { showCloudCertificateDialog } from "../dialog-cloud-certificate/show-dialog-cloud-certificate";
import { showAlertDialog } from "../../../lovelace/custom-card-helpers";
@customElement("cloud-remote-pref") @customElement("cloud-remote-pref")
export class CloudRemotePref extends LitElement { export class CloudRemotePref extends LitElement {
@@ -33,7 +34,7 @@ export class CloudRemotePref extends LitElement {
return nothing; return nothing;
} }
const { remote_enabled, remote_allow_remote_enable } = const { remote_enabled, remote_allow_remote_enable, strict_connection } =
this.cloudStatus.prefs; this.cloudStatus.prefs;
const { const {
@@ -153,6 +154,61 @@ export class CloudRemotePref extends LitElement {
@change=${this._toggleAllowRemoteEnabledChanged} @change=${this._toggleAllowRemoteEnabledChanged}
></ha-switch> ></ha-switch>
</ha-settings-row> </ha-settings-row>
<ha-settings-row>
<span slot="heading"
>${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection"
)}</span
>
<span slot="description"
>${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_secondary"
)}</span
>
<ha-select
.label=${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_mode"
)}
@selected=${this._setStrictConnectionMode}
naturalMenuWidth
.value=${strict_connection}
>
<ha-list-item value="disabled">
${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_modes.disabled"
)}
</ha-list-item>
<ha-list-item value="guard_page">
${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_modes.guard_page"
)}
</ha-list-item>
<ha-list-item value="drop_connection">
${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_modes.drop_connection"
)}
</ha-list-item>
</ha-select>
</ha-settings-row>
${strict_connection !== "disabled"
? html` <ha-settings-row>
<span slot="heading"
>${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_link"
)}</span
>
<span slot="description"
>${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_link_secondary"
)}</span
>
<ha-button @click=${this._createLoginUrl}
>${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_create_link"
)}</ha-button
>
</ha-settings-row>`
: nothing}
<ha-settings-row> <ha-settings-row>
<span slot="heading" <span slot="heading"
>${this.hass.localize( >${this.hass.localize(
@@ -223,6 +279,18 @@ export class CloudRemotePref extends LitElement {
} }
} }
private async _setStrictConnectionMode(ev) {
const mode = ev.target.value;
try {
await updateCloudPref(this.hass, {
strict_connection: mode,
});
fireEvent(this, "ha-refresh-cloud-status");
} catch (err: any) {
alert(err.message);
}
}
private async _copyURL(ev): Promise<void> { private async _copyURL(ev): Promise<void> {
const url = ev.currentTarget.url; const url = ev.currentTarget.url;
await copyToClipboard(url); await copyToClipboard(url);
@@ -231,6 +299,40 @@ export class CloudRemotePref extends LitElement {
}); });
} }
private async _createLoginUrl() {
try {
const result = await this.hass.callService(
"cloud",
"create_temporary_strict_connection_url",
undefined,
undefined,
false,
true
);
showAlertDialog(this, {
title: this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_link"
),
text: html`${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_link_created_message"
)}
<pre>${result.response.url}</pre>
<ha-button
.url=${result.response.url}
@click=${this._copyURL}
unelevated
>
<ha-svg-icon slot="icon" .path=${mdiContentCopy}></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.cloud.account.remote.strict_connection_copy_link"
)}
</ha-button>`,
});
} catch (err: any) {
showAlertDialog(this, { text: err.message });
}
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return css` return css`
.preparing { .preparing {

View File

@@ -1,7 +1,6 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { css, html, LitElement, TemplateResult } from "lit"; import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { UNIT_C } from "../../../common/const"; import { UNIT_C } from "../../../common/const";
import { stopPropagation } from "../../../common/dom/stop_propagation"; import { stopPropagation } from "../../../common/dom/stop_propagation";
import { navigate } from "../../../common/navigate"; import { navigate } from "../../../common/navigate";
@@ -22,8 +21,6 @@ import "../../../components/ha-settings-row";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import type { HaTextField } from "../../../components/ha-textfield"; import type { HaTextField } from "../../../components/ha-textfield";
import "../../../components/ha-timezone-picker"; import "../../../components/ha-timezone-picker";
import "../../../components/map/ha-locations-editor";
import type { MarkerLocation } from "../../../components/map/ha-locations-editor";
import { ConfigUpdateValues, saveCoreConfig } from "../../../data/core"; import { ConfigUpdateValues, saveCoreConfig } from "../../../data/core";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
import "../../../layouts/hass-subpage"; import "../../../layouts/hass-subpage";
@@ -242,35 +239,22 @@ class HaConfigSectionGeneral extends LitElement {
> >
</ha-language-picker> </ha-language-picker>
</div> </div>
${this.narrow
? html` <ha-settings-row>
<ha-locations-editor <div slot="heading">
.hass=${this.hass} ${this.hass.localize(
.locations=${this._markerLocation( "ui.panel.config.core.section.core.core_config.edit_location"
this.hass.config.latitude, )}
this.hass.config.longitude, </div>
this._location <div slot="description" class="secondary">
)} ${this.hass.localize(
@location-updated=${this._locationChanged} "ui.panel.config.core.section.core.core_config.edit_location_description"
></ha-locations-editor> )}
` </div>
: html` <mwc-button @click=${this._editLocation}
<ha-settings-row> >${this.hass.localize("ui.common.edit")}</mwc-button
<div slot="heading"> >
${this.hass.localize( </ha-settings-row>
"ui.panel.config.core.section.core.core_config.edit_location"
)}
</div>
<div slot="description" class="secondary">
${this.hass.localize(
"ui.panel.config.core.section.core.core_config.edit_location_description"
)}
</div>
<mwc-button @click=${this._editLocation}
>${this.hass.localize("ui.common.edit")}</mwc-button
>
</ha-settings-row>
`}
<div class="card-actions"> <div class="card-actions">
<ha-progress-button @click=${this._updateEntry}> <ha-progress-button @click=${this._updateEntry}>
${this.hass!.localize("ui.panel.config.zone.detail.update")} ${this.hass!.localize("ui.panel.config.zone.detail.update")}
@@ -319,10 +303,6 @@ class HaConfigSectionGeneral extends LitElement {
this._updateUnits = (ev.target as HaCheckbox).checked; this._updateUnits = (ev.target as HaCheckbox).checked;
} }
private _locationChanged(ev: CustomEvent) {
this._location = ev.detail.location;
}
private async _updateEntry(ev: CustomEvent) { private async _updateEntry(ev: CustomEvent) {
const button = ev.target as HaProgressButton; const button = ev.target as HaProgressButton;
if (button.progress) { if (button.progress) {
@@ -381,21 +361,6 @@ class HaConfigSectionGeneral extends LitElement {
} }
} }
private _markerLocation = memoizeOne(
(
lat: number,
lng: number,
location?: [number, number]
): MarkerLocation[] => [
{
id: "location",
latitude: location ? location[0] : lat,
longitude: location ? location[1] : lng,
location_editable: true,
},
]
);
private _editLocation() { private _editLocation() {
navigate("/config/zone/edit/zone.home"); navigate("/config/zone/edit/zone.home");
} }
@@ -441,11 +406,6 @@ class HaConfigSectionGeneral extends LitElement {
margin-top: 8px; margin-top: 8px;
display: inline-block; display: inline-block;
} }
ha-locations-editor {
display: block;
height: 400px;
padding: 16px;
}
`, `,
]; ];
} }

View File

@@ -82,11 +82,11 @@ class HaConfigSectionUpdates extends LitElement {
> >
${this.hass.localize("ui.panel.config.updates.show_skipped")} ${this.hass.localize("ui.panel.config.updates.show_skipped")}
</ha-check-list-item> </ha-check-list-item>
${this._supervisorInfo?.channel !== "dev" ${this._supervisorInfo && this._supervisorInfo.channel !== "dev"
? html` ? html`
<li divider role="separator"></li> <li divider role="separator"></li>
<mwc-list-item @request-selected=${this._toggleBeta}> <mwc-list-item @request-selected=${this._toggleBeta}>
${this._supervisorInfo?.channel === "stable" ${this._supervisorInfo.channel === "stable"
? this.hass.localize("ui.panel.config.updates.join_beta") ? this.hass.localize("ui.panel.config.updates.join_beta")
: this.hass.localize( : this.hass.localize(
"ui.panel.config.updates.leave_beta" "ui.panel.config.updates.leave_beta"

View File

@@ -93,10 +93,19 @@ const randomTip = (hass: HomeAssistant, narrow: boolean) => {
weight: 2, weight: 2,
narrow: true, narrow: true,
}, },
{ content: hass.localize("ui.tips.key_c_hint"), weight: 1, narrow: false },
{ content: hass.localize("ui.tips.key_m_hint"), weight: 1, narrow: false },
]; ];
if (hass?.enableShortcuts) {
tips.push(
{
content: hass.localize("ui.tips.key_c_hint"),
weight: 1,
narrow: false,
},
{ content: hass.localize("ui.tips.key_m_hint"), weight: 1, narrow: false }
);
}
if (narrow) { if (narrow) {
tips = tips.filter((tip) => tip.narrow); tips = tips.filter((tip) => tip.narrow);
} }
@@ -310,7 +319,9 @@ class HaConfigDashboard extends SubscribeMixin(LitElement) {
private _showQuickBar(): void { private _showQuickBar(): void {
showQuickBar(this, { showQuickBar(this, {
commandMode: true, commandMode: true,
hint: this.hass.localize("ui.dialogs.quick-bar.key_c_hint"), hint: this.hass.enableShortcuts
? this.hass.localize("ui.dialogs.quick-bar.key_c_hint")
: undefined,
}); });
} }

View File

@@ -1,6 +1,12 @@
import { consume } from "@lit-labs/context"; import { consume } from "@lit-labs/context";
import "@lrnwebcomponents/simple-tooltip/simple-tooltip"; import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
import { mdiChevronRight, mdiMenuDown, mdiPlus } from "@mdi/js"; import {
mdiChevronRight,
mdiDotsVertical,
mdiMenuDown,
mdiPlus,
mdiTextureBox,
} from "@mdi/js";
import { import {
CSSResultGroup, CSSResultGroup,
LitElement, LitElement,
@@ -10,10 +16,12 @@ import {
nothing, nothing,
} from "lit"; } from "lit";
import { ResizeController } from "@lit-labs/observers/resize-controller";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { computeCssColor } from "../../../common/color/compute-color"; import { computeCssColor } from "../../../common/color/compute-color";
import { storage } from "../../../common/decorators/storage";
import { HASSDomEvent } from "../../../common/dom/fire_event"; import { HASSDomEvent } from "../../../common/dom/fire_event";
import { computeStateDomain } from "../../../common/entity/compute_state_domain"; import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { import {
@@ -22,10 +30,15 @@ import {
} from "../../../common/integrations/protocolIntegrationPicked"; } from "../../../common/integrations/protocolIntegrationPicked";
import { navigate } from "../../../common/navigate"; import { navigate } from "../../../common/navigate";
import { LocalizeFunc } from "../../../common/translations/localize"; import { LocalizeFunc } from "../../../common/translations/localize";
import {
hasRejectedItems,
rejectedItems,
} from "../../../common/util/promise-all-settled-results";
import { import {
DataTableColumnContainer, DataTableColumnContainer,
RowClickedEvent, RowClickedEvent,
SelectionChangedEvent, SelectionChangedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/data-table/ha-data-table-labels"; import "../../../components/data-table/ha-data-table-labels";
import "../../../components/entity/ha-battery-icon"; import "../../../components/entity/ha-battery-icon";
@@ -41,6 +54,7 @@ import "../../../components/ha-filter-states";
import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button";
import "../../../components/ha-menu-item"; import "../../../components/ha-menu-item";
import "../../../components/ha-sub-menu"; import "../../../components/ha-sub-menu";
import { createAreaRegistryEntry } from "../../../data/area_registry";
import { ConfigEntry, sortConfigEntries } from "../../../data/config_entries"; import { ConfigEntry, sortConfigEntries } from "../../../data/config_entries";
import { fullEntitiesContext } from "../../../data/context"; import { fullEntitiesContext } from "../../../data/context";
import { import {
@@ -65,10 +79,12 @@ import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
import { haStyle } from "../../../resources/styles"; import { haStyle } from "../../../resources/styles";
import { HomeAssistant, Route } from "../../../types"; import { HomeAssistant, Route } from "../../../types";
import { brandsUrl } from "../../../util/brands-url"; import { brandsUrl } from "../../../util/brands-url";
import { showAreaRegistryDetailDialog } from "../areas/show-dialog-area-registry-detail";
import { configSections } from "../ha-panel-config"; import { configSections } from "../ha-panel-config";
import "../integrations/ha-integration-overflow-menu"; import "../integrations/ha-integration-overflow-menu";
import { showAddIntegrationDialog } from "../integrations/show-add-integration-dialog"; import { showAddIntegrationDialog } from "../integrations/show-add-integration-dialog";
import { showLabelDetailDialog } from "../labels/show-dialog-label-detail"; import { showLabelDetailDialog } from "../labels/show-dialog-label-detail";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
interface DeviceRowData extends DeviceRegistryEntry { interface DeviceRowData extends DeviceRegistryEntry {
device?: DeviceRowData; device?: DeviceRowData;
@@ -112,6 +128,19 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
@state() @state()
_labels!: LabelRegistryEntry[]; _labels!: LabelRegistryEntry[];
@storage({ key: "devices-table-sort", state: false, subscribe: false })
private _activeSorting?: SortingChangedEvent;
@storage({ key: "devices-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;
@storage({ key: "devices-table-collapsed", state: false, subscribe: false })
private _activeCollapsed?: string;
private _sizeController = new ResizeController(this, {
callback: (entries) => entries[0]?.contentRect.width,
});
private _ignoreLocationChange = false; private _ignoreLocationChange = false;
public connectedCallback() { public connectedCallback() {
@@ -544,6 +573,41 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
this._labels this._labels
); );
const areasInOverflow =
(this._sizeController.value && this._sizeController.value < 700) ||
(!this._sizeController.value && this.hass.dockedSidebar === "docked");
const areaItems = html`${Object.values(this.hass.areas).map(
(area) =>
html`<ha-menu-item
.value=${area.area_id}
@click=${this._handleBulkArea}
>
${area.icon
? html`<ha-icon slot="start" .icon=${area.icon}></ha-icon>`
: html`<ha-svg-icon
slot="start"
.path=${mdiTextureBox}
></ha-svg-icon>`}
<div slot="headline">${area.name}</div>
</ha-menu-item>`
)}
<ha-menu-item .value=${null} @click=${this._handleBulkArea}>
<div slot="headline">
${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.no_area"
)}
</div>
</ha-menu-item>
<md-divider role="separator" tabindex="-1"></md-divider>
<ha-menu-item @click=${this._bulkCreateArea}>
<div slot="headline">
${this.hass.localize(
"ui.panel.config.devices.picker.bulk_actions.add_area"
)}
</div>
</ha-menu-item>`;
const labelItems = html`${this._labels?.map((label) => { const labelItems = html`${this._labels?.map((label) => {
const color = label.color ? computeCssColor(label.color) : undefined; const color = label.color ? computeCssColor(label.color) : undefined;
const selected = this._selected.every((deviceId) => const selected = this._selected.every((deviceId) =>
@@ -591,7 +655,8 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
.tabs=${configSections.devices} .tabs=${configSections.devices}
.route=${this.route} .route=${this.route}
.searchLabel=${this.hass.localize( .searchLabel=${this.hass.localize(
"ui.panel.config.devices.picker.search" "ui.panel.config.devices.picker.search",
{ number: devicesOutput.length }
)} )}
.columns=${this._columns(this.hass.localize, this.narrow)} .columns=${this._columns(this.hass.localize, this.narrow)}
.data=${devicesOutput} .data=${devicesOutput}
@@ -600,11 +665,22 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
@selection-changed=${this._handleSelectionChanged} @selection-changed=${this._handleSelectionChanged}
.filter=${this._filter} .filter=${this._filter}
hasFilters hasFilters
.filters=${Object.values(this._filters).filter( .filters=${Object.values(this._filters).filter((filter) =>
(filter) => filter.value?.length Array.isArray(filter.value)
? filter.value.length
: filter.value &&
Object.values(filter.value).some((val) =>
Array.isArray(val) ? val.length : val
)
).length} ).length}
.initialGroupColumn=${this._activeGrouping}
.initialCollapsedGroups=${this._activeCollapsed}
.initialSorting=${this._activeSorting}
@clear-filter=${this._clearFilter} @clear-filter=${this._clearFilter}
@search-changed=${this._handleSearchChange} @search-changed=${this._handleSearchChange}
@sorting-changed=${this._handleSortingChanged}
@grouping-changed=${this._handleGroupingChanged}
@collapsed-changed=${this._handleCollapseChanged}
@row-click=${this._handleRowClicked} @row-click=${this._handleRowClicked}
clickable clickable
hasFab hasFab
@@ -673,36 +749,77 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
${!this.narrow ${!this.narrow
? html`<ha-button-menu-new slot="selection-bar"> ? html`<ha-button-menu-new slot="selection-bar">
<ha-assist-chip <ha-assist-chip
slot="trigger" slot="trigger"
.label=${this.hass.localize( .label=${this.hass.localize(
"ui.panel.config.automation.picker.bulk_actions.add_label" "ui.panel.config.automation.picker.bulk_actions.add_label"
)} )}
> >
<ha-svg-icon <ha-svg-icon
slot="trailing-icon" slot="trailing-icon"
.path=${mdiMenuDown} .path=${mdiMenuDown}
></ha-svg-icon> ></ha-svg-icon>
</ha-assist-chip> </ha-assist-chip>
${labelItems} ${labelItems}
</ha-button-menu-new>` </ha-button-menu-new>
: html` <ha-button-menu-new has-overflow slot="selection-bar"
><ha-assist-chip ${areasInOverflow
.label=${this.hass.localize( ? nothing
"ui.panel.config.automation.picker.bulk_action" : html`<ha-button-menu-new slot="selection-bar">
)} <ha-assist-chip
slot="trigger" slot="trigger"
> .label=${this.hass.localize(
<ha-svg-icon "ui.panel.config.devices.picker.bulk_actions.move_area"
slot="trailing-icon" )}
.path=${mdiMenuDown} >
></ha-svg-icon> <ha-svg-icon
</ha-assist-chip> slot="trailing-icon"
.path=${mdiMenuDown}
></ha-svg-icon>
</ha-assist-chip>
${areaItems}
</ha-button-menu-new>`}`
: nothing}
${this.narrow || areasInOverflow
? html`<ha-button-menu-new has-overflow slot="selection-bar">
${this.narrow
? html`<ha-assist-chip
.label=${this.hass.localize(
"ui.panel.config.automation.picker.bulk_action"
)}
slot="trigger"
>
<ha-svg-icon
slot="trailing-icon"
.path=${mdiMenuDown}
></ha-svg-icon>
</ha-assist-chip>`
: html`<ha-icon-button
.path=${mdiDotsVertical}
.label=${"ui.panel.config.automation.picker.bulk_action"}
slot="trigger"
></ha-icon-button>`}
${this.narrow
? html` <ha-sub-menu>
<ha-menu-item slot="item">
<div slot="headline">
${this.hass.localize(
"ui.panel.config.automation.picker.bulk_actions.add_label"
)}
</div>
<ha-svg-icon
slot="end"
.path=${mdiChevronRight}
></ha-svg-icon>
</ha-menu-item>
<ha-menu slot="menu">${labelItems}</ha-menu>
</ha-sub-menu>`
: nothing}
<ha-sub-menu> <ha-sub-menu>
<ha-menu-item slot="item"> <ha-menu-item slot="item">
<div slot="headline"> <div slot="headline">
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.automation.picker.bulk_actions.add_label" "ui.panel.config.devices.picker.bulk_actions.move_area"
)} )}
</div> </div>
<ha-svg-icon <ha-svg-icon
@@ -710,9 +827,10 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
.path=${mdiChevronRight} .path=${mdiChevronRight}
></ha-svg-icon> ></ha-svg-icon>
</ha-menu-item> </ha-menu-item>
<ha-menu slot="menu">${labelItems}</ha-menu> <ha-menu slot="menu">${areaItems}</ha-menu>
</ha-sub-menu> </ha-sub-menu>
</ha-button-menu-new>`} </ha-button-menu-new>`
: nothing}
</hass-tabs-subpage-data-table> </hass-tabs-subpage-data-table>
`; `;
} }
@@ -798,6 +916,46 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
this._selected = ev.detail.value; this._selected = ev.detail.value;
} }
private async _handleBulkArea(ev) {
const area = ev.currentTarget.value;
this._bulkAddArea(area);
}
private async _bulkAddArea(area: string) {
const promises: Promise<DeviceRegistryEntry>[] = [];
this._selected.forEach((deviceId) => {
promises.push(
updateDeviceRegistryEntry(this.hass, deviceId, {
area_id: area,
})
);
});
const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
}
private async _bulkCreateArea() {
showAreaRegistryDetailDialog(this, {
createEntry: async (values) => {
const area = await createAreaRegistryEntry(this.hass, values);
this._bulkAddArea(area.area_id);
return area;
},
});
}
private async _handleBulkLabel(ev) { private async _handleBulkLabel(ev) {
const label = ev.currentTarget.value; const label = ev.currentTarget.value;
const action = ev.currentTarget.action; const action = ev.currentTarget.action;
@@ -818,7 +976,20 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private _bulkCreateLabel() { private _bulkCreateLabel() {
@@ -831,9 +1002,24 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
}); });
} }
private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
css` css`
:host {
display: block;
}
hass-tabs-subpage-data-table { hass-tabs-subpage-data-table {
--data-table-row-height: 60px; --data-table-row-height: 60px;
} }

View File

@@ -1,5 +1,5 @@
import "@material/mwc-button/mwc-button"; import "@material/mwc-button/mwc-button";
import { mdiDelete, mdiDevices } from "@mdi/js"; import { mdiDelete, mdiDevices, mdiPencil } from "@mdi/js";
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
@@ -83,18 +83,24 @@ export class EnergyDeviceSettings extends LitElement {
${this.preferences.device_consumption.map((device) => { ${this.preferences.device_consumption.map((device) => {
const entityState = this.hass.states[device.stat_consumption]; const entityState = this.hass.states[device.stat_consumption];
return html` return html`
<div class="row"> <div class="row" .device=${device}>
<ha-state-icon <ha-state-icon
.hass=${this.hass} .hass=${this.hass}
.stateObj=${entityState} .stateObj=${entityState}
></ha-state-icon> ></ha-state-icon>
<span class="content" <span class="content"
>${getStatisticLabel( >${device.name ||
getStatisticLabel(
this.hass, this.hass,
device.stat_consumption, device.stat_consumption,
this.statsMetadata?.[device.stat_consumption] this.statsMetadata?.[device.stat_consumption]
)}</span )}</span
> >
<ha-icon-button
.label=${this.hass.localize("ui.common.edit")}
@click=${this._editDevice}
.path=${mdiPencil}
></ha-icon-button>
<ha-icon-button <ha-icon-button
.label=${this.hass.localize("ui.common.delete")} .label=${this.hass.localize("ui.common.delete")}
@click=${this._deleteDevice} @click=${this._deleteDevice}
@@ -117,6 +123,24 @@ export class EnergyDeviceSettings extends LitElement {
`; `;
} }
private _editDevice(ev) {
const origDevice: DeviceConsumptionEnergyPreference =
ev.currentTarget.closest(".row").device;
showEnergySettingsDeviceDialog(this, {
device: { ...origDevice },
device_consumptions: this.preferences
.device_consumption as DeviceConsumptionEnergyPreference[],
saveCallback: async (newDevice) => {
await this._savePreferences({
...this.preferences,
device_consumption: this.preferences.device_consumption.map((d) =>
d === origDevice ? newDevice : d
),
});
},
});
}
private _addDevice() { private _addDevice() {
showEnergySettingsDeviceDialog(this, { showEnergySettingsDeviceDialog(this, {
device_consumptions: this.preferences device_consumptions: this.preferences

View File

@@ -44,9 +44,10 @@ export class DialogEnergyDeviceSettings
this._energy_units = ( this._energy_units = (
await getSensorDeviceClassConvertibleUnits(this.hass, "energy") await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
).units; ).units;
this._excludeList = this._params.device_consumptions.map( this._device = this._params.device;
(entry) => entry.stat_consumption this._excludeList = this._params.device_consumptions
); .map((entry) => entry.stat_consumption)
.filter((id) => id !== this._device?.stat_consumption);
} }
public closeDialog(): void { public closeDialog(): void {
@@ -88,6 +89,7 @@ export class DialogEnergyDeviceSettings
.hass=${this.hass} .hass=${this.hass}
.helpMissingEntityUrl=${energyStatisticHelpUrl} .helpMissingEntityUrl=${energyStatisticHelpUrl}
.includeUnitClass=${energyUnitClasses} .includeUnitClass=${energyUnitClasses}
.value=${this._device?.stat_consumption}
.label=${this.hass.localize( .label=${this.hass.localize(
"ui.panel.config.energy.device_consumption.dialog.device_consumption_energy" "ui.panel.config.energy.device_consumption.dialog.device_consumption_energy"
)} )}
@@ -96,6 +98,17 @@ export class DialogEnergyDeviceSettings
dialogInitialFocus dialogInitialFocus
></ha-statistic-picker> ></ha-statistic-picker>
<ha-textfield
.label=${this.hass.localize(
"ui.panel.config.energy.device_consumption.dialog.display_name"
)}
type="text"
.disabled=${!this._device}
.value=${this._device?.name || ""}
@change=${this._nameChanged}
>
</ha-textfield>
<mwc-button @click=${this.closeDialog} slot="secondaryAction"> <mwc-button @click=${this.closeDialog} slot="secondaryAction">
${this.hass.localize("ui.common.cancel")} ${this.hass.localize("ui.common.cancel")}
</mwc-button> </mwc-button>
@@ -118,6 +131,17 @@ export class DialogEnergyDeviceSettings
this._device = { stat_consumption: ev.detail.value }; this._device = { stat_consumption: ev.detail.value };
} }
private _nameChanged(ev) {
const newDevice = {
...this._device!,
name: ev.target!.value,
} as DeviceConsumptionEnergyPreference;
if (!newDevice.name) {
delete newDevice.name;
}
this._device = newDevice;
}
private async _save() { private async _save() {
try { try {
await this._params!.saveCallback(this._device!); await this._params!.saveCallback(this._device!);
@@ -134,6 +158,10 @@ export class DialogEnergyDeviceSettings
ha-statistic-picker { ha-statistic-picker {
width: 100%; width: 100%;
} }
ha-textfield {
margin-top: 16px;
width: 100%;
}
`, `,
]; ];
} }

View File

@@ -70,6 +70,7 @@ export interface EnergySettingsWaterDialogParams {
} }
export interface EnergySettingsDeviceDialogParams { export interface EnergySettingsDeviceDialogParams {
device?: DeviceConsumptionEnergyPreference;
device_consumptions: DeviceConsumptionEnergyPreference[]; device_consumptions: DeviceConsumptionEnergyPreference[];
saveCallback: (device: DeviceConsumptionEnergyPreference) => Promise<void>; saveCallback: (device: DeviceConsumptionEnergyPreference) => Promise<void>;
} }

View File

@@ -27,9 +27,9 @@ import {
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined"; import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { until } from "lit/directives/until";
import memoize from "memoize-one"; import memoize from "memoize-one";
import { computeCssColor } from "../../../common/color/compute-color"; import { computeCssColor } from "../../../common/color/compute-color";
import { storage } from "../../../common/decorators/storage";
import type { HASSDomEvent } from "../../../common/dom/fire_event"; import type { HASSDomEvent } from "../../../common/dom/fire_event";
import { computeDomain } from "../../../common/entity/compute_domain"; import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
@@ -38,16 +38,22 @@ import {
protocolIntegrationPicked, protocolIntegrationPicked,
} from "../../../common/integrations/protocolIntegrationPicked"; } from "../../../common/integrations/protocolIntegrationPicked";
import { LocalizeFunc } from "../../../common/translations/localize"; import { LocalizeFunc } from "../../../common/translations/localize";
import {
hasRejectedItems,
rejectedItems,
} from "../../../common/util/promise-all-settled-results";
import type { import type {
DataTableColumnContainer, DataTableColumnContainer,
RowClickedEvent, RowClickedEvent,
SelectionChangedEvent, SelectionChangedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/data-table/ha-data-table-labels"; import "../../../components/data-table/ha-data-table-labels";
import "../../../components/ha-alert"; import "../../../components/ha-alert";
import "../../../components/ha-button-menu"; import "../../../components/ha-button-menu";
import "../../../components/ha-check-list-item"; import "../../../components/ha-check-list-item";
import "../../../components/ha-filter-devices"; import "../../../components/ha-filter-devices";
import "../../../components/ha-filter-domains";
import "../../../components/ha-filter-floor-areas"; import "../../../components/ha-filter-floor-areas";
import "../../../components/ha-filter-integrations"; import "../../../components/ha-filter-integrations";
import "../../../components/ha-filter-labels"; import "../../../components/ha-filter-labels";
@@ -67,7 +73,11 @@ import {
removeEntityRegistryEntry, removeEntityRegistryEntry,
updateEntityRegistryEntry, updateEntityRegistryEntry,
} from "../../../data/entity_registry"; } from "../../../data/entity_registry";
import { entryIcon } from "../../../data/icons"; import {
EntitySources,
fetchEntitySourcesWithCache,
} from "../../../data/entity_sources";
import { domainToName } from "../../../data/integration";
import { import {
LabelRegistryEntry, LabelRegistryEntry,
createLabelRegistryEntry, createLabelRegistryEntry,
@@ -88,10 +98,6 @@ import { configSections } from "../ha-panel-config";
import "../integrations/ha-integration-overflow-menu"; import "../integrations/ha-integration-overflow-menu";
import { showAddIntegrationDialog } from "../integrations/show-add-integration-dialog"; import { showAddIntegrationDialog } from "../integrations/show-add-integration-dialog";
import { showLabelDetailDialog } from "../labels/show-dialog-label-detail"; import { showLabelDetailDialog } from "../labels/show-dialog-label-detail";
import {
EntitySources,
fetchEntitySourcesWithCache,
} from "../../../data/entity_sources";
export interface StateEntity export interface StateEntity
extends Omit<EntityRegistryEntry, "id" | "unique_id"> { extends Omit<EntityRegistryEntry, "id" | "unique_id"> {
@@ -108,6 +114,7 @@ export interface EntityRow extends StateEntity {
status: string | undefined; status: string | undefined;
area?: string; area?: string;
localized_platform: string; localized_platform: string;
domain: string;
label_entries: LabelRegistryEntry[]; label_entries: LabelRegistryEntry[];
} }
@@ -147,6 +154,19 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
@state() private _entitySources?: EntitySources; @state() private _entitySources?: EntitySources;
@storage({ key: "entities-table-sort", state: false, subscribe: false })
private _activeSorting?: SortingChangedEvent;
@storage({ key: "entities-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;
@storage({
key: "entities-table-collapsed",
state: false,
subscribe: false,
})
private _activeCollapsed?: string;
@query("hass-tabs-subpage-data-table", true) @query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable; private _dataTable!: HaTabsSubpageDataTable;
@@ -207,21 +227,19 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
type: "icon", type: "icon",
template: (entry) => template: (entry) =>
entry.icon entry.icon
? html` ? html`<ha-icon .icon=${entry.icon}></ha-icon>`
<ha-state-icon : entry.entity
title=${ifDefined(entry.entity?.state)} ? html`
slot="item-icon" <ha-state-icon
.hass=${this.hass} title=${ifDefined(entry.entity?.state)}
.stateObj=${entry.entity} slot="item-icon"
></ha-state-icon> .hass=${this.hass}
` .stateObj=${entry.entity}
: html` ></ha-state-icon>
<ha-icon `
icon=${until( : html`<ha-domain-icon
entryIcon(this.hass, entry as EntityRegistryEntry) .domain=${computeDomain(entry.entity_id)}
)} ></ha-domain-icon>`,
></ha-icon>
`,
}, },
name: { name: {
main: true, main: true,
@@ -261,6 +279,13 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
filterable: true, filterable: true,
width: "20%", width: "20%",
}, },
domain: {
title: localize("ui.panel.config.entities.picker.headers.domain"),
sortable: false,
hidden: true,
filterable: true,
groupable: true,
},
area: { area: {
title: localize("ui.panel.config.entities.picker.headers.area"), title: localize("ui.panel.config.entities.picker.headers.area"),
sortable: true, sortable: true,
@@ -419,6 +444,10 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
entryIds.includes(entity.config_entry_id)) entryIds.includes(entity.config_entry_id))
); );
filter.value!.forEach((domain) => filteredDomains.add(domain)); filter.value!.forEach((domain) => filteredDomains.add(domain));
} else if (key === "ha-filter-domains" && filter.value?.length) {
filteredEntities = filteredEntities.filter((entity) =>
filter.value?.includes(computeDomain(entity.entity_id))
);
} else if (key === "ha-filter-labels" && filter.value?.length) { } else if (key === "ha-filter-labels" && filter.value?.length) {
filteredEntities = filteredEntities.filter((entity) => filteredEntities = filteredEntities.filter((entity) =>
entity.labels.some((lbl) => filter.value!.includes(lbl)) entity.labels.some((lbl) => filter.value!.includes(lbl))
@@ -467,9 +496,9 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
), ),
unavailable, unavailable,
restored, restored,
localized_platform: localized_platform: domainToName(localize, entry.platform),
localize(`component.${entry.platform}.title`) || entry.platform,
area: area ? area.name : "—", area: area ? area.name : "—",
domain: domainToName(localize, computeDomain(entry.entity_id)),
status: restored status: restored
? localize("ui.panel.config.entities.picker.status.restored") ? localize("ui.panel.config.entities.picker.status.restored")
: unavailable : unavailable
@@ -577,16 +606,29 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
)} )}
.data=${filteredEntities} .data=${filteredEntities}
.searchLabel=${this.hass.localize( .searchLabel=${this.hass.localize(
"ui.panel.config.entities.picker.search" "ui.panel.config.entities.picker.search",
{ number: filteredEntities.length }
)} )}
hasFilters hasFilters
.filters=${ .filters=${
Object.values(this._filters).filter((filter) => filter.value?.length) Object.values(this._filters).filter((filter) =>
.length Array.isArray(filter.value)
? filter.value.length
: filter.value &&
Object.values(filter.value).some((val) =>
Array.isArray(val) ? val.length : val
)
).length
} }
.filter=${this._filter} .filter=${this._filter}
selectable selectable
.selected=${this._selected.length} .selected=${this._selected.length}
.initialGroupColumn=${this._activeGrouping}
.initialCollapsedGroups=${this._activeCollapsed}
.initialSorting=${this._activeSorting}
@sorting-changed=${this._handleSortingChanged}
@grouping-changed=${this._handleGroupingChanged}
@collapsed-changed=${this._handleCollapseChanged}
@selection-changed=${this._handleSelectionChanged} @selection-changed=${this._handleSelectionChanged}
clickable clickable
@clear-filter=${this._clearFilter} @clear-filter=${this._clearFilter}
@@ -745,6 +787,15 @@ ${
.narrow=${this.narrow} .narrow=${this.narrow}
@expanded-changed=${this._filterExpanded} @expanded-changed=${this._filterExpanded}
></ha-filter-devices> ></ha-filter-devices>
<ha-filter-domains
.hass=${this.hass}
.value=${this._filters["ha-filter-domains"]?.value}
@data-table-filter-changed=${this._filterChanged}
slot="filter-pane"
.expanded=${this._expandedFilter === "ha-filter-domains"}
.narrow=${this.narrow}
@expanded-changed=${this._filterExpanded}
></ha-filter-domains>
<ha-filter-integrations <ha-filter-integrations
.hass=${this.hass} .hass=${this.hass}
.value=${this._filters["ha-filter-integrations"]?.value} .value=${this._filters["ha-filter-integrations"]?.value}
@@ -954,19 +1005,41 @@ ${
confirm: async () => { confirm: async () => {
let require_restart = false; let require_restart = false;
let reload_delay = 0; let reload_delay = 0;
await Promise.all( const result = await Promise.allSettled(
this._selected.map(async (entity) => { this._selected.map(async (entity) => {
const result = await updateEntityRegistryEntry(this.hass, entity, { const updateResult = await updateEntityRegistryEntry(
disabled_by: null, this.hass,
}); entity,
if (result.require_restart) { {
disabled_by: null,
}
);
if (updateResult.require_restart) {
require_restart = true; require_restart = true;
} }
if (result.reload_delay) { if (updateResult.reload_delay) {
reload_delay = Math.max(reload_delay, result.reload_delay); reload_delay = Math.max(reload_delay, updateResult.reload_delay);
} }
}) })
); );
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize(
"ui.panel.config.common.multiselect.failed",
{
number: rejected.length,
}
),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
this._clearSelection(); this._clearSelection();
// If restart is required by any entity, show a dialog. // If restart is required by any entity, show a dialog.
// Otherwise, show a dialog explaining that some patience is needed // Otherwise, show a dialog explaining that some patience is needed
@@ -1065,7 +1138,20 @@ ${
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private _bulkCreateLabel() { private _bulkCreateLabel() {
@@ -1154,6 +1240,18 @@ ${
}); });
} }
private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,

View File

@@ -35,7 +35,11 @@ import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { listenMediaQuery } from "../../common/dom/media_query"; import { listenMediaQuery } from "../../common/dom/media_query";
import { CloudStatus, fetchCloudStatus } from "../../data/cloud"; import { CloudStatus, fetchCloudStatus } from "../../data/cloud";
import { fullEntitiesContext } from "../../data/context"; import {
floorsContext,
fullEntitiesContext,
labelsContext,
} from "../../data/context";
import { import {
entityRegistryByEntityId, entityRegistryByEntityId,
entityRegistryById, entityRegistryById,
@@ -45,6 +49,8 @@ import { HassRouterPage, RouterOptions } from "../../layouts/hass-router-page";
import { PageNavigation } from "../../layouts/hass-tabs-subpage"; import { PageNavigation } from "../../layouts/hass-tabs-subpage";
import { SubscribeMixin } from "../../mixins/subscribe-mixin"; import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import { HomeAssistant, Route } from "../../types"; import { HomeAssistant, Route } from "../../types";
import { subscribeLabelRegistry } from "../../data/label_registry";
import { subscribeFloorRegistry } from "../../data/floor_registry";
declare global { declare global {
// for fire event // for fire event
@@ -379,11 +385,27 @@ class HaPanelConfig extends SubscribeMixin(HassRouterPage) {
initialValue: [], initialValue: [],
}); });
private _labelsContext = new ContextProvider(this, {
context: labelsContext,
initialValue: [],
});
private _floorsContext = new ContextProvider(this, {
context: floorsContext,
initialValue: [],
});
public hassSubscribe(): UnsubscribeFunc[] { public hassSubscribe(): UnsubscribeFunc[] {
return [ return [
subscribeEntityRegistry(this.hass.connection!, (entities) => { subscribeEntityRegistry(this.hass.connection!, (entities) => {
this._entitiesContext.setValue(entities); this._entitiesContext.setValue(entities);
}), }),
subscribeLabelRegistry(this.hass.connection!, (labels) => {
this._labelsContext.setValue(labels);
}),
subscribeFloorRegistry(this.hass.connection!, (floors) => {
this._floorsContext.setValue(floors);
}),
]; ];
} }

View File

@@ -32,7 +32,7 @@ import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-c
import { haStyleDialog } from "../../../resources/styles"; import { haStyleDialog } from "../../../resources/styles";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { brandsUrl } from "../../../util/brands-url"; import { brandsUrl } from "../../../util/brands-url";
import { Helper, HelperDomain } from "./const"; import { Helper, HelperDomain, isHelperDomain } from "./const";
import type { ShowDialogHelperDetailParams } from "./show-dialog-helper-detail"; import type { ShowDialogHelperDetailParams } from "./show-dialog-helper-detail";
type HelperCreators = { type HelperCreators = {
@@ -96,7 +96,7 @@ export class DialogHelperDetail extends LitElement {
@state() private _opened = false; @state() private _opened = false;
@state() private _domain?: HelperDomain; @state() private _domain?: string;
@state() private _error?: string; @state() private _error?: string;
@@ -114,8 +114,12 @@ export class DialogHelperDetail extends LitElement {
this._params = params; this._params = params;
this._domain = params.domain; this._domain = params.domain;
this._item = undefined; this._item = undefined;
if (this._domain && this._domain in HELPERS) {
await HELPERS[this._domain].import();
}
this._opened = true; this._opened = true;
await this.updateComplete; await this.updateComplete;
this.hass.loadFragmentTranslation("config");
Promise.all([ Promise.all([
getConfigFlowHandlers(this.hass, ["helper"]), getConfigFlowHandlers(this.hass, ["helper"]),
// Ensure the titles are loaded before we render the flows. // Ensure the titles are loaded before we render the flows.
@@ -141,7 +145,7 @@ export class DialogHelperDetail extends LitElement {
if (this._domain) { if (this._domain) {
content = html` content = html`
<div class="form" @value-changed=${this._valueChanged}> <div class="form" @value-changed=${this._valueChanged}>
${this._error ? html` <div class="error">${this._error}</div> ` : ""} ${this._error ? html`<div class="error">${this._error}</div>` : ""}
${dynamicElement(`ha-${this._domain}-form`, { ${dynamicElement(`ha-${this._domain}-form`, {
hass: this.hass, hass: this.hass,
item: this._item, item: this._item,
@@ -155,13 +159,15 @@ export class DialogHelperDetail extends LitElement {
> >
${this.hass!.localize("ui.panel.config.helpers.dialog.create")} ${this.hass!.localize("ui.panel.config.helpers.dialog.create")}
</mwc-button> </mwc-button>
<mwc-button ${this._params?.domain
slot="secondaryAction" ? nothing
@click=${this._goBack} : html`<mwc-button
.disabled=${this._submitting} slot="secondaryAction"
> @click=${this._goBack}
${this.hass!.localize("ui.common.back")} .disabled=${this._submitting}
</mwc-button> >
${this.hass!.localize("ui.common.back")}
</mwc-button>`}
`; `;
} else if (this._loading || this._helperFlows === undefined) { } else if (this._loading || this._helperFlows === undefined) {
content = html`<ha-circular-progress content = html`<ha-circular-progress
@@ -253,9 +259,13 @@ export class DialogHelperDetail extends LitElement {
"ui.panel.config.helpers.dialog.create_platform", "ui.panel.config.helpers.dialog.create_platform",
{ {
platform: platform:
this.hass.localize( (isHelperDomain(this._domain) &&
`ui.panel.config.helpers.types.${this._domain}` this.hass.localize(
) || this._domain, `ui.panel.config.helpers.types.${
this._domain as HelperDomain
}`
)) ||
this._domain,
} }
) )
: this.hass.localize("ui.panel.config.helpers.dialog.create_helper") : this.hass.localize("ui.panel.config.helpers.dialog.create_helper")
@@ -277,7 +287,16 @@ export class DialogHelperDetail extends LitElement {
this._submitting = true; this._submitting = true;
this._error = ""; this._error = "";
try { try {
await HELPERS[this._domain].create(this.hass, this._item); const createdEntity = await HELPERS[this._domain].create(
this.hass,
this._item
);
if (this._params?.dialogClosedCallback && createdEntity.id) {
this._params.dialogClosedCallback({
flowFinished: true,
entityId: `${this._domain}.${createdEntity.id}`,
});
}
this.closeDialog(); this.closeDialog();
} catch (err: any) { } catch (err: any) {
this._error = err.message || "Unknown error"; this._error = err.message || "Unknown error";

View File

@@ -2,7 +2,7 @@ import { Calendar, CalendarOptions } from "@fullcalendar/core";
import allLocales from "@fullcalendar/core/locales-all"; import allLocales from "@fullcalendar/core/locales-all";
import interactionPlugin from "@fullcalendar/interaction"; import interactionPlugin from "@fullcalendar/interaction";
import timeGridPlugin from "@fullcalendar/timegrid"; import timeGridPlugin from "@fullcalendar/timegrid";
import { addDays, isSameDay, isSameWeek, nextDay } from "date-fns"; import { Day, addDays, isSameDay, isSameWeek, nextDay } from "date-fns";
import { import {
CSSResultGroup, CSSResultGroup,
LitElement, LitElement,

View File

@@ -24,6 +24,7 @@ import {
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { computeCssColor } from "../../../common/color/compute-color"; import { computeCssColor } from "../../../common/color/compute-color";
import { storage } from "../../../common/decorators/storage";
import { HASSDomEvent } from "../../../common/dom/fire_event"; import { HASSDomEvent } from "../../../common/dom/fire_event";
import { computeStateDomain } from "../../../common/entity/compute_state_domain"; import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { navigate } from "../../../common/navigate"; import { navigate } from "../../../common/navigate";
@@ -32,10 +33,15 @@ import {
LocalizeKeys, LocalizeKeys,
} from "../../../common/translations/localize"; } from "../../../common/translations/localize";
import { extractSearchParam } from "../../../common/url/search-params"; import { extractSearchParam } from "../../../common/url/search-params";
import {
hasRejectedItems,
rejectedItems,
} from "../../../common/util/promise-all-settled-results";
import { import {
DataTableColumnContainer, DataTableColumnContainer,
RowClickedEvent, RowClickedEvent,
SelectionChangedEvent, SelectionChangedEvent,
SortingChangedEvent,
} from "../../../components/data-table/ha-data-table"; } from "../../../components/data-table/ha-data-table";
import "../../../components/data-table/ha-data-table-labels"; import "../../../components/data-table/ha-data-table-labels";
import "../../../components/ha-fab"; import "../../../components/ha-fab";
@@ -135,6 +141,19 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public route!: Route; @property({ attribute: false }) public route!: Route;
@storage({ key: "helpers-table-sort", state: false, subscribe: false })
private _activeSorting?: SortingChangedEvent;
@storage({ key: "helpers-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;
@storage({
key: "helpers-table-collapsed",
state: false,
subscribe: false,
})
private _activeCollapsed?: string;
@state() private _stateItems: HassEntity[] = []; @state() private _stateItems: HassEntity[] = [];
@state() private _entityEntries?: Record<string, EntityRegistryEntry>; @state() private _entityEntries?: Record<string, EntityRegistryEntry>;
@@ -486,6 +505,16 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
const labelsInOverflow = const labelsInOverflow =
(this._sizeController.value && this._sizeController.value < 700) || (this._sizeController.value && this._sizeController.value < 700) ||
(!this._sizeController.value && this.hass.dockedSidebar === "docked"); (!this._sizeController.value && this.hass.dockedSidebar === "docked");
const helpers = this._getItems(
this.hass.localize,
this._stateItems,
this._entityEntries,
this._configEntries,
this._entityReg,
this._categories,
this._labels,
this._filteredStateItems
);
return html` return html`
<hass-tabs-subpage-data-table <hass-tabs-subpage-data-table
.hass=${this.hass} .hass=${this.hass}
@@ -493,25 +522,30 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
back-path="/config" back-path="/config"
.route=${this.route} .route=${this.route}
.tabs=${configSections.devices} .tabs=${configSections.devices}
.searchLabel=${this.hass.localize(
"ui.panel.config.helpers.picker.search",
{ number: helpers.length }
)}
selectable selectable
.selected=${this._selected.length} .selected=${this._selected.length}
@selection-changed=${this._handleSelectionChanged} @selection-changed=${this._handleSelectionChanged}
hasFilters hasFilters
.filters=${Object.values(this._filters).filter( .filters=${Object.values(this._filters).filter((filter) =>
(filter) => filter.value?.length Array.isArray(filter.value)
? filter.value.length
: filter.value &&
Object.values(filter.value).some((val) =>
Array.isArray(val) ? val.length : val
)
).length} ).length}
.columns=${this._columns(this.narrow, this.hass.localize)} .columns=${this._columns(this.narrow, this.hass.localize)}
.data=${this._getItems( .data=${helpers}
this.hass.localize, .initialGroupColumn=${this._activeGrouping || "category"}
this._stateItems, .initialCollapsedGroups=${this._activeCollapsed}
this._entityEntries, .initialSorting=${this._activeSorting}
this._configEntries, @sorting-changed=${this._handleSortingChanged}
this._entityReg, @grouping-changed=${this._handleGroupingChanged}
this._categories, @collapsed-changed=${this._handleCollapseChanged}
this._labels,
this._filteredStateItems
)}
initialGroupColumn="category"
.activeFilters=${this._activeFilters} .activeFilters=${this._activeFilters}
@clear-filter=${this._clearFilter} @clear-filter=${this._clearFilter}
@row-click=${this._openEditDialog} @row-click=${this._openEditDialog}
@@ -791,7 +825,20 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private async _handleBulkLabel(ev) { private async _handleBulkLabel(ev) {
@@ -814,7 +861,20 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
}) })
); );
}); });
await Promise.all(promises); const result = await Promise.allSettled(promises);
if (hasRejectedItems(result)) {
const rejected = rejectedItems(result);
showAlertDialog(this, {
title: this.hass.localize("ui.panel.config.common.multiselect.failed", {
number: rejected.length,
}),
text: html`<pre>
${rejected
.map((r) => r.reason.message || r.reason.code || r.reason)
.join("\r\n")}</pre
>`,
});
}
} }
private _handleSelectionChanged( private _handleSelectionChanged(
@@ -980,6 +1040,18 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
}); });
} }
private _handleSortingChanged(ev: CustomEvent) {
this._activeSorting = ev.detail;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,

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