Compare commits

...

92 Commits

Author SHA1 Message Date
Bram Kragten 88b36ec314 Cleanup some subscriptions 2023-01-09 10:29:40 +01:00
Felipe Santos f31a7c3af0 Fix issue with reload not working sometimes (#14939)
fixes undefined
2023-01-03 11:09:18 +01:00
Bram Kragten 44d91eaa4f Bumped version to 20230102.0 2023-01-02 21:28:30 +01:00
Allen Porter 3cc1cb7893 Rollback calendar trigger day offset support (#14933) 2023-01-02 21:27:50 +01:00
Paul Bottein e7354ed5a2 Do not close aliases dialog on enter (#14952)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2023-01-02 21:27:30 +01:00
Allen Porter e3ac2c149d Use translations for all fields in recurrence rule editor (#14940)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2023-01-02 20:19:36 +00:00
epenet afcd45a780 Enable unit conversion for DATA_SIZE (#14903)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2023-01-02 20:17:14 +00:00
Bram Kragten fe87466351 Add link to aliases in cloud config entity settings (#14959) 2023-01-02 20:42:31 +01:00
epenet bdef924426 Enable unit conversion for DATA_RATE (#14902)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2023-01-02 17:50:12 +00:00
Paul Bottein 86ea3082f7 Add aliases editor for helpers (#14951) 2023-01-02 12:10:52 +01:00
930913 0374330676 Add helper text to select slider (#14884)
* Add helper text to select slider

* Make helper text conditional

Only show if set.

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

* Lint changes

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-31 15:38:21 -05:00
Bram Kragten d8a68326fb Bumped version to 20221230.0 2022-12-30 13:21:47 +01:00
Allen Porter 4901d50918 Fix All Day recurring events that end on a specific date (#14905) 2022-12-30 13:15:07 +01:00
SukramJ a16e41a7ac Add support for unit conversion of electric current (#14916) 2022-12-30 13:06:11 +01:00
Jan Bouwhuis f1d644ac51 Add mV as unit for sensor device_class voltage (#14921) 2022-12-30 13:05:44 +01:00
karwosts a9378abe31 Fix days missing from ha-base-time-input _valueChanged (#14910)
* Fix days missing from ha-base-time-input _valueChanged

* style change
2022-12-29 00:06:48 -05:00
Gia Ferrari 5c2fcd7f9b Add alt attribute to various images (#14405)
* ha-config-area-page: Add alt tag for area-picture

* dialog-tag-detail: Add alt tag for generated QR code image.

* ha-config-hardware: Blank alt tag for hardware pic, info already elsewhere

* dialog-energy-solar-settings: Blank alt tag for brand icon.

* ha-energy-grid-settings: Blank alt tag for co2signal brand icon.

* Add a few more appropriately-blank alt texts.

* ha-config-device-page: Logo alt text set to name of device domain.

* ha-config-repairs: Logo alt text set to name of issue domain.

* hui-picture-card(-editor): Alternate Text via config (blank default)

* hui-picture-entity-card(-editor): Alternate Text via config (blank default)

* ha-long-lived-access-token-dialog: Alt text for QR code.

* hui-picture-header-footer: Support alt text via optional property.

* A few more blank alt attributes.

* ha-tile-image: Support alt tag (but it is blank in current usage).

* prod cla-bot

* Lint. Fix whitespace.

* Add missing alt text properties to TS types.

* Fix my silly typo in picture-entity-card-editor's SCHEMA (+ minor reformat)

* Add alt_text to Picture(Entity)CardConfig TypeScript types.

* Format with prettier.

* Revise alt text for tag QR

* Revise alt text for token QR

* Revise alternate to alternative

* Add alt to logo in gallery

* Add alt text to crop image

* Use ifDefined for tile image alt

* Change area picture alt to area name

* Remove entry from entities config struct

* Revert altText changes for Picture Entity Card (to revisit in future PR)

See:
https://github.com/home-assistant/frontend/pull/14405#discussion_r1032735871

* Revert changes to hui-image and picture entity editor

Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
2022-12-29 01:16:05 +00:00
Bram Kragten 0015559e24 Merge branch 'master' into dev 2022-12-28 14:42:47 +01:00
Bram Kragten 2fbe6809c1 Bumped version to 20221228.0 2022-12-28 14:40:38 +01:00
Jaroslav Hanslík e926091e54 Sort strings by locale language (#14533) 2022-12-28 14:25:45 +01:00
karwosts 1198f983aa Prevent duplicate entities from being chosen in the target picker (#14882)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-28 13:24:32 +00:00
Allen Porter 6a15216104 Add monthly variations for recurrence rules (#14849)
* Add variations on monthly recurrence rules

* Recurrence rule code simplificiation

* Invalidate when the interval changes

* update

* Update ha-recurrence-rule-editor.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-28 14:07:17 +01:00
Bram Kragten b99a139f51 Fix target selector (#14895) 2022-12-28 14:02:46 +01:00
Paulus Schoutsen 0e9a013549 Conversation dialog tweaks (#14869) 2022-12-28 13:50:38 +01:00
Jan Bouwhuis 1d1ff410b2 Make using template rendering optional when using MQTT publish from the config entry page (#14828) 2022-12-28 12:12:30 +01:00
Jan Bouwhuis d4d3a1cb65 Use _ prefix for local vars on MQTT config entry page (#14898) 2022-12-28 11:22:40 +01:00
Jan Bouwhuis 81e3652446 Make JSON formatting optional when using MQTT subscribe from config entry page (#14830) 2022-12-27 22:03:14 +01:00
Philip Allgaier adb61ab99b Enforce valid entity ID in card config YAML (#14792) 2022-12-27 22:00:37 +01:00
karwosts 1c139d0bc7 Fix map card not loading in sidebar view (#14872)
fixes undefined
2022-12-27 22:00:19 +01:00
karwosts 419f23879a Fix broken numeric text entry in state-card-input_number (#14812)
fixes undefined
2022-12-27 21:57:47 +01:00
Allen Porter e175c7ba3c Add edit/update support for calendar events (#14814)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-27 21:47:42 +01:00
Paul Bottein 2575d35f2c Add aliases dialog to entity registry settings (#14860) 2022-12-27 21:36:08 +01:00
Steve Repsher 5eb45209e8 Pin action versions to minor and patch (#14894) 2022-12-27 21:20:47 +01:00
Paul Bottein 0e70b866ae Uses backend translation for climate attributes (#14827)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-27 20:08:47 +00:00
albatorsk c6aa2886ed Change Z-Wave to Zigbee in help setup dialog (#14892) 2022-12-27 12:55:16 +00:00
dependabot[bot] 77e01812d1 Bump actions/stale from 6.0.1 to 7.0.0 (#14886)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-27 08:25:47 +01:00
Paulus Schoutsen a5863a9a67 Redirect to new Matter device (#14867)
* Redirect to new Matter device

* Use hass.devices
2022-12-23 20:49:07 -05:00
Paulus Schoutsen 526c34993c Allow opening conversation dialog via URL (#14868)
* Allow opening conversation dialog via URL

* Update URL
2022-12-23 20:37:58 -05:00
Bram Kragten 3199319830 Fix water compare (#14864) 2022-12-22 11:20:40 -05:00
Allen Porter 6bb350b5ec Fix bug in non-recurring calendar event creation (#14854)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-22 16:14:30 +00:00
Jan Bouwhuis f41330a29b Allign MQTT config panel controls (#14818)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-22 15:43:55 +01:00
Paul Bottein 7780ae8f76 Fixes select selector filter (#14850) 2022-12-22 13:03:14 +01:00
Paul Bottein 40cf15c1f3 Fix history type device class (#14851) 2022-12-22 12:59:00 +01:00
smonesi 9be6a47d88 Attempt to fix picture-elements functionality broken in 2022.11 (#14813)
fixes undefined
2022-12-22 12:52:15 +01:00
Franck Nijhof 5933c2eb8e Add Calendar redirect support for My (#14859) 2022-12-22 12:51:36 +01:00
karwosts a8b7937d75 Fix zwave automations not handling 0 values in the visual editor (#14835)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-22 12:48:48 +01:00
Jan Bouwhuis 4919341871 Fix localization Solar total in Enery dashboard (#14841)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-22 12:47:33 +01:00
Allen Porter 36e99c3c0f Fix calendar date display and parsing issues (#14817)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-21 17:07:31 +01:00
Jan Bouwhuis 825008e24a Use a capitol for Topic in MQTT config panel. (#14843) 2022-12-21 17:06:40 +01:00
Paul Bottein ae04a5457e Allow custom value for multiple select (#14839) 2022-12-21 10:51:35 +00:00
Paul Bottein a7c3774c29 Fixes alarm triggered color in alarm card (#14840) 2022-12-21 11:22:48 +01:00
Paul Bottein 9c24dbe333 Enforces disabled to false for ha-form (#14842) 2022-12-21 11:22:09 +01:00
epenet 50f089fd4f Add CCF (centum cubic feet) to volume units (#14796) 2022-12-19 17:27:36 +01:00
Joost Lekkerkerker 019ef4ba8f Fix suffix not showing up (#14816) 2022-12-19 13:24:57 +00:00
Bram Kragten b31a9d590e Change layout of Zwave JS device config page (#14788) 2022-12-15 17:41:38 +01:00
Bram Kragten 43ea175a1a Bumped version to 20221213.1 2022-12-15 16:13:20 +01:00
Bram Kragten b2f0b6a814 Check if area exists during default dashboard generation (#14767) 2022-12-15 16:10:26 +01:00
Paul Bottein 614496d65c Add pulse animation for jammed state for lock (#14766) 2022-12-15 16:09:57 +01:00
Philip Allgaier d121c1cd18 Classify binary sensor locks active state as alert (= red) (#14761)
fixes undefined
2022-12-15 16:09:15 +01:00
Paul Bottein b18160d987 Use CSS colors for tile components (#14770)
* Do not use rgb colors for tile components

* Fixes gallery

* Change tile color

* Do not use rgb colors in tile button
2022-12-15 11:27:45 +01:00
Bram Kragten 5b17c59a56 Check if area exists during default dashboard generation (#14767) 2022-12-15 11:09:49 +01:00
Philip Allgaier 139cbb363c Cover in state "closing" should be in "active" color (#14785) 2022-12-15 11:02:47 +01:00
Steve Repsher e8e4733fc9 Fix localize key type errors for states (#14691)
* Replace unavailable state checks with type predicate

* Remove localize exceptions related to state

* Use literal types for climate attributes

* Add fan action to climate tile badge

* Use literal types for truncated states in badges

* Use literal type for humidifier state

* Replace unavailable state checks in calendar and tile card

* Avoid string split for truncated key
2022-12-14 19:39:10 +01:00
Philip Allgaier b4d6fc3c20 Handle "idle" state of alert entity (#14779) 2022-12-14 19:08:08 +01:00
karwosts 25a5bd568a Fix entity-filter handling of numeric states for == and != operators. (#14726)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
2022-12-14 17:51:33 +00:00
karwosts 77b8152c55 Make map card trails clickable, provide time context. (#14515)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 18:39:38 +01:00
Steve Repsher ebcbfda92d Remove prefixes from dependabot commit messages (#14778) 2022-12-14 16:42:36 +00:00
Bram Kragten 01a4b55ed8 Use entity picker in calendar event editor (#14772) 2022-12-14 16:27:05 +00:00
Steve Repsher 311d11f2da Add title attributes to iframes for accessibility (#14760)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 16:50:14 +01:00
dependabot[bot] c400e771cb dev(deps-dev): bump fancy-log from 1.3.3 to 2.0.0 (#14773)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-14 16:49:35 +01:00
dependabot[bot] 7611a99f55 dev(deps-dev): bump @typescript-eslint/eslint-plugin from 5.44.0 to 5.46.1 (#14774)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-14 16:47:24 +01:00
Jan Bouwhuis 1044b3c399 Add retain switch for MQTT publish (#14714) 2022-12-14 16:42:44 +01:00
Jan Bouwhuis 239d3ca00c Add QoS option for MQTT subscribe (#14565)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 16:42:11 +01:00
Steve Repsher 00c2cb731b Remove unnecessary labels from dashboard menu (#14605) 2022-12-14 12:16:45 +01:00
Philip Allgaier ef7d839c0f Use the calendar color for state icon in event details (#14670)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 12:15:36 +01:00
Steve Repsher 66a22ae102 Enable dependabot for yarn packages (#14607) 2022-12-14 12:13:56 +01:00
Steve Repsher d48853fcdd Add precommit hook to deduplicate dependencies (#14609) 2022-12-14 12:11:58 +01:00
Philip Allgaier 175a388822 Add sun domain to gallery entity states (#14742) 2022-12-14 11:43:49 +01:00
uvjustin 872395bec5 Enable http cache for local media-player-browse thumbnails (#13339) 2022-12-14 11:38:20 +01:00
Paul Bottein 5faf7cf0af Add pulse animation for jammed state for lock (#14766) 2022-12-14 11:35:41 +01:00
Philip Allgaier e768c78dce Enable weather entity row to show secondary info (#14639) 2022-12-14 11:35:25 +01:00
Denis Shulyaka 50cc8594be humidifier card: fix humidity not visible (#14575) 2022-12-14 11:34:10 +01:00
karwosts 363092ff03 Remove min/max >=1 requirement from gauge-card-editor (#14682)
fixes undefined
2022-12-14 11:25:24 +01:00
epenet 1bce5efc9e Add new sound pressure device class (#14592)
* Add sound pressure device class

* Update const.ts

* sort

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 10:20:27 +01:00
epenet 14513e5905 Add new data rate device class (#14594)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2022-12-14 10:18:55 +01:00
epenet b168f8d027 Add new data size device class (#14595) 2022-12-14 10:18:11 +01:00
epenet e151520d74 Add stones to weight units (#14749) 2022-12-14 10:17:55 +01:00
Philip Allgaier 02b763e8f3 Add snow weather icon SVG class (#14655)
fixes undefined
2022-12-14 10:17:34 +01:00
Philip Allgaier 498102ddd9 Classify binary sensor locks active state as alert (= red) (#14761)
fixes undefined
2022-12-14 09:44:43 +01:00
Joakim Sørensen 6aba5c1017 Add action to publish demo when pushing to master (#14723) 2022-12-14 09:37:16 +01:00
Bram Kragten 2176d4dcea Make editing home location more clear (#14636) 2022-12-14 09:13:31 +01:00
Paulus Schoutsen 9fdef3df6d Update conversation API (#14763)
* Update conversation API

* Update action done

* Add query done data

* Update conversation_id type
2022-12-13 23:10:57 -05:00
218 changed files with 3122 additions and 1539 deletions
+6
View File
@@ -6,3 +6,9 @@ updates:
interval: weekly
time: "06:00"
open-pull-requests-limit: 10
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
time: "06:00"
open-pull-requests-limit: 5
+4 -4
View File
@@ -22,12 +22,12 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
with:
ref: dev
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
@@ -60,12 +60,12 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
with:
ref: master
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+8 -8
View File
@@ -20,9 +20,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
@@ -44,9 +44,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
@@ -63,9 +63,9 @@ jobs:
needs: [lint, test]
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
@@ -82,9 +82,9 @@ jobs:
needs: [lint, test]
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+1 -1
View File
@@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
+47 -4
View File
@@ -7,23 +7,28 @@ on:
push:
branches:
- dev
- master
env:
NODE_VERSION: 16
NODE_OPTIONS: --max_old_space_size=6144
jobs:
deploy:
deploy_dev:
runs-on: ubuntu-latest
name: Demo Development
if: github.event_name != 'push' || github.ref != 'master'
environment:
name: Demo
name: Demo Development
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
with:
ref: dev
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
@@ -46,3 +51,41 @@ jobs:
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_DEV_SITE_ID }}
deploy_master:
runs-on: ubuntu-latest
name: Demo Production
if: github.event_name == 'push' && github.ref == 'master'
environment:
name: Demo Production
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3.2.0
with:
ref: master
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- name: Install dependencies
run: yarn install
env:
CI: true
- name: Build Demo
run: ./node_modules/.bin/gulp build-demo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Netlify
id: deploy
uses: netlify/actions/cli@master
with:
args: deploy --dir=demo/dist --prod
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }}
+2 -2
View File
@@ -17,10 +17,10 @@ jobs:
url: ${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+2 -2
View File
@@ -22,10 +22,10 @@ jobs:
if: github.repository == 'home-assistant/frontend' && contains(github.event.pull_request.labels.*.name, 'needs design preview')
steps:
- name: Check out files from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+2 -2
View File
@@ -21,7 +21,7 @@ jobs:
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
@@ -29,7 +29,7 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+2 -2
View File
@@ -24,7 +24,7 @@ jobs:
contents: write # Required to upload release assets
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Verify version
uses: home-assistant/actions/helpers/verify-version@master
@@ -35,7 +35,7 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
uses: actions/setup-node@v3.5.1
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
+1 -1
View File
@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 90 days stale policy
uses: actions/stale@v6.0.1
uses: actions/stale@v7.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 90
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v3.2.0
- name: Upload Translations
run: |
+3 -1
View File
@@ -98,7 +98,9 @@ const alerts: {
description: "Alert with slotted image",
type: "warning",
iconSlot: html`<span slot="icon" class="image"
><img src="https://www.home-assistant.io/images/home-assistant-logo.svg"
><img
alt="Home Assistant logo"
src="https://www.home-assistant.io/images/home-assistant-logo.svg"
/></span>`,
},
{
@@ -142,7 +142,8 @@ export class DemoHaBarSlider extends LitElement {
}
.custom {
--slider-bar-color: #ffcf4c;
--slider-bar-background: #ffcf4c64;
--slider-bar-background: #ffcf4c;
--slider-bar-background-opacity: 0.2;
--slider-bar-thickness: 100px;
--slider-bar-border-radius: 24px;
}
@@ -115,8 +115,8 @@ export class DemoHaBarSwitch extends LitElement {
font-weight: 600;
}
.custom {
--switch-bar-color-on: var(--rgb-green-color);
--switch-bar-color-off: var(--rgb-red-color);
--switch-bar-on-color: rgb(var(--rgb-green-color));
--switch-bar-off-color: rgb(var(--rgb-red-color));
--switch-bar-thickness: 100px;
--switch-bar-border-radius: 24px;
--switch-bar-padding: 6px;
+7 -1
View File
@@ -106,6 +106,7 @@ const ENTITIES: HassEntity[] = [
// Alert
createEntity("alert.off", "off"),
createEntity("alert.on", "on"),
createEntity("alert.idle", "idle"),
// Automation
createEntity("automation.off", "off"),
createEntity("automation.on", "on"),
@@ -219,6 +220,11 @@ const ENTITIES: HassEntity[] = [
// Siren
createEntity("siren.off", "off"),
createEntity("siren.on", "on"),
// Sun
createEntity("sun.below", "below_horizon"),
createEntity("sun.above", "above_horizon"),
createEntity("sun.unknown", "unknown"),
createEntity("sun.unavailable", "unavailable"),
// Switch
createEntity("switch.off", "off"),
createEntity("switch.on", "on"),
@@ -322,7 +328,7 @@ export class DemoEntityState extends LitElement {
`,
},
entity_id: {
title: "Entity id",
title: "Entity ID",
width: "30%",
filterable: true,
sortable: true,
@@ -29,7 +29,9 @@ class HassioAddonRepositoryEl extends LitElement {
if (filter) {
return filterAndSort(addons, filter);
}
return addons.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name));
return addons.sort((a, b) =>
caseInsensitiveStringCompare(a.name, b.name, this.hass.locale.language)
);
});
protected render(): TemplateResult {
@@ -404,6 +404,7 @@ class HassioAddonInfo extends LitElement {
? html`
<img
class="logo"
alt=""
src="/api/hassio/addons/${this.addon.slug}/logo"
/>
`
+7 -1
View File
@@ -35,7 +35,13 @@ class HassioAddons extends LitElement {
</ha-card>
`
: this.supervisor.addon.addons
.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name))
.sort((a, b) =>
caseInsensitiveStringCompare(
a.name,
b.name,
this.hass.locale.language
)
)
.map(
(addon) => html`
<ha-card
@@ -15,7 +15,12 @@ import { HomeAssistant } from "../../../../src/types";
import { HassioHardwareDialogParams } from "./show-dialog-hassio-hardware";
const _filterDevices = memoizeOne(
(showAdvanced: boolean, hardware: HassioHardwareInfo, filter: string) =>
(
showAdvanced: boolean,
hardware: HassioHardwareInfo,
filter: string,
language: string
) =>
hardware.devices
.filter(
(device) =>
@@ -28,7 +33,7 @@ const _filterDevices = memoizeOne(
.toLocaleLowerCase()
.includes(filter))
)
.sort((a, b) => stringCompare(a.name, b.name))
.sort((a, b) => stringCompare(a.name, b.name, language))
);
@customElement("dialog-hassio-hardware")
@@ -56,7 +61,8 @@ class HassioHardwareDialog extends LitElement {
const devices = _filterDevices(
this.hass.userData?.showAdvanced || false,
this._dialogParams.hardware,
(this._filter || "").toLowerCase()
(this._filter || "").toLowerCase(),
this.hass.locale.language
);
return html`
@@ -68,7 +68,9 @@ class HassioRepositoriesDialog extends LitElement {
repo.slug !== "a0d7b954" && // Home Assistant Community Add-ons
repo.slug !== "5c53de3b" // The ESPHome repository
)
.sort((a, b) => caseInsensitiveStringCompare(a.name, b.name))
.sort((a, b) =>
caseInsensitiveStringCompare(a.name, b.name, this.hass.locale.language)
)
);
private _filteredUsedRepositories = memoizeOne(
@@ -59,7 +59,11 @@ class HassioIngressView extends LitElement {
return html` <hass-loading-screen></hass-loading-screen> `;
}
const iframe = html`<iframe src=${this._addon.ingress_url!}></iframe>`;
const iframe = html`<iframe
.title=${this._addon.name}
.src=${this._addon.ingress_url!}
>
</iframe>`;
if (!this.ingressPanel) {
return html`<hass-subpage
+1
View File
@@ -5,4 +5,5 @@ module.exports = {
'printf "%s\n" "Translation files should not be added or modified here. Instead, make the necessary modifications in src/translations/en.json. Other languages are managed externally. Please see https://developers.home-assistant.io/docs/translations/ for details." ' +
files.join(" ") +
" >&2 && exit 1",
"/yarn.lock": () => "yarn dedupe",
};
+3 -2
View File
@@ -106,6 +106,7 @@
"core-js": "^3.15.2",
"cropperjs": "^1.5.12",
"date-fns": "^2.23.0",
"date-fns-tz": "^1.3.7",
"deep-clone-simple": "^1.1.1",
"deep-freeze": "^0.0.1",
"fuse.js": "^6.0.0",
@@ -183,7 +184,7 @@
"@types/sortablejs": "^1",
"@types/tar": "^6",
"@types/webspeechapi": "^0.0.29",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.44.0",
"@web/dev-server": "^0.0.24",
"@web/dev-server-rollup": "^0.2.11",
@@ -200,7 +201,7 @@
"eslint-plugin-lit": "^1.6.1",
"eslint-plugin-unused-imports": "^1.1.5",
"eslint-plugin-wc": "^1.3.2",
"fancy-log": "^1.3.3",
"fancy-log": "^2.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.2.0",
"gulp": "^4.0.2",
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "home-assistant-frontend"
version = "20221213.0"
version = "20230102.0"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
+2 -11
View File
@@ -1,5 +1,3 @@
import { hex2rgb } from "./convert-color";
export const THEME_COLORS = new Set([
"primary",
"accent",
@@ -27,16 +25,9 @@ export const THEME_COLORS = new Set([
"white",
]);
export function computeRgbColor(color: string): string {
export function computeCssColor(color: string): string {
if (THEME_COLORS.has(color)) {
return `var(--rgb-${color}-color)`;
}
if (color.startsWith("#")) {
try {
return hex2rgb(color).join(", ");
} catch (err) {
return "";
}
return `rgb(var(--rgb-${color}-color))`;
}
return color;
}
+6
View File
@@ -21,6 +21,8 @@ import {
mdiCommentAlert,
mdiCounter,
mdiCurrentAc,
mdiDatabase,
mdiEarHearing,
mdiEye,
mdiFan,
mdiFlash,
@@ -57,6 +59,7 @@ import {
mdiThermometerLines,
mdiThermostat,
mdiTimerOutline,
mdiTransmissionTower,
mdiVideo,
mdiWater,
mdiWaterPercent,
@@ -133,6 +136,8 @@ export const FIXED_DEVICE_CLASS_ICONS = {
carbon_dioxide: mdiMoleculeCo2,
carbon_monoxide: mdiMoleculeCo,
current: mdiCurrentAc,
data_rate: mdiTransmissionTower,
data_size: mdiDatabase,
date: mdiCalendar,
distance: mdiArrowLeftRight,
duration: mdiProgressClock,
@@ -158,6 +163,7 @@ export const FIXED_DEVICE_CLASS_ICONS = {
pressure: mdiGauge,
reactive_power: mdiFlash,
signal_strength: mdiWifi,
sound_pressure: mdiEarHearing,
speed: mdiSpeedometer,
sulphur_dioxide: mdiMolecule,
temperature: mdiThermometer,
+10
View File
@@ -0,0 +1,10 @@
export const alertColor = (state?: string): string | undefined => {
switch (state) {
case "on":
return "alert";
case "off":
return "alert-off";
default:
return undefined;
}
};
@@ -6,6 +6,7 @@ const ALERTING_DEVICE_CLASSES = new Set([
"carbon_monoxide",
"gas",
"heat",
"lock",
"moisture",
"problem",
"safety",
+1
View File
@@ -3,6 +3,7 @@ import { HvacAction } from "../../../data/climate";
export const CLIMATE_HVAC_ACTION_COLORS: Record<HvacAction, string> = {
cooling: "var(--rgb-state-climate-cool-color)",
drying: "var(--rgb-state-climate-dry-color)",
fan: "var(--rgb-state-climate-fan-only-color)",
heating: "var(--rgb-state-climate-heat-color)",
idle: "var(--rgb-state-climate-idle-color)",
off: "var(--rgb-state-climate-off-color)",
@@ -0,0 +1,52 @@
import { HassEntity } from "home-assistant-js-websocket";
import { EntityRegistryEntry } from "../../data/entity_registry";
import { HomeAssistant } from "../../types";
import { LocalizeFunc } from "../translations/localize";
import { computeDomain } from "./compute_domain";
export const computeAttributeValueDisplay = (
localize: LocalizeFunc,
stateObj: HassEntity,
entities: HomeAssistant["entities"],
attribute: string,
value?: any
): string => {
const entityId = stateObj.entity_id;
const attributeValue =
value !== undefined ? value : stateObj.attributes[attribute];
const domain = computeDomain(entityId);
const entity = entities[entityId] as EntityRegistryEntry | undefined;
const translationKey = entity?.translation_key;
return (
(translationKey &&
localize(
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.state.${attributeValue}`
)) ||
localize(
`component.${domain}.state_attributes._.${attribute}.state.${attributeValue}`
) ||
attributeValue
);
};
export const computeAttributeNameDisplay = (
localize: LocalizeFunc,
stateObj: HassEntity,
entities: HomeAssistant["entities"],
attribute: string
): string => {
const entityId = stateObj.entity_id;
const domain = computeDomain(entityId);
const entity = entities[entityId] as EntityRegistryEntry | undefined;
const translationKey = entity?.translation_key;
return (
(translationKey &&
localize(
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.name`
)) ||
localize(`component.${domain}.state_attributes._.${attribute}.name`) ||
attribute
);
};
+2 -2
View File
@@ -2,7 +2,7 @@ import { HassEntity } from "home-assistant-js-websocket";
import { computeStateDomain } from "./compute_state_domain";
import { UNAVAILABLE_STATES } from "../../data/entity";
const FIXED_DOMAIN_STATES = {
export const FIXED_DOMAIN_STATES = {
alarm_control_panel: [
"armed_away",
"armed_custom_bypass",
@@ -57,7 +57,7 @@ const FIXED_DOMAIN_STATES = {
"windy-variant",
"windy",
],
};
} as const;
const FIXED_DOMAIN_ATTRIBUTE_STATES = {
alarm_control_panel: {
+16 -5
View File
@@ -1,5 +1,5 @@
import { HassEntity } from "home-assistant-js-websocket";
import { OFF_STATES, UNAVAILABLE } from "../../data/entity";
import { isUnavailableState, OFF, UNAVAILABLE } from "../../data/entity";
import { computeDomain } from "./compute_domain";
export function stateActive(stateObj: HassEntity, state?: string): boolean {
@@ -10,7 +10,15 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
return compareState !== UNAVAILABLE;
}
if (OFF_STATES.includes(compareState)) {
if (isUnavailableState(compareState)) {
return false;
}
// The "off" check is relevant for most domains, but there are exceptions
// such as "alert" where "off" is still a somewhat active state and
// therefore gets a custom color and "idle" is instead the state that
// matches what most other domains consider inactive.
if (compareState === OFF && domain !== "alert") {
return false;
}
@@ -18,8 +26,11 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
switch (domain) {
case "alarm_control_panel":
return compareState !== "disarmed";
case "alert":
// "on" and "off" are active, as "off" just means alert was acknowledged but is still active
return compareState !== "idle";
case "cover":
return !["closed", "closing"].includes(compareState);
return compareState !== "closed";
case "device_tracker":
case "person":
return compareState !== "not_home";
@@ -37,7 +48,7 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
return compareState === "active";
case "camera":
return compareState === "streaming";
default:
return true;
}
return true;
}
+4 -1
View File
@@ -2,6 +2,7 @@
import { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE } from "../../data/entity";
import { alarmControlPanelColor } from "./color/alarm_control_panel_color";
import { alertColor } from "./color/alert_color";
import { binarySensorColor } from "./color/binary_sensor_color";
import { climateColor } from "./color/climate_color";
import { lockColor } from "./color/lock_color";
@@ -12,7 +13,6 @@ import { computeDomain } from "./compute_domain";
import { stateActive } from "./state_active";
const STATIC_ACTIVE_COLORED_DOMAIN = new Set([
"alert",
"automation",
"calendar",
"camera",
@@ -65,6 +65,9 @@ export const stateColor = (stateObj: HassEntity, state?: string) => {
case "alarm_control_panel":
return alarmControlPanelColor(compareState);
case "alert":
return alertColor(compareState);
case "binary_sensor":
return binarySensorColor(stateObj, compareState);
@@ -86,7 +86,7 @@ export const protocolIntegrationPicked = async (
"ui.panel.config.integrations.config_flow.missing_zwave_zigbee",
{
integration: "Zigbee",
brand: options?.brand || options?.domain || "Z-Wave",
brand: options?.brand || options?.domain || "Zigbee",
supported_hardware_link: html`<a
href=${documentationUrl(
hass,
+37 -3
View File
@@ -1,4 +1,15 @@
export const stringCompare = (a: string, b: string) => {
import memoizeOne from "memoize-one";
const collator = memoizeOne(
(language: string | undefined) => new Intl.Collator(language)
);
const caseInsensitiveCollator = memoizeOne(
(language: string | undefined) =>
new Intl.Collator(language, { sensitivity: "accent" })
);
const fallbackStringCompare = (a: string, b: string) => {
if (a < b) {
return -1;
}
@@ -9,5 +20,28 @@ export const stringCompare = (a: string, b: string) => {
return 0;
};
export const caseInsensitiveStringCompare = (a: string, b: string) =>
stringCompare(a.toLowerCase(), b.toLowerCase());
export const stringCompare = (
a: string,
b: string,
language: string | undefined = undefined
) => {
// @ts-ignore
if (Intl?.Collator) {
return collator(language).compare(a, b);
}
return fallbackStringCompare(a, b);
};
export const caseInsensitiveStringCompare = (
a: string,
b: string,
language: string | undefined = undefined
) => {
// @ts-ignore
if (Intl?.Collator) {
return caseInsensitiveCollator(language).compare(a, b);
}
return fallbackStringCompare(a.toLowerCase(), b.toLowerCase());
};
+4 -3
View File
@@ -1,9 +1,10 @@
import { css } from "lit";
export const iconColorCSS = css`
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="pending"],
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="arming"],
ha-state-icon[data-active][data-domain="alarm_control_panel"][data-state="triggered"] {
ha-state-icon[data-domain="alarm_control_panel"][data-state="pending"],
ha-state-icon[data-domain="alarm_control_panel"][data-state="arming"],
ha-state-icon[data-domain="alarm_control_panel"][data-state="triggered"],
ha-state-icon[data-domain="lock"][data-state="jammed"] {
animation: pulse 1s infinite;
}
-3
View File
@@ -12,9 +12,6 @@ import { getLocalLanguage } from "../../util/common-translation";
export type LocalizeKeys =
| FlattenObjectKeys<Omit<TranslationDict, "supervisor">>
| `panel.${string}`
| `state.${string}`
| `state_attributes.${string}`
| `state_badge.${string}`
| `ui.card.alarm_control_panel.${string}`
| `ui.card.weather.attributes.${string}`
| `ui.card.weather.cardinal_direction.${string}`
+5 -3
View File
@@ -266,14 +266,16 @@ export const getCountryOptions = memoizeOne((language?: string) => {
value: country,
label: countryDisplayNames ? countryDisplayNames.of(country)! : country,
}));
options.sort((a, b) => caseInsensitiveStringCompare(a.label, b.label));
options.sort((a, b) =>
caseInsensitiveStringCompare(a.label, b.label, language)
);
return options;
});
export const createCountryListEl = () => {
export const createCountryListEl = (language?: string) => {
const list = document.createElement("datalist");
list.id = "countries";
const options = getCountryOptions();
const options = getCountryOptions(language);
for (const country of options) {
const option = document.createElement("option");
option.value = country.value;
+5 -3
View File
@@ -173,14 +173,16 @@ export const getCurrencyOptions = memoizeOne((language?: string) => {
value: currency,
label: currencyDisplayNames ? currencyDisplayNames.of(currency)! : currency,
}));
options.sort((a, b) => caseInsensitiveStringCompare(a.label, b.label));
options.sort((a, b) =>
caseInsensitiveStringCompare(a.label, b.label, language)
);
return options;
});
export const createCurrencyListEl = () => {
export const createCurrencyListEl = (language: string) => {
const list = document.createElement("datalist");
list.id = "currencies";
for (const currency of getCurrencyOptions()) {
for (const currency of getCurrencyOptions(language)) {
const option = document.createElement("option");
option.value = currency.value;
option.innerText = currency.label;
+14 -49
View File
@@ -1,26 +1,15 @@
import "@material/mwc-button/mwc-button";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain";
import { stringCompare } from "../../common/string/compare";
import {
AreaRegistryEntry,
subscribeAreaRegistry,
} from "../../data/area_registry";
import {
DeviceEntityLookup,
DeviceRegistryEntry,
subscribeDeviceRegistry,
} from "../../data/device_registry";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
} from "../../data/entity_registry";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types";
import "../ha-icon-button";
@@ -45,7 +34,7 @@ const rowRenderer: ComboBoxLitRenderer<AreaDevices> = (
</mwc-list-item>`;
@customElement("ha-area-devices-picker")
export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
export class HaAreaDevicesPicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public label?: string;
@@ -82,25 +71,22 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
@state() private _areaPicker = true;
@state() private _devices?: DeviceRegistryEntry[];
@state() private _areas?: AreaRegistryEntry[];
@state() private _entities?: EntityRegistryEntry[];
private _selectedDevices: string[] = [];
private _filteredDevices: DeviceRegistryEntry[] = [];
private _getAreasWithDevices = memoizeOne(
(
devices: DeviceRegistryEntry[],
areas: AreaRegistryEntry[],
entities: EntityRegistryEntry[],
deviceReg: HomeAssistant["devices"],
areas: HomeAssistant["areas"],
entityReg: HomeAssistant["entities"],
includeDomains: this["includeDomains"],
excludeDomains: this["excludeDomains"],
includeDeviceClasses: this["includeDeviceClasses"]
): AreaDevices[] => {
const devices = Object.values(deviceReg);
const entities = Object.values(entityReg);
if (!devices.length) {
return [];
}
@@ -164,11 +150,6 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
this._filteredDevices = inputDevices;
const areaLookup: { [areaId: string]: AreaRegistryEntry } = {};
for (const area of areas) {
areaLookup[area.area_id] = area;
}
const devicesByArea: DevicesByArea = {};
for (const device of inputDevices) {
@@ -177,7 +158,7 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
if (!(areaId in devicesByArea)) {
devicesByArea[areaId] = {
id: areaId,
name: areaLookup[areaId].name,
name: areas[areaId].name,
devices: [],
};
}
@@ -189,7 +170,8 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
.sort((a, b) =>
stringCompare(
devicesByArea[a].name || "",
devicesByArea[b].name || ""
devicesByArea[b].name || "",
this.hass.locale.language
)
)
.map((key) => devicesByArea[key]);
@@ -198,20 +180,6 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
}
);
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
this._devices = devices;
}),
subscribeAreaRegistry(this.hass.connection!, (areas) => {
this._areas = areas;
}),
subscribeEntityRegistry(this.hass.connection!, (entities) => {
this._entities = entities;
}),
];
}
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (changedProps.has("area") && this.area) {
@@ -230,13 +198,10 @@ export class HaAreaDevicesPicker extends SubscribeMixin(LitElement) {
}
protected render(): TemplateResult {
if (!this._devices || !this._areas || !this._entities) {
return html``;
}
const areas = this._getAreasWithDevices(
this._devices,
this._areas,
this._entities,
this.hass.devices,
this.hass.areas,
this.hass.entities,
this.includeDomains,
this.excludeDomains,
this.includeDeviceClasses
+36 -50
View File
@@ -1,5 +1,4 @@
import "@material/mwc-list/mwc-list-item";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -7,21 +6,15 @@ import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain";
import { stringCompare } from "../../common/string/compare";
import {
AreaRegistryEntry,
subscribeAreaRegistry,
} from "../../data/area_registry";
import {
computeDeviceName,
DeviceEntityLookup,
DeviceRegistryEntry,
subscribeDeviceRegistry,
} from "../../data/device_registry";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
} from "../../data/entity_registry";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types";
import "../ha-combo-box";
@@ -45,7 +38,7 @@ const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item
</mwc-list-item>`;
@customElement("ha-device-picker")
export class HaDevicePicker extends SubscribeMixin(LitElement) {
export class HaDevicePicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public label?: string;
@@ -54,12 +47,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
@property() public helper?: string;
@property() public devices?: DeviceRegistryEntry[];
@property() public areas?: AreaRegistryEntry[];
@property() public entities?: EntityRegistryEntry[];
/**
* Show only devices with entities from specific domains.
* @type {Array}
@@ -84,6 +71,14 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
@property({ type: Array, attribute: "include-device-classes" })
public includeDeviceClasses?: string[];
/**
* List of devices to be excluded.
* @type {Array}
* @attr exclude-devices
*/
@property({ type: Array, attribute: "exclude-devices" })
public excludeDevices?: string[];
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ type: Boolean }) public disabled?: boolean;
@@ -98,14 +93,18 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
private _getDevices = memoizeOne(
(
devices: DeviceRegistryEntry[],
areas: AreaRegistryEntry[],
entities: EntityRegistryEntry[],
deviceReg: HomeAssistant["devices"],
areas: HomeAssistant["areas"],
entityReg: HomeAssistant["entities"],
includeDomains: this["includeDomains"],
excludeDomains: this["excludeDomains"],
includeDeviceClasses: this["includeDeviceClasses"],
deviceFilter: this["deviceFilter"]
deviceFilter: this["deviceFilter"],
excludeDevices: this["excludeDevices"]
): Device[] => {
const devices = Object.values(deviceReg);
const entities = Object.values(entityReg);
if (!devices.length) {
return [
{
@@ -129,12 +128,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
deviceEntityLookup[entity.device_id].push(entity);
}
}
const areaLookup: { [areaId: string]: AreaRegistryEntry } = {};
for (const area of areas) {
areaLookup[area.area_id] = area;
}
let inputDevices = devices.filter(
(device) => device.id === this.value || !device.disabled_by
);
@@ -164,6 +157,12 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
});
}
if (excludeDevices) {
inputDevices = inputDevices.filter(
(device) => !excludeDevices!.includes(device.id)
);
}
if (includeDeviceClasses) {
inputDevices = inputDevices.filter((device) => {
const devEntities = deviceEntityLookup[device.id];
@@ -199,8 +198,8 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
deviceEntityLookup[device.id]
),
area:
device.area_id && areaLookup[device.area_id]
? areaLookup[device.area_id].name
device.area_id && device.area_id in areas
? areas[device.area_id].name
: this.hass.localize("ui.components.device-picker.no_area"),
}));
if (!outputDevices.length) {
@@ -216,7 +215,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
return outputDevices;
}
return outputDevices.sort((a, b) =>
stringCompare(a.name || "", b.name || "")
stringCompare(a.name || "", b.name || "", this.hass.locale.language)
);
}
);
@@ -231,34 +230,21 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
await this.comboBox?.focus();
}
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
this.devices = devices;
}),
subscribeAreaRegistry(this.hass.connection!, (areas) => {
this.areas = areas;
}),
subscribeEntityRegistry(this.hass.connection!, (entities) => {
this.entities = entities;
}),
];
}
protected updated(changedProps: PropertyValues) {
if (
(!this._init && this.devices && this.areas && this.entities) ||
!this._init ||
(this._init && changedProps.has("_opened") && this._opened)
) {
this._init = true;
(this.comboBox as any).items = this._getDevices(
this.devices!,
this.areas!,
this.entities!,
this.hass.devices,
this.hass.areas,
this.hass.entities,
this.includeDomains,
this.excludeDomains,
this.includeDeviceClasses,
this.deviceFilter
this.deviceFilter,
this.excludeDevices
);
}
}
+4 -2
View File
@@ -174,7 +174,8 @@ export class HaEntityPicker extends LitElement {
.sort((entityA, entityB) =>
caseInsensitiveStringCompare(
entityA.friendly_name,
entityB.friendly_name
entityB.friendly_name,
this.hass.locale.language
)
);
}
@@ -205,7 +206,8 @@ export class HaEntityPicker extends LitElement {
.sort((entityA, entityB) =>
caseInsensitiveStringCompare(
entityA.friendly_name,
entityB.friendly_name
entityB.friendly_name,
this.hass.locale.language
)
);
+2 -2
View File
@@ -12,7 +12,7 @@ import { property, state } from "lit/decorators";
import { STATES_OFF } from "../../common/const";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { UNAVAILABLE, UNAVAILABLE_STATES, UNKNOWN } from "../../data/entity";
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { forwardHaptic } from "../../data/haptics";
import { HomeAssistant } from "../../types";
import "../ha-formfield";
@@ -22,7 +22,7 @@ import "../ha-switch";
const isOn = (stateObj?: HassEntity) =>
stateObj !== undefined &&
!STATES_OFF.includes(stateObj.state) &&
!UNAVAILABLE_STATES.includes(stateObj.state);
!isUnavailableState(stateObj.state);
export class HaEntityToggle extends LitElement {
// hass is not a property so that we only re-render on stateObj changes
+37 -14
View File
@@ -10,21 +10,45 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { arrayLiteralIncludes } from "../../common/array/literal-includes";
import secondsToDuration from "../../common/datetime/seconds_to_duration";
import { computeStateDisplay } from "../../common/entity/compute_state_display";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
import {
formatNumber,
getNumberFormatOptions,
isNumericState,
} from "../../common/number/format_number";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { timerTimeRemaining } from "../../data/timer";
import { HomeAssistant } from "../../types";
import "../ha-label-badge";
import "../ha-state-icon";
// Define the domains whose states have special truncated strings
const TRUNCATED_DOMAINS = [
"alarm_control_panel",
"device_tracker",
"person",
] as const satisfies ReadonlyArray<keyof typeof FIXED_DOMAIN_STATES>;
type TruncatedDomain = typeof TRUNCATED_DOMAINS[number];
type TruncatedKey = {
[T in TruncatedDomain]: `${T}.${typeof FIXED_DOMAIN_STATES[T][number]}`;
}[TruncatedDomain];
const getTruncatedKey = (domainKey: string, stateKey: string) => {
if (
arrayLiteralIncludes(TRUNCATED_DOMAINS)(domainKey) &&
arrayLiteralIncludes(FIXED_DOMAIN_STATES[domainKey])(stateKey)
) {
return `${domainKey}.${stateKey}` as TruncatedKey;
}
return null;
};
@customElement("ha-state-label-badge")
export class HaStateLabelBadge extends LitElement {
@property({ attribute: false }) public hass?: HomeAssistant;
@@ -186,19 +210,18 @@ export class HaStateLabelBadge extends LitElement {
}
}
private _computeLabel(domain, entityState, _timerTimeRemaining) {
if (
entityState.state === UNAVAILABLE ||
["device_tracker", "alarm_control_panel", "person"].includes(domain)
) {
// Localize the state with a special state_badge namespace, which has variations of
// the state translations that are truncated to fit within the badge label. Translations
// are only added for device_tracker, alarm_control_panel and person.
return (
this.hass!.localize(`state_badge.${domain}.${entityState.state}`) ||
this.hass!.localize(`state_badge.default.${entityState.state}`) ||
entityState.state
);
private _computeLabel(
domain: string,
entityState: HassEntity,
_timerTimeRemaining = 0
) {
// For unavailable states or certain domains, use a special translation that is truncated to fit within the badge label
if (isUnavailableState(entityState.state)) {
return this.hass!.localize(`state_badge.default.${entityState.state}`);
}
const domainStateKey = getTruncatedKey(domain, entityState.state);
if (domainStateKey) {
return this.hass!.localize(`state_badge.${domainStateKey}`);
}
if (domain === "timer") {
return secondsToDuration(_timerTimeRemaining);
+3 -1
View File
@@ -177,7 +177,9 @@ export class HaStatisticPicker extends LitElement {
}
if (output.length > 1) {
output.sort((a, b) => stringCompare(a.name || "", b.name || ""));
output.sort((a, b) =>
stringCompare(a.name || "", b.name || "", this.hass.locale.language)
);
}
output.push({
+7 -3
View File
@@ -32,6 +32,8 @@ export class StateBadge extends LitElement {
@property({ type: Boolean }) public stateColor?: boolean;
@property() public color?: string;
@property({ type: Boolean, reflect: true, attribute: "icon" })
private _showIcon = true;
@@ -59,11 +61,9 @@ export class StateBadge extends LitElement {
}
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
const active = this._stateColor && stateObj ? stateActive(stateObj) : false;
return html`<ha-state-icon
style=${styleMap(this._iconStyle)}
?data-active=${active}
data-domain=${ifDefined(domain)}
data-state=${ifDefined(stateObj?.state)}
.icon=${this.overrideIcon}
@@ -77,7 +77,8 @@ export class StateBadge extends LitElement {
!changedProps.has("stateObj") &&
!changedProps.has("overrideImage") &&
!changedProps.has("overrideIcon") &&
!changedProps.has("stateColor")
!changedProps.has("stateColor") &&
!changedProps.has("color")
) {
return;
}
@@ -108,6 +109,9 @@ export class StateBadge extends LitElement {
}
hostStyle.backgroundImage = `url(${imageUrl})`;
this._showIcon = false;
} else if (this.color) {
// Externally provided overriding color wins over state color
iconStyle.color = this.color;
} else if (this._stateColor && stateActive(stateObj)) {
const color = stateColorCss(stateObj);
if (color) {
+3
View File
@@ -19,6 +19,8 @@ class StateInfo extends LitElement {
// property used only in CSS
@property({ type: Boolean, reflect: true }) public rtl = false;
@property() public color?: string;
protected render(): TemplateResult {
if (!this.hass || !this.stateObj) {
return html``;
@@ -29,6 +31,7 @@ class StateInfo extends LitElement {
return html`<state-badge
.stateObj=${this.stateObj}
.stateColor=${true}
.color=${this.color}
></state-badge>
<div class="info">
<div class="name" .title=${name} .inDialog=${this.inDialog}>
+8 -2
View File
@@ -16,7 +16,11 @@ const rowRenderer: ComboBoxLitRenderer<HassioAddonInfo> = (
<span>${item.name}</span>
<span slot="secondary">${item.slug}</span>
${item.icon
? html`<img slot="graphic" .src="/api/hassio/addons/${item.slug}/icon" />`
? html`<img
alt=""
slot="graphic"
.src="/api/hassio/addons/${item.slug}/icon"
/>`
: ""}
</mwc-list-item>`;
@@ -80,7 +84,9 @@ class HaAddonPicker extends LitElement {
const addonsInfo = await fetchHassioAddonsInfo(this.hass);
this._addons = addonsInfo.addons
.filter((addon) => addon.version)
.sort((a, b) => stringCompare(a.name, b.name));
.sort((a, b) =>
stringCompare(a.name, b.name, this.hass.locale.language)
);
} else {
showAlertDialog(this, {
title: this.hass.localize(
+23 -4
View File
@@ -73,6 +73,14 @@ export class HaAreaPicker extends LitElement {
@property({ type: Array, attribute: "include-device-classes" })
public includeDeviceClasses?: string[];
/**
* List of areas to be excluded.
* @type {Array}
* @attr exclude-areas
*/
@property({ type: Array, attribute: "exclude-areas" })
public excludeAreas?: string[];
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property() public entityFilter?: (entity: EntityRegistryEntry) => boolean;
@@ -109,7 +117,8 @@ export class HaAreaPicker extends LitElement {
includeDeviceClasses: this["includeDeviceClasses"],
deviceFilter: this["deviceFilter"],
entityFilter: this["entityFilter"],
noAdd: this["noAdd"]
noAdd: this["noAdd"],
excludeAreas: this["excludeAreas"]
): AreaRegistryEntry[] => {
if (!areas.length) {
return [
@@ -235,6 +244,12 @@ export class HaAreaPicker extends LitElement {
outputAreas = areas.filter((area) => areaIds!.includes(area.area_id));
}
if (excludeAreas) {
outputAreas = outputAreas.filter(
(area) => !excludeAreas!.includes(area.area_id)
);
}
if (!outputAreas.length) {
outputAreas = [
{
@@ -264,7 +279,7 @@ export class HaAreaPicker extends LitElement {
(this._init && changedProps.has("_opened") && this._opened)
) {
this._init = true;
(this.comboBox as any).items = this._getAreas(
const areas = this._getAreas(
Object.values(this.hass.areas),
Object.values(this.hass.devices),
Object.values(this.hass.entities),
@@ -273,8 +288,11 @@ export class HaAreaPicker extends LitElement {
this.includeDeviceClasses,
this.deviceFilter,
this.entityFilter,
this.noAdd
this.noAdd,
this.excludeAreas
);
(this.comboBox as any).items = areas;
(this.comboBox as any).filteredItems = areas;
}
}
@@ -384,7 +402,8 @@ export class HaAreaPicker extends LitElement {
this.includeDeviceClasses,
this.deviceFilter,
this.entityFilter,
this.noAdd
this.noAdd,
this.excludeAreas
);
await this.updateComplete;
await this.comboBox.updateComplete;
+1 -2
View File
@@ -2,13 +2,12 @@ import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import type { EntityRegistryEntry } from "../data/entity_registry";
import { SubscribeMixin } from "../mixins/subscribe-mixin";
import type { HomeAssistant } from "../types";
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
import "./ha-area-picker";
@customElement("ha-areas-picker")
export class HaAreasPicker extends SubscribeMixin(LitElement) {
export class HaAreasPicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public label?: string;
+3 -1
View File
@@ -272,7 +272,8 @@ export class HaBarSlider extends LitElement {
:host {
display: block;
--slider-bar-color: rgb(var(--rgb-primary-color));
--slider-bar-background: rgba(var(--rgb-disabled-color), 0.2);
--slider-bar-background: rgb(var(--rgb-disabled-color));
--slider-bar-background-opacity: 0.2;
--slider-bar-thickness: 40px;
--slider-bar-border-radius: 10px;
height: var(--slider-bar-thickness);
@@ -301,6 +302,7 @@ export class HaBarSlider extends LitElement {
height: 100%;
width: 100%;
background: var(--slider-bar-background);
opacity: var(--slider-bar-background-opacity);
}
.slider .slider-track-bar {
--border-radius: var(--slider-bar-border-radius);
+19 -8
View File
@@ -74,6 +74,7 @@ export class HaBarSwitch extends LitElement {
protected render(): TemplateResult {
return html`
<div class="switch">
<div class="background"></div>
<div class="button" aria-hidden="true">
${this.checked
? this.pathOn
@@ -91,8 +92,9 @@ export class HaBarSwitch extends LitElement {
return css`
:host {
display: block;
--switch-bar-color-on: var(--rgb-primary-color);
--switch-bar-color-off: var(--rgb-disabled-color);
--switch-bar-on-color: rgb(var(--rgb-primary-color));
--switch-bar-off-color: rgb(var(--rgb-disabled-color));
--switch-bar-background-opacity: 0.2;
--switch-bar-thickness: 40px;
--switch-bar-border-radius: 12px;
--switch-bar-padding: 4px;
@@ -109,11 +111,20 @@ export class HaBarSwitch extends LitElement {
height: 100%;
width: 100%;
border-radius: var(--switch-bar-border-radius);
background-color: rgba(var(--switch-bar-color-off), 0.3);
overflow: hidden;
padding: var(--switch-bar-padding);
transition: background-color 180ms ease-in-out;
display: flex;
}
.switch .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: var(--switch-bar-off-color);
transition: background-color 180ms ease-in-out;
opacity: var(--switch-bar-background-opacity);
}
.switch .button {
width: 50%;
height: 100%;
@@ -123,18 +134,18 @@ export class HaBarSwitch extends LitElement {
);
transition: transform 180ms ease-in-out,
background-color 180ms ease-in-out;
background-color: rgb(var(--switch-bar-color-off));
background-color: var(--switch-bar-off-color);
color: white;
display: flex;
align-items: center;
justify-content: center;
}
:host([checked]) .switch {
background-color: rgba(var(--switch-bar-color-on), 0.3);
:host([checked]) .switch .background {
background-color: var(--switch-bar-on-color);
}
:host([checked]) .switch .button {
transform: translateX(100%);
background-color: rgb(var(--switch-bar-color-on));
background-color: var(--switch-bar-on-color);
}
:host([reversed]) .switch {
flex-direction: row-reverse;
+3
View File
@@ -266,6 +266,9 @@ export class HaBaseTimeInput extends LitElement {
seconds: this.seconds,
milliseconds: this.milliseconds,
};
if (this.enableDay) {
value.days = this.days;
}
if (this.format === 12) {
value.amPm = this.amPm;
}
+3 -1
View File
@@ -46,7 +46,9 @@ class HaBluePrintPicker extends LitElement {
...(blueprint as Blueprint).metadata,
path,
}));
return result.sort((a, b) => stringCompare(a.name, b.name));
return result.sort((a, b) =>
stringCompare(a.name, b.name, this.hass!.locale.language)
);
});
protected render(): TemplateResult {
+24 -14
View File
@@ -1,37 +1,41 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { computeAttributeValueDisplay } from "../common/entity/compute_attribute_display";
import { computeStateDisplay } from "../common/entity/compute_state_display";
import { formatNumber } from "../common/number/format_number";
import { CLIMATE_PRESET_NONE } from "../data/climate";
import { UNAVAILABLE_STATES } from "../data/entity";
import { ClimateEntity, CLIMATE_PRESET_NONE } from "../data/climate";
import { isUnavailableState } from "../data/entity";
import type { HomeAssistant } from "../types";
@customElement("ha-climate-state")
class HaClimateState extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public stateObj!: HassEntity;
@property({ attribute: false }) public stateObj!: ClimateEntity;
protected render(): TemplateResult {
const currentStatus = this._computeCurrentStatus();
return html`<div class="target">
${!UNAVAILABLE_STATES.includes(this.stateObj.state)
${!isUnavailableState(this.stateObj.state)
? html`<span class="state-label">
${this._localizeState()}
${this.stateObj.attributes.preset_mode &&
this.stateObj.attributes.preset_mode !== CLIMATE_PRESET_NONE
? html`-
${this.hass.localize(
`state_attributes.climate.preset_mode.${this.stateObj.attributes.preset_mode}`
) || this.stateObj.attributes.preset_mode}`
${computeAttributeValueDisplay(
this.hass.localize,
this.stateObj,
this.hass.entities,
"preset_mode"
)}`
: ""}
</span>
<div class="unit">${this._computeTarget()}</div>`
: this._localizeState()}
</div>
${currentStatus && !UNAVAILABLE_STATES.includes(this.stateObj.state)
${currentStatus && !isUnavailableState(this.stateObj.state)
? html`<div class="current">
${this.hass.localize("ui.card.climate.currently")}:
<div class="unit">${currentStatus}</div>
@@ -109,17 +113,23 @@ class HaClimateState extends LitElement {
}
private _localizeState(): string {
if (UNAVAILABLE_STATES.includes(this.stateObj.state)) {
if (isUnavailableState(this.stateObj.state)) {
return this.hass.localize(`state.default.${this.stateObj.state}`);
}
const stateString = this.hass.localize(
`component.climate.state._.${this.stateObj.state}`
const stateString = computeStateDisplay(
this.hass.localize,
this.stateObj,
this.hass.locale,
this.hass.entities
);
return this.stateObj.attributes.hvac_action
? `${this.hass.localize(
`state_attributes.climate.hvac_action.${this.stateObj.attributes.hvac_action}`
? `${computeAttributeValueDisplay(
this.hass.localize,
this.stateObj,
this.hass.entities,
"hvac_action"
)} (${stateString})`
: stateString;
}
+3 -1
View File
@@ -59,6 +59,7 @@ class HaConfigEntryPicker extends LitElement {
>
<span slot="secondary">${item.localized_domain_name}</span>
<img
alt=""
slot="graphic"
src=${brandsUrl({
domain: item.domain,
@@ -121,7 +122,8 @@ class HaConfigEntryPicker extends LitElement {
.sort((conf1, conf2) =>
caseInsensitiveStringCompare(
conf1.localized_domain_name + conf1.title,
conf2.localized_domain_name + conf2.title
conf2.localized_domain_name + conf2.title,
this.hass.locale.language
)
);
});
+11 -1
View File
@@ -3,10 +3,12 @@ import { styles } from "@material/mwc-dialog/mwc-dialog.css";
import { mdiClose } from "@mdi/js";
import { css, html, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import type { HomeAssistant } from "../types";
import { FOCUS_TARGET } from "../dialogs/make-dialog-manager";
import type { HomeAssistant } from "../types";
import "./ha-icon-button";
const SUPPRESS_DEFAULT_PRESS_SELECTOR = ["button"];
export const createCloseHeading = (
hass: HomeAssistant,
title: string | TemplateResult
@@ -32,6 +34,14 @@ export class HaDialog extends DialogBase {
return html`<slot name="heading"> ${super.renderHeading()} </slot>`;
}
protected firstUpdated(): void {
super.firstUpdated();
this.suppressDefaultPressSelector = [
this.suppressDefaultPressSelector,
SUPPRESS_DEFAULT_PRESS_SELECTOR,
].join(", ");
}
static override styles = [
styles,
css`
@@ -67,6 +67,9 @@ export class HaFormInteger extends LitElement implements HaFormElement {
@change=${this._valueChanged}
></ha-slider>
</div>
${this.helper
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
: ""}
</div>
`;
}
+2 -2
View File
@@ -85,7 +85,7 @@ export class HaForm extends LitElement implements HaFormElement {
.selector=${item.selector}
.value=${getValue(this.data, item)}
.label=${this._computeLabel(item, this.data)}
.disabled=${item.disabled || this.disabled}
.disabled=${item.disabled || this.disabled || false}
.helper=${this._computeHelper(item)}
.required=${item.required || false}
.context=${this._generateContext(item)}
@@ -95,7 +95,7 @@ export class HaForm extends LitElement implements HaFormElement {
data: getValue(this.data, item),
label: this._computeLabel(item, this.data),
helper: this._computeHelper(item),
disabled: this.disabled || item.disabled,
disabled: this.disabled || item.disabled || false,
hass: this.hass,
computeLabel: this.computeLabel,
computeHelper: this.computeHelper,
+10 -34
View File
@@ -1,4 +1,4 @@
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
import { HassEntity } from "home-assistant-js-websocket";
import {
css,
CSSResultGroup,
@@ -9,23 +9,16 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import {
AreaRegistryEntry,
subscribeAreaRegistry,
} from "../data/area_registry";
import { AreaRegistryEntry } from "../data/area_registry";
import { ConfigEntry, getConfigEntries } from "../data/config_entries";
import {
DeviceRegistryEntry,
subscribeDeviceRegistry,
} from "../data/device_registry";
import { DeviceRegistryEntry } from "../data/device_registry";
import { SceneEntity } from "../data/scene";
import { findRelated, ItemType, RelatedResult } from "../data/search";
import { SubscribeMixin } from "../mixins/subscribe-mixin";
import { HomeAssistant } from "../types";
import "./ha-switch";
@customElement("ha-related-items")
export class HaRelatedItems extends SubscribeMixin(LitElement) {
export class HaRelatedItems extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public itemType!: ItemType;
@@ -34,23 +27,8 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
@state() private _entries?: ConfigEntry[];
@state() private _devices?: DeviceRegistryEntry[];
@state() private _areas?: AreaRegistryEntry[];
@state() private _related?: RelatedResult;
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeDeviceRegistry(this.hass.connection!, (devices) => {
this._devices = devices;
}),
subscribeAreaRegistry(this.hass.connection!, (areas) => {
this._areas = areas;
}),
];
}
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
getConfigEntries(this.hass).then((configEntries) => {
@@ -104,11 +82,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
`;
})
: ""}
${this._related.device && this._devices
${this._related.device
? this._related.device.map((relatedDeviceId) => {
const device: DeviceRegistryEntry | undefined = this._devices!.find(
(dev) => dev.id === relatedDeviceId
);
const device: DeviceRegistryEntry | undefined =
this.hass.devices[relatedDeviceId];
if (!device) {
return "";
}
@@ -125,11 +102,10 @@ export class HaRelatedItems extends SubscribeMixin(LitElement) {
`;
})
: ""}
${this._related.area && this._areas
${this._related.area
? this._related.area.map((relatedAreaId) => {
const area: AreaRegistryEntry | undefined = this._areas!.find(
(ar) => ar.area_id === relatedAreaId
);
const area: AreaRegistryEntry | undefined =
this.hass.areas[relatedAreaId];
if (!area) {
return "";
}
+13 -13
View File
@@ -1,13 +1,10 @@
import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
import { HassEntity } from "home-assistant-js-websocket";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import type { DeviceRegistryEntry } from "../../data/device_registry";
import { getDeviceIntegrationLookup } from "../../data/device_registry";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
} from "../../data/entity_registry";
import { EntityRegistryEntry } from "../../data/entity_registry";
import {
EntitySources,
fetchEntitySourcesWithCache,
@@ -17,13 +14,12 @@ import {
filterSelectorDevices,
filterSelectorEntities,
} from "../../data/selector";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import { HomeAssistant } from "../../types";
import "../ha-area-picker";
import "../ha-areas-picker";
@customElement("ha-selector-area")
export class HaAreaSelector extends SubscribeMixin(LitElement) {
export class HaAreaSelector extends LitElement {
@property() public hass!: HomeAssistant;
@property() public selector!: AreaSelector;
@@ -44,12 +40,16 @@ export class HaAreaSelector extends SubscribeMixin(LitElement) {
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeEntityRegistry(this.hass.connection!, (entities) => {
this._entities = entities.filter((entity) => entity.device_id !== null);
}),
];
protected willUpdate(changedProperties: PropertyValues): void {
if (
changedProperties.has("hass") &&
(changedProperties.get("hass") as HomeAssistant | undefined)?.entities !==
this.hass.entities
) {
this._entities = Object.values(this.hass.entities).filter(
(entity) => entity.device_id !== null
);
}
}
protected updated(changedProperties: PropertyValues): void {
@@ -88,6 +88,10 @@ export class HaSelectSelector extends LitElement {
const value =
!this.value || this.value === "" ? [] : (this.value as string[]);
const optionItems = options.filter(
(option) => !option.disabled && !value?.includes(option.value)
);
return html`
${value?.length
? html`<ha-chip-set>
@@ -118,11 +122,11 @@ export class HaSelectSelector extends LitElement {
.disabled=${this.disabled}
.required=${this.required && !value.length}
.value=${this._filter}
.filteredItems=${options.filter(
(option) => !option.disabled && !value?.includes(option.value)
)}
.items=${optionItems}
.allowCustomValue=${this.selector.select.custom_value ?? false}
@filter-changed=${this._filterChanged}
@value-changed=${this._comboBoxValueChanged}
@opened-changed=${this._openedChanged}
></ha-combo-box>
`;
}
@@ -130,11 +134,14 @@ export class HaSelectSelector extends LitElement {
if (this.selector.select?.custom_value) {
if (
this.value !== undefined &&
!Array.isArray(this.value) &&
!options.find((option) => option.value === this.value)
) {
options.unshift({ value: this.value, label: this.value });
}
const optionItems = options.filter((option) => !option.disabled);
return html`
<ha-combo-box
item-value-path="value"
@@ -144,10 +151,11 @@ export class HaSelectSelector extends LitElement {
.helper=${this.helper}
.disabled=${this.disabled}
.required=${this.required}
.items=${options.filter((item) => !item.disabled)}
.items=${optionItems}
.value=${this.value}
@filter-changed=${this._filterChanged}
@value-changed=${this._comboBoxValueChanged}
@opened-changed=${this._openedChanged}
></ha-combo-box>
`;
}
@@ -190,7 +198,7 @@ export class HaSelectSelector extends LitElement {
private _valueChanged(ev) {
ev.stopPropagation();
const value = ev.detail?.value || ev.target.value;
if (this.disabled || !value) {
if (this.disabled || value === undefined) {
return;
}
fireEvent(this, "value-changed", {
@@ -271,13 +279,16 @@ export class HaSelectSelector extends LitElement {
});
}
private _openedChanged(ev?: CustomEvent): void {
if (ev?.detail.value) {
this._filterChanged();
}
}
private _filterChanged(ev?: CustomEvent): void {
this._filter = ev?.detail.value || "";
const filteredItems = this.comboBox.items?.filter((item) => {
if (this.selector.select?.multiple && this.value?.includes(item.value)) {
return false;
}
const label = item.label || item.value;
return label.toLowerCase().includes(this._filter?.toLowerCase());
});
@@ -1,8 +1,4 @@
import {
HassEntity,
HassServiceTarget,
UnsubscribeFunc,
} from "home-assistant-js-websocket";
import { HassEntity, HassServiceTarget } from "home-assistant-js-websocket";
import {
css,
CSSResultGroup,
@@ -17,8 +13,7 @@ import {
DeviceRegistryEntry,
getDeviceIntegrationLookup,
} from "../../data/device_registry";
import type { EntityRegistryEntry } from "../../data/entity_registry";
import { subscribeEntityRegistry } from "../../data/entity_registry";
import { EntityRegistryEntry } from "../../data/entity_registry";
import {
EntitySources,
fetchEntitySourcesWithCache,
@@ -28,12 +23,11 @@ import {
filterSelectorEntities,
TargetSelector,
} from "../../data/selector";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import type { HomeAssistant } from "../../types";
import "../ha-target-picker";
@customElement("ha-selector-target")
export class HaTargetSelector extends SubscribeMixin(LitElement) {
export class HaTargetSelector extends LitElement {
@property() public hass!: HomeAssistant;
@property() public selector!: TargetSelector;
@@ -48,18 +42,8 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
@state() private _entitySources?: EntitySources;
@state() private _entities?: EntityRegistryEntry[];
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
public hassSubscribe(): UnsubscribeFunc[] {
return [
subscribeEntityRegistry(this.hass.connection!, (entities) => {
this._entities = entities.filter((entity) => entity.device_id !== null);
}),
];
}
protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);
if (
@@ -88,12 +72,19 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
.value=${this.value}
.helper=${this.helper}
.deviceFilter=${this._filterDevices}
.entityFilter=${this._filterEntities}
.entityFilter=${this._filterStates}
.entityRegFilter=${this._filterRegEntities}
.includeDeviceClasses=${this.selector.target?.entity?.device_class
? [this.selector.target?.entity.device_class]
: undefined}
.includeDomains=${this.selector.target?.entity?.domain
? [this.selector.target?.entity.domain]
: undefined}
.disabled=${this.disabled}
></ha-target-picker>`;
}
private _filterEntities = (entity: HassEntity): boolean => {
private _filterStates = (entity: HassEntity): boolean => {
if (!this.selector.target?.entity) {
return true;
}
@@ -105,15 +96,26 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
);
};
private _filterRegEntities = (entity: EntityRegistryEntry): boolean => {
if (this.selector.target?.entity?.integration) {
if (entity.platform !== this.selector.target.entity.integration) {
return false;
}
}
return true;
};
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
if (!this.selector.target?.device) {
return true;
}
const deviceIntegrations =
this._entitySources && this._entities
? this._deviceIntegrationLookup(this._entitySources, this._entities)
: undefined;
const deviceIntegrations = this._entitySources
? this._deviceIntegrationLookup(
this._entitySources,
Object.values(this.hass.entities)
)
: undefined;
return filterSelectorDevices(
this.selector.target.device,
+17 -9
View File
@@ -87,7 +87,8 @@ const panelSorter = (
reverseSort: string[],
defaultPanel: string,
a: PanelInfo,
b: PanelInfo
b: PanelInfo,
language: string
) => {
const indexA = reverseSort.indexOf(a.url_path);
const indexB = reverseSort.indexOf(b.url_path);
@@ -97,13 +98,14 @@ const panelSorter = (
}
return -1;
}
return defaultPanelSorter(defaultPanel, a, b);
return defaultPanelSorter(defaultPanel, a, b, language);
};
const defaultPanelSorter = (
defaultPanel: string,
a: PanelInfo,
b: PanelInfo
b: PanelInfo,
language: string
) => {
// Put all the Lovelace at the top.
const aLovelace = a.component_name === "lovelace";
@@ -117,7 +119,7 @@ const defaultPanelSorter = (
}
if (aLovelace && bLovelace) {
return stringCompare(a.title!, b.title!);
return stringCompare(a.title!, b.title!, language);
}
if (aLovelace && !bLovelace) {
return -1;
@@ -139,7 +141,7 @@ const defaultPanelSorter = (
return 1;
}
// both not built in, sort by title
return stringCompare(a.title!, b.title!);
return stringCompare(a.title!, b.title!, language);
};
const computePanels = memoizeOne(
@@ -147,7 +149,8 @@ const computePanels = memoizeOne(
panels: HomeAssistant["panels"],
defaultPanel: HomeAssistant["defaultPanel"],
panelsOrder: string[],
hiddenPanels: string[]
hiddenPanels: string[],
locale: HomeAssistant["locale"]
): [PanelInfo[], PanelInfo[]] => {
if (!panels) {
return [[], []];
@@ -171,8 +174,12 @@ const computePanels = memoizeOne(
const reverseSort = [...panelsOrder].reverse();
beforeSpacer.sort((a, b) => panelSorter(reverseSort, defaultPanel, a, b));
afterSpacer.sort((a, b) => panelSorter(reverseSort, defaultPanel, a, b));
beforeSpacer.sort((a, b) =>
panelSorter(reverseSort, defaultPanel, a, b, locale.language)
);
afterSpacer.sort((a, b) =>
panelSorter(reverseSort, defaultPanel, a, b, locale.language)
);
return [beforeSpacer, afterSpacer];
}
@@ -374,7 +381,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
this.hass.panels,
this.hass.defaultPanel,
this._panelOrder,
this._hiddenPanels
this._hiddenPanels,
this.hass.locale
);
// Show the supervisor as beeing part of configuration
+10 -1
View File
@@ -345,6 +345,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
.entityFilter=${this.entityRegFilter}
.includeDeviceClasses=${this.includeDeviceClasses}
.includeDomains=${this.includeDomains}
.excludeAreas=${ensureArray(this.value?.area_id)}
@value-changed=${this._targetPicked}
></ha-area-picker>
`;
@@ -358,9 +359,9 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
"ui.components.target-picker.add_device_id"
)}
.deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityRegFilter}
.includeDeviceClasses=${this.includeDeviceClasses}
.includeDomains=${this.includeDomains}
.excludeDevices=${ensureArray(this.value?.device_id)}
@value-changed=${this._targetPicked}
></ha-device-picker>
`;
@@ -376,6 +377,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
.entityFilter=${this.entityFilter}
.includeDeviceClasses=${this.includeDeviceClasses}
.includeDomains=${this.includeDomains}
.excludeEntities=${ensureArray(this.value?.entity_id)}
@value-changed=${this._targetPicked}
allow-custom-entity
></ha-entity-picker>
@@ -393,6 +395,13 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
const target = ev.currentTarget;
target.value = "";
this._addMode = undefined;
if (
this.value &&
this.value[target.type] &&
ensureArray(this.value[target.type]).includes(value)
) {
return;
}
fireEvent(this, "value-changed", {
value: this.value
? {
+10 -5
View File
@@ -67,23 +67,28 @@ export class HaLocationsEditor extends LitElement {
private Leaflet?: LeafletModuleType;
private _loadPromise: Promise<boolean | void>;
constructor() {
super();
import("leaflet").then((module) => {
this._loadPromise = import("leaflet").then((module) =>
import("leaflet-draw").then(() => {
this.Leaflet = module.default as LeafletModuleType;
this._updateMarkers();
this.updateComplete.then(() => this.fitMap());
});
});
return this.updateComplete.then(() => this.fitMap());
})
);
}
public fitMap(): void {
this.map.fitMap();
}
public fitMarker(id: string): void {
public async fitMarker(id: string): Promise<void> {
if (!this.Leaflet) {
await this._loadPromise;
}
if (!this.map.leafletMap || !this._locationMarkers) {
return;
}
+32 -16
View File
@@ -23,8 +23,12 @@ import "./ha-entity-marker";
const getEntityId = (entity: string | HaMapEntity): string =>
typeof entity === "string" ? entity : entity.entity_id;
export interface HaMapPathPoint {
point: LatLngTuple;
tooltip: string;
}
export interface HaMapPaths {
points: LatLngTuple[];
points: HaMapPathPoint[];
color?: string;
gradualOpacity?: number;
}
@@ -247,19 +251,21 @@ export class HaMap extends ReactiveElement {
// DRAW point
this._mapPaths.push(
Leaflet!.circleMarker(path.points[pointIndex], {
radius: 3,
color: path.color || darkPrimaryColor,
opacity,
fillOpacity: opacity,
interactive: false,
})
Leaflet!
.circleMarker(path.points[pointIndex].point, {
radius: 3,
color: path.color || darkPrimaryColor,
opacity,
fillOpacity: opacity,
interactive: true,
})
.bindTooltip(path.points[pointIndex].tooltip, { direction: "top" })
);
// DRAW line between this and next point
this._mapPaths.push(
Leaflet!.polyline(
[path.points[pointIndex], path.points[pointIndex + 1]],
[path.points[pointIndex].point, path.points[pointIndex + 1].point],
{
color: path.color || darkPrimaryColor,
opacity,
@@ -275,13 +281,15 @@ export class HaMap extends ReactiveElement {
: undefined;
// DRAW end path point
this._mapPaths.push(
Leaflet!.circleMarker(path.points[pointIndex], {
radius: 3,
color: path.color || darkPrimaryColor,
opacity,
fillOpacity: opacity,
interactive: false,
})
Leaflet!
.circleMarker(path.points[pointIndex].point, {
radius: 3,
color: path.color || darkPrimaryColor,
opacity,
fillOpacity: opacity,
interactive: true,
})
.bindTooltip(path.points[pointIndex].tooltip, { direction: "top" })
);
}
this._mapPaths.forEach((marker) => map.addLayer(marker));
@@ -491,6 +499,14 @@ export class HaMap extends ReactiveElement {
.leaflet-bottom {
z-index: 1 !important;
}
.leaflet-tooltip {
padding: 8px;
font-size: 90%;
background: rgba(80, 80, 80, 0.9) !important;
color: white !important;
border-radius: 4px;
box-shadow: none !important;
}
`;
}
}
@@ -27,8 +27,7 @@ import { until } from "lit/directives/until";
import { fireEvent } from "../../common/dom/fire_event";
import { computeRTLDirection } from "../../common/util/compute_rtl";
import { debounce } from "../../common/util/debounce";
import { getSignedPath } from "../../data/auth";
import { UNAVAILABLE_STATES } from "../../data/entity";
import { isUnavailableState } from "../../data/entity";
import type { MediaPlayerItem } from "../../data/media-player";
import {
browseMediaPlayer,
@@ -248,7 +247,7 @@ export class HaMediaPlayerBrowse extends LitElement {
});
} else if (
err.code === "entity_not_found" &&
UNAVAILABLE_STATES.includes(this.hass.states[this.entityId]?.state)
isUnavailableState(this.hass.states[this.entityId]?.state)
) {
this._setError({
message: this.hass.localize(
@@ -339,7 +338,7 @@ export class HaMediaPlayerBrowse extends LitElement {
: MediaClassBrowserSettings.directory;
const backgroundImage = currentItem.thumbnail
? this._getSignedThumbnail(currentItem.thumbnail).then(
? this._getThumbnailURLorBase64(currentItem.thumbnail).then(
(value) => `url(${value})`
)
: "none";
@@ -550,7 +549,7 @@ export class HaMediaPlayerBrowse extends LitElement {
private _renderGridItem = (child: MediaPlayerItem): TemplateResult => {
const backgroundImage = child.thumbnail
? this._getSignedThumbnail(child.thumbnail).then(
? this._getThumbnailURLorBase64(child.thumbnail).then(
(value) => `url(${value})`
)
: "none";
@@ -615,7 +614,7 @@ export class HaMediaPlayerBrowse extends LitElement {
const backgroundImage =
mediaClass.show_list_images && child.thumbnail
? this._getSignedThumbnail(child.thumbnail).then(
? this._getThumbnailURLorBase64(child.thumbnail).then(
(value) => `url(${value})`
)
: "none";
@@ -652,7 +651,7 @@ export class HaMediaPlayerBrowse extends LitElement {
`;
};
private async _getSignedThumbnail(
private async _getThumbnailURLorBase64(
thumbnailUrl: string | undefined
): Promise<string> {
if (!thumbnailUrl) {
@@ -661,7 +660,24 @@ export class HaMediaPlayerBrowse extends LitElement {
if (thumbnailUrl.startsWith("/")) {
// Thumbnails served by local API require authentication
return (await getSignedPath(this.hass, thumbnailUrl)).path;
return new Promise((resolve, reject) => {
this.hass
.fetchWithAuth(thumbnailUrl!)
// Since we are fetching with an authorization header, we cannot just put the
// URL directly into the document; we need to embed the image. We could do this
// using blob URLs, but then we would need to keep track of them in order to
// release them properly. Instead, we embed the thumbnail using base64.
.then((response) => response.blob())
.then((blob) => {
const reader = new FileReader();
reader.onload = () => {
const result = reader.result;
resolve(typeof result === "string" ? result : "");
};
reader.onerror = (e) => reject(e);
reader.readAsDataURL(blob);
});
});
}
if (isBrandUrl(thumbnailUrl)) {
+26 -11
View File
@@ -41,7 +41,9 @@ export class HaTileButton extends LitElement {
@touchcancel=${this.handleRippleDeactivate}
>
<slot></slot>
${this._shouldRenderRipple ? html`<mwc-ripple></mwc-ripple>` : ""}
${this._shouldRenderRipple && !this.disabled
? html`<mwc-ripple></mwc-ripple>`
: ""}
</button>
`;
}
@@ -79,9 +81,10 @@ export class HaTileButton extends LitElement {
static get styles(): CSSResultGroup {
return css`
:host {
--icon-color: rgb(var(--color, var(--rgb-primary-text-color)));
--bg-color: rgba(var(--color, var(--rgb-disabled-color)), 0.2);
--mdc-ripple-color: rgba(var(--color, var(--rgb-disabled-color)));
--tile-button-icon-color: var(--primary-text-color);
--tile-button-background-color: rgb(var(--rgb-disabled-color));
--tile-button-background-opacity: 0.2;
--mdc-ripple-color: var(--tile-button-background-color);
width: 40px;
height: 40px;
-webkit-tap-highlight-color: transparent;
@@ -97,25 +100,37 @@ export class HaTileButton extends LitElement {
height: 100%;
border-radius: 10px;
border: none;
background-color: var(--bg-color);
transition: background-color 280ms ease-in-out, transform 180ms ease-out;
margin: 0;
padding: 0;
box-sizing: border-box;
line-height: 0;
outline: none;
overflow: hidden;
background: none;
}
.button::before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: var(--tile-button-background-color);
transition: background-color 180ms ease-in-out,
opacity 180ms ease-in-out;
opacity: var(--tile-button-background-opacity);
}
.button ::slotted(*) {
--mdc-icon-size: 20px;
color: var(--icon-color);
transition: color 180ms ease-in-out;
color: var(--tile-button-icon-color);
pointer-events: none;
}
.button:disabled {
cursor: not-allowed;
background-color: rgba(var(--rgb-disabled-color), 0.2);
}
.button:disabled ::slotted(*) {
color: rgb(var(--rgb-disabled-color));
--tile-button-background-color: rgb(var(--rgb-disabled-color));
--tile-button-icon-color: var(--disabled-text-color);
--tile-button-background-opacity: 0.2;
}
`;
}
+15 -5
View File
@@ -22,10 +22,20 @@ export class HaTileIcon extends LitElement {
static get styles(): CSSResultGroup {
return css`
:host {
--icon-color: rgb(var(--color));
--shape-color: rgba(var(--color), 0.2);
--tile-icon-color: rgb(var(--rgb-disabled-color));
--mdc-icon-size: 24px;
}
.shape::before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: var(--tile-icon-color);
transition: background-color 180ms ease-in-out;
opacity: 0.2;
}
.shape {
position: relative;
width: 40px;
@@ -34,13 +44,13 @@ export class HaTileIcon extends LitElement {
display: flex;
align-items: center;
justify-content: center;
background-color: var(--shape-color);
transition: background-color 180ms ease-in-out, color 180ms ease-in-out;
transition: color 180ms ease-in-out;
overflow: hidden;
}
.shape ha-icon,
.shape ha-svg-icon {
display: flex;
color: var(--icon-color);
color: var(--tile-icon-color);
transition: color 180ms ease-in-out;
}
`;
+6 -1
View File
@@ -1,14 +1,19 @@
import { CSSResultGroup, html, css, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
@customElement("ha-tile-image")
export class HaTileImage extends LitElement {
@property() public imageUrl?: string;
@property() public imageAlt?: string;
protected render(): TemplateResult {
return html`
<div class="image">
${this.imageUrl ? html`<img src=${this.imageUrl} />` : null}
${this.imageUrl
? html`<img alt=${ifDefined(this.imageAlt)} src=${this.imageUrl} />`
: null}
</div>
`;
}
+7 -3
View File
@@ -48,12 +48,16 @@ export class HaTileSlider extends LitElement {
return css`
ha-bar-slider {
--slider-bar-color: var(
--tile-slider-bar-color,
--tile-slider-color,
rgb(var(--rgb-primary-color))
);
--slider-bar-background: var(
--tile-slider-bar-background,
rgba(var(--rgb-disabled-color), 0.2)
--tile-slider-background,
rgb(var(--rgb-disabled-color))
);
--slider-bar-background-opacity: var(
--tile-slider-background-opacity,
0.2
);
--slider-bar-thickness: 40px;
--slider-bar-border-radius: 10px;
+3 -1
View File
@@ -30,7 +30,9 @@ class HaUserPicker extends LitElement {
return users
.filter((user) => !user.system_generated)
.sort((a, b) => stringCompare(a.name, b.name));
.sort((a, b) =>
stringCompare(a.name, b.name, this.hass!.locale.language)
);
});
protected render(): TemplateResult {
+5 -58
View File
@@ -23,63 +23,8 @@ interface CachedResults {
data: HistoryResult;
}
// This is a different interface, a different cache :(
interface RecentCacheResults {
created: number;
language: string;
data: Promise<HistoryResult>;
}
const RECENT_THRESHOLD = 60000; // 1 minute
const RECENT_CACHE: { [cacheKey: string]: RecentCacheResults } = {};
const stateHistoryCache: { [cacheKey: string]: CachedResults } = {};
// Cached type 1 function. Without cache config.
export const getRecent = (
hass: HomeAssistant,
entityId: string,
startTime: Date,
endTime: Date,
localize: LocalizeFunc,
language: string
) => {
const cacheKey = entityId;
const cache = RECENT_CACHE[cacheKey];
if (
cache &&
Date.now() - cache.created < RECENT_THRESHOLD &&
cache.language === language
) {
return cache.data;
}
const noAttributes = !entityIdHistoryNeedsAttributes(hass, entityId);
const prom = fetchRecentWS(
hass,
entityId,
startTime,
endTime,
false,
undefined,
true,
noAttributes
).then(
(stateHistory) => computeHistory(hass, stateHistory, localize),
(err) => {
delete RECENT_CACHE[entityId];
throw err;
}
);
RECENT_CACHE[cacheKey] = {
created: Date.now(),
language,
data: prom,
};
return prom;
};
// Cache type 2 functionality
function getEmptyCache(
language: string,
@@ -97,7 +42,7 @@ function getEmptyCache(
export const getRecentWithCache = (
hass: HomeAssistant,
entityId: string,
entityIds: string[],
cacheConfig: CacheConfig,
localize: LocalizeFunc,
language: string
@@ -132,7 +77,9 @@ export const getRecentWithCache = (
}
const curCacheProm = cache.prom;
const noAttributes = !entityIdHistoryNeedsAttributes(hass, entityId);
const noAttributes = !entityIds.some((entityId) =>
entityIdHistoryNeedsAttributes(hass, entityId)
);
const genProm = async () => {
let fetchedHistory: HistoryStates;
@@ -142,7 +89,7 @@ export const getRecentWithCache = (
curCacheProm,
fetchRecentWS(
hass,
entityId,
entityIds,
toFetchStartTime,
endTime,
appendingToCache,
+11 -4
View File
@@ -2,7 +2,7 @@ import { getColorByIndex } from "../common/color/colors";
import { computeDomain } from "../common/entity/compute_domain";
import { computeStateName } from "../common/entity/compute_state_name";
import type { HomeAssistant } from "../types";
import { UNAVAILABLE_STATES } from "./entity";
import { isUnavailableState } from "./entity";
export interface Calendar {
entity_id: string;
@@ -50,6 +50,7 @@ export enum RecurrenceRange {
export const enum CalendarEntityFeature {
CREATE_EVENT = 1,
DELETE_EVENT = 2,
UPDATE_EVENT = 4,
}
export const fetchCalendarEvents = async (
@@ -138,7 +139,7 @@ export const getCalendars = (hass: HomeAssistant): Calendar[] =>
.filter(
(eid) =>
computeDomain(eid) === "calendar" &&
!UNAVAILABLE_STATES.includes(hass.states[eid].state)
!isUnavailableState(hass.states[eid].state)
)
.sort()
.map((eid, idx) => ({
@@ -161,12 +162,18 @@ export const createCalendarEvent = (
export const updateCalendarEvent = (
hass: HomeAssistant,
entityId: string,
event: CalendarEventMutableParams
uid: string,
event: CalendarEventMutableParams,
recurrence_id?: string,
recurrence_range?: RecurrenceRange
) =>
hass.callWS<void>({
type: "calendar/event/update",
entity_id: entityId,
event: event,
uid,
recurrence_id,
recurrence_range,
event,
});
export const deleteCalendarEvent = (
+16 -8
View File
@@ -14,7 +14,13 @@ export type HvacMode =
export const CLIMATE_PRESET_NONE = "none";
export type HvacAction = "off" | "heating" | "cooling" | "drying" | "idle";
export type HvacAction =
| "off"
| "heating"
| "cooling"
| "drying"
| "idle"
| "fan";
export type ClimateEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
@@ -44,13 +50,15 @@ export type ClimateEntity = HassEntityBase & {
};
};
export const CLIMATE_SUPPORT_TARGET_TEMPERATURE = 1;
export const CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE = 2;
export const CLIMATE_SUPPORT_TARGET_HUMIDITY = 4;
export const CLIMATE_SUPPORT_FAN_MODE = 8;
export const CLIMATE_SUPPORT_PRESET_MODE = 16;
export const CLIMATE_SUPPORT_SWING_MODE = 32;
export const CLIMATE_SUPPORT_AUX_HEAT = 64;
export const enum ClimateEntityFeature {
TARGET_TEMPERATURE = 1,
TARGET_TEMPERATURE_RANGE = 2,
TARGET_HUMIDITY = 4,
FAN_MODE = 8,
PRESET_MODE = 16,
SWING_MODE = 32,
AUX_HEAT = 64,
}
const hvacModeOrdering: { [key in HvacMode]: number } = {
auto: 1,
+54 -7
View File
@@ -1,27 +1,74 @@
import { HomeAssistant } from "../types";
interface ProcessResults {
card: { [key: string]: Record<string, string> };
speech: {
[SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string };
interface IntentTarget {
type: "area" | "device" | "entity" | "domain" | "device_class" | "custom";
name: string;
id: string | null;
}
interface IntentResultBase {
language: string;
speech:
| {
[SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string };
}
| null;
}
interface IntentResultActionDone extends IntentResultBase {
response_type: "action_done";
data: {
targets: IntentTarget[];
success: IntentTarget[];
failed: IntentTarget[];
};
}
interface IntentResultQueryAnswer extends IntentResultBase {
response_type: "query_answer";
data: {
targets: IntentTarget[];
success: IntentTarget[];
failed: IntentTarget[];
};
}
interface IntentResultError extends IntentResultBase {
response_type: "error";
data: {
code:
| "no_intent_match"
| "no_valid_targets"
| "failed_to_handle"
| "unknown";
};
}
interface ConversationResult {
conversation_id: string | null;
response:
| IntentResultActionDone
| IntentResultQueryAnswer
| IntentResultError;
}
export interface AgentInfo {
attribution?: { name: string; url: string };
onboarding?: { text: string; url: string };
}
export const processText = (
export const processConversationInput = (
hass: HomeAssistant,
text: string,
// eslint-disable-next-line: variable-name
conversation_id: string
): Promise<ProcessResults> =>
conversation_id: string | null,
language: string
): Promise<ConversationResult> =>
hass.callWS({
type: "conversation/process",
text,
conversation_id,
language,
});
export const getAgentInfo = (hass: HomeAssistant): Promise<AgentInfo> =>
+5 -2
View File
@@ -123,9 +123,12 @@ export const subscribeDeviceRegistry = (
onChange
);
export const sortDeviceRegistryByName = (entries: DeviceRegistryEntry[]) =>
export const sortDeviceRegistryByName = (
entries: DeviceRegistryEntry[],
language: string
) =>
entries.sort((entry1, entry2) =>
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
);
export const getDeviceEntityLookup = (
+1 -1
View File
@@ -451,7 +451,7 @@ const getEnergyData = async (
...(await fetchStatistics(
hass!,
compareStartMinHour,
end,
endCompare,
waterStatIds,
period,
waterUnits,
+7 -2
View File
@@ -1,7 +1,12 @@
import { arrayLiteralIncludes } from "../common/array/literal-includes";
export const UNAVAILABLE = "unavailable";
export const UNKNOWN = "unknown";
export const ON = "on";
export const OFF = "off";
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN];
export const OFF_STATES = [UNAVAILABLE, UNKNOWN, OFF];
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN] as const;
export const OFF_STATES = [UNAVAILABLE, UNKNOWN, OFF] as const;
export const isUnavailableState = arrayLiteralIncludes(UNAVAILABLE_STATES);
export const isOffState = arrayLiteralIncludes(OFF_STATES);
+7 -2
View File
@@ -29,6 +29,7 @@ export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
original_icon?: string;
device_class?: string;
original_device_class?: string;
aliases: string[];
}
export interface UpdateEntityRegistryEntryResult {
@@ -63,6 +64,7 @@ export interface EntityRegistryEntryUpdateParams {
new_entity_id?: string;
options_domain?: string;
options?: SensorEntityOptions | NumberEntityOptions | WeatherEntityOptions;
aliases?: string[];
}
export const findBatteryEntity = (
@@ -162,9 +164,12 @@ export const subscribeEntityRegistry = (
onChange
);
export const sortEntityRegistryByName = (entries: EntityRegistryEntry[]) =>
export const sortEntityRegistryByName = (
entries: EntityRegistryEntry[],
language: string
) =>
entries.sort((entry1, entry2) =>
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "")
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
);
export const entityRegistryById = memoizeOne(
+20 -7
View File
@@ -1,4 +1,8 @@
import { HassEntities, HassEntity } from "home-assistant-js-websocket";
import {
HassEntities,
HassEntity,
HassEntityAttributeBase,
} from "home-assistant-js-websocket";
import { computeDomain } from "../common/entity/compute_domain";
import { computeStateDisplayFromEntityAttributes } from "../common/entity/compute_state_display";
import { computeStateNameFromEntityAttributes } from "../common/entity/compute_state_name";
@@ -117,7 +121,7 @@ export const fetchRecent = (
export const fetchRecentWS = (
hass: HomeAssistant,
entityId: string, // This may be CSV
entityIds: string[],
startTime: Date,
endTime: Date,
skipInitialState = false,
@@ -133,7 +137,7 @@ export const fetchRecentWS = (
include_start_time_state: !skipInitialState,
minimal_response: minimalResponse,
no_attributes: noAttributes || false,
entity_ids: entityId.split(","),
entity_ids: entityIds,
});
export const fetchDate = (
@@ -160,9 +164,9 @@ export const fetchDateWS = (
start_time: startTime.toISOString(),
end_time: endTime.toISOString(),
minimal_response: true,
no_attributes: !entityIds
.map((entityId) => entityIdHistoryNeedsAttributes(hass, entityId))
.reduce((cur, next) => cur || next, false),
no_attributes: !entityIds.some((entityId) =>
entityIdHistoryNeedsAttributes(hass, entityId)
),
};
if (entityIds.length !== 0) {
return hass.callWS<HistoryStates>({ ...params, entity_ids: entityIds });
@@ -195,13 +199,22 @@ const processTimelineEntity = (
if (data.length > 0 && state.s === data[data.length - 1].state) {
continue;
}
const currentAttributes: HassEntityAttributeBase = {};
if (current_state?.attributes.device_class) {
currentAttributes.device_class = current_state?.attributes.device_class;
}
data.push({
state_localize: computeStateDisplayFromEntityAttributes(
localize,
language,
entities,
entityId,
state.a || first.a,
{
...(state.a || first.a),
...currentAttributes,
},
state.s
),
state: state.s,
+12 -2
View File
@@ -2,14 +2,24 @@ import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { FIXED_DOMAIN_STATES } from "../common/entity/get_states";
import { TranslationDict } from "../types";
import { UNAVAILABLE_STATES } from "./entity";
type HumidifierState =
| typeof FIXED_DOMAIN_STATES.humidifier[number]
| typeof UNAVAILABLE_STATES[number];
type HumidifierMode =
keyof TranslationDict["state_attributes"]["humidifier"]["mode"];
export type HumidifierEntity = HassEntityBase & {
state: HumidifierState;
attributes: HassEntityAttributeBase & {
humidity?: number;
min_humidity?: number;
max_humidity?: number;
mode?: string;
available_modes?: string[];
mode?: HumidifierMode;
available_modes?: HumidifierMode[];
};
};
+2 -2
View File
@@ -35,7 +35,7 @@ import type {
import { supportsFeature } from "../common/entity/supports-feature";
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
import type { HomeAssistant, TranslationDict } from "../types";
import { UNAVAILABLE_STATES } from "./entity";
import { isUnavailableState } from "./entity";
import { isTTSMediaSource } from "./tts";
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
@@ -259,7 +259,7 @@ export const computeMediaControls = (
const state = stateObj.state;
if (UNAVAILABLE_STATES.includes(state)) {
if (isUnavailableState(state)) {
return undefined;
}
+3 -1
View File
@@ -37,11 +37,13 @@ export interface MQTTDeviceDebugInfo {
export const subscribeMQTTTopic = (
hass: HomeAssistant,
topic: string,
callback: (message: MQTTMessage) => void
callback: (message: MQTTMessage) => void,
qos?: number
) =>
hass.connection.subscribeMessage<MQTTMessage>(callback, {
type: "mqtt/subscribe",
topic,
qos,
});
export const fetchMQTTDebugInfo = (
+1
View File
@@ -44,6 +44,7 @@ declare global {
export type TranslationCategory =
| "title"
| "state"
| "state_attributes"
| "entity"
| "config"
| "config_panel"
+7 -3
View File
@@ -68,7 +68,10 @@ export const updateReleaseNotes = (hass: HomeAssistant, entityId: string) =>
entity_id: entityId,
});
export const filterUpdateEntities = (entities: HassEntities) =>
export const filterUpdateEntities = (
entities: HassEntities,
language?: string
) =>
(
Object.values(entities).filter(
(entity) => computeStateDomain(entity) === "update"
@@ -94,7 +97,8 @@ export const filterUpdateEntities = (entities: HassEntities) =>
}
return caseInsensitiveStringCompare(
a.attributes.title || a.attributes.friendly_name || "",
b.attributes.title || b.attributes.friendly_name || ""
b.attributes.title || b.attributes.friendly_name || "",
language
);
});
@@ -110,7 +114,7 @@ export const checkForEntityUpdates = async (
element: HTMLElement,
hass: HomeAssistant
) => {
const entities = filterUpdateEntities(hass.states).map(
const entities = filterUpdateEntities(hass.states, hass.locale.language).map(
(entity) => entity.entity_id
);
+9 -3
View File
@@ -319,6 +319,12 @@ export const weatherSVGStyles = css`
.cloud-front {
fill: var(--weather-icon-cloud-front-color, #f9f9f9);
}
.snow {
fill: var(--weather-icon-snow-color, #f9f9f9);
stroke: var(--weather-icon-snow-stroke-color, #d4d4d4);
stroke-width: 1;
paint-order: stroke;
}
`;
const getWeatherStateSVG = (
@@ -434,15 +440,15 @@ const getWeatherStateSVG = (
snowyStates.has(state)
? svg`
<path
class="rain"
class="snow"
d="m 8.4319893,15.348341 c 0,0.257881 -0.209197,0.467079 -0.467078,0.467079 -0.258586,0 -0.46743,-0.209198 -0.46743,-0.467079 0,-0.258233 0.208844,-0.467431 0.46743,-0.467431 0.257881,0 0.467078,0.209198 0.467078,0.467431"
/>
<path
class="rain"
class="snow"
d="m 11.263878,14.358553 c 0,0.364067 -0.295275,0.659694 -0.659695,0.659694 -0.364419,0 -0.6596937,-0.295627 -0.6596937,-0.659694 0,-0.364419 0.2952747,-0.659694 0.6596937,-0.659694 0.36442,0 0.659695,0.295275 0.659695,0.659694"
/>
<path
class="rain"
class="snow"
d="m 5.3252173,13.69847 c 0,0.364419 -0.295275,0.660047 -0.659695,0.660047 -0.364067,0 -0.659694,-0.295628 -0.659694,-0.660047 0,-0.364067 0.295627,-0.659694 0.659694,-0.659694 0.36442,0 0.659695,0.295627 0.659695,0.659694"
/>
`
@@ -74,7 +74,7 @@ export class HaImagecropperDialog extends LitElement {
round: Boolean(this._params?.options.round),
})}"
>
<img />
<img alt=${this.hass.localize("ui.dialogs.image_cropper.crop_image")} />
</div>
<mwc-button slot="secondaryAction" @click=${this.closeDialog}>
${this.hass.localize("ui.common.cancel")}
@@ -4,7 +4,7 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../components/ha-relative-time";
import { triggerAutomationActions } from "../../../data/automation";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { isUnavailableState } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
@customElement("more-info-automation")
@@ -32,7 +32,7 @@ class MoreInfoAutomation extends LitElement {
<div class="actions">
<mwc-button
@click=${this._runActions}
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj!.state)}
.disabled=${isUnavailableState(this.stateObj!.state)}
>
${this.hass.localize("ui.card.automation.trigger")}
</mwc-button>
@@ -11,6 +11,11 @@ import { property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../../common/dom/fire_event";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import {
computeAttributeNameDisplay,
computeAttributeValueDisplay,
} from "../../../common/entity/compute_attribute_display";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import "../../../components/ha-climate-control";
@@ -19,13 +24,7 @@ import "../../../components/ha-slider";
import "../../../components/ha-switch";
import {
ClimateEntity,
CLIMATE_SUPPORT_AUX_HEAT,
CLIMATE_SUPPORT_FAN_MODE,
CLIMATE_SUPPORT_PRESET_MODE,
CLIMATE_SUPPORT_SWING_MODE,
CLIMATE_SUPPORT_TARGET_HUMIDITY,
CLIMATE_SUPPORT_TARGET_TEMPERATURE,
CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE,
ClimateEntityFeature,
compareClimateHvacModes,
} from "../../../data/climate";
import { HomeAssistant } from "../../../types";
@@ -47,26 +46,32 @@ class MoreInfoClimate extends LitElement {
const supportTargetTemperature = supportsFeature(
stateObj,
CLIMATE_SUPPORT_TARGET_TEMPERATURE
ClimateEntityFeature.TARGET_TEMPERATURE
);
const supportTargetTemperatureRange = supportsFeature(
stateObj,
CLIMATE_SUPPORT_TARGET_TEMPERATURE_RANGE
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
);
const supportTargetHumidity = supportsFeature(
stateObj,
CLIMATE_SUPPORT_TARGET_HUMIDITY
ClimateEntityFeature.TARGET_HUMIDITY
);
const supportFanMode = supportsFeature(
stateObj,
ClimateEntityFeature.FAN_MODE
);
const supportFanMode = supportsFeature(stateObj, CLIMATE_SUPPORT_FAN_MODE);
const supportPresetMode = supportsFeature(
stateObj,
CLIMATE_SUPPORT_PRESET_MODE
ClimateEntityFeature.PRESET_MODE
);
const supportSwingMode = supportsFeature(
stateObj,
CLIMATE_SUPPORT_SWING_MODE
ClimateEntityFeature.SWING_MODE
);
const supportAuxHeat = supportsFeature(
stateObj,
ClimateEntityFeature.AUX_HEAT
);
const supportAuxHeat = supportsFeature(stateObj, CLIMATE_SUPPORT_AUX_HEAT);
const temperatureStepSize =
stateObj.attributes.target_temp_step ||
@@ -94,7 +99,12 @@ class MoreInfoClimate extends LitElement {
${supportTargetTemperature || supportTargetTemperatureRange
? html`
<div>
${hass.localize("ui.card.climate.target_temperature")}
${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"temperature"
)}
</div>
`
: ""}
@@ -145,7 +155,14 @@ class MoreInfoClimate extends LitElement {
${supportTargetHumidity
? html`
<div class="container-humidity">
<div>${hass.localize("ui.card.climate.target_humidity")}</div>
<div>
${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"humidity"
)}
</div>
<div class="single-row">
<div class="target-humidity">
${stateObj.attributes.humidity} %
@@ -182,7 +199,13 @@ class MoreInfoClimate extends LitElement {
.map(
(mode) => html`
<mwc-list-item .value=${mode}>
${hass.localize(`component.climate.state._.${mode}`)}
${computeStateDisplay(
hass.localize,
stateObj,
hass.locale,
hass.entities,
mode
)}
</mwc-list-item>
`
)}
@@ -194,7 +217,12 @@ class MoreInfoClimate extends LitElement {
? html`
<div class="container-preset_modes">
<ha-select
.label=${hass.localize("ui.card.climate.preset_mode")}
.label=${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"preset_mode"
)}
.value=${stateObj.attributes.preset_mode}
fixedMenuPosition
naturalMenuWidth
@@ -204,9 +232,13 @@ class MoreInfoClimate extends LitElement {
${stateObj.attributes.preset_modes!.map(
(mode) => html`
<mwc-list-item .value=${mode}>
${hass.localize(
`state_attributes.climate.preset_mode.${mode}`
) || mode}
${computeAttributeValueDisplay(
hass.localize,
stateObj,
hass.entities,
"preset_mode",
mode
)}
</mwc-list-item>
`
)}
@@ -218,7 +250,12 @@ class MoreInfoClimate extends LitElement {
? html`
<div class="container-fan_list">
<ha-select
.label=${hass.localize("ui.card.climate.fan_mode")}
.label=${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"fan_mode"
)}
.value=${stateObj.attributes.fan_mode}
fixedMenuPosition
naturalMenuWidth
@@ -228,9 +265,13 @@ class MoreInfoClimate extends LitElement {
${stateObj.attributes.fan_modes!.map(
(mode) => html`
<mwc-list-item .value=${mode}>
${hass.localize(
`state_attributes.climate.fan_mode.${mode}`
) || mode}
${computeAttributeValueDisplay(
hass.localize,
stateObj,
hass.entities,
"fan_mode",
mode
)}
</mwc-list-item>
`
)}
@@ -242,7 +283,12 @@ class MoreInfoClimate extends LitElement {
? html`
<div class="container-swing_list">
<ha-select
.label=${hass.localize("ui.card.climate.swing_mode")}
.label=${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"swing_mode"
)}
.value=${stateObj.attributes.swing_mode}
fixedMenuPosition
naturalMenuWidth
@@ -251,7 +297,15 @@ class MoreInfoClimate extends LitElement {
>
${stateObj.attributes.swing_modes!.map(
(mode) => html`
<mwc-list-item .value=${mode}>${mode}</mwc-list-item>
<mwc-list-item .value=${mode}>
${computeAttributeValueDisplay(
hass.localize,
stateObj,
hass.entities,
"swing_mode",
mode
)}
</mwc-list-item>
`
)}
</ha-select>
@@ -263,7 +317,12 @@ class MoreInfoClimate extends LitElement {
<div class="container-aux_heat">
<div class="center horizontal layout single-row">
<div class="flex">
${hass.localize("ui.card.climate.aux_heat")}
${computeAttributeNameDisplay(
hass.localize,
stateObj,
hass.entities,
"aux_heat"
)}
</div>
<ha-switch
.checked=${stateObj.attributes.aux_heat === "on"}
@@ -2,7 +2,7 @@ import "@material/mwc-button";
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { isUnavailableState } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
@customElement("more-info-counter")
@@ -16,7 +16,7 @@ class MoreInfoCounter extends LitElement {
return html``;
}
const disabled = UNAVAILABLE_STATES.includes(this.stateObj!.state);
const disabled = isUnavailableState(this.stateObj!.state);
return html`
<div class="actions">
@@ -3,7 +3,7 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../components/ha-date-input";
import "../../../components/ha-time-input";
import { UNAVAILABLE_STATES, UNKNOWN } from "../../../data/entity";
import { isUnavailableState, UNKNOWN } from "../../../data/entity";
import {
setInputDateTimeValue,
stateToIsoDateString,
@@ -28,7 +28,7 @@ class MoreInfoInputDatetime extends LitElement {
<ha-date-input
.locale=${this.hass.locale}
.value=${stateToIsoDateString(this.stateObj)}
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
.disabled=${isUnavailableState(this.stateObj.state)}
@value-changed=${this._dateChanged}
>
</ha-date-input>
@@ -45,7 +45,7 @@ class MoreInfoInputDatetime extends LitElement {
? this.stateObj.state.split(" ")[1]
: this.stateObj.state}
.locale=${this.hass.locale}
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj.state)}
.disabled=${isUnavailableState(this.stateObj.state)}
@value-changed=${this._timeChanged}
@click=${this._stopEventPropagation}
></ha-time-input>
@@ -9,7 +9,7 @@ import "../../../components/ha-checkbox";
import "../../../components/ha-circular-progress";
import "../../../components/ha-formfield";
import "../../../components/ha-markdown";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { isUnavailableState } from "../../../data/entity";
import {
UpdateEntity,
updateIsInstalling,
@@ -37,7 +37,7 @@ class MoreInfoUpdate extends LitElement {
if (
!this.hass ||
!this.stateObj ||
UNAVAILABLE_STATES.includes(this.stateObj.state)
isUnavailableState(this.stateObj.state)
) {
return html``;
}
@@ -139,7 +139,7 @@ export class MoreInfoHistory extends LitElement {
}
this._stateHistory = await getRecentWithCache(
this.hass!,
this.entityId,
[this.entityId],
{
cacheKey: `more_info.${this.entityId}`,
hoursToShow: 24,
+10 -2
View File
@@ -484,7 +484,11 @@ export class QuickBar extends LitElement {
};
})
.sort((a, b) =>
caseInsensitiveStringCompare(a.primaryText, b.primaryText)
caseInsensitiveStringCompare(
a.primaryText,
b.primaryText,
this.hass.locale.language
)
);
}
@@ -494,7 +498,11 @@ export class QuickBar extends LitElement {
...this._generateServerControlCommands(),
...(await this._generateNavigationCommands()),
].sort((a, b) =>
caseInsensitiveStringCompare(a.strings.join(" "), b.strings.join(" "))
caseInsensitiveStringCompare(
a.strings.join(" "),
b.strings.join(" "),
this.hass.locale.language
)
);
}
@@ -13,7 +13,6 @@ import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../common/dom/fire_event";
import { SpeechRecognition } from "../../common/dom/speech-recognition";
import { uid } from "../../common/util/uid";
import "../../components/ha-dialog";
import type { HaDialog } from "../../components/ha-dialog";
import "../../components/ha-icon-button";
@@ -22,7 +21,7 @@ import type { HaTextField } from "../../components/ha-textfield";
import {
AgentInfo,
getAgentInfo,
processText,
processConversationInput,
setConversationOnboarding,
} from "../../data/conversation";
import { haStyleDialog } from "../../resources/styles";
@@ -60,7 +59,7 @@ export class HaVoiceCommandDialog extends LitElement {
private recognition!: SpeechRecognition;
private _conversationId?: string;
private _conversationId: string | null = null;
public async showDialog(): Promise<void> {
this._opened = true;
@@ -175,7 +174,6 @@ export class HaVoiceCommandDialog extends LitElement {
protected firstUpdated(changedProps: PropertyValues) {
super.updated(changedProps);
this._conversationId = uid();
this._conversation = [
{
who: "hass",
@@ -211,18 +209,29 @@ export class HaVoiceCommandDialog extends LitElement {
private _initRecognition() {
this.recognition = new SpeechRecognition();
this.recognition.interimResults = true;
this.recognition.lang = "en-US";
this.recognition.lang = this.hass.language;
this.recognition.onstart = () => {
this.recognition.addEventListener("start", () => {
this.results = {
final: false,
transcript: "",
};
};
this.recognition.onerror = (event) => {
});
this.recognition.addEventListener("nomatch", () => {
this._addMessage({
who: "user",
text: `<${this.hass.localize(
"ui.dialogs.voice_command.did_not_understand"
)}>`,
error: true,
});
});
this.recognition.addEventListener("error", (event) => {
// eslint-disable-next-line
console.error("Error recognizing text", event);
this.recognition!.abort();
// @ts-ignore
if (event.error !== "aborted") {
if (event.error !== "aborted" && event.error !== "no-speech") {
const text =
this.results && this.results.transcript
? this.results.transcript
@@ -232,8 +241,8 @@ export class HaVoiceCommandDialog extends LitElement {
this._addMessage({ who: "user", text, error: true });
}
this.results = null;
};
this.recognition.onend = () => {
});
this.recognition.addEventListener("end", () => {
// Already handled by onerror
if (this.results == null) {
return;
@@ -251,15 +260,14 @@ export class HaVoiceCommandDialog extends LitElement {
error: true,
});
}
};
this.recognition.onresult = (event) => {
});
this.recognition.addEventListener("result", (event) => {
const result = event.results[0];
this.results = {
transcript: result[0].transcript,
final: result.isFinal,
};
};
});
}
private async _processText(text: string) {
@@ -274,13 +282,19 @@ export class HaVoiceCommandDialog extends LitElement {
// To make sure the answer is placed at the right user text, we add it before we process it
this._addMessage(message);
try {
const response = await processText(
const response = await processConversationInput(
this.hass,
text,
this._conversationId!
this._conversationId,
this.hass.language
);
const plain = response.speech.plain;
message.text = plain.speech;
this._conversationId = response.conversation_id;
const plain = response.response.speech?.plain;
if (plain) {
message.text = plain.speech;
} else {
message.text = "<silence>";
}
this.requestUpdate("_conversation");
} catch {
+2
View File
@@ -138,6 +138,8 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
// @ts-ignore
this._loadHassTranslations(this.hass!.language, "state");
// @ts-ignore
this._loadHassTranslations(this.hass!.language, "state_attributes");
// @ts-ignore
this._loadHassTranslations(this.hass!.language, "entity");
document.addEventListener(
+1
View File
@@ -19,6 +19,7 @@ class IntegrationBadge extends LitElement {
return html`
<div class="icon">
<img
alt=""
src=${brandsUrl({
domain: this.domain,
type: "icon",
+9 -7
View File
@@ -156,13 +156,11 @@ class OnboardingCoreConfig extends LitElement {
type="number"
.disabled=${this._working}
.value=${this._elevationValue}
.suffix=${this.hass.localize(
"ui.panel.config.core.section.core.core_config.elevation_meters"
)}
@change=${this._handleChange}
>
<span slot="suffix">
${this.hass.localize(
"ui.panel.config.core.section.core.core_config.elevation_meters"
)}
</span>
</ha-textfield>
</div>
@@ -273,7 +271,9 @@ class OnboardingCoreConfig extends LitElement {
"[name=currency]"
) as HaTextField;
curInput.updateComplete.then(() => {
curInput.shadowRoot!.appendChild(createCurrencyListEl());
curInput.shadowRoot!.appendChild(
createCurrencyListEl(this.hass.locale.language)
);
curInput.formElement.setAttribute("list", "currencies");
});
@@ -281,7 +281,9 @@ class OnboardingCoreConfig extends LitElement {
"[name=country]"
) as HaTextField;
countryInput.updateComplete.then(() => {
countryInput.shadowRoot!.appendChild(createCountryListEl());
countryInput.shadowRoot!.appendChild(
createCountryListEl(this.hass.locale.language)
);
countryInput.formElement.setAttribute("list", "countries");
});

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