mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-30 16:49:04 +00:00
Compare commits
90
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78f64081dd | ||
|
|
cafb485e1e | ||
|
|
5fc4ad4e0c | ||
|
|
ba33d2897b | ||
|
|
9484d51694 | ||
|
|
55739f2666 | ||
|
|
483b8d1c76 | ||
|
|
f589ae2113 | ||
|
|
1c01df1d6c | ||
|
|
3216ebc19a | ||
|
|
f18ccc28c6 | ||
|
|
483fb4093f | ||
|
|
0f54967037 | ||
|
|
21ba8fbf79 | ||
|
|
ad8cea50d7 | ||
|
|
7df3f5ca88 | ||
|
|
50e61275d5 | ||
|
|
91a941475c | ||
|
|
cf79aecca9 | ||
|
|
a2dd10adee | ||
|
|
e3adc4adb6 | ||
|
|
3defae4364 | ||
|
|
262763a10e | ||
|
|
db9a56cd4b | ||
|
|
dc874ffdb5 | ||
|
|
ef6a1222b2 | ||
|
|
a25a643a31 | ||
|
|
d7fbb1efac | ||
|
|
4d643b7133 | ||
|
|
c196356d05 | ||
|
|
53d9395b44 | ||
|
|
dc031d0566 | ||
|
|
893daa8333 | ||
|
|
bbc67bb9d6 | ||
|
|
48b56c4653 | ||
|
|
9dd88a24ce | ||
|
|
963711b8fd | ||
|
|
55b43df5b5 | ||
|
|
0481cfdde3 | ||
|
|
2ce8646318 | ||
|
|
459a48b51f | ||
|
|
c148beafd3 | ||
|
|
696c3fb093 | ||
|
|
12008d3a06 | ||
|
|
a2179425e0 | ||
|
|
261debd0d9 | ||
|
|
9a7d6c2892 | ||
|
|
90d9e3e87a | ||
|
|
1490f8ff12 | ||
|
|
2cb6974ab7 | ||
|
|
53abe40f72 | ||
|
|
0a63f12c50 | ||
|
|
8f0a6539ac | ||
|
|
31678bba2d | ||
|
|
3a9f461e46 | ||
|
|
6198a100f0 | ||
|
|
6517d24017 | ||
|
|
1343ac5bc2 | ||
|
|
133dd06b07 | ||
|
|
bbc4d57fe8 | ||
|
|
0d5588ae56 | ||
|
|
67d858b828 | ||
|
|
95e00f1e36 | ||
|
|
01f9c5eb5b | ||
|
|
40a28525fb | ||
|
|
f80deb0240 | ||
|
|
68313876d3 | ||
|
|
c3db90ae22 | ||
|
|
95e0988b93 | ||
|
|
00312420d8 | ||
|
|
f2116b61fc | ||
|
|
2e872965f6 | ||
|
|
cbf745f38a | ||
|
|
fe7cedd04b | ||
|
|
2e9d8a1788 | ||
|
|
332d612956 | ||
|
|
11ef852384 | ||
|
|
394d5999b8 | ||
|
|
384fdfdbc9 | ||
|
|
0cccdc5972 | ||
|
|
771eaa70ff | ||
|
|
aff47efe5e | ||
|
|
f13470719c | ||
|
|
5f769d613c | ||
|
|
f214ef8667 | ||
|
|
528ebe6b27 | ||
|
|
82e6f1106f | ||
|
|
f02656da54 | ||
|
|
25307e427d | ||
|
|
207cbcc585 |
No files matched your search
@@ -0,0 +1,43 @@
|
||||
---
|
||||
name: ha-frontend-browser-checks
|
||||
description: Check a Home Assistant frontend change in a browser and show it in a pull request. Use when checking how a change looks or behaves at different screen sizes, in light and dark mode, right to left (RTL) or with long translations, or when taking before and after screenshots or recording a demo of a feature for a pull request.
|
||||
---
|
||||
|
||||
# HA Frontend Browser Checks
|
||||
|
||||
Use this skill to check a visible change in a browser and to show it in a pull request. Any browser tool you already have works if it can open a page, set its size, run a script in it, take screenshots and record video. Load `ha-frontend-testing` for the dev servers, and `ha-frontend-loading` for loading states.
|
||||
|
||||
Screenshots and recordings help reviewers see what changed, but they don't make a large change easy to review. [Keep pull requests small](https://contributors.home-assistant.io/start/pull-requests/#keep-it-small), and make sure you have reviewed and understood the change and can explain it, as the [AI policy](https://contributors.home-assistant.io/start/ai-policy/) asks.
|
||||
|
||||
## Check Real Devices
|
||||
|
||||
Check the sizes the change affects rather than one fixed size, such as a phone, a tablet in both orientations, a laptop and a large desktop monitor. Include a small phone. Take each device's viewport in CSS pixels, its pixel ratio and touch support from the device presets your tools have, rather than from memory, and check the page really has that size once it's set.
|
||||
|
||||
## Check Light And Dark
|
||||
|
||||
When the change can look different in light and dark mode, such as a colour, border, background or image, check it in both. Switch the colour scheme in your browser tool, with the profile's theme following it, or pick light and dark in the profile. A fix for one mode only needs that mode.
|
||||
|
||||
## Check Right To Left (RTL)
|
||||
|
||||
Check layout, alignment, icons and anything with a direction in RTL. In the app, set your profile language to one written right to left, then set it back: many components take their direction from the language, so setting the page to RTL in your browser tool leaves them left to right. The gallery's RTL toggle checks styling only.
|
||||
|
||||
## Check Long Text
|
||||
|
||||
When a change adds or changes text, check it in a language with long words or long translations too, so labels, descriptions and buttons don't overflow or wrap badly. When the new string isn't translated yet, try a rough translation to check its length.
|
||||
|
||||
## Show It In The Pull Request
|
||||
|
||||
- When the change alters something that exists already, capture the same screen on `dev` and on your branch, in the same state, and put them side by side. Only a new screen, with nothing before it, needs just the after.
|
||||
- Keep the size of every capture fixed, screenshots as well as videos. Set the page size before you capture and don't change it in between, and capture the same area each time, so the subject sits in the same place in before and after. For a card or other part of the page, work out a fixed area around it for each size you test, and use that same area on both branches.
|
||||
- Say which device, size or mode each capture shows.
|
||||
- Make the change easy to see: capture the part of the screen it affects rather than a whole page where it's a few pixels.
|
||||
- Save captures outside the repository, so they can't be committed by accident.
|
||||
- Keep personal details out: use demo data, such as the demo or the Demo integration, and mask anything else before you capture, such as names, addresses, IP and MAC addresses, hostnames, serial numbers and tokens. Check each capture before you attach it.
|
||||
|
||||
Record a video when it shows the change better than a still, such as an animation, a drag, a loading sequence (hold the loading state as "Checking It" in `ha-frontend-loading` shows) or a flow across several screens. Keep each video short and small: GitHub limits upload sizes, and reviewers have to watch it. You can record it yourself with the tools you have; it doesn't need a person.
|
||||
|
||||
- Use the recording tools at hand: your browser tool's recorder for a page, or a desktop screen recorder for a window, such as a phone emulator, so the device frame shows.
|
||||
- Don't resize, zoom or take screenshots while recording, which redraw the page at another size and make the video jump.
|
||||
- Check the whole recording before you attach it. For a short clip, look at a frame every second or half second, not only the first and last, since the page can jump to another size partway through. Record again if it does. Take stills from the same frames, so they match the video.
|
||||
- Keep the window drawn on a screen. A hidden or minimised window records only a frame every few seconds.
|
||||
- Label each video, such as **Before** and **After**, and say what it shows and how you set it up. Say what you didn't record and why.
|
||||
@@ -20,7 +20,7 @@ When creating a pull request, use `.github/PULL_REQUEST_TEMPLATE.md` as the body
|
||||
- Do not omit, reorder, or rewrite template sections.
|
||||
- Check the appropriate "Type of change" box based on the actual change.
|
||||
- Do not check checklist items on behalf of the user.
|
||||
- If the PR includes UI changes, remind the user to add screenshots or a short video.
|
||||
- If the PR includes UI changes, add screenshots or a short video, taken as `ha-frontend-browser-checks` describes. Only ask the user to add them when you can't take them yourself.
|
||||
- Explain what the change does for users, not only implementation details.
|
||||
- Use Markdown.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ workflows:
|
||||
- 'actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9'
|
||||
'.github/workflows/codeql-analysis.yaml':
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
- 'github/codeql-action@33d7b85da1a04171e211befe2c739303b9a4c066'
|
||||
- 'github/codeql-action@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea'
|
||||
'.github/workflows/copilot-setup-steps.yml':
|
||||
- 'actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9'
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
@@ -29,7 +29,7 @@ workflows:
|
||||
- 'actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1'
|
||||
'.github/workflows/dependency-review.yaml':
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
- 'actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294'
|
||||
- 'actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec'
|
||||
- 'actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3'
|
||||
'.github/workflows/design_deployment.yaml':
|
||||
- 'actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9'
|
||||
@@ -101,9 +101,9 @@ dependencies:
|
||||
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
owner_id: 44036562
|
||||
repo_id: 197814629
|
||||
'actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294':
|
||||
ref: 'v5.0.0'
|
||||
commit: 'sha1-a1d282b36b6f3519aa1f3fc636f609c47dddb294'
|
||||
'actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec':
|
||||
ref: 'v5.0.1'
|
||||
commit: 'sha1-bbc44d14a204704ccc493733616cd1e93a0321ec'
|
||||
owner_id: 44036562
|
||||
repo_id: 476372928
|
||||
'actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333':
|
||||
@@ -151,9 +151,9 @@ dependencies:
|
||||
commit: 'sha1-89ae32b08ed1a541efecbab17912962a5e38981c'
|
||||
owner_id: 7513068
|
||||
repo_id: 113918130
|
||||
'github/codeql-action@33d7b85da1a04171e211befe2c739303b9a4c066':
|
||||
ref: 'v4.39.3'
|
||||
commit: 'sha1-33d7b85da1a04171e211befe2c739303b9a4c066'
|
||||
'github/codeql-action@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea':
|
||||
ref: 'v4.39.4'
|
||||
commit: 'sha1-1bd86f2fdb4b86187fa4059f16f31a3202acc9ea'
|
||||
owner_id: 9919
|
||||
repo_id: 259445878
|
||||
'home-assistant/[email protected]':
|
||||
|
||||
@@ -32,12 +32,12 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
||||
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
|
||||
with:
|
||||
languages: javascript-typescript
|
||||
build-mode: none
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
||||
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
|
||||
with:
|
||||
category: "/language:javascript-typescript"
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
contents: read # To compare the dependency graph between base and head
|
||||
steps:
|
||||
- name: Dependency review
|
||||
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
|
||||
uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec # v5.0.1
|
||||
with:
|
||||
license-check: false # Covered by pnpm lint:licenses
|
||||
fail-on-severity: high
|
||||
|
||||
@@ -53,10 +53,11 @@ Detailed guidance lives in `.agents/skills/<name>/SKILL.md`. Load every matching
|
||||
- `ha-frontend-ux-readiness`: UI/UX routing that complements frontend review for new user experiences.
|
||||
- `ha-frontend-gallery`: gallery pages, demos, sidebar structure, content, and verification.
|
||||
- `ha-frontend-demo`: standalone demo structure, configurations, navigation, shared stubs, and verification.
|
||||
- `ha-frontend-browser-checks`: checking a change in a browser at real device sizes, in light and dark mode, right to left (RTL) and with long translations, and screenshots and recorded demos for pull requests.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
When creating a pull request, use `.github/PULL_REQUEST_TEMPLATE.md` as the PR body. Preserve template sections, check only the appropriate type-of-change boxes, and do not check checklist items on behalf of the user. If the PR includes UI changes, remind the user to add screenshots or a short video.
|
||||
When creating a pull request, use `.github/PULL_REQUEST_TEMPLATE.md` as the PR body. Preserve template sections, check only the appropriate type-of-change boxes, and do not check checklist items on behalf of the user. If the PR includes UI changes, add screenshots or a short video, taken as `ha-frontend-browser-checks` describes. Only ask the user to add them when you can't take them yourself.
|
||||
|
||||
## AI policy
|
||||
|
||||
|
||||
@@ -25,13 +25,7 @@ const NOTICE_FILES = [path.join(NODE_MODULES, "echarts/NOTICE")];
|
||||
// that the new version's license still matches. The build will fail if
|
||||
// the pinned version is no longer installed.
|
||||
const LICENSE_OVERRIDES = [
|
||||
{
|
||||
// type-fest ships two license files (MIT for code, CC0 for types).
|
||||
// We use the MIT license since that covers the bundled code.
|
||||
packageName: "type-fest",
|
||||
version: "5.10.0",
|
||||
licenseFile: "license-mit",
|
||||
},
|
||||
// No entries currently needed.
|
||||
];
|
||||
|
||||
// Locate the directory of an installed package matching an exact version.
|
||||
|
||||
@@ -70,6 +70,32 @@ const ENTITIES = [
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_closed",
|
||||
state: "closed",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind closed",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_open",
|
||||
state: "open",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind open",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_slider_half",
|
||||
state: "on",
|
||||
|
||||
+31
-31
@@ -43,28 +43,28 @@
|
||||
"@babel/runtime": "8.1.3",
|
||||
"@braintree/sanitize-url": "7.1.2",
|
||||
"@codemirror/autocomplete": "6.20.4",
|
||||
"@codemirror/commands": "6.11.1",
|
||||
"@codemirror/commands": "6.11.2",
|
||||
"@codemirror/lang-jinja": "6.0.1",
|
||||
"@codemirror/lang-python": "6.2.1",
|
||||
"@codemirror/lang-yaml": "6.1.3",
|
||||
"@codemirror/language": "6.13.1",
|
||||
"@codemirror/lint": "6.9.8",
|
||||
"@codemirror/search": "6.7.2",
|
||||
"@codemirror/search": "6.7.3",
|
||||
"@codemirror/state": "6.7.6",
|
||||
"@codemirror/view": "6.43.15",
|
||||
"@codemirror/view": "6.44.2",
|
||||
"@date-fns/tz": "1.5.0",
|
||||
"@egjs/hammerjs": "2.0.17",
|
||||
"@formatjs/intl-datetimeformat": "8.0.3",
|
||||
"@formatjs/intl-displaynames": "8.0.3",
|
||||
"@formatjs/intl-durationformat": "0.13.0",
|
||||
"@formatjs/intl-getcanonicallocales": "3.4.0",
|
||||
"@formatjs/intl-listformat": "9.1.0",
|
||||
"@formatjs/intl-locale": "5.5.0",
|
||||
"@formatjs/intl-numberformat": "10.1.0",
|
||||
"@formatjs/intl-pluralrules": "7.1.0",
|
||||
"@formatjs/intl-relativetimeformat": "13.0.3",
|
||||
"@formatjs/intl-datetimeformat": "8.2.2",
|
||||
"@formatjs/intl-displaynames": "8.0.5",
|
||||
"@formatjs/intl-durationformat": "0.13.2",
|
||||
"@formatjs/intl-getcanonicallocales": "3.4.2",
|
||||
"@formatjs/intl-listformat": "9.1.2",
|
||||
"@formatjs/intl-locale": "5.5.2",
|
||||
"@formatjs/intl-numberformat": "10.1.2",
|
||||
"@formatjs/intl-pluralrules": "7.1.2",
|
||||
"@formatjs/intl-relativetimeformat": "13.0.5",
|
||||
"@home-assistant/webawesome": "3.14.0-ha.2",
|
||||
"@lezer/common": "1.5.6",
|
||||
"@lezer/common": "1.5.7",
|
||||
"@lezer/highlight": "1.2.5",
|
||||
"@lit-labs/motion": "1.1.0",
|
||||
"@lit-labs/observers": "2.1.0",
|
||||
@@ -79,12 +79,12 @@
|
||||
"@swc/helpers": "0.5.24",
|
||||
"@tsparticles/engine": "4.5.4",
|
||||
"@tsparticles/preset-links": "4.5.4",
|
||||
"@versatiles/style": "9.1.0",
|
||||
"@versatiles/style": "9.1.3",
|
||||
"@vibrant/color": "4.0.4",
|
||||
"@vvo/tzdb": "6.204.0",
|
||||
"@vvo/tzdb": "6.208.0",
|
||||
"@webcomponents/scoped-custom-element-registry": "0.0.11",
|
||||
"barcode-detector": "3.2.4",
|
||||
"cally": "0.9.2",
|
||||
"barcode-detector": "3.2.5",
|
||||
"cally": "0.10.0",
|
||||
"color-name": "2.1.1",
|
||||
"comlink": "4.4.2",
|
||||
"core-js": "3.51.0",
|
||||
@@ -102,15 +102,15 @@
|
||||
"hls.js": "1.7.4",
|
||||
"home-assistant-js-websocket": "9.9.0",
|
||||
"idb-keyval": "6.3.0",
|
||||
"intl-messageformat": "12.2.0",
|
||||
"intl-messageformat": "12.2.1",
|
||||
"js-yaml": "5.5.0",
|
||||
"leaflet": "1.9.4",
|
||||
"leaflet.markercluster": "1.5.3",
|
||||
"lit": "3.3.3",
|
||||
"lit-html": "3.3.3",
|
||||
"maplibre-gl": "6.19.0",
|
||||
"marked": "18.2.1",
|
||||
"memoize-one": "6.0.0",
|
||||
"maplibre-gl": "6.20.0",
|
||||
"marked": "18.3.0",
|
||||
"memoize-one": "7.0.0",
|
||||
"nanoid": "6.0.2",
|
||||
"node-vibrant": "4.0.4",
|
||||
"object-hash": "3.0.0",
|
||||
@@ -147,13 +147,13 @@
|
||||
"@eslint/js": "10.0.1",
|
||||
"@gfx/zopfli": "1.0.15",
|
||||
"@home-assistant/components": "workspace:*",
|
||||
"@html-eslint/eslint-plugin": "0.68.0",
|
||||
"@html-eslint/eslint-plugin": "0.69.0",
|
||||
"@lokalise/node-api": "17.0.1",
|
||||
"@octokit/auth-oauth-device": "8.0.5",
|
||||
"@octokit/rest": "22.0.1",
|
||||
"@playwright/test": "1.65.1",
|
||||
"@rsdoctor/rspack-plugin": "1.6.5",
|
||||
"@rspack/core": "2.3.3",
|
||||
"@rspack/core": "2.3.4",
|
||||
"@rspack/dev-server": "2.2.2",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||
"@types/chromecast-caf-receiver": "7.0.1",
|
||||
@@ -162,15 +162,15 @@
|
||||
"@types/culori": "4.0.1",
|
||||
"@types/geojson": "7946.0.16",
|
||||
"@types/html-minifier-terser": "7.0.2",
|
||||
"@types/leaflet": "1.9.22",
|
||||
"@types/leaflet": "1.9.23",
|
||||
"@types/leaflet.markercluster": "1.5.6",
|
||||
"@types/lodash.merge": "4.6.9",
|
||||
"@types/node": "24.19.2",
|
||||
"@types/node": "24.19.4",
|
||||
"@types/qrcode": "1.5.6",
|
||||
"@types/sortablejs": "1.15.9",
|
||||
"@types/tar": "7.0.87",
|
||||
"@typescript/native": "npm:[email protected]",
|
||||
"@vitest/coverage-v8": "5.1.1",
|
||||
"@vitest/coverage-v8": "5.1.2",
|
||||
"babel-loader": "10.1.1",
|
||||
"babel-plugin-polyfill-corejs3": "1.0.0",
|
||||
"browserslist": "4.29.6",
|
||||
@@ -178,7 +178,7 @@
|
||||
"core-js-compat": "3.51.0",
|
||||
"del": "9.0.1",
|
||||
"eslint": "10.15.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-config-prettier": "10.1.9",
|
||||
"eslint-import-resolver-webpack": "0.13.11",
|
||||
"eslint-plugin-import-x": "4.18.1",
|
||||
"eslint-plugin-lit": "2.3.1",
|
||||
@@ -210,14 +210,14 @@
|
||||
"rspack-manifest-plugin": "5.2.2",
|
||||
"serve": "14.2.8",
|
||||
"sinon": "22.1.0",
|
||||
"tar": "7.5.23",
|
||||
"tar": "7.5.24",
|
||||
"terser-webpack-plugin": "5.6.1",
|
||||
"ts-lit-plugin": "2.0.2",
|
||||
"typescript": "6.0.3",
|
||||
"typescript-eslint": "8.73.0",
|
||||
"vite": "8.3.8",
|
||||
"typescript-eslint": "8.74.0",
|
||||
"vite": "8.4.0",
|
||||
"vite-tsconfig-paths": "6.1.1",
|
||||
"vitest": "5.1.1",
|
||||
"vitest": "5.1.2",
|
||||
"webpack-stats-plugin": "1.1.3",
|
||||
"webpackbar": "7.0.0",
|
||||
"workbox-build": "7.4.1"
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@custom-elements-manifest/analyzer": "0.11.0",
|
||||
"@rslib/core": "1.0.7",
|
||||
"@rslib/core": "1.1.0",
|
||||
"lit": "3.3.3",
|
||||
"typescript": "6.0.3"
|
||||
}
|
||||
|
||||
Generated
+784
-702
File diff suppressed because it is too large.
Load diff
@@ -18,6 +18,8 @@ trustPolicyExclude:
|
||||
- [email protected]
|
||||
# Pre-release published without provenance, used by workbox-build
|
||||
- "@trickfilm400/[email protected]"
|
||||
# Published without the trusted-publisher record; provenance still from vvo/tzdb release.yml
|
||||
- "@vvo/[email protected]"
|
||||
|
||||
# Dependency build scripts are denied unless listed here with true
|
||||
allowBuilds:
|
||||
|
||||
+2
-2
@@ -126,9 +126,9 @@
|
||||
"matchPackageNames": ["echarts", "zrender"]
|
||||
},
|
||||
{
|
||||
"description": "Group formatjs monorepo package",
|
||||
"description": "Group formatjs monorepo packages",
|
||||
"groupName": "formatjs",
|
||||
"matchPackageNames": ["@formatjs/**"]
|
||||
"matchPackageNames": ["@formatjs/**", "intl-messageformat"]
|
||||
},
|
||||
{
|
||||
"description": "Group Playwright package and CI container updates",
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* How long after the full screen button the companion apps hide the page for
|
||||
* the change, and after that how long they keep it hidden. A later hide ends
|
||||
* streams as usual.
|
||||
*/
|
||||
export const FULLSCREEN_ENTER_TIME = 1000;
|
||||
|
||||
let enterStart = 0;
|
||||
|
||||
let enterId = 0;
|
||||
|
||||
// The last entering each stream let a hidden page through for
|
||||
const claimedEnters = new WeakMap<object, number>();
|
||||
|
||||
/**
|
||||
* Marks that the full screen button was pressed to enter full screen. The
|
||||
* companion apps hide the page for a moment then, which shouldn't end a
|
||||
* stream. Leaving full screen isn't marked, so locking the phone or leaving
|
||||
* the app right after it always ends the streams.
|
||||
*/
|
||||
export const startEnteringFullscreen = () => {
|
||||
enterId++;
|
||||
enterStart = Date.now();
|
||||
};
|
||||
|
||||
/** Ends it early, like when the browser denies full screen. */
|
||||
export const cancelEnteringFullscreen = () => {
|
||||
enterStart = 0;
|
||||
};
|
||||
|
||||
export const isEnteringFullscreen = () =>
|
||||
Date.now() - enterStart < FULLSCREEN_ENTER_TIME;
|
||||
|
||||
/**
|
||||
* Whether the page is hidden by entering full screen, which hides it only
|
||||
* once. Any later hiding is the user leaving, so each stream gets true only
|
||||
* once per entering.
|
||||
*/
|
||||
export const claimFullscreenEnterHide = (stream: object): boolean => {
|
||||
if (!isEnteringFullscreen() || claimedEnters.get(stream) === enterId) {
|
||||
return false;
|
||||
}
|
||||
claimedEnters.set(stream, enterId);
|
||||
// Counts from here, so the video still plays on when the page shows again
|
||||
enterStart = Date.now();
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
import { mdiVideoOffOutline } from "@mdi/js";
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import "../ha-svg-icon";
|
||||
|
||||
/**
|
||||
* @element ha-camera-placeholder
|
||||
*
|
||||
* @summary Shows instead of a camera's picture when there is none, like
|
||||
* while the camera is unavailable.
|
||||
*/
|
||||
@customElement("ha-camera-placeholder")
|
||||
export class HaCameraPlaceholder extends LitElement {
|
||||
protected render() {
|
||||
return html`<ha-svg-icon .path=${mdiVideoOffOutline}></ha-svg-icon>`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--secondary-text-color);
|
||||
--mdc-icon-size: 40px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-camera-placeholder": HaCameraPlaceholder;
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,27 @@ import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
import { storage } from "../../common/decorators/storage";
|
||||
import { deepActiveElement } from "../../common/dom/deep-active-element";
|
||||
import { fireEvent, type HASSDomEvent } from "../../common/dom/fire_event";
|
||||
import {
|
||||
cancelEnteringFullscreen,
|
||||
isEnteringFullscreen,
|
||||
startEnteringFullscreen,
|
||||
} from "../../common/dom/entering-fullscreen";
|
||||
import { ctrlOrCmdLabel } from "../../common/keyboard/ctrl-or-cmd";
|
||||
import type { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { nextRender } from "../../common/util/render-status";
|
||||
import type { CameraCapabilities, CameraEntity } from "../../data/camera";
|
||||
import type { CameraStreamStatus } from "../../data/camera-streams";
|
||||
import { showCameraStreamInfoDialog } from "../../dialogs/camera/show-dialog-camera-stream-info";
|
||||
import { isExternal } from "../../data/external";
|
||||
import {
|
||||
showCameraStreamInfoDialog,
|
||||
type CameraStreamInfo,
|
||||
} from "../../dialogs/camera/show-dialog-camera-stream-info";
|
||||
import "../ha-camera-stream";
|
||||
import type { HaCameraStream } from "../ha-camera-stream";
|
||||
import "../ha-icon-button";
|
||||
import "../ha-spinner";
|
||||
import "../ha-svg-icon";
|
||||
import "./ha-camera-placeholder";
|
||||
import "./ha-camera-stream-badge";
|
||||
import {
|
||||
fitPicture,
|
||||
@@ -97,6 +107,9 @@ export class HaCameraPlayer extends LitElement {
|
||||
@property({ type: Boolean, attribute: "keep-awake" })
|
||||
public keepAwake = false;
|
||||
|
||||
/** Fills the height it is given, with the picture in the middle. */
|
||||
@property({ type: Boolean, reflect: true }) public fill = false;
|
||||
|
||||
@state() private _status: CameraStreamStatus = {
|
||||
connecting: true,
|
||||
hasAudio: false,
|
||||
@@ -104,6 +117,8 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
@state() private _capabilities?: CameraCapabilities;
|
||||
|
||||
private _streamInfoCallbacks = new Set<(info: CameraStreamInfo) => void>();
|
||||
|
||||
@state() private _video?: HTMLVideoElement;
|
||||
|
||||
@state() private _muted = false;
|
||||
@@ -133,6 +148,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
// full screen player
|
||||
@state() private _paused = false;
|
||||
|
||||
// Playing when its button entered full screen, so a pause meanwhile is the
|
||||
// companion app's
|
||||
private _playingBeforeFullscreen = false;
|
||||
|
||||
@query("ha-camera-stream") private _stream?: HaCameraStream;
|
||||
|
||||
@query(".player") private _player?: HTMLElement;
|
||||
@@ -186,7 +205,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
document.addEventListener("visibilitychange", this._requestWakeLock);
|
||||
document.addEventListener("visibilitychange", this._visibilityChanged);
|
||||
// The first update requests it, once keep-awake is set
|
||||
if (this.hasUpdated) {
|
||||
this._requestWakeLock();
|
||||
@@ -200,7 +219,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener("visibilitychange", this._requestWakeLock);
|
||||
document.removeEventListener("visibilitychange", this._visibilityChanged);
|
||||
this._releaseWakeLock();
|
||||
document.removeEventListener("fullscreenchange", this._fullscreenChanged);
|
||||
document.removeEventListener(
|
||||
@@ -209,6 +228,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
);
|
||||
clearTimeout(this._controlsTimeout);
|
||||
clearTimeout(this._wheelHintTimeout);
|
||||
this._streamInfoCallbacks.clear();
|
||||
this._unbindVideo(this._video);
|
||||
this._video = undefined;
|
||||
this._pointers.clear();
|
||||
@@ -235,7 +255,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
const aspectRatio = this._aspectRatio();
|
||||
if (aspectRatio !== this._firedAspectRatio) {
|
||||
this._firedAspectRatio = aspectRatio;
|
||||
fireEvent(this, "camera-aspect-ratio-changed", { aspectRatio });
|
||||
fireEvent(this, "media-size-changed", { aspectRatio });
|
||||
}
|
||||
if (changedProps.has("keepAwake")) {
|
||||
if (this.keepAwake) {
|
||||
@@ -248,6 +268,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._unbindVideo(changedProps.get("_video") as HTMLVideoElement);
|
||||
this._bindVideo(this._video);
|
||||
}
|
||||
if (changedProps.has("_status") || changedProps.has("_capabilities")) {
|
||||
const info = this._streamInfo();
|
||||
this._streamInfoCallbacks.forEach((callback) => callback(info));
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -259,11 +283,12 @@ export class HaCameraPlayer extends LitElement {
|
||||
// controls and zoom of this one can't reach, so it shows just the stream
|
||||
const inApp = Boolean(status.inApp);
|
||||
const zoomed = !inApp && isZoomed(this._zoom);
|
||||
// Stays while the connection changes, so the user sees what happens
|
||||
// Stays while not live, so the user sees what happens
|
||||
const badgeVisible =
|
||||
this._controlsVisible ||
|
||||
status.connecting ||
|
||||
status.upgrading !== undefined;
|
||||
Boolean(status.unavailable) ||
|
||||
Boolean(status.disconnected);
|
||||
|
||||
return html`
|
||||
<div
|
||||
@@ -284,9 +309,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
gesture: this._gesture,
|
||||
})}
|
||||
style=${styleMap({
|
||||
aspectRatio: this._fullscreen
|
||||
? undefined
|
||||
: String(this._aspectRatio()),
|
||||
aspectRatio:
|
||||
this._fullscreen || this.fill
|
||||
? undefined
|
||||
: String(this._aspectRatio()),
|
||||
})}
|
||||
@pointerdown=${this._pointerDown}
|
||||
@pointerup=${this._pointerUp}
|
||||
@@ -303,6 +329,9 @@ export class HaCameraPlayer extends LitElement {
|
||||
mjpeg-video
|
||||
measure-poster
|
||||
style=${styleMap({
|
||||
"--picture-aspect-ratio": this.fill
|
||||
? String(this._aspectRatio())
|
||||
: undefined,
|
||||
transform: zoomed
|
||||
? `translate(${this._zoom.x}px, ${this._zoom.y}px) scale(${this._zoom.scale})`
|
||||
: undefined,
|
||||
@@ -312,6 +341,11 @@ export class HaCameraPlayer extends LitElement {
|
||||
@camera-capabilities-changed=${this._capabilitiesChanged}
|
||||
@camera-poster-size-changed=${this._posterSizeChanged}
|
||||
></ha-camera-stream>
|
||||
${
|
||||
status.unavailable
|
||||
? html`<ha-camera-placeholder></ha-camera-placeholder>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
${inApp ? nothing : this._renderControls(status, zoomed, badgeVisible)}
|
||||
</div>
|
||||
@@ -325,7 +359,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
) {
|
||||
return html`
|
||||
${
|
||||
this._paused && !status.connecting
|
||||
this._paused &&
|
||||
!status.connecting &&
|
||||
!status.unavailable &&
|
||||
!status.disconnected
|
||||
? html`<ha-icon-button
|
||||
class="control pinned play"
|
||||
.label=${this._localize("ui.components.camera-player.play")}
|
||||
@@ -458,6 +495,11 @@ export class HaCameraPlayer extends LitElement {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _visibilityChanged = () => {
|
||||
this._requestWakeLock();
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
/**
|
||||
* Browsers release the lock when the page is hidden, so it is requested
|
||||
* again whenever the page shows.
|
||||
@@ -536,15 +578,21 @@ export class HaCameraPlayer extends LitElement {
|
||||
) {
|
||||
const oldStatus = this._status;
|
||||
this._status = ev.detail;
|
||||
if (ev.detail.inApp) {
|
||||
if (ev.detail.inApp || ev.detail.unavailable) {
|
||||
this._zoom = ZOOM_PAN_IDENTITY;
|
||||
}
|
||||
if (
|
||||
oldStatus.connecting !== ev.detail.connecting ||
|
||||
oldStatus.unavailable !== ev.detail.unavailable ||
|
||||
oldStatus.disconnected !== ev.detail.disconnected
|
||||
) {
|
||||
// Shows the new state for a moment
|
||||
this._showControls();
|
||||
}
|
||||
if (
|
||||
oldStatus.connecting !== ev.detail.connecting ||
|
||||
oldStatus.type !== ev.detail.type
|
||||
) {
|
||||
// Shows the new connection for a moment
|
||||
this._showControls();
|
||||
this._updateVideo();
|
||||
}
|
||||
}
|
||||
@@ -579,10 +627,26 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._posterSize = ev.detail.size;
|
||||
}
|
||||
|
||||
private _showStreamInfo() {
|
||||
showCameraStreamInfoDialog(this, {
|
||||
private _streamInfo(): CameraStreamInfo {
|
||||
return {
|
||||
status: this._status,
|
||||
supportedTypes: this._capabilities?.frontend_stream_types,
|
||||
};
|
||||
}
|
||||
|
||||
private _subscribeStreamInfo = (
|
||||
callback: (info: CameraStreamInfo) => void
|
||||
) => {
|
||||
this._streamInfoCallbacks.add(callback);
|
||||
callback(this._streamInfo());
|
||||
return () => {
|
||||
this._streamInfoCallbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
|
||||
private _showStreamInfo() {
|
||||
showCameraStreamInfoDialog(this, {
|
||||
subscribe: this._subscribeStreamInfo,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -671,6 +735,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._paused = Boolean(
|
||||
video?.paused && (video.srcObject || video.currentSrc)
|
||||
);
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
private _toggleMute() {
|
||||
@@ -722,16 +787,25 @@ export class HaCameraPlayer extends LitElement {
|
||||
("webkitFullscreenElement" in document
|
||||
? (document.webkitFullscreenElement as Element | null)
|
||||
: null);
|
||||
const fullscreen = Boolean(
|
||||
this._fullscreen = Boolean(
|
||||
this._player && fullscreenElement === this._player
|
||||
);
|
||||
if (fullscreen !== this._fullscreen) {
|
||||
this._fullscreen = fullscreen;
|
||||
// The size changes, so the zoomed in area would be off
|
||||
this._zoom = ZOOM_PAN_IDENTITY;
|
||||
}
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
// The companion apps pause the video while entering full screen
|
||||
private _resumeAfterEnteringFullscreen() {
|
||||
if (
|
||||
isExternal &&
|
||||
this._playingBeforeFullscreen &&
|
||||
this._paused &&
|
||||
document.visibilityState === "visible" &&
|
||||
isEnteringFullscreen()
|
||||
) {
|
||||
this._ensurePlaying();
|
||||
}
|
||||
}
|
||||
|
||||
private async _toggleFullscreen() {
|
||||
const player = this._player;
|
||||
if (!player) {
|
||||
@@ -746,6 +820,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._playingBeforeFullscreen = Boolean(
|
||||
this._video && !this._video.paused
|
||||
);
|
||||
startEnteringFullscreen();
|
||||
if (player.requestFullscreen) {
|
||||
await player.requestFullscreen();
|
||||
} else if ("webkitRequestFullscreen" in player) {
|
||||
@@ -759,6 +837,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
}
|
||||
} catch (_err: unknown) {
|
||||
// Denied by the browser
|
||||
cancelEnteringFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -813,12 +892,17 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._zoom = refitZoomPan(this._zoom, oldViewport, viewport);
|
||||
};
|
||||
|
||||
// The app's own player and a camera without picture can't be zoomed
|
||||
private _canZoom(): boolean {
|
||||
return !this._status.inApp && !this._status.unavailable;
|
||||
}
|
||||
|
||||
private _resetZoom() {
|
||||
this._zoom = ZOOM_PAN_IDENTITY;
|
||||
}
|
||||
|
||||
private _wheel(ev: WheelEvent) {
|
||||
if (!this._viewport || this._status.inApp) {
|
||||
if (!this._viewport || !this._canZoom()) {
|
||||
return;
|
||||
}
|
||||
// A pinch on a touchpad scrolls with ctrl held
|
||||
@@ -862,7 +946,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
}
|
||||
|
||||
private _doubleClick(ev: MouseEvent) {
|
||||
if (!this._viewport || this._status.inApp) {
|
||||
if (!this._viewport || !this._canZoom()) {
|
||||
return;
|
||||
}
|
||||
if (isZoomed(this._zoom)) {
|
||||
@@ -905,7 +989,8 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._showControls();
|
||||
}
|
||||
const pointer = this._pointers.get(ev.pointerId);
|
||||
if (!pointer || !this._viewport) {
|
||||
// Taps still toggle the controls when the picture can't be zoomed
|
||||
if (!pointer || !this._viewport || !this._canZoom()) {
|
||||
return;
|
||||
}
|
||||
const { rect, viewport } = this._measureViewport();
|
||||
@@ -1030,6 +1115,38 @@ export class HaCameraPlayer extends LitElement {
|
||||
cursor: none;
|
||||
}
|
||||
|
||||
:host([fill]) {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
:host([fill]) .player {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
|
||||
:host([fill]) .viewport {
|
||||
height: 100%;
|
||||
max-height: none;
|
||||
container-type: size;
|
||||
--video-max-height: 100%;
|
||||
}
|
||||
|
||||
/* As large as the picture fits in the middle, zoomed from the corner of
|
||||
the viewport like a stream that fills it */
|
||||
:host([fill]) ha-camera-stream {
|
||||
--picture-width: min(100cqw, 100cqh * var(--picture-aspect-ratio));
|
||||
--picture-height: min(100cqh, 100cqw / var(--picture-aspect-ratio));
|
||||
position: absolute;
|
||||
top: calc((100cqh - var(--picture-height)) / 2);
|
||||
left: calc((100cqw - var(--picture-width)) / 2);
|
||||
width: var(--picture-width);
|
||||
height: var(--picture-height);
|
||||
transform-origin: calc((var(--picture-width) - 100cqw) / 2)
|
||||
calc((var(--picture-height) - 100cqh) / 2);
|
||||
}
|
||||
|
||||
.viewport {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
@@ -1067,6 +1184,12 @@ export class HaCameraPlayer extends LitElement {
|
||||
transition: transform var(--ha-animation-duration-fast) ease-out;
|
||||
}
|
||||
|
||||
ha-camera-placeholder {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.viewport.gesture ha-camera-stream {
|
||||
transition: none;
|
||||
will-change: transform;
|
||||
@@ -1189,6 +1312,7 @@ declare global {
|
||||
"ha-camera-player": HaCameraPlayer;
|
||||
}
|
||||
interface HASSDomEvents {
|
||||
"camera-aspect-ratio-changed": { aspectRatio: number };
|
||||
/** The natural width limits the picture's width when it is set */
|
||||
"media-size-changed": { aspectRatio: number; naturalWidth?: number };
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import type {
|
||||
CameraStreamStatus,
|
||||
CameraStreamType,
|
||||
} from "../../data/camera-streams";
|
||||
import "../ha-spinner";
|
||||
|
||||
/** Names of the protocols, the same in every language. */
|
||||
export const CAMERA_STREAM_TYPE_NAMES: Record<CameraStreamType, string> = {
|
||||
@@ -16,8 +15,10 @@ export const CAMERA_STREAM_TYPE_NAMES: Record<CameraStreamType, string> = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows over a camera stream how it is connected. A faster stream that still
|
||||
* connects in the background is shown next to the current one.
|
||||
* @element ha-camera-stream-badge
|
||||
*
|
||||
* @summary Shows over a camera stream whether it is live. Selecting it
|
||||
* shows how it is connected.
|
||||
*/
|
||||
@customElement("ha-camera-stream-badge")
|
||||
export class HaCameraStreamBadge extends LitElement {
|
||||
@@ -32,51 +33,27 @@ export class HaCameraStreamBadge extends LitElement {
|
||||
if (!status) {
|
||||
return nothing;
|
||||
}
|
||||
const connecting = status.connecting || !status.type;
|
||||
const label = connecting
|
||||
? this._localize("ui.components.camera-player.connecting")
|
||||
: CAMERA_STREAM_TYPE_NAMES[status.type!];
|
||||
const connection = status.disconnected
|
||||
? "disconnected"
|
||||
: status.unavailable
|
||||
? "unavailable"
|
||||
: status.connecting || !status.type
|
||||
? "connecting"
|
||||
: "live";
|
||||
|
||||
return html`
|
||||
<button
|
||||
type="button"
|
||||
aria-label=${this._ariaLabel(status)}
|
||||
class=${connecting ? "connecting" : "live"}
|
||||
>
|
||||
<button type="button" class=${connection} aria-describedby="details">
|
||||
<span class="dot"></span>
|
||||
<span class="label">${label}</span>
|
||||
${
|
||||
status.upgrading
|
||||
? html`<span class="upgrading" aria-hidden="true">
|
||||
<ha-spinner></ha-spinner>
|
||||
${CAMERA_STREAM_TYPE_NAMES[status.upgrading]}
|
||||
</span>`
|
||||
: nothing
|
||||
}
|
||||
<span class="label"
|
||||
>${this._localize(`ui.components.camera-player.${connection}`)}</span
|
||||
>
|
||||
</button>
|
||||
<span id="details" hidden
|
||||
>${this._localize("ui.components.camera-player.show_details")}</span
|
||||
>
|
||||
`;
|
||||
}
|
||||
|
||||
private _ariaLabel(status: CameraStreamStatus): string {
|
||||
if (status.connecting || !status.type) {
|
||||
return this._localize(
|
||||
"ui.components.camera-player.stream_info_connecting"
|
||||
);
|
||||
}
|
||||
if (status.upgrading) {
|
||||
return this._localize(
|
||||
"ui.components.camera-player.stream_info_upgrading",
|
||||
{
|
||||
type: CAMERA_STREAM_TYPE_NAMES[status.type],
|
||||
upgrading: CAMERA_STREAM_TYPE_NAMES[status.upgrading],
|
||||
}
|
||||
);
|
||||
}
|
||||
return this._localize("ui.components.camera-player.stream_info", {
|
||||
type: CAMERA_STREAM_TYPE_NAMES[status.type],
|
||||
});
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: inline-flex;
|
||||
@@ -120,16 +97,12 @@ export class HaCameraStreamBadge extends LitElement {
|
||||
animation: pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.upgrading {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-1);
|
||||
padding-inline-start: var(--ha-space-1);
|
||||
border-inline-start: 1px solid rgba(255, 255, 255, 0.3);
|
||||
opacity: 0.7;
|
||||
--ha-spinner-indicator-color: var(--ha-color-white);
|
||||
--ha-spinner-size: 10px;
|
||||
--ha-spinner-divider-color: rgba(255, 255, 255, 0.3);
|
||||
.unavailable .dot {
|
||||
background-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.disconnected .dot {
|
||||
background-color: var(--ha-color-red-60);
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
|
||||
@@ -328,6 +328,11 @@ export function generateStatisticsChartData(
|
||||
: undefined,
|
||||
color: chartType === "bar" ? backgroundColor : borderColor,
|
||||
};
|
||||
if (chartType === "bar") {
|
||||
// echarts sizes bars from the smallest gap between points, so sparse
|
||||
// data (one point, or points far apart) gets huge bars without a cap
|
||||
(series as BarSeriesOption).barMaxWidth = 50;
|
||||
}
|
||||
if (chartStacked) {
|
||||
series.stack = `band-stacked`;
|
||||
series.stackStrategy = "samesign";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mdiClose } from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { createContext, provide } from "@lit/context";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { consume } from "../common/decorators/consume";
|
||||
@@ -11,7 +12,10 @@ import "./ha-icon-button";
|
||||
import "./ha-dialog";
|
||||
import type { DialogWidth } from "./ha-dialog";
|
||||
|
||||
type DialogSheetMode = "dialog" | "bottom-sheet";
|
||||
export type DialogSheetMode = "dialog" | "bottom-sheet";
|
||||
|
||||
export const adaptiveDialogModeContext =
|
||||
createContext<DialogSheetMode>("adaptiveDialogMode");
|
||||
|
||||
export const ADAPTIVE_DIALOG_MEDIA_QUERY =
|
||||
"(max-width: 870px), (max-height: 500px)";
|
||||
@@ -125,7 +129,9 @@ export class HaAdaptiveDialog extends LitElement {
|
||||
@property({ type: Boolean, reflect: true, attribute: "flexcontent" })
|
||||
public flexContent = false;
|
||||
|
||||
@state() public mode: DialogSheetMode = "dialog";
|
||||
@provide({ context: adaptiveDialogModeContext })
|
||||
@state()
|
||||
public mode: DialogSheetMode = "dialog";
|
||||
|
||||
@state()
|
||||
@consume({ context: internationalizationContext, subscribe: true })
|
||||
|
||||
@@ -34,6 +34,8 @@ import {
|
||||
connectionContext,
|
||||
formattersContext,
|
||||
} from "../data/context";
|
||||
import { UNAVAILABLE } from "../data/entity/entity";
|
||||
import "./camera/ha-camera-placeholder";
|
||||
import "./ha-hls-player";
|
||||
import type { HaHLSPlayer } from "./ha-hls-player";
|
||||
import "./ha-mjpeg-player";
|
||||
@@ -111,6 +113,13 @@ export class HaCameraStream extends LitElement {
|
||||
// The app plays the HLS stream in its own player, over the page
|
||||
@state() private _hlsInApp = false;
|
||||
|
||||
// WebRTC is the only stream and failed, its player shows why
|
||||
@state() private _webRtcFailed = false;
|
||||
|
||||
// The MJPEG image failed, it is tried again with the next access token or
|
||||
// once Home Assistant reconnects
|
||||
@state() private _mjpegImageFailed = false;
|
||||
|
||||
@query("ha-web-rtc-player") private _webRtcPlayer?: HaWebRtcPlayer;
|
||||
|
||||
@query("ha-mjpeg-player") private _mjpegPlayer?: HaMjpegPlayer;
|
||||
@@ -153,9 +162,32 @@ export class HaCameraStream extends LitElement {
|
||||
this._config.config.state === STATE_RUNNING &&
|
||||
oldConfig.config?.state !== STATE_RUNNING;
|
||||
|
||||
if (entityChanged || backendStarted) {
|
||||
this._getCapabilities();
|
||||
this._getPosterUrl();
|
||||
const oldStateObj = changedProps.get("stateObj") as
|
||||
CameraEntity | undefined;
|
||||
const becameAvailable =
|
||||
!entityChanged &&
|
||||
this.stateObj !== undefined &&
|
||||
oldStateObj?.state === UNAVAILABLE &&
|
||||
!this._unavailable;
|
||||
|
||||
if (entityChanged || backendStarted || becameAvailable) {
|
||||
if (this._unavailable) {
|
||||
// Core often doesn't know the camera then, as its integration
|
||||
// didn't load. Its capabilities are fetched once it is back.
|
||||
this._clearCapabilities();
|
||||
} else {
|
||||
this._getCapabilities();
|
||||
this._getPosterUrl();
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
oldStateObj &&
|
||||
oldStateObj.attributes.access_token !==
|
||||
this.stateObj?.attributes.access_token
|
||||
) {
|
||||
// A new token gives a new MJPEG address, worth another try
|
||||
this._mjpegImageFailed = false;
|
||||
}
|
||||
|
||||
const oldConnection = changedProps.get("_connection") as
|
||||
@@ -170,6 +202,10 @@ export class HaCameraStream extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private get _unavailable(): boolean {
|
||||
return this.stateObj?.state === UNAVAILABLE;
|
||||
}
|
||||
|
||||
/** The microphone track sent to the camera, only on WebRTC streams. */
|
||||
public get microphoneTrack(): MediaStreamTrack | undefined {
|
||||
return this._webRtcPlayer?.microphoneTrack;
|
||||
@@ -238,29 +274,63 @@ export class HaCameraStream extends LitElement {
|
||||
this._visibleStreamType = visibleStreamType;
|
||||
fireEvent(this, "stream-type-changed", { type: visibleStreamType });
|
||||
}
|
||||
const status: CameraStreamStatus = {
|
||||
...computeCameraStreamStatus(
|
||||
streams,
|
||||
// Nothing plays while Home Assistant is disconnected
|
||||
this._connection.connected ? this._loadedStreams : new Set(),
|
||||
this._hlsStreams,
|
||||
this._webRtcStreams
|
||||
),
|
||||
inApp: visibleStreamType === STREAM_TYPE_HLS && this._hlsInApp,
|
||||
};
|
||||
const status = this._computeStatus(streams, visibleStreamType);
|
||||
if (
|
||||
!this._status ||
|
||||
status.type !== this._status.type ||
|
||||
status.connecting !== this._status.connecting ||
|
||||
status.upgrading !== this._status.upgrading ||
|
||||
status.hasAudio !== this._status.hasAudio ||
|
||||
status.inApp !== this._status.inApp
|
||||
status.inApp !== this._status.inApp ||
|
||||
status.unavailable !== this._status.unavailable ||
|
||||
status.disconnected !== this._status.disconnected
|
||||
) {
|
||||
this._status = status;
|
||||
fireEvent(this, "camera-stream-status-changed", status);
|
||||
}
|
||||
}
|
||||
|
||||
private _computeStatus(
|
||||
streams: CameraStream[],
|
||||
visibleStreamType?: CameraStreamType
|
||||
): CameraStreamStatus {
|
||||
// A playing WebRTC stream can come straight from the camera or an
|
||||
// external go2rtc, it then keeps playing without Home Assistant
|
||||
const playsWithoutHomeAssistant =
|
||||
visibleStreamType === STREAM_TYPE_WEB_RTC &&
|
||||
this._loadedStreams.has(STREAM_TYPE_WEB_RTC);
|
||||
const inApp = visibleStreamType === STREAM_TYPE_HLS && this._hlsInApp;
|
||||
if (!this._connection.connected && !playsWithoutHomeAssistant) {
|
||||
// Kept so the player still shows its placeholder instead of nothing
|
||||
return {
|
||||
connecting: false,
|
||||
hasAudio: false,
|
||||
inApp,
|
||||
disconnected: "home_assistant",
|
||||
unavailable: this._unavailable,
|
||||
};
|
||||
}
|
||||
if (this._unavailable) {
|
||||
return { connecting: false, hasAudio: false, unavailable: true };
|
||||
}
|
||||
if (this._webRtcFailed) {
|
||||
return {
|
||||
connecting: false,
|
||||
hasAudio: false,
|
||||
disconnected: "stream_failed",
|
||||
};
|
||||
}
|
||||
return {
|
||||
...computeCameraStreamStatus(
|
||||
streams,
|
||||
this._loadedStreams,
|
||||
this._hlsStreams,
|
||||
this._webRtcStreams
|
||||
),
|
||||
inApp,
|
||||
};
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.stateObj) {
|
||||
return nothing;
|
||||
@@ -297,6 +367,11 @@ export class HaCameraStream extends LitElement {
|
||||
@load=${this._handleMjpegLoad}
|
||||
></ha-mjpeg-player>`;
|
||||
}
|
||||
if (this._mjpegImageFailed) {
|
||||
return html`<ha-camera-placeholder
|
||||
style=${styleMap({ aspectRatio: this.aspectRatio ?? 16 / 9 })}
|
||||
></ha-camera-placeholder>`;
|
||||
}
|
||||
return html`<img
|
||||
.src=${streamUrl}
|
||||
style=${styleMap({
|
||||
@@ -305,6 +380,7 @@ export class HaCameraStream extends LitElement {
|
||||
})}
|
||||
alt=${`Preview of the ${this._formatters?.formatEntityName(this.stateObj) ?? ""} camera.`}
|
||||
@load=${this._handleImageLoad}
|
||||
@error=${this._handleImageError}
|
||||
/>`;
|
||||
}
|
||||
|
||||
@@ -346,6 +422,9 @@ export class HaCameraStream extends LitElement {
|
||||
}
|
||||
|
||||
private _currentStreams() {
|
||||
if (this._unavailable) {
|
||||
return [];
|
||||
}
|
||||
return this._streams(
|
||||
this._capabilities?.frontend_stream_types,
|
||||
this._hlsStreams,
|
||||
@@ -353,10 +432,15 @@ export class HaCameraStream extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
private async _getCapabilities() {
|
||||
/** Returns the request number, so an older request can be dropped. */
|
||||
private _clearCapabilities() {
|
||||
this._capabilities = undefined;
|
||||
this._resetStreams();
|
||||
const request = ++this._capabilitiesRequest;
|
||||
return ++this._capabilitiesRequest;
|
||||
}
|
||||
|
||||
private async _getCapabilities() {
|
||||
const request = this._clearCapabilities();
|
||||
if (!supportsFeature(this.stateObj!, CameraEntityFeature.STREAM)) {
|
||||
this._capabilities = {
|
||||
frontend_stream_types: [],
|
||||
@@ -379,11 +463,14 @@ export class HaCameraStream extends LitElement {
|
||||
this._webRtcStreams = undefined;
|
||||
this._loadedStreams = new Set();
|
||||
this._hlsInApp = false;
|
||||
this._webRtcFailed = false;
|
||||
this._mjpegImageFailed = false;
|
||||
this._mjpegPlayer?.restart();
|
||||
}
|
||||
|
||||
private _restartMjpeg() {
|
||||
this._setLoaded(MJPEG_STREAM, false);
|
||||
this._mjpegImageFailed = false;
|
||||
this._mjpegPlayer?.restart();
|
||||
}
|
||||
|
||||
@@ -443,6 +530,11 @@ export class HaCameraStream extends LitElement {
|
||||
fireEvent(this, "load");
|
||||
}
|
||||
|
||||
private _handleImageError() {
|
||||
this._mjpegImageFailed = true;
|
||||
this._setLoaded(MJPEG_STREAM, false);
|
||||
}
|
||||
|
||||
private _handleMjpegLoad() {
|
||||
this._setLoaded(MJPEG_STREAM, true);
|
||||
}
|
||||
@@ -458,6 +550,7 @@ export class HaCameraStream extends LitElement {
|
||||
}
|
||||
|
||||
private _handleWebRtcLoad() {
|
||||
this._webRtcFailed = false;
|
||||
this._setLoaded(STREAM_TYPE_WEB_RTC, true);
|
||||
}
|
||||
|
||||
@@ -477,6 +570,7 @@ export class HaCameraStream extends LitElement {
|
||||
) {
|
||||
// Without another stream type, keep the player to show why it failed.
|
||||
// Only a browser without WebRTC falls back to MJPEG.
|
||||
this._webRtcFailed = true;
|
||||
this._setLoaded(STREAM_TYPE_WEB_RTC, false);
|
||||
return;
|
||||
}
|
||||
@@ -510,10 +604,15 @@ export class HaCameraStream extends LitElement {
|
||||
display: block;
|
||||
}
|
||||
|
||||
img {
|
||||
img,
|
||||
ha-camera-placeholder {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
ha-camera-placeholder {
|
||||
background-color: var(--ha-color-fill-neutral-normal-resting);
|
||||
}
|
||||
|
||||
ha-web-rtc-player {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
@@ -139,12 +139,17 @@ export class HaControlCircularSlider extends LitElement {
|
||||
|
||||
protected updated(changedProps: PropertyValues): void {
|
||||
super.updated(changedProps);
|
||||
const activeValue = this._getActiveValue();
|
||||
if (
|
||||
this._activeSlider &&
|
||||
activeValue != null &&
|
||||
changedProps.has(this._activeSlider) &&
|
||||
this[this._activeSlider] !== this._lastChanging
|
||||
) {
|
||||
this._lastChanging = undefined;
|
||||
this._lastChanging = this._steppedValue(activeValue);
|
||||
fireEvent(this, `${this._activeSlider}-changing`, {
|
||||
value: this._lastChanging,
|
||||
});
|
||||
}
|
||||
if (!this._activeSlider) {
|
||||
if (changedProps.has("value")) {
|
||||
@@ -179,6 +184,10 @@ export class HaControlCircularSlider extends LitElement {
|
||||
|
||||
disconnectedCallback(): void {
|
||||
super.disconnectedCallback();
|
||||
this._destroyListeners();
|
||||
if (this._activeSlider) {
|
||||
this._cancelInteraction();
|
||||
}
|
||||
}
|
||||
|
||||
private _managers: HammerManager[] = [];
|
||||
@@ -248,6 +257,18 @@ export class HaControlCircularSlider extends LitElement {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _cancelInteraction() {
|
||||
if (this._activeSlider) {
|
||||
fireEvent(this, `${this._activeSlider}-changing`, {
|
||||
value: undefined,
|
||||
});
|
||||
}
|
||||
this._activeSlider = undefined;
|
||||
this._localValue = this.value;
|
||||
this._localLow = this.low;
|
||||
this._localHigh = this.high;
|
||||
}
|
||||
|
||||
private _setupListeners() {
|
||||
if (this._interactions && this._managers.length === 0) {
|
||||
this._interactions.forEach((interaction) => {
|
||||
@@ -279,15 +300,7 @@ export class HaControlCircularSlider extends LitElement {
|
||||
mc.add(new Tap({ event: "singletap" }));
|
||||
|
||||
const cancelInteraction = () => {
|
||||
if (this._activeSlider) {
|
||||
fireEvent(this, `${this._activeSlider}-changing`, {
|
||||
value: undefined,
|
||||
});
|
||||
}
|
||||
this._activeSlider = undefined;
|
||||
this._localValue = this.value;
|
||||
this._localLow = this.low;
|
||||
this._localHigh = this.high;
|
||||
this._cancelInteraction();
|
||||
if (pressToActivate) {
|
||||
panRecognizer.set({ enable: false });
|
||||
}
|
||||
|
||||
@@ -250,8 +250,8 @@ export class HaDialog extends ScrollableFadeMixin(LitElement) {
|
||||
this._hassConfig?.auth.external &&
|
||||
isIosApp(this._hassConfig.auth.external)
|
||||
) {
|
||||
const element = this.querySelector("[autofocus]");
|
||||
if (element !== null) {
|
||||
const element = this._autofocusElement();
|
||||
if (element) {
|
||||
if (!element.id) {
|
||||
element.id = "ha-dialog-autofocus";
|
||||
}
|
||||
@@ -264,10 +264,30 @@ export class HaDialog extends ScrollableFadeMixin(LitElement) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
(this.querySelector("[autofocus]") as HTMLElement | null)?.focus();
|
||||
this._autofocusElement()?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
// Wrappers like ha-adaptive-dialog pass their content in through slots
|
||||
private _autofocusElement(): HTMLElement | null {
|
||||
const element = this.querySelector<HTMLElement>("[autofocus]");
|
||||
if (element) {
|
||||
return element;
|
||||
}
|
||||
for (const slot of this.querySelectorAll("slot")) {
|
||||
for (const assigned of slot.assignedElements({ flatten: true })) {
|
||||
if (assigned.matches("[autofocus]")) {
|
||||
return assigned as HTMLElement;
|
||||
}
|
||||
const nested = assigned.querySelector<HTMLElement>("[autofocus]");
|
||||
if (nested) {
|
||||
return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _handleAfterShow = (ev: Event) => {
|
||||
if (ev.eventPhase !== Event.AT_TARGET) {
|
||||
return;
|
||||
|
||||
@@ -73,6 +73,15 @@ export class HaDropdown extends Dropdown {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
private override async showMenu() {
|
||||
// Flip away from the safe areas instead of opening into them, where the
|
||||
// max-height below would squeeze the menu.
|
||||
const styles = getComputedStyle(this);
|
||||
// @ts-ignore flipPadding is typed as a number, floating-ui accepts sides
|
||||
this.popup.flipPadding = {
|
||||
top: parseFloat(styles.getPropertyValue("--safe-area-inset-top")) || 0,
|
||||
bottom:
|
||||
parseFloat(styles.getPropertyValue("--safe-area-inset-bottom")) || 0,
|
||||
};
|
||||
// @ts-ignore
|
||||
await super.showMenu();
|
||||
const triggerElement = this.getTrigger();
|
||||
|
||||
@@ -238,6 +238,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: var(--ha-space-2);
|
||||
padding-left: var(--ha-space-4);
|
||||
}
|
||||
.precise {
|
||||
grid-area: precise;
|
||||
|
||||
@@ -9,6 +9,10 @@ import { consume } from "../common/decorators/consume";
|
||||
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||
import { consumeLocalize } from "../common/decorators/consume-context-entry";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import {
|
||||
claimFullscreenEnterHide,
|
||||
FULLSCREEN_ENTER_TIME,
|
||||
} from "../common/dom/entering-fullscreen";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import { nextRender } from "../common/util/render-status";
|
||||
import { fetchStreamUrl } from "../data/camera";
|
||||
@@ -101,16 +105,19 @@ export class HaHLSPlayer extends LitElement {
|
||||
return;
|
||||
}
|
||||
if (document.hidden) {
|
||||
if (isExternal) {
|
||||
if (isExternal && !claimFullscreenEnterHide(this)) {
|
||||
// The companion apps pause JavaScript timers while in the background,
|
||||
// so a delayed clean up would not run until the app is opened again
|
||||
this._cleanUp();
|
||||
return;
|
||||
}
|
||||
this._hiddenCleanupTimeout = window.setTimeout(() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
}, HIDDEN_CLEANUP_DELAY);
|
||||
this._hiddenCleanupTimeout = window.setTimeout(
|
||||
() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
},
|
||||
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
|
||||
);
|
||||
} else if (this._hiddenCleanupTimeout) {
|
||||
// stream was not cleaned up yet, just cancel the cleanup
|
||||
clearTimeout(this._hiddenCleanupTimeout);
|
||||
|
||||
@@ -45,7 +45,7 @@ function adjustRgb(
|
||||
if (wv != null) {
|
||||
return rgbw2rgb([...rgb, wv] as [number, number, number, number]);
|
||||
}
|
||||
if (cw != null && ww !== null) {
|
||||
if (cw != null && ww != null) {
|
||||
return rgbww2rgb(
|
||||
[...rgb, cw, ww] as [number, number, number, number, number],
|
||||
minKelvin,
|
||||
|
||||
@@ -42,6 +42,8 @@ export class HaMjpegPlayer extends LitElement {
|
||||
|
||||
private _drawInterval?: number;
|
||||
|
||||
private _copyingFrame = false;
|
||||
|
||||
/** The video for picture in picture, undefined when it can't be shown. */
|
||||
public get videoElement(): HTMLVideoElement | undefined {
|
||||
return this._canCopy ? this._videoEl : undefined;
|
||||
@@ -66,12 +68,13 @@ export class HaMjpegPlayer extends LitElement {
|
||||
}
|
||||
try {
|
||||
if (!this._stream) {
|
||||
this._drawFrame();
|
||||
// The canvas already has a frame from the copy test
|
||||
this._copyFrame();
|
||||
// Captures a frame whenever the canvas is drawn
|
||||
this._stream = this._canvas!.captureStream();
|
||||
video.srcObject = this._stream;
|
||||
this._drawInterval = window.setInterval(
|
||||
() => this._drawFrame(),
|
||||
() => this._copyFrame(),
|
||||
1000 / PICTURE_IN_PICTURE_FRAME_RATE
|
||||
);
|
||||
}
|
||||
@@ -178,32 +181,45 @@ export class HaMjpegPlayer extends LitElement {
|
||||
|
||||
/** An image from another origin can't be copied out of a canvas. */
|
||||
private _testCopy(): boolean {
|
||||
const image = this._imageEl!;
|
||||
try {
|
||||
this._drawFrame();
|
||||
this._canvas?.getContext("2d")?.getImageData(0, 0, 1, 1);
|
||||
return Boolean(this._canvas);
|
||||
this._drawFrame(image, image.naturalWidth, image.naturalHeight);
|
||||
this._canvas!.getContext("2d")?.getImageData(0, 0, 1, 1);
|
||||
return true;
|
||||
} catch (_err: unknown) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private _drawFrame() {
|
||||
// Firefox only draws the first frame of an MJPEG image, a bitmap of it
|
||||
// has the current one
|
||||
private async _copyFrame() {
|
||||
const image = this._imageEl;
|
||||
if (!image?.naturalWidth) {
|
||||
if (this._copyingFrame || !image?.naturalWidth) {
|
||||
return;
|
||||
}
|
||||
this._copyingFrame = true;
|
||||
try {
|
||||
const bitmap = await createImageBitmap(image);
|
||||
this._drawFrame(bitmap, bitmap.width, bitmap.height);
|
||||
bitmap.close();
|
||||
} catch (_err: unknown) {
|
||||
// The stream is between frames or restarting, the next copy tries again
|
||||
} finally {
|
||||
this._copyingFrame = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _drawFrame(frame: CanvasImageSource, width: number, height: number) {
|
||||
if (!this._canvas) {
|
||||
this._canvas = document.createElement("canvas");
|
||||
}
|
||||
const canvas = this._canvas;
|
||||
if (
|
||||
canvas.width !== image.naturalWidth ||
|
||||
canvas.height !== image.naturalHeight
|
||||
) {
|
||||
canvas.width = image.naturalWidth;
|
||||
canvas.height = image.naturalHeight;
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
}
|
||||
canvas.getContext("2d")?.drawImage(image, 0, 0);
|
||||
canvas.getContext("2d")?.drawImage(frame, 0, 0);
|
||||
}
|
||||
|
||||
private _stopVideo = () => {
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
getPanelIcon,
|
||||
getPanelIconPath,
|
||||
getPanelTitle,
|
||||
getSelectedPanelUrlPath,
|
||||
} from "../data/panel";
|
||||
import type { PersistentNotification } from "../data/persistent_notification";
|
||||
import { subscribeNotifications } from "../data/persistent_notification";
|
||||
@@ -231,12 +232,36 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const selectedPanel = this.hass.panelUrl;
|
||||
|
||||
// prettier-ignore
|
||||
return html`
|
||||
${this._renderHeader()}
|
||||
${this._renderAllPanels(selectedPanel)}`;
|
||||
${this._renderAllPanels()}`;
|
||||
}
|
||||
|
||||
private _computeSidebarPanels(): [PanelInfo[], PanelInfo[]] | undefined {
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
return undefined;
|
||||
}
|
||||
return computePanels(
|
||||
this.hass.panels,
|
||||
getDefaultPanelUrlPath(this.hass),
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
}
|
||||
|
||||
private _computeSelectedPanel(
|
||||
sidebarPanels: [PanelInfo[], PanelInfo[]] | undefined,
|
||||
route: Route | undefined
|
||||
): string {
|
||||
if (!route) {
|
||||
return this.hass.panelUrl;
|
||||
}
|
||||
const urlPaths = (sidebarPanels ?? [[], []])
|
||||
.flat()
|
||||
.map((panel) => panel.url_path);
|
||||
return getSelectedPanelUrlPath(urlPaths, route.path);
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
@@ -254,7 +279,20 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (!this.hass || !changedProps.has("hass")) {
|
||||
if (!this.hass) {
|
||||
return false;
|
||||
}
|
||||
if (changedProps.has("route")) {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const oldRoute = changedProps.get("route") as Route | undefined;
|
||||
if (
|
||||
this._computeSelectedPanel(sidebarPanels, oldRoute) !==
|
||||
this._computeSelectedPanel(sidebarPanels, this.route)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!changedProps.has("hass")) {
|
||||
return false;
|
||||
}
|
||||
const oldHass = changedProps.get("hass") as HomeAssistant;
|
||||
@@ -355,7 +393,9 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _renderAllPanels(selectedPanel: string) {
|
||||
private _renderAllPanels() {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const selectedPanel = this._computeSelectedPanel(sidebarPanels, this.route);
|
||||
const renderList = (content, cls: string, scrollable: boolean) =>
|
||||
html`<ha-list-nav
|
||||
class=${classMap({
|
||||
@@ -365,7 +405,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
>${content}</ha-list-nav
|
||||
>`;
|
||||
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
if (!sidebarPanels) {
|
||||
return html`<div class="panels-list">
|
||||
<div class="wrapper">
|
||||
${renderList(
|
||||
@@ -390,15 +430,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||
|
||||
const [beforeSpacer, afterSpacer] = computePanels(
|
||||
this.hass.panels,
|
||||
defaultPanel,
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
const [beforeSpacer, afterSpacer] = sidebarPanels;
|
||||
|
||||
// prettier-ignore
|
||||
return html`<div class="panels-list">
|
||||
|
||||
@@ -8,6 +8,10 @@ import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../common/decorators/consume";
|
||||
import { consumeLocalize } from "../common/decorators/consume-context-entry";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import {
|
||||
claimFullscreenEnterHide,
|
||||
FULLSCREEN_ENTER_TIME,
|
||||
} from "../common/dom/entering-fullscreen";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import {
|
||||
addWebRtcCandidate,
|
||||
@@ -242,16 +246,19 @@ export class HaWebRtcPlayer extends LitElement {
|
||||
return;
|
||||
}
|
||||
if (document.hidden) {
|
||||
if (isExternal) {
|
||||
if (isExternal && !claimFullscreenEnterHide(this)) {
|
||||
// The companion apps pause JavaScript timers while in the background,
|
||||
// so a delayed clean up would not run until the app is opened again
|
||||
this._cleanUp();
|
||||
return;
|
||||
}
|
||||
this._hiddenCleanupTimeout = window.setTimeout(() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
}, HIDDEN_CLEANUP_DELAY);
|
||||
this._hiddenCleanupTimeout = window.setTimeout(
|
||||
() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
},
|
||||
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
|
||||
);
|
||||
} else if (this._hiddenCleanupTimeout) {
|
||||
// stream was not cleaned up yet, just cancel the cleanup
|
||||
clearTimeout(this._hiddenCleanupTimeout);
|
||||
|
||||
@@ -200,6 +200,7 @@ class HaEntityMarker extends LitElement {
|
||||
}
|
||||
.entity-picture {
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { TemplateResult } from "lit";
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import type { ActionHandlerOptions } from "../../data/lovelace/action_handler";
|
||||
import { actionHandler } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import { actionHandlerBind } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import "../ha-icon";
|
||||
import "../ha-svg-icon";
|
||||
|
||||
@@ -56,6 +56,11 @@ export class HaTileIcon extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>): void {
|
||||
super.updated(changedProps);
|
||||
actionHandlerBind(this, this.actionHandlerOptions);
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const hasImage = Boolean(this.imageUrl);
|
||||
|
||||
@@ -67,7 +72,6 @@ export class HaTileIcon extends LitElement {
|
||||
aria-label=${ifDefined(
|
||||
this.interactive ? this.accessibleLabel : undefined
|
||||
)}
|
||||
.actionHandler=${actionHandler(this.actionHandlerOptions)}
|
||||
>
|
||||
<slot name="icon">${this._renderIcon()}</slot>
|
||||
</div>
|
||||
@@ -94,6 +98,7 @@ export class HaTileIcon extends LitElement {
|
||||
:host([interactive]) {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
pointer-events: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
:host([interactive]:active) {
|
||||
transform: scale(1.2);
|
||||
@@ -143,6 +148,9 @@ export class HaTileIcon extends LitElement {
|
||||
transition: color 180ms ease-in-out;
|
||||
pointer-events: none;
|
||||
}
|
||||
::slotted(:not([slot])) {
|
||||
pointer-events: none;
|
||||
}
|
||||
.container img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
@@ -5,6 +5,9 @@ import {
|
||||
} from "home-assistant-js-websocket";
|
||||
import type { Store } from "home-assistant-js-websocket/dist/store";
|
||||
import type { DataTableRowData } from "../components/data-table/ha-data-table";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { ConfigEntry } from "./config_entries";
|
||||
import type { DeviceRegistryEntry } from "./device/device_registry";
|
||||
|
||||
export interface BluetoothDeviceData extends DataTableRowData {
|
||||
address: string;
|
||||
@@ -74,6 +77,54 @@ export const isScannerStateMismatch = (state: BluetoothScannerState): boolean =>
|
||||
state.requested_mode !== "auto" &&
|
||||
state.current_mode !== state.requested_mode;
|
||||
|
||||
export interface BluetoothAdapterDevice {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the Bluetooth adapters into enabled and disabled ones. An adapter is
|
||||
* a device with a Bluetooth connection that belongs to a `bluetooth` config
|
||||
* entry. Config entries without such a device (for example ignored discoveries
|
||||
* or removed proxies) are not adapters, unless they are disabled, so they can
|
||||
* still be enabled again.
|
||||
*/
|
||||
export const getBluetoothAdapters = (
|
||||
devices: HomeAssistant["devices"],
|
||||
configEntries: ConfigEntry[]
|
||||
) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const disabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find((c) => c[0] === "bluetooth");
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
};
|
||||
|
||||
export const subscribeBluetoothScannersDetailsUpdates = (
|
||||
conn: Connection,
|
||||
store: Store<BluetoothScannersDetails>
|
||||
|
||||
@@ -79,6 +79,8 @@ export const selectCameraStreams = ({
|
||||
];
|
||||
};
|
||||
|
||||
export type CameraStreamDisconnectReason = "home_assistant" | "stream_failed";
|
||||
|
||||
/** What the player tells the user about the connection of its stream. */
|
||||
export interface CameraStreamStatus {
|
||||
/** The stream that is shown, undefined until the camera's types are known */
|
||||
@@ -91,6 +93,10 @@ export interface CameraStreamStatus {
|
||||
hasAudio: boolean;
|
||||
/** The app plays the shown stream in its own player, over the page */
|
||||
inApp?: boolean;
|
||||
/** The camera is unavailable, no stream is started */
|
||||
unavailable?: boolean;
|
||||
/** Home Assistant is disconnected, or the only stream failed */
|
||||
disconnected?: CameraStreamDisconnectReason;
|
||||
}
|
||||
|
||||
export const computeCameraStreamStatus = (
|
||||
|
||||
+19
-5
@@ -239,12 +239,29 @@ export interface CoverEntity extends HassEntityBase {
|
||||
attributes: CoverEntityAttributes;
|
||||
}
|
||||
|
||||
// For covers that report no value, the open or closed state tells where it is
|
||||
const valueFromState = (stateObj: CoverEntity): number | undefined => {
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
};
|
||||
|
||||
export const coverCurrentValue = (
|
||||
stateObj: CoverEntity,
|
||||
mode: CoverControlMode
|
||||
): number | undefined => {
|
||||
if (mode === "tilt") {
|
||||
return stateObj.attributes.current_tilt_position ?? undefined;
|
||||
const tilt = stateObj.attributes.current_tilt_position;
|
||||
// The state only describes the slats when the cover can't move up or down
|
||||
if (
|
||||
tilt != null ||
|
||||
coverSupportsTiltPosition(stateObj) ||
|
||||
coverHasPositionControls(stateObj)
|
||||
) {
|
||||
return tilt ?? undefined;
|
||||
}
|
||||
return valueFromState(stateObj);
|
||||
}
|
||||
const position = stateObj.attributes.current_position;
|
||||
if (
|
||||
@@ -253,10 +270,7 @@ export const coverCurrentValue = (
|
||||
) {
|
||||
return position ?? undefined;
|
||||
}
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
return valueFromState(stateObj);
|
||||
};
|
||||
|
||||
declare global {
|
||||
|
||||
+11
-3
@@ -567,7 +567,9 @@ export const computeEnergyStatisticArea = (
|
||||
* device in the same list, which happens when one device has several meters of
|
||||
* the same type. Those are named with the entity name as well, so they stay
|
||||
* apart in the charts. Lists hold one type of device, so an energy meter and a
|
||||
* water meter of one device never collide.
|
||||
* water meter of one device never collide. Separate devices that only share
|
||||
* a name keep their label when their entity names match too, since adding
|
||||
* those would not tell them apart, unless a custom name takes the same label.
|
||||
*/
|
||||
export const computeAmbiguousEnergyDevices = (
|
||||
states: HomeAssistant["states"],
|
||||
@@ -606,8 +608,14 @@ export const computeAmbiguousEnergyDevices = (
|
||||
const ambiguous = new Set<string>();
|
||||
for (const statisticIds of statisticIdsByLabel.values()) {
|
||||
if (statisticIds.size > 1) {
|
||||
for (const statisticId of statisticIds) {
|
||||
if (!named.has(statisticId)) {
|
||||
const unnamed = [...statisticIds].filter((id) => !named.has(id));
|
||||
const entityLabels = new Set(
|
||||
unnamed.map((statisticId) =>
|
||||
formatEntityName(states[statisticId], ENERGY_DEVICE_ENTITY_NAME)
|
||||
)
|
||||
);
|
||||
if (unnamed.length < statisticIds.size || entityLabels.size > 1) {
|
||||
for (const statisticId of unnamed) {
|
||||
ambiguous.add(statisticId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,17 +153,23 @@ export const computeEnergySuggestions = (
|
||||
};
|
||||
|
||||
/**
|
||||
* The dismissed statistics with the new one added, dropping statistics that
|
||||
* The dismissed statistics with the new ones added, dropping statistics that
|
||||
* no longer exist.
|
||||
*/
|
||||
export const updateDismissedSuggestions = (
|
||||
dismissed: string[],
|
||||
statisticId: string,
|
||||
statisticIds: string[],
|
||||
statistics: StatisticsMetaData[]
|
||||
): string[] => {
|
||||
const existing = new Set(statistics.map((meta) => meta.statistic_id));
|
||||
return [
|
||||
...dismissed.filter((id) => id !== statisticId && existing.has(id)),
|
||||
statisticId,
|
||||
...dismissed.filter((id) => !statisticIds.includes(id) && existing.has(id)),
|
||||
...statisticIds,
|
||||
];
|
||||
};
|
||||
|
||||
/** The dismissed statistics without the restored one. */
|
||||
export const restoreDismissedSuggestion = (
|
||||
dismissed: string[],
|
||||
statisticId: string
|
||||
): string[] => dismissed.filter((id) => id !== statisticId);
|
||||
@@ -196,6 +196,21 @@ export const getPanelIconPath = (panel: PanelInfo): string | undefined => {
|
||||
|
||||
export const FIXED_PANELS = [PROFILE_PANEL, "config", NOT_FOUND_PANEL];
|
||||
|
||||
// A panel's url_path can span several segments (e.g. "config/logs"), so the
|
||||
// most specific url_path matching the path wins over its first segment.
|
||||
export const getSelectedPanelUrlPath = (
|
||||
urlPaths: string[],
|
||||
path: string
|
||||
): string =>
|
||||
urlPaths.reduce(
|
||||
(selected, urlPath) =>
|
||||
urlPath.length > selected.length &&
|
||||
(path === `/${urlPath}` || path.startsWith(`/${urlPath}/`))
|
||||
? urlPath
|
||||
: selected,
|
||||
path.split("/")[1] ?? ""
|
||||
);
|
||||
|
||||
export interface PanelMutableParams {
|
||||
title?: string | null;
|
||||
icon?: string | null;
|
||||
|
||||
@@ -223,6 +223,7 @@ export const SENSOR_DEVICE_CLASS_UNITS: Record<string, (string | null)[]> = {
|
||||
voltage: ["kV", "MV", "mV", "V", "μV"],
|
||||
volume: ["CCF", "fl. oz.", "ft³", "gal", "L", "MCF", "mL", "m³"],
|
||||
volume_flow_rate: [
|
||||
"ft³/h",
|
||||
"ft³/min",
|
||||
"gal/d",
|
||||
"gal/h",
|
||||
@@ -399,6 +400,7 @@ export const SENSOR_DEVICE_CLASS_CONVERTIBLE_UNITS: Record<
|
||||
voltage: ["kV", "MV", "mV", "V", "μV"],
|
||||
volume: ["CCF", "fl. oz.", "ft³", "gal", "L", "MCF", "mL", "m³"],
|
||||
volume_flow_rate: [
|
||||
"ft³/h",
|
||||
"ft³/min",
|
||||
"gal/d",
|
||||
"gal/h",
|
||||
|
||||
@@ -3,8 +3,11 @@ import {
|
||||
mdiImageMultipleOutline,
|
||||
mdiLightningBolt,
|
||||
} from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
import type { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { CAMERA_STREAM_TYPE_NAMES } from "../../components/camera/ha-camera-stream-badge";
|
||||
@@ -21,9 +24,14 @@ import {
|
||||
type CameraStreamType,
|
||||
type StreamType,
|
||||
} from "../../data/camera-streams";
|
||||
import { fetchCloudStatus } from "../../data/cloud";
|
||||
import { apiContext, configContext } from "../../data/context";
|
||||
import { haStyleDialog, haStyleDialogFixedTop } from "../../resources/styles";
|
||||
import { DialogMixin } from "../dialog-mixin";
|
||||
import type { CameraStreamInfoDialogParams } from "./show-dialog-camera-stream-info";
|
||||
import type {
|
||||
CameraStreamInfo,
|
||||
CameraStreamInfoDialogParams,
|
||||
} from "./show-dialog-camera-stream-info";
|
||||
|
||||
// Ordered from the fastest to the most compatible
|
||||
const STREAM_TYPES: { type: CameraStreamType; icon: string }[] = [
|
||||
@@ -40,11 +48,56 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
@consumeLocalize()
|
||||
private _localize!: LocalizeFunc;
|
||||
|
||||
@consume({ context: apiContext })
|
||||
private _api!: ContextType<typeof apiContext>;
|
||||
|
||||
@consume({ context: configContext })
|
||||
private _hassConfig!: ContextType<typeof configContext>;
|
||||
|
||||
@state() private _cloudIceServers = false;
|
||||
|
||||
@state() private _info?: CameraStreamInfo;
|
||||
|
||||
private _unsubscribe?: () => void;
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._unsubscribe = this.params?.subscribe((info) => {
|
||||
this._info = info;
|
||||
});
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
this._unsubscribe?.();
|
||||
this._unsubscribe = undefined;
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
protected firstUpdated() {
|
||||
this._fetchCloudIceServers();
|
||||
}
|
||||
|
||||
// The same check that core uses to add the cloud TURN servers
|
||||
private async _fetchCloudIceServers() {
|
||||
if (!isComponentLoaded(this._hassConfig.config, "cloud")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const status = await fetchCloudStatus(this._api.callWS);
|
||||
this._cloudIceServers =
|
||||
status.logged_in &&
|
||||
status.active_subscription &&
|
||||
status.prefs.cloud_ice_servers_enabled;
|
||||
} catch (_err) {
|
||||
// Without the cloud status the label stays hidden
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
if (!this._info) {
|
||||
return nothing;
|
||||
}
|
||||
const { status, supportedTypes } = this.params;
|
||||
const { status, supportedTypes } = this._info;
|
||||
// Without a video stream, still images are all the camera has
|
||||
const stillImagesOnly = supportedTypes?.length === 0;
|
||||
// MJPEG is only the fallback, only worth explaining while it shows
|
||||
@@ -73,6 +126,22 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
: "ui.dialogs.camera_stream_info.intro"
|
||||
)}
|
||||
</p>
|
||||
${
|
||||
status.disconnected
|
||||
? html`<ha-alert alert-type="error">
|
||||
${this._localize(
|
||||
`ui.dialogs.camera_stream_info.disconnected.${status.disconnected}`
|
||||
)}
|
||||
</ha-alert>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
status.unavailable
|
||||
? html`<ha-alert alert-type="warning">
|
||||
${this._localize("ui.dialogs.camera_stream_info.unavailable")}
|
||||
</ha-alert>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
mjpegInUse && !stillImagesOnly
|
||||
? html`<ha-alert alert-type="info">
|
||||
@@ -112,7 +181,7 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
type: CameraStreamType;
|
||||
icon: string;
|
||||
}) {
|
||||
const { status } = this.params!;
|
||||
const { status } = this._info!;
|
||||
const current = !status.connecting && status.type === type;
|
||||
const upgrading = status.upgrading === type;
|
||||
return html`
|
||||
@@ -124,6 +193,18 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
wrap-supporting-text
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${icon}></ha-svg-icon>
|
||||
${
|
||||
type === STREAM_TYPE_WEB_RTC && this._cloudIceServers
|
||||
? html`<span slot="headline" class="headline">
|
||||
${CAMERA_STREAM_TYPE_NAMES[type]}
|
||||
<span class="tag cloud"
|
||||
>${this._localize(
|
||||
"ui.dialogs.camera_stream_info.enhanced_by_cloud"
|
||||
)}</span
|
||||
>
|
||||
</span>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
current
|
||||
? html`<span slot="end" class="tag current"
|
||||
@@ -188,6 +269,20 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
|
||||
.headline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-2);
|
||||
/* The row keeps the headline on one line, but a long tag must wrap */
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.tag.cloud {
|
||||
background-color: var(--ha-color-fill-primary-quiet-resting);
|
||||
color: var(--ha-color-on-primary-quiet);
|
||||
}
|
||||
|
||||
.tag.current {
|
||||
background-color: var(--ha-color-fill-success-quiet-resting);
|
||||
color: var(--ha-color-on-success-quiet);
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import type { CameraStreamStatus, StreamType } from "../../data/camera-streams";
|
||||
|
||||
export interface CameraStreamInfoDialogParams {
|
||||
export interface CameraStreamInfo {
|
||||
status: CameraStreamStatus;
|
||||
/** The stream types the camera supports, undefined while unknown */
|
||||
supportedTypes?: StreamType[];
|
||||
}
|
||||
|
||||
export interface CameraStreamInfoDialogParams {
|
||||
/** Calls back with the current info right away and on every change */
|
||||
subscribe: (callback: (info: CameraStreamInfo) => void) => () => void;
|
||||
}
|
||||
|
||||
export const showCameraStreamInfoDialog = (
|
||||
element: HTMLElement,
|
||||
params: CameraStreamInfoDialogParams
|
||||
|
||||
@@ -46,7 +46,7 @@ export const DOMAINS_WITH_NEW_MORE_INFO = [
|
||||
"media_player",
|
||||
];
|
||||
/** Domains with full height more info dialog */
|
||||
export const DOMAINS_FULL_HEIGHT_MORE_INFO = ["update"];
|
||||
export const DOMAINS_FULL_HEIGHT_MORE_INFO = ["camera", "update"];
|
||||
|
||||
/** Domains with separate more info dialog. */
|
||||
export const DOMAINS_WITH_MORE_INFO = [
|
||||
|
||||
@@ -9,6 +9,10 @@ import { consumeLocalize } from "../../../common/decorators/consume-context-entr
|
||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||
import {
|
||||
adaptiveDialogModeContext,
|
||||
type DialogSheetMode,
|
||||
} from "../../../components/ha-adaptive-dialog";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/camera/ha-camera-player";
|
||||
import type { HaCameraPlayer } from "../../../components/camera/ha-camera-player";
|
||||
@@ -50,6 +54,10 @@ class MoreInfoCamera extends LitElement {
|
||||
|
||||
@state() private _attached = false;
|
||||
|
||||
@state()
|
||||
@consume({ context: adaptiveDialogModeContext, subscribe: true })
|
||||
private _dialogMode?: DialogSheetMode;
|
||||
|
||||
@state() private _microphoneState: WebRtcMicrophoneState = "off";
|
||||
|
||||
@state() private _streamType?: CameraStreamType;
|
||||
@@ -133,6 +141,7 @@ class MoreInfoCamera extends LitElement {
|
||||
.stateObj=${this.stateObj}
|
||||
allow-exoplayer
|
||||
keep-awake
|
||||
?fill=${this._dialogMode === "bottom-sheet"}
|
||||
@microphone-changed=${this._microphoneChanged}
|
||||
@stream-type-changed=${this._streamTypeChanged}
|
||||
@camera-capabilities-changed=${this._capabilitiesChanged}
|
||||
@@ -315,6 +324,10 @@ class MoreInfoCamera extends LitElement {
|
||||
ev: HASSDomEvent<HASSDomEvents["stream-type-changed"]>
|
||||
) {
|
||||
this._streamType = ev.detail.type;
|
||||
// A removed WebRTC player can't tell that its microphone stopped
|
||||
if (ev.detail.type !== STREAM_TYPE_WEB_RTC && !this._useAppMicrophone) {
|
||||
this._microphoneState = "off";
|
||||
}
|
||||
}
|
||||
|
||||
private _capabilitiesChanged(
|
||||
@@ -334,7 +347,9 @@ class MoreInfoCamera extends LitElement {
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: block;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
coverHasPositionControls,
|
||||
coverHasTiltControls,
|
||||
coverModeAttribute,
|
||||
coverSupportsPosition,
|
||||
coverSupportsSetValue,
|
||||
defaultCoverMode,
|
||||
} from "../../../data/cover";
|
||||
@@ -164,7 +163,7 @@ class MoreInfoCover extends LitElement {
|
||||
if (!request || this._drag) {
|
||||
return undefined;
|
||||
}
|
||||
if (request.mode === "position" && !coverSupportsPosition(this.stateObj!)) {
|
||||
if (!coverSupportsSetValue(this.stateObj!, request.mode)) {
|
||||
return this._hint(request.value ? "requested_open" : "requested_closed");
|
||||
}
|
||||
return this._hint("requested", {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import { transform } from "../../../common/decorators/transform";
|
||||
import type { HASSDomCurrentTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { connectionContext, formattersContext } from "../../../data/context";
|
||||
import type { ImageEntity } from "../../../data/image";
|
||||
import { computeImageUrl } from "../../../data/image";
|
||||
@@ -28,6 +30,17 @@ class MoreInfoImage extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public stateObj?: ImageEntity;
|
||||
|
||||
private _size?: HASSDomEvents["media-size-changed"];
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
// A cached view that was detached while the picture loaded couldn't send
|
||||
// its size, and the picture doesn't load again when it's shown
|
||||
if (this._size) {
|
||||
fireEvent(this, "media-size-changed", this._size);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this._connection || !this.stateObj) {
|
||||
return nothing;
|
||||
@@ -39,16 +52,28 @@ class MoreInfoImage extends LitElement {
|
||||
return html`<img
|
||||
alt=${this._formatEntityName?.(this.stateObj) || this.stateObj.entity_id}
|
||||
src=${this._connection.hassUrl(imageUrl)}
|
||||
@load=${this._imageLoaded}
|
||||
/> `;
|
||||
}
|
||||
|
||||
private _imageLoaded(ev: HASSDomCurrentTargetEvent<HTMLImageElement>) {
|
||||
const { naturalWidth, naturalHeight } = ev.currentTarget;
|
||||
if (!naturalWidth || !naturalHeight) {
|
||||
return;
|
||||
}
|
||||
this._size = { aspectRatio: naturalWidth / naturalHeight, naturalWidth };
|
||||
fireEvent(this, "media-size-changed", this._size);
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
max-width: 100%;
|
||||
max-height: var(--more-info-media-max-height, none);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -149,10 +149,12 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public large = false;
|
||||
|
||||
@state() private _fill = false;
|
||||
// The dialog grows with the camera's or image's picture, as high as there
|
||||
// is room for
|
||||
@state() private _mediaAspectRatio?: number;
|
||||
|
||||
// The dialog grows with the camera's picture, as high as there is room for
|
||||
@state() private _cameraAspectRatio?: number;
|
||||
// An image is not shown larger than it is
|
||||
@state() private _mediaNaturalWidth?: number;
|
||||
|
||||
// Height of the controls the camera's info shows below the picture
|
||||
@state() private _cameraControlsHeight?: string;
|
||||
@@ -196,12 +198,6 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
}
|
||||
|
||||
public showDialog(params: MoreInfoDialogParams) {
|
||||
// The camera player keeps running for the same entity and doesn't send
|
||||
// its size again
|
||||
if (params.entityId !== this._entityId) {
|
||||
this._cameraAspectRatio = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
}
|
||||
this._entityId = params.entityId;
|
||||
if (!this._entityId) {
|
||||
this.closeDialog();
|
||||
@@ -219,7 +215,6 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._detailsYamlMode = false;
|
||||
|
||||
this.large = params.large ?? false;
|
||||
this._fill = false;
|
||||
this._open = true;
|
||||
this._loadEntityRegistryEntry();
|
||||
}
|
||||
@@ -265,8 +260,6 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._currView = DEFAULT_VIEW;
|
||||
this._childViewStack = [];
|
||||
this._returnUrl = undefined;
|
||||
this._cameraAspectRatio = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
this._isEscapeEnabled = true;
|
||||
window.removeEventListener("dialog-closed", this._enableEscapeKeyClose);
|
||||
window.removeEventListener("show-dialog", this._disableEscapeKeyClose);
|
||||
@@ -691,30 +684,32 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
`
|
||||
: nothing;
|
||||
|
||||
// Also when the camera was opened from a smaller entity's related view
|
||||
const cameraAspectRatio =
|
||||
domain === "camera" && isDefaultView
|
||||
? this._cameraAspectRatio
|
||||
// Also when it was opened from a smaller entity's related view
|
||||
const mediaAspectRatio =
|
||||
(domain === "camera" || domain === "image") && isDefaultView
|
||||
? this._mediaAspectRatio
|
||||
: undefined;
|
||||
// As wide as the picture is when it's as high as there is room for
|
||||
const fullHeightWidth = `var(--more-info-media-max-height) * ${mediaAspectRatio}`;
|
||||
const mediaPictureWidth = this._mediaNaturalWidth
|
||||
? `min(${fullHeightWidth}, ${this._mediaNaturalWidth}px)`
|
||||
: fullHeightWidth;
|
||||
|
||||
return html`
|
||||
<ha-adaptive-dialog
|
||||
.open=${this._open}
|
||||
.width=${
|
||||
this._fill
|
||||
? "full"
|
||||
: this.large || cameraAspectRatio
|
||||
? "large"
|
||||
: "medium"
|
||||
}
|
||||
class=${classMap({ camera: domain === "camera" })}
|
||||
.width=${this.large || mediaAspectRatio ? "large" : "medium"}
|
||||
class=${classMap({
|
||||
camera: domain === "camera",
|
||||
image: domain === "image",
|
||||
})}
|
||||
style=${styleMap({
|
||||
"--more-info-camera-controls-height": this._cameraControlsHeight,
|
||||
"--ha-dialog-width-lg": cameraAspectRatio
|
||||
? `clamp(var(--ha-dialog-width-md, 580px), calc(var(--video-max-height) * ${cameraAspectRatio}), 1920px)`
|
||||
"--ha-dialog-width-lg": mediaAspectRatio
|
||||
? `clamp(var(--ha-dialog-width-md, 580px), calc(${mediaPictureWidth} + var(--more-info-media-inline-padding, 0px)), 1920px)`
|
||||
: undefined,
|
||||
})}
|
||||
@camera-aspect-ratio-changed=${this._cameraAspectRatioChanged}
|
||||
@media-size-changed=${this._mediaSizeChanged}
|
||||
@camera-controls-height-changed=${this._cameraControlsHeightChanged}
|
||||
.accessibleLabel=${title}
|
||||
@closed=${this._dialogClosed}
|
||||
@@ -747,7 +742,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
></ha-icon-button-prev>
|
||||
`
|
||||
}
|
||||
<span slot="headerTitle" @click=${this._enlarge} class="title">
|
||||
<span slot="headerTitle" class="title">
|
||||
${
|
||||
breadcrumb.length > 0
|
||||
? !__DEMO__ && isAdmin
|
||||
@@ -1071,6 +1066,17 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
`;
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
// Also when going to a related entity or back. The camera player or image
|
||||
// of the same entity keeps running and doesn't send its size again.
|
||||
if (changedProps.has("_entityId")) {
|
||||
this._mediaAspectRatio = undefined;
|
||||
this._mediaNaturalWidth = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
super.firstUpdated(changedProps);
|
||||
this.addEventListener("close-dialog", () => this.closeDialog());
|
||||
@@ -1140,10 +1146,11 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._entry = ev.detail;
|
||||
}
|
||||
|
||||
private _cameraAspectRatioChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["camera-aspect-ratio-changed"]>
|
||||
private _mediaSizeChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["media-size-changed"]>
|
||||
) {
|
||||
this._cameraAspectRatio = ev.detail.aspectRatio;
|
||||
this._mediaAspectRatio = ev.detail.aspectRatio;
|
||||
this._mediaNaturalWidth = ev.detail.naturalWidth;
|
||||
}
|
||||
|
||||
private _cameraControlsHeightChanged(
|
||||
@@ -1152,12 +1159,6 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._cameraControlsHeight = ev.detail.height;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this._fill = !this._fill;
|
||||
});
|
||||
}
|
||||
|
||||
private _handleOpened() {
|
||||
window.addEventListener("dialog-closed", this._enableEscapeKeyClose);
|
||||
window.addEventListener("show-dialog", this._disableEscapeKeyClose);
|
||||
@@ -1216,12 +1217,14 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
|
||||
/* The dialog's margin, its header of about 68px and the controls
|
||||
below the picture */
|
||||
ha-adaptive-dialog.camera {
|
||||
--video-max-height: calc(
|
||||
100vh - var(--ha-space-20) -
|
||||
68px - var(--more-info-camera-controls-height, 0px)
|
||||
/* The dialog's margin, the safe area like the dialog's height limit,
|
||||
its header of about 68px and what the info shows besides the
|
||||
picture */
|
||||
ha-adaptive-dialog.camera,
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-max-height: calc(
|
||||
100vh - var(--ha-space-20) - var(--safe-area-inset-y, 0px) -
|
||||
68px - var(--more-info-media-reserved-height, 0px)
|
||||
);
|
||||
/* Along with the height of the picture */
|
||||
--ha-dialog-width-transition:
|
||||
@@ -1232,14 +1235,33 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
/* A custom property takes any value, so it can't fall back to the
|
||||
declaration before it. svh like the height limit of the dialog. */
|
||||
@supports (height: 1svh) {
|
||||
ha-adaptive-dialog.camera {
|
||||
--video-max-height: calc(
|
||||
100svh - var(--ha-space-20) -
|
||||
68px - var(--more-info-camera-controls-height, 0px)
|
||||
ha-adaptive-dialog.camera,
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-max-height: calc(
|
||||
100svh - var(--ha-space-20) - var(--safe-area-inset-y, 0px) -
|
||||
68px - var(--more-info-media-reserved-height, 0px)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ha-adaptive-dialog.camera {
|
||||
--more-info-media-reserved-height: var(
|
||||
--more-info-camera-controls-height,
|
||||
0px
|
||||
);
|
||||
--video-max-height: var(--more-info-media-max-height);
|
||||
}
|
||||
|
||||
/* The info's padding around the picture and the entity's row of 40px
|
||||
above it, with 16px between them */
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-reserved-height: calc(
|
||||
var(--ha-space-6) +
|
||||
max(var(--safe-area-inset-bottom, 0px), var(--ha-space-6)) + 56px
|
||||
);
|
||||
--more-info-media-inline-padding: calc(var(--ha-space-6) * 2);
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
|
||||
@@ -13,7 +13,6 @@ import { fireEvent } from "../../common/dom/fire_event";
|
||||
import type { HASSDomCurrentTargetEvent } from "../../common/dom/fire_event";
|
||||
import "../../components/animation/ha-fade-in";
|
||||
import "../../components/ha-adaptive-dialog";
|
||||
import "../../components/ha-alert";
|
||||
import "../../components/ha-expansion-panel";
|
||||
import "../../components/ha-icon-next";
|
||||
import "../../components/ha-spinner";
|
||||
@@ -21,10 +20,6 @@ import "../../components/item/ha-list-item-button";
|
||||
import type { HaListItemButton } from "../../components/item/ha-list-item-button";
|
||||
import "../../components/list/ha-list-base";
|
||||
import "../../components/progress/ha-progress-bar";
|
||||
import {
|
||||
getBackupState,
|
||||
type BackupManagerState,
|
||||
} from "../../data/backup_manager";
|
||||
import {
|
||||
extractApiErrorMessage,
|
||||
ignoreSupervisorError,
|
||||
@@ -36,14 +31,14 @@ import {
|
||||
shutdownHost,
|
||||
} from "../../data/hassio/host";
|
||||
import { haStyle, haStyleDialog } from "../../resources/styles";
|
||||
import type { HomeAssistant, ServiceCallRequest } from "../../types";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { HOST_ACTION_TOAST_ID, showToast } from "../../util/toast";
|
||||
import { showAlertDialog } from "../generic/show-dialog-box";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showConfirmationDialog,
|
||||
} from "../generic/show-dialog-box";
|
||||
import { showRestartWaitDialog } from "./show-dialog-restart";
|
||||
import "./automation-restart-status";
|
||||
confirmRestartAction,
|
||||
showRestartConfirmation,
|
||||
type RestartAction,
|
||||
} from "./show-restart-confirmation";
|
||||
|
||||
@customElement("dialog-restart")
|
||||
class DialogRestart extends LitElement {
|
||||
@@ -74,15 +69,6 @@ class DialogRestart extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async _loadBackupState() {
|
||||
try {
|
||||
return await getBackupState(this.hass);
|
||||
} catch (_err) {
|
||||
// Do nothing
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
|
||||
private async _loadHostInfo() {
|
||||
this._loadingHostInfo = true;
|
||||
try {
|
||||
@@ -273,45 +259,16 @@ class DialogRestart extends LitElement {
|
||||
duration: 1000,
|
||||
});
|
||||
|
||||
this._restartAction(
|
||||
"homeassistant",
|
||||
"reload_all",
|
||||
this.hass.localize("ui.dialogs.restart.reload.failed")
|
||||
)();
|
||||
}
|
||||
|
||||
private _getBackupProgressMessage(backupState: BackupManagerState) {
|
||||
switch (backupState) {
|
||||
case "create_backup":
|
||||
return this.hass.localize("ui.dialogs.restart.backup_in_progress");
|
||||
case "receive_backup":
|
||||
return this.hass.localize("ui.dialogs.restart.upload_in_progress");
|
||||
case "restore_backup":
|
||||
return this.hass.localize("ui.dialogs.restart.restore_in_progress");
|
||||
default:
|
||||
return "";
|
||||
try {
|
||||
await this.hass.callService("homeassistant", "reload_all");
|
||||
} catch (err: any) {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass.localize("ui.dialogs.restart.reload.failed"),
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _restartAction =
|
||||
(
|
||||
domain: ServiceCallRequest["domain"],
|
||||
service: ServiceCallRequest["service"],
|
||||
errorTitle: string,
|
||||
|
||||
serviceData?: ServiceCallRequest["serviceData"]
|
||||
) =>
|
||||
async () => {
|
||||
try {
|
||||
await this.hass.callService(domain, service, serviceData);
|
||||
} catch (err: any) {
|
||||
showAlertDialog(this, {
|
||||
title: errorTitle,
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private _hostAction =
|
||||
(toastMessage: string, action: "reboot" | "shutdown") => async () => {
|
||||
showToast(this, {
|
||||
@@ -343,75 +300,32 @@ class DialogRestart extends LitElement {
|
||||
};
|
||||
|
||||
private async _handleAction(
|
||||
ev: HASSDomCurrentTargetEvent<
|
||||
HaListItemButton & {
|
||||
action: "restart" | "reboot" | "shutdown" | "restart-safe-mode";
|
||||
}
|
||||
>
|
||||
ev: HASSDomCurrentTargetEvent<HaListItemButton & { action: RestartAction }>
|
||||
) {
|
||||
if (this._loadingBackupInfo) {
|
||||
return;
|
||||
}
|
||||
this._loadingBackupInfo = true;
|
||||
const action = ev.currentTarget.action;
|
||||
|
||||
const backupState = await this._loadBackupState();
|
||||
|
||||
const backupProgressMessage = this._getBackupProgressMessage(backupState);
|
||||
|
||||
this._loadingBackupInfo = false;
|
||||
|
||||
const confirmed = await showConfirmationDialog(this, {
|
||||
title: this.hass.localize(`ui.dialogs.restart.${action}.confirm_title`),
|
||||
text: html`${this.hass.localize(
|
||||
`ui.dialogs.restart.${action}.confirm_description`
|
||||
)}${
|
||||
backupProgressMessage
|
||||
? html`<br /><br /><ha-alert>${backupProgressMessage}</ha-alert>`
|
||||
: nothing
|
||||
} <br /><br /><automation-restart-status></automation-restart-status>`,
|
||||
confirmText: this.hass.localize(
|
||||
`ui.dialogs.restart.${action}.confirm_action${backupState === "idle" ? "" : "_backup"}`
|
||||
),
|
||||
destructive: true,
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
try {
|
||||
const confirmed =
|
||||
action === "restart" || action === "restart-safe-mode"
|
||||
? await showRestartConfirmation(this, this.hass, action)
|
||||
: await confirmRestartAction(
|
||||
this,
|
||||
this.hass,
|
||||
action,
|
||||
this._hostAction(
|
||||
this.hass.localize(`ui.dialogs.restart.${action}.action_toast`),
|
||||
action
|
||||
)
|
||||
);
|
||||
if (confirmed) {
|
||||
this._dialogOpen = false;
|
||||
}
|
||||
} finally {
|
||||
this._loadingBackupInfo = false;
|
||||
}
|
||||
|
||||
this._dialogOpen = false;
|
||||
|
||||
let actionFunc: () => Promise<void>;
|
||||
|
||||
if (["restart", "restart-safe-mode"].includes(action)) {
|
||||
const serviceData =
|
||||
action === "restart-safe-mode" ? { safe_mode: true } : undefined;
|
||||
actionFunc = this._restartAction(
|
||||
"homeassistant",
|
||||
"restart",
|
||||
this.hass.localize(`ui.dialogs.restart.${action}.failed`),
|
||||
serviceData
|
||||
);
|
||||
} else {
|
||||
actionFunc = this._hostAction(
|
||||
this.hass.localize(
|
||||
`ui.dialogs.restart.${action as "reboot" | "shutdown"}.action_toast`
|
||||
),
|
||||
action as "reboot" | "shutdown"
|
||||
);
|
||||
}
|
||||
|
||||
if (backupState !== "idle") {
|
||||
showRestartWaitDialog(this, {
|
||||
title: this.hass.localize(`ui.dialogs.restart.${action}.title`),
|
||||
initialBackupState: backupState,
|
||||
action: actionFunc,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
actionFunc();
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { html, nothing } from "lit";
|
||||
import "../../components/ha-alert";
|
||||
import {
|
||||
getBackupState,
|
||||
type BackupManagerState,
|
||||
} from "../../data/backup_manager";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showConfirmationDialog,
|
||||
} from "../generic/show-dialog-box";
|
||||
import "./automation-restart-status";
|
||||
import { showRestartWaitDialog } from "./show-dialog-restart";
|
||||
|
||||
export type RestartAction =
|
||||
"restart" | "reboot" | "shutdown" | "restart-safe-mode";
|
||||
type ConfirmationContext = Pick<HomeAssistant, "connection" | "localize">;
|
||||
|
||||
function getBackupProgressMessage(
|
||||
localize: HomeAssistant["localize"],
|
||||
backupState: BackupManagerState
|
||||
) {
|
||||
switch (backupState) {
|
||||
case "create_backup":
|
||||
return localize("ui.dialogs.restart.backup_in_progress");
|
||||
case "receive_backup":
|
||||
return localize("ui.dialogs.restart.upload_in_progress");
|
||||
case "restore_backup":
|
||||
return localize("ui.dialogs.restart.restore_in_progress");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export async function confirmRestartAction(
|
||||
element: HTMLElement,
|
||||
hass: ConfirmationContext,
|
||||
action: RestartAction,
|
||||
run: () => Promise<void>
|
||||
) {
|
||||
const backupState = await getBackupState(hass).catch(() => "idle" as const);
|
||||
const backupProgressMessage = getBackupProgressMessage(
|
||||
hass.localize,
|
||||
backupState
|
||||
);
|
||||
const confirmed = await showConfirmationDialog(element, {
|
||||
title: hass.localize(`ui.dialogs.restart.${action}.confirm_title`),
|
||||
text: html`${hass.localize(
|
||||
`ui.dialogs.restart.${action}.confirm_description`
|
||||
)}${
|
||||
backupProgressMessage
|
||||
? html`<br /><br /><ha-alert>${backupProgressMessage}</ha-alert>`
|
||||
: nothing
|
||||
} <br /><br /><automation-restart-status></automation-restart-status>`,
|
||||
confirmText: hass.localize(
|
||||
`ui.dialogs.restart.${action}.confirm_action${backupState === "idle" ? "" : "_backup"}`
|
||||
),
|
||||
destructive: true,
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (backupState !== "idle") {
|
||||
showRestartWaitDialog(element, {
|
||||
title: hass.localize(`ui.dialogs.restart.${action}.title`),
|
||||
initialBackupState: backupState,
|
||||
action: run,
|
||||
});
|
||||
} else {
|
||||
run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function showRestartConfirmation(
|
||||
element: HTMLElement,
|
||||
hass: ConfirmationContext & Pick<HomeAssistant, "callService">,
|
||||
action: "restart" | "restart-safe-mode" = "restart"
|
||||
) {
|
||||
return confirmRestartAction(element, hass, action, async () => {
|
||||
try {
|
||||
await hass.callService(
|
||||
"homeassistant",
|
||||
"restart",
|
||||
action === "restart-safe-mode" ? { safe_mode: true } : undefined
|
||||
);
|
||||
} catch (err: any) {
|
||||
showAlertDialog(element, {
|
||||
title: hass.localize(`ui.dialogs.restart.${action}.failed`),
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -95,6 +95,23 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
.slice(0, MAX_SLOWEST);
|
||||
});
|
||||
}
|
||||
if (changedProps.has("_progress") || changedProps.has("_setups")) {
|
||||
this._loadTitles();
|
||||
}
|
||||
}
|
||||
|
||||
private _loadTitles() {
|
||||
const progress = this._progress
|
||||
? this._computeProgress(this._progress, this._config.config.state)
|
||||
: undefined;
|
||||
const domains = [
|
||||
...(progress?.active.map(([domain]) => domain) ?? []),
|
||||
...(progress?.failed ?? []),
|
||||
...(this._setups?.map((setup) => setup.domain) ?? []),
|
||||
];
|
||||
if (domains.length) {
|
||||
this._i18n.loadBackendTranslation("title", domains);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -264,6 +281,13 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
static styles = [
|
||||
haStyleDialog,
|
||||
css`
|
||||
@media (min-width: 451px) and (min-height: 501px) {
|
||||
ha-dialog {
|
||||
/* Fixed height so the dialog keeps its size as setups change. */
|
||||
--ha-dialog-min-height: calc(var(--safe-height) / 2);
|
||||
--ha-dialog-max-height: var(--ha-dialog-min-height);
|
||||
}
|
||||
}
|
||||
ha-spinner {
|
||||
display: block;
|
||||
margin: var(--ha-space-6) auto;
|
||||
@@ -272,6 +296,15 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--ha-space-1);
|
||||
/* Keeps the progress in view while the active list scrolls. */
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
padding-bottom: var(--ha-space-4);
|
||||
background: var(
|
||||
--ha-dialog-surface-background,
|
||||
var(--card-background-color, var(--ha-color-surface-default))
|
||||
);
|
||||
}
|
||||
.phase {
|
||||
font-weight: var(--ha-font-weight-medium);
|
||||
@@ -288,6 +321,9 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
font-size: var(--ha-font-size-m);
|
||||
font-weight: var(--ha-font-weight-medium);
|
||||
}
|
||||
.status + h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
ha-svg-icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--error-color);
|
||||
|
||||
@@ -145,7 +145,9 @@ export class HaVoiceAssistantSetupDialog extends LitElement {
|
||||
return html`
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
header-title="Voice Satellite setup"
|
||||
header-title=${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.satellite_wizard.title"
|
||||
)}
|
||||
prevent-scrim-close
|
||||
@closed=${this._dialogClosed}
|
||||
>
|
||||
|
||||
@@ -44,7 +44,7 @@ export class HaVoiceAssistantSetupStepChangeWakeWord extends LitElement {
|
||||
@click=${this._wakeWordPicked}
|
||||
.value=${wakeWord.id}
|
||||
>
|
||||
${wakeWord.wake_word}
|
||||
<div slot="headline">${wakeWord.wake_word}</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>`
|
||||
)}
|
||||
|
||||
+29
-3
@@ -11,7 +11,6 @@ import {
|
||||
import { loadTokens, saveTokens } from "../common/auth/token_storage";
|
||||
import { hassUrl } from "../data/auth";
|
||||
import { isExternal } from "../data/external";
|
||||
import { subscribeFrontendUserData } from "../data/frontend";
|
||||
import { fetchConfig } from "../data/lovelace/config/types";
|
||||
import { fetchResources } from "../data/lovelace/resource";
|
||||
import { MAIN_WINDOW_NAME } from "../data/main_window";
|
||||
@@ -75,11 +74,39 @@ const clearUrlParams = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const SERVER_CHECK_TIMEOUT = 10_000;
|
||||
|
||||
const checkServer = async () => {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), SERVER_CHECK_TIMEOUT);
|
||||
try {
|
||||
const response = await fetch(`${hassUrl}/manifest.json`, {
|
||||
mode: "no-cors",
|
||||
cache: "no-store",
|
||||
signal: controller.signal,
|
||||
});
|
||||
if (response.status >= 500) {
|
||||
throw new Error(`Home Assistant responded with ${response.status}`);
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
// The login page is never cached, so check the server is up before getAuth redirects to it.
|
||||
const loadTokensOrCheckServer = async () => {
|
||||
const tokens = loadTokens();
|
||||
if (!tokens || tokens.hassUrl !== hassUrl) {
|
||||
await checkServer();
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
|
||||
const authOptions = {
|
||||
hassUrl,
|
||||
limitHassInstance: true,
|
||||
saveTokens,
|
||||
loadTokens: () => Promise.resolve(loadTokens()),
|
||||
loadTokens: loadTokensOrCheckServer,
|
||||
};
|
||||
|
||||
const getAuthDroppingStaleCallback = async () => {
|
||||
@@ -160,7 +187,6 @@ window.hassConnection.then(({ conn }) => {
|
||||
subscribePanels(conn, noop);
|
||||
subscribeThemes(conn, noop);
|
||||
subscribeUser(conn, noop);
|
||||
subscribeFrontendUserData(conn, "core", noop);
|
||||
subscribeRepairsIssueRegistry(conn, noop);
|
||||
|
||||
const preloadWindow = window as WindowWithPreloads;
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import { supportsFeatureFromAttributes } from "../../common/entity/supports-feature";
|
||||
import {
|
||||
CLIMATE_HVAC_ACTION_TO_MODE,
|
||||
ClimateEntityFeature,
|
||||
} from "../../data/climate";
|
||||
import { ClimateEntityFeature } from "../../data/climate";
|
||||
import type { HvacAction } from "../../data/climate";
|
||||
import { MockBaseEntity } from "./base-entity";
|
||||
import type { EntityAttributes } from "./types";
|
||||
|
||||
// Reverse mapping: mode → action (e.g. "cool" → "cooling")
|
||||
const HVAC_MODE_TO_ACTION: Partial<Record<string, HvacAction>> =
|
||||
Object.fromEntries(
|
||||
Object.entries(CLIMATE_HVAC_ACTION_TO_MODE).map(([action, mode]) => [
|
||||
mode,
|
||||
action as HvacAction,
|
||||
])
|
||||
);
|
||||
|
||||
export class MockClimateEntity extends MockBaseEntity {
|
||||
public async handleService(
|
||||
domain: string,
|
||||
@@ -243,10 +231,13 @@ export class MockClimateEntity extends MockBaseEntity {
|
||||
return "off";
|
||||
}
|
||||
|
||||
// Use the reverse mapping for direct mode → action (e.g. "fan_only" → "fan", "dry" → "drying")
|
||||
const directAction = HVAC_MODE_TO_ACTION[state];
|
||||
if (directAction && directAction !== "idle" && directAction !== "off") {
|
||||
return directAction;
|
||||
// Heat and cool get their action from the temperatures below
|
||||
if (state === "dry") {
|
||||
return "drying";
|
||||
}
|
||||
|
||||
if (state === "fan_only") {
|
||||
return "fan";
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -276,13 +267,17 @@ export class MockClimateEntity extends MockBaseEntity {
|
||||
const current = attrs.current_temperature;
|
||||
const lowTarget = attrs.target_temp_low;
|
||||
const highTarget = attrs.target_temp_high;
|
||||
// Heat mode can only heat and cool mode only cool, while auto and
|
||||
// heat_cool use both ends of the range
|
||||
if (current != null) {
|
||||
if (lowTarget != null && lowTarget > current) {
|
||||
if (state !== "cool" && lowTarget != null && lowTarget > current) {
|
||||
return "heating";
|
||||
}
|
||||
if (highTarget != null && highTarget < current) {
|
||||
|
||||
if (state !== "heat" && highTarget != null && highTarget < current) {
|
||||
return "cooling";
|
||||
}
|
||||
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,6 +607,22 @@ export const ENTITY_COMPONENT_ICONS: Record<string, ComponentIcons> = {
|
||||
atmospheric_pressure: {
|
||||
default: "mdi:thermometer-lines",
|
||||
},
|
||||
battery: {
|
||||
default: "mdi:battery-unknown",
|
||||
range: {
|
||||
"0": "mdi:battery-alert",
|
||||
"10": "mdi:battery-10",
|
||||
"20": "mdi:battery-20",
|
||||
"30": "mdi:battery-30",
|
||||
"40": "mdi:battery-40",
|
||||
"50": "mdi:battery-50",
|
||||
"60": "mdi:battery-60",
|
||||
"70": "mdi:battery-70",
|
||||
"80": "mdi:battery-80",
|
||||
"90": "mdi:battery-90",
|
||||
"100": "mdi:battery",
|
||||
},
|
||||
},
|
||||
carbon_dioxide: {
|
||||
default: "mdi:molecule-co2",
|
||||
},
|
||||
|
||||
@@ -27,6 +27,12 @@ import {
|
||||
import { updateHassGroups } from "../data/context/updateContext";
|
||||
import type { IconCategory } from "../data/icons";
|
||||
import type { EntityRegistryDisplayEntry } from "../data/entity/entity_registry";
|
||||
import { evaluateConditionsLocally } from "../common/condition/evaluate-locally";
|
||||
import {
|
||||
isLogicalCondition,
|
||||
logicalChildren,
|
||||
} from "../common/condition/translate";
|
||||
import type { VisibilityCondition } from "../panels/lovelace/common/validate-condition";
|
||||
import {
|
||||
DateFormat,
|
||||
FirstWeekday,
|
||||
@@ -53,6 +59,24 @@ import type { EntityInput } from "./entities/types";
|
||||
const ensureArray = <T>(val: T | T[]): T[] =>
|
||||
Array.isArray(val) ? val : [val];
|
||||
|
||||
// Core's `not` passes when none of its conditions pass, and the frontend's
|
||||
// unless all of them pass, so each `not` gets one `or` of its conditions
|
||||
const withCoreNot = (condition: VisibilityCondition): VisibilityCondition => {
|
||||
if (!isLogicalCondition(condition) || condition.conditions === undefined) {
|
||||
return condition;
|
||||
}
|
||||
|
||||
const conditions = logicalChildren(condition).map(withCoreNot);
|
||||
|
||||
return {
|
||||
...condition,
|
||||
conditions:
|
||||
condition.condition === "not"
|
||||
? [{ condition: "or", conditions }]
|
||||
: conditions,
|
||||
};
|
||||
};
|
||||
|
||||
type MockServiceCallback = (
|
||||
data: Record<string, any> | undefined,
|
||||
target: Record<string, any> | undefined,
|
||||
@@ -221,6 +245,8 @@ export const provideHass = (
|
||||
return lazyLoaderPromise;
|
||||
};
|
||||
const eventListeners: Record<string, ((event) => void)[]> = {};
|
||||
// Checks each subscribed condition again, for when the states change.
|
||||
const conditionChecks = new Set<() => void>();
|
||||
const entities = {};
|
||||
let localResources: Resources = {};
|
||||
|
||||
@@ -664,6 +690,51 @@ export const provideHass = (
|
||||
resources: category === "entity_component" ? ENTITY_COMPONENT_ICONS : {},
|
||||
}));
|
||||
|
||||
// Core answers the visibility conditions of cards and rows that depend on
|
||||
// states. Here they are checked against the mock states, as the frontend
|
||||
// does itself before Core answers, and again each time the states change.
|
||||
// A condition only Core can check, such as a template, gets an error, so
|
||||
// a `not` around it can't show the card.
|
||||
hassObj.mockWS(
|
||||
"subscribe_condition",
|
||||
({ condition }: { condition: VisibilityCondition }, _hass, onChange) => {
|
||||
const check = () => {
|
||||
const result = evaluateConditionsLocally(
|
||||
[withCoreNot(condition)],
|
||||
hass(),
|
||||
{}
|
||||
);
|
||||
|
||||
onChange?.(
|
||||
result === undefined
|
||||
? {
|
||||
error: {
|
||||
code: "not_supported",
|
||||
message: "The demo can't check this condition",
|
||||
},
|
||||
}
|
||||
: { result }
|
||||
);
|
||||
};
|
||||
|
||||
conditionChecks.add(check);
|
||||
check();
|
||||
|
||||
return () => conditionChecks.delete(check);
|
||||
}
|
||||
);
|
||||
|
||||
// Check the conditions again after each state update, also when the host
|
||||
// passed its own updateHass, as the demo does
|
||||
const applyUpdate = hassObj.updateHass;
|
||||
hassObj.updateHass = (obj: Partial<MockHomeAssistant>) => {
|
||||
applyUpdate(obj);
|
||||
|
||||
if (obj.states) {
|
||||
conditionChecks.forEach((check) => check());
|
||||
}
|
||||
};
|
||||
|
||||
// Set hass if required
|
||||
if (setHassProperty) {
|
||||
elements.forEach((el) => {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import "@home-assistant/webawesome/dist/components/divider/divider";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import {
|
||||
mdiApplicationImport,
|
||||
mdiArrowUpBoldCircleOutline,
|
||||
mdiCheckCircle,
|
||||
mdiChip,
|
||||
mdiCursorDefaultClickOutline,
|
||||
mdiDelete,
|
||||
mdiDocker,
|
||||
mdiDotsVertical,
|
||||
mdiDownload,
|
||||
mdiExclamationThick,
|
||||
mdiFlask,
|
||||
mdiHammer,
|
||||
@@ -22,7 +23,6 @@ import {
|
||||
mdiNumeric6,
|
||||
mdiNumeric7,
|
||||
mdiNumeric8,
|
||||
mdiPackageVariantRemove,
|
||||
mdiPlay,
|
||||
mdiPound,
|
||||
mdiRestart,
|
||||
@@ -637,7 +637,7 @@ class SupervisorAppInfo extends MobileAwareMixin(LitElement) {
|
||||
<ha-progress-button
|
||||
.disabled=${!this._currentAddon.available}
|
||||
@click=${this._installClicked}
|
||||
.iconPath=${mdiApplicationImport}
|
||||
.iconPath=${mdiDownload}
|
||||
>
|
||||
${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.install"
|
||||
@@ -714,10 +714,7 @@ class SupervisorAppInfo extends MobileAwareMixin(LitElement) {
|
||||
this._uninstalling
|
||||
}
|
||||
>
|
||||
<ha-svg-icon
|
||||
slot="icon"
|
||||
.path=${mdiPackageVariantRemove}
|
||||
></ha-svg-icon>
|
||||
<ha-svg-icon slot="icon" .path=${mdiDelete}></ha-svg-icon>
|
||||
${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.uninstall"
|
||||
)}
|
||||
|
||||
@@ -89,7 +89,11 @@ class HaBackupConfigAgents extends LitElement {
|
||||
|
||||
const retention = this.agentsConfig?.[agentId]?.retention;
|
||||
|
||||
if (retention) {
|
||||
if (retention && !this._value.includes(agentId)) {
|
||||
texts.push(
|
||||
this.hass.localize("ui.panel.config.backup.agents.retention_inactive")
|
||||
);
|
||||
} else if (retention) {
|
||||
if (retention.copies === null && retention.days === null) {
|
||||
texts.push(
|
||||
this.hass.localize("ui.panel.config.backup.agents.retention_all")
|
||||
|
||||
@@ -120,21 +120,34 @@ class HaConfigBackupDetails extends LitElement {
|
||||
</p>
|
||||
</div>
|
||||
`
|
||||
: html`<ha-backup-config-retention
|
||||
location-specific
|
||||
.headline=${this.hass.localize(
|
||||
`ui.panel.config.backup.location.retention_for_${isLocalAgent(this.agentId) ? "this_system" : "location"}`,
|
||||
{ location: agentName }
|
||||
)}
|
||||
.hass=${this.hass}
|
||||
.retention=${
|
||||
!this.config
|
||||
? undefined
|
||||
: this.config.agents[this.agentId]
|
||||
?.retention || null
|
||||
}
|
||||
@value-changed=${this._retentionChanged}
|
||||
></ha-backup-config-retention>`
|
||||
: html`${
|
||||
this.config &&
|
||||
!this.config.create_backup.agent_ids.includes(
|
||||
this.agentId
|
||||
)
|
||||
? html`<div class="card-content">
|
||||
<ha-alert alert-type="info">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.backup.location.retention_inactive"
|
||||
)}
|
||||
</ha-alert>
|
||||
</div>`
|
||||
: nothing
|
||||
}<ha-backup-config-retention
|
||||
location-specific
|
||||
.headline=${this.hass.localize(
|
||||
`ui.panel.config.backup.location.retention_for_${isLocalAgent(this.agentId) ? "this_system" : "location"}`,
|
||||
{ location: agentName }
|
||||
)}
|
||||
.hass=${this.hass}
|
||||
.retention=${
|
||||
!this.config
|
||||
? undefined
|
||||
: this.config.agents[this.agentId]
|
||||
?.retention || null
|
||||
}
|
||||
@value-changed=${this._retentionChanged}
|
||||
></ha-backup-config-retention>`
|
||||
}
|
||||
</ha-card>
|
||||
<ha-card>
|
||||
|
||||
@@ -50,9 +50,7 @@ export class CloudStart extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
back-path="/config"
|
||||
.header=${this.hass.localize(
|
||||
"ui.panel.config.cloud.login.landing_title"
|
||||
)}
|
||||
header="Home Assistant Link"
|
||||
>
|
||||
<cloud-signed-out-menu
|
||||
slot="toolbar-icon"
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { mdiFire, mdiFlash, mdiLightbulbOnOutline, mdiWater } from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { consume } from "../../../../common/decorators/consume";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import type { HASSDomCurrentTargetEvent } from "../../../../common/dom/fire_event";
|
||||
import { consumeEntityStates } from "../../../../common/decorators/consume-context-entry";
|
||||
import { computeAreaName } from "../../../../common/entity/compute_area_name";
|
||||
import { getEntityAreaId } from "../../../../common/entity/context/get_entity_context";
|
||||
@@ -35,6 +37,7 @@ import type {
|
||||
import {
|
||||
computeEnergySuggestions,
|
||||
ENERGY_SUGGESTION_EDITORS,
|
||||
restoreDismissedSuggestion,
|
||||
updateDismissedSuggestions,
|
||||
} from "../../../../data/energy_suggestions";
|
||||
import {
|
||||
@@ -55,6 +58,8 @@ const TAB_ICONS: Record<EnergySuggestionTab, string> = {
|
||||
water: mdiWater,
|
||||
};
|
||||
|
||||
const DISMISS_ALL_THRESHOLD = 3;
|
||||
|
||||
@customElement("ha-energy-suggestions")
|
||||
export class EnergySuggestions extends LitElement {
|
||||
@property({ attribute: false })
|
||||
@@ -65,6 +70,8 @@ export class EnergySuggestions extends LitElement {
|
||||
|
||||
@property() public tab: EnergySuggestionTab = "electricity";
|
||||
|
||||
@property({ type: Boolean, attribute: false }) public showDismissed = false;
|
||||
|
||||
@state() private _statistics?: StatisticsMetaData[];
|
||||
|
||||
@state() private _dismissed?: string[];
|
||||
@@ -72,6 +79,11 @@ export class EnergySuggestions extends LitElement {
|
||||
// Dismissals not yet echoed by the subscription, so an older echo can't drop them
|
||||
@state() private _pendingDismissed: string[] = [];
|
||||
|
||||
// Restores not yet echoed by the subscription
|
||||
@state() private _pendingRestored: string[] = [];
|
||||
|
||||
private _reportedDismissedCount?: number;
|
||||
|
||||
@state() private _slots: Record<string, EnergySuggestionSlot> = {};
|
||||
|
||||
@state() private _loadFailed = false;
|
||||
@@ -114,27 +126,46 @@ export class EnergySuggestions extends LitElement {
|
||||
(
|
||||
statistics: StatisticsMetaData[],
|
||||
preferences: EnergyPreferences,
|
||||
dismissed: string[],
|
||||
states: HomeAssistant["states"],
|
||||
tab: EnergySuggestionTab
|
||||
) =>
|
||||
computeEnergySuggestions({
|
||||
statistics,
|
||||
preferences,
|
||||
dismissed,
|
||||
states,
|
||||
}).filter((suggestion) => suggestion.tab === tab)
|
||||
computeEnergySuggestions({ statistics, preferences, states }).filter(
|
||||
(suggestion) => suggestion.tab === tab
|
||||
)
|
||||
);
|
||||
|
||||
private _allDismissed = memoizeOne((stored: string[], pending: string[]) =>
|
||||
pending.length
|
||||
? [...stored, ...pending.filter((id) => !stored.includes(id))]
|
||||
: stored
|
||||
private _splitSuggestions = memoizeOne(
|
||||
(all: EnergyMeterSuggestion[], dismissed: string[]) => ({
|
||||
suggestions: all.filter(
|
||||
(suggestion) => !dismissed.includes(suggestion.statisticId)
|
||||
),
|
||||
dismissedSuggestions: all.filter((suggestion) =>
|
||||
dismissed.includes(suggestion.statisticId)
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
private _allDismissed = memoizeOne(
|
||||
(stored: string[], pending: string[], restored: string[]) =>
|
||||
[...stored, ...pending.filter((id) => !stored.includes(id))].filter(
|
||||
(id) => !restored.includes(id)
|
||||
)
|
||||
);
|
||||
|
||||
private get _currentDismissed(): string[] {
|
||||
return this._allDismissed(
|
||||
this._dismissed!,
|
||||
this._pendingDismissed,
|
||||
this._pendingRestored
|
||||
);
|
||||
}
|
||||
|
||||
// Kept live so a dismiss in another tab isn't overwritten by this one.
|
||||
private _unsubDismissed?: Promise<UnsubscribeFunc>;
|
||||
|
||||
// Each save builds on the list the previous one stored
|
||||
private _saveQueue: Promise<unknown> = Promise.resolve();
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._load();
|
||||
@@ -161,6 +192,9 @@ export class EnergySuggestions extends LitElement {
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => !dismissed.includes(id)
|
||||
);
|
||||
this._pendingRestored = this._pendingRestored.filter((id) =>
|
||||
dismissed.includes(id)
|
||||
);
|
||||
}
|
||||
);
|
||||
try {
|
||||
@@ -203,14 +237,8 @@ export class EnergySuggestions extends LitElement {
|
||||
if (!this._statistics || !this._dismissed) {
|
||||
return nothing;
|
||||
}
|
||||
const suggestions = this._computeSuggestions(
|
||||
this._statistics,
|
||||
this.preferences,
|
||||
this._allDismissed(this._dismissed, this._pendingDismissed),
|
||||
this._states,
|
||||
this.tab
|
||||
);
|
||||
if (!suggestions.length) {
|
||||
const { suggestions, dismissedSuggestions, showDismissed } = this._view()!;
|
||||
if (!suggestions.length && !showDismissed) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
@@ -218,27 +246,82 @@ export class EnergySuggestions extends LitElement {
|
||||
<ha-card>
|
||||
<h1 class="card-header">
|
||||
<ha-svg-icon .path=${mdiLightbulbOnOutline}></ha-svg-icon>
|
||||
${this._i18n.localize("ui.panel.config.energy.suggestions.title", {
|
||||
count: suggestions.length,
|
||||
})}
|
||||
${
|
||||
suggestions.length
|
||||
? this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.title",
|
||||
{
|
||||
count: suggestions.length,
|
||||
}
|
||||
)
|
||||
: this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismissed_title"
|
||||
)
|
||||
}
|
||||
</h1>
|
||||
<div class="card-content">
|
||||
<p>
|
||||
${this._i18n.localize("ui.panel.config.energy.suggestions.sub")}
|
||||
</p>
|
||||
<div class="items-container">
|
||||
${repeat(
|
||||
suggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion)
|
||||
)}
|
||||
<div class="intro">
|
||||
<p>
|
||||
${this._i18n.localize(
|
||||
suggestions.length
|
||||
? "ui.panel.config.energy.suggestions.sub"
|
||||
: "ui.panel.config.energy.suggestions.dismissed_sub"
|
||||
)}
|
||||
</p>
|
||||
${
|
||||
suggestions.length > DISMISS_ALL_THRESHOLD
|
||||
? html`<ha-button
|
||||
size="s"
|
||||
appearance="plain"
|
||||
variant="neutral"
|
||||
@click=${this._dismissAll}
|
||||
>${this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismiss_all"
|
||||
)}</ha-button
|
||||
>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
${
|
||||
suggestions.length
|
||||
? html`<div class="items-container">
|
||||
${repeat(
|
||||
suggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion, false)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDismissed
|
||||
? html`${
|
||||
suggestions.length
|
||||
? html`<h3>
|
||||
${this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismissed"
|
||||
)}
|
||||
</h3>`
|
||||
: nothing
|
||||
}
|
||||
<div class="items-container">
|
||||
${repeat(
|
||||
dismissedSuggestions,
|
||||
(suggestion) => suggestion.statisticId,
|
||||
(suggestion) => this._renderSuggestion(suggestion, true)
|
||||
)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderSuggestion(suggestion: EnergyMeterSuggestion) {
|
||||
private _renderSuggestion(
|
||||
suggestion: EnergyMeterSuggestion,
|
||||
dismissed: boolean
|
||||
) {
|
||||
const slot = this._slotFor(suggestion);
|
||||
const label = getStatisticLabel(
|
||||
this._states,
|
||||
@@ -259,7 +342,13 @@ export class EnergySuggestions extends LitElement {
|
||||
<div class="suggestion" role="group" aria-label=${label}>
|
||||
<ha-svg-icon .path=${TAB_ICONS[suggestion.tab]}></ha-svg-icon>
|
||||
<div class="content">
|
||||
<span class="label">${label}</span>
|
||||
<button
|
||||
class="link label"
|
||||
.suggestion=${suggestion}
|
||||
@click=${this._showMoreInfo}
|
||||
>
|
||||
${label}
|
||||
</button>
|
||||
${
|
||||
area
|
||||
? html`<span class="label secondary"
|
||||
@@ -300,9 +389,11 @@ export class EnergySuggestions extends LitElement {
|
||||
appearance="plain"
|
||||
variant="neutral"
|
||||
.suggestion=${suggestion}
|
||||
@click=${this._dismiss}
|
||||
@click=${dismissed ? this._restore : this._dismiss}
|
||||
>${this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismiss"
|
||||
dismissed
|
||||
? "ui.panel.config.energy.suggestions.restore"
|
||||
: "ui.panel.config.energy.suggestions.dismiss"
|
||||
)}</ha-button
|
||||
>
|
||||
</div>
|
||||
@@ -336,37 +427,132 @@ export class EnergySuggestions extends LitElement {
|
||||
})}`;
|
||||
}
|
||||
|
||||
private async _dismiss(ev: Event) {
|
||||
private _showMoreInfo(
|
||||
ev: HASSDomCurrentTargetEvent<
|
||||
HTMLButtonElement & { suggestion: EnergyMeterSuggestion }
|
||||
>
|
||||
) {
|
||||
fireEvent(this, "hass-more-info", {
|
||||
entityId: ev.currentTarget.suggestion.statisticId,
|
||||
});
|
||||
}
|
||||
|
||||
private _dismiss(ev: Event) {
|
||||
const suggestion: EnergyMeterSuggestion = (ev.currentTarget as any)
|
||||
.suggestion;
|
||||
const statisticId = suggestion.statisticId;
|
||||
this._pendingDismissed = [...this._pendingDismissed, statisticId];
|
||||
this._dismissStatistics([suggestion.statisticId], "dismiss_failed");
|
||||
}
|
||||
|
||||
private _dismissAll() {
|
||||
this._dismissStatistics(
|
||||
this._view()!.suggestions.map((suggestion) => suggestion.statisticId),
|
||||
"dismiss_all_failed"
|
||||
);
|
||||
}
|
||||
|
||||
private async _dismissStatistics(
|
||||
statisticIds: string[],
|
||||
failedKey: "dismiss_failed" | "dismiss_all_failed"
|
||||
) {
|
||||
this._pendingDismissed = [...this._pendingDismissed, ...statisticIds];
|
||||
this._pendingRestored = this._pendingRestored.filter(
|
||||
(id) => !statisticIds.includes(id)
|
||||
);
|
||||
try {
|
||||
await saveFrontendUserData(this._connection.connection, "energy", {
|
||||
dismissed_suggestions: updateDismissedSuggestions(
|
||||
this._allDismissed(this._dismissed!, this._pendingDismissed),
|
||||
statisticId,
|
||||
this._statistics!
|
||||
),
|
||||
});
|
||||
await this._saveDismissed((dismissed) =>
|
||||
updateDismissedSuggestions(dismissed, statisticIds, this._statistics!)
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => id !== statisticId
|
||||
(id) => !statisticIds.includes(id)
|
||||
);
|
||||
showAlertDialog(this, {
|
||||
title: this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.dismiss_failed"
|
||||
`ui.panel.config.energy.suggestions.${failedKey}`
|
||||
),
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _view() {
|
||||
if (this._loadFailed || !this._statistics || !this._dismissed) {
|
||||
return undefined;
|
||||
}
|
||||
const { suggestions, dismissedSuggestions } = this._splitSuggestions(
|
||||
this._computeSuggestions(
|
||||
this._statistics,
|
||||
this.preferences,
|
||||
this._states,
|
||||
this.tab
|
||||
),
|
||||
this._currentDismissed
|
||||
);
|
||||
return {
|
||||
suggestions,
|
||||
dismissedSuggestions,
|
||||
showDismissed: this.showDismissed && dismissedSuggestions.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues): void {
|
||||
super.updated(changedProps);
|
||||
const count = this._view()?.dismissedSuggestions.length ?? 0;
|
||||
if (count !== this._reportedDismissedCount) {
|
||||
this._reportedDismissedCount = count;
|
||||
fireEvent(this, "energy-suggestions-dismissed-count", { count });
|
||||
}
|
||||
}
|
||||
|
||||
private async _restore(ev: Event) {
|
||||
const suggestion: EnergyMeterSuggestion = (ev.currentTarget as any)
|
||||
.suggestion;
|
||||
const statisticId = suggestion.statisticId;
|
||||
this._pendingRestored = [...this._pendingRestored, statisticId];
|
||||
this._pendingDismissed = this._pendingDismissed.filter(
|
||||
(id) => id !== statisticId
|
||||
);
|
||||
try {
|
||||
await this._saveDismissed((dismissed) =>
|
||||
restoreDismissedSuggestion(dismissed, statisticId)
|
||||
);
|
||||
} catch (err: any) {
|
||||
this._pendingRestored = this._pendingRestored.filter(
|
||||
(id) => id !== statisticId
|
||||
);
|
||||
showAlertDialog(this, {
|
||||
title: this._i18n.localize(
|
||||
"ui.panel.config.energy.suggestions.restore_failed"
|
||||
),
|
||||
text: err.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _saveDismissed(update: (dismissed: string[]) => string[]) {
|
||||
const save = this._saveQueue.then(() =>
|
||||
saveFrontendUserData(this._connection.connection, "energy", {
|
||||
dismissed_suggestions: update(this._dismissed!),
|
||||
})
|
||||
);
|
||||
this._saveQueue = save.catch(() => undefined);
|
||||
return save;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
energyCardStyles,
|
||||
css`
|
||||
.intro {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0 var(--ha-space-4);
|
||||
}
|
||||
.intro ha-button {
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
.suggestion {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -384,6 +570,21 @@ export class EnergySuggestions extends LitElement {
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
button.link {
|
||||
align-self: flex-start;
|
||||
max-width: 100%;
|
||||
text-align: start;
|
||||
text-decoration: none;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
button.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
button.link:focus-visible {
|
||||
outline: 2px solid var(--primary-color);
|
||||
outline-offset: 2px;
|
||||
border-radius: var(--ha-border-radius-sm);
|
||||
}
|
||||
.secondary {
|
||||
color: var(--secondary-text-color);
|
||||
font-size: var(--ha-font-size-s);
|
||||
@@ -407,4 +608,8 @@ declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-energy-suggestions": EnergySuggestions;
|
||||
}
|
||||
|
||||
interface HASSDomEvents {
|
||||
"energy-suggestions-dismissed-count": { count: number };
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import "../../../layouts/hass-error-screen";
|
||||
import {
|
||||
mdiDotsVertical,
|
||||
mdiDownload,
|
||||
mdiEye,
|
||||
mdiEyeOff,
|
||||
mdiFire,
|
||||
mdiLightningBolt,
|
||||
mdiViewDashboardEdit,
|
||||
@@ -10,6 +13,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { cache } from "lit/directives/cache";
|
||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import type {
|
||||
EnergyPreferencesValidation,
|
||||
@@ -38,6 +42,9 @@ import "./components/ha-energy-battery-settings";
|
||||
import "./components/ha-energy-gas-settings";
|
||||
import "./components/ha-energy-water-settings";
|
||||
import "./components/ha-energy-suggestions";
|
||||
import "../../../components/ha-dropdown";
|
||||
import "../../../components/ha-dropdown-item";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import { fileDownload } from "../../../util/file_download";
|
||||
import { showToast } from "../../../util/toast";
|
||||
import type { PageNavigation } from "../../../layouts/hass-tabs-subpage";
|
||||
@@ -98,6 +105,11 @@ class HaConfigEnergy extends LitElement {
|
||||
|
||||
@state() private _statsMetadata?: Record<string, StatisticsMetaData>;
|
||||
|
||||
// Dismissed meters on the current tab, as counted by the suggestions card
|
||||
@state() private _dismissedSuggestions = 0;
|
||||
|
||||
@state() private _showDismissedSuggestions = false;
|
||||
|
||||
private get _currTab(): string {
|
||||
return this.route.path.split("/")[1] || "electricity";
|
||||
}
|
||||
@@ -105,6 +117,10 @@ class HaConfigEnergy extends LitElement {
|
||||
protected willUpdate(changedProperties: PropertyValues<this>) {
|
||||
if (changedProperties.has("route")) {
|
||||
const [, tab, kind, ...key] = this.route.path.split("/");
|
||||
const oldTab = changedProperties.get("route")?.path.split("/")[1];
|
||||
if (oldTab !== undefined && oldTab !== tab) {
|
||||
this._showDismissedSuggestions = false;
|
||||
}
|
||||
if (!tab || !TABS.some((t) => t.path.endsWith(`/${tab}`))) {
|
||||
navigate(`${this.route.prefix}/electricity${location.search}`, {
|
||||
replace: true,
|
||||
@@ -175,6 +191,35 @@ class HaConfigEnergy extends LitElement {
|
||||
)}
|
||||
@click=${this._downloadDiagnostics}
|
||||
></ha-icon-button>
|
||||
${
|
||||
this._dismissedSuggestions
|
||||
? html`<ha-dropdown
|
||||
@wa-select=${this._toggleDismissedSuggestions}
|
||||
>
|
||||
<ha-icon-button
|
||||
slot="trigger"
|
||||
.label=${this.hass.localize("ui.common.menu")}
|
||||
.path=${mdiDotsVertical}
|
||||
></ha-icon-button>
|
||||
<ha-dropdown-item value="toggle_dismissed">
|
||||
<ha-svg-icon
|
||||
slot="icon"
|
||||
.path=${this._showDismissedSuggestions ? mdiEyeOff : mdiEye}
|
||||
></ha-svg-icon>
|
||||
${
|
||||
this._showDismissedSuggestions
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.energy.suggestions.hide_dismissed"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.energy.suggestions.show_dismissed",
|
||||
{ count: this._dismissedSuggestions }
|
||||
)
|
||||
}
|
||||
</ha-dropdown-item>
|
||||
</ha-dropdown>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
<ha-alert>
|
||||
${this.hass.localize("ui.panel.config.energy.new_device_info")}
|
||||
@@ -184,6 +229,8 @@ class HaConfigEnergy extends LitElement {
|
||||
.preferences=${this._preferences!}
|
||||
.listPath=${`${this.route.prefix}/${this._currTab}`}
|
||||
.tab=${this._currTab}
|
||||
.showDismissed=${this._showDismissedSuggestions}
|
||||
@energy-suggestions-dismissed-count=${this._dismissedSuggestionsChanged}
|
||||
></ha-energy-suggestions>
|
||||
${cache(this._renderTabContent())}
|
||||
</div>
|
||||
@@ -446,6 +493,19 @@ class HaConfigEnergy extends LitElement {
|
||||
this._statsMetadata = statsMetadata;
|
||||
}
|
||||
|
||||
private _dismissedSuggestionsChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["energy-suggestions-dismissed-count"]>
|
||||
) {
|
||||
this._dismissedSuggestions = ev.detail.count;
|
||||
if (!this._dismissedSuggestions) {
|
||||
this._showDismissedSuggestions = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _toggleDismissedSuggestions() {
|
||||
this._showDismissedSuggestions = !this._showDismissedSuggestions;
|
||||
}
|
||||
|
||||
private _customise() {
|
||||
if (!this._preferences) {
|
||||
return;
|
||||
|
||||
@@ -514,8 +514,16 @@ class AddIntegrationDialog extends LitElement {
|
||||
return [...integrations]
|
||||
.filter((item) => !brand || item.domain === brand)
|
||||
.sort(byName)
|
||||
.flatMap((item) => this._brandRows(item))
|
||||
.filter((row) => !brand || !row.is_header);
|
||||
.flatMap((item) =>
|
||||
this._brandRows(item)
|
||||
.filter((row) => !row.is_header)
|
||||
// The brand on the second line, so its entries read as a group
|
||||
.map((row) =>
|
||||
brand || !this._isBrand(item)
|
||||
? row
|
||||
: { ...row, description: item.name }
|
||||
)
|
||||
);
|
||||
}
|
||||
// A brand shows its integrations here, not itself, like the website
|
||||
if (category) {
|
||||
@@ -1207,17 +1215,11 @@ class AddIntegrationDialog extends LitElement {
|
||||
})}
|
||||
>
|
||||
${
|
||||
!this._stickyBrand
|
||||
? nothing
|
||||
: this._filter
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: html`<ha-integration-list-title
|
||||
class="sticky raised"
|
||||
>
|
||||
${this._stickyBrand}
|
||||
</ha-integration-list-title>`
|
||||
this._stickyBrand
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: nothing
|
||||
}
|
||||
<ha-list-virtualized
|
||||
.rows=${this._filter ? rows : this._withEndSpace(rows)}
|
||||
@@ -1771,7 +1773,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the brand
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the section title
|
||||
@eventOptions({ passive: true })
|
||||
private _visibilityChanged(ev: HASSDomEvent<HaListVisibilityChangedDetail>) {
|
||||
const rows = this._getRows();
|
||||
@@ -1794,11 +1796,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
return html`<div style="height: var(--ha-space-2)"></div>`;
|
||||
}
|
||||
if (integration.is_header) {
|
||||
return this._filter
|
||||
? html`<ha-section-title>${integration.name}</ha-section-title>`
|
||||
: html`<ha-integration-list-title>
|
||||
${integration.name}
|
||||
</ha-integration-list-title>`;
|
||||
return html`<ha-section-title>${integration.name}</ha-section-title>`;
|
||||
}
|
||||
return html`
|
||||
<ha-integration-list-item
|
||||
|
||||
@@ -26,6 +26,7 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import { formatListWithAnds } from "../../../common/string/format-list";
|
||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||
import "../../../components/ha-dropdown";
|
||||
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
|
||||
@@ -95,6 +96,9 @@ export class HaConfigEntryRow extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public data!: ConfigEntryData;
|
||||
|
||||
/** The loaded integrations that lose this integration with this entry. */
|
||||
@property({ attribute: false }) public dependents?: IntegrationManifest[];
|
||||
|
||||
@state() private _expanded = true;
|
||||
|
||||
@state() private _devicesExpanded = true;
|
||||
@@ -812,14 +816,33 @@ export class HaConfigEntryRow extends LitElement {
|
||||
const applicationCredentialsId =
|
||||
await this._applicationCredentialForRemove(entryId);
|
||||
|
||||
const text = this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
);
|
||||
const confirmed = await showConfirmationDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_title",
|
||||
{ title: this.data.entry.title }
|
||||
),
|
||||
text: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
),
|
||||
text: this.dependents?.length
|
||||
? html`${text}<br /><br />${this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_dependents",
|
||||
{
|
||||
count: this.dependents.length,
|
||||
integrations: formatListWithAnds(
|
||||
this.hass.locale,
|
||||
this.dependents.map((manifest) =>
|
||||
domainToName(this.hass.localize, manifest.domain, manifest)
|
||||
)
|
||||
),
|
||||
name: domainToName(
|
||||
this.hass.localize,
|
||||
this.data.entry.domain,
|
||||
this.manifest
|
||||
),
|
||||
}
|
||||
)}`
|
||||
: text,
|
||||
confirmText: this.hass!.localize("ui.common.delete"),
|
||||
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||
destructive: true,
|
||||
|
||||
@@ -21,7 +21,7 @@ import memoizeOne from "memoize-one";
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { QueryParamsController } from "../../../common/controllers/query-params-controller";
|
||||
import { ContextSubscriptionController } from "../../../common/decorators/consume";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import type { HASSDomTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { computeDeviceNameDisplay } from "../../../common/entity/compute_device_name";
|
||||
import {
|
||||
@@ -176,9 +176,9 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
@state() private _manifest?: IntegrationManifest;
|
||||
|
||||
/** The manifests of all loaded integrations, to find the dependents. */
|
||||
@state() private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
private _manifestsConsumer?: ContextSubscriptionController<DomainManifestLookup>;
|
||||
@consume({ context: manifestsContext, subscribe: true })
|
||||
@state()
|
||||
private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
@state() private _extraConfigEntries?: ConfigEntry[];
|
||||
|
||||
@@ -432,17 +432,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
this.domain
|
||||
);
|
||||
|
||||
const dependents = this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
);
|
||||
// Without the dependents, a dependency looks like a YAML integration.
|
||||
const dependents =
|
||||
this._manifest && !this._manifest.config_flow
|
||||
? this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
)
|
||||
: [];
|
||||
const showDependents = normalEntries.length === 0 && dependents.length > 0;
|
||||
const dependencyOnly =
|
||||
normalEntries.length === 0 &&
|
||||
dependents.length > 0 &&
|
||||
!this._manifest?.config_flow;
|
||||
// Deleting the last entry in use leaves the dependents without it.
|
||||
const entriesInUse = configEntries.filter(
|
||||
(entry) => entry.source !== "ignore" && !entry.disabled_by
|
||||
);
|
||||
const lastEntryId =
|
||||
entriesInUse.length === 1 ? entriesInUse[0].entry_id : undefined;
|
||||
// Hold back the YAML texts and "Add entry" until the manifest and the
|
||||
// dependents are known. Entries do not wait, so a failed request cannot
|
||||
// hide them.
|
||||
@@ -461,7 +467,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
|
||||
const showAddEntry =
|
||||
this._manifest?.integration_type !== "hardware" &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
(!this._manifest?.single_config_entry ||
|
||||
@@ -653,7 +659,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
${
|
||||
normalEntries.length === 0 &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
this._manifest &&
|
||||
@@ -1010,6 +1016,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1018,19 +1029,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents ||
|
||||
dependencyOnly ||
|
||||
dependentsLoading ||
|
||||
(setUpInPanel && normalEntries.length === 0)
|
||||
? nothing
|
||||
@@ -1077,6 +1076,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1084,26 +1088,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
</div>`
|
||||
}
|
||||
${
|
||||
dependents.length
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
</hass-subpage>
|
||||
`;
|
||||
}
|
||||
|
||||
// Only an integration without a config flow needs the loaded manifests, so
|
||||
// other integration pages do not make the context fetch them.
|
||||
private _watchLoadedManifests(): void {
|
||||
if (this._manifestsConsumer) {
|
||||
return;
|
||||
}
|
||||
this._manifestsConsumer = new ContextSubscriptionController(
|
||||
this,
|
||||
manifestsContext,
|
||||
(manifests) => {
|
||||
this._loadedManifests = manifests;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private _getDependents = memoizeOne(
|
||||
(
|
||||
domain: string,
|
||||
@@ -1199,9 +1200,6 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
this._manifest = await fetchIntegrationManifest(this.hass, this.domain);
|
||||
if (!this._manifest.config_flow) {
|
||||
this._watchLoadedManifests();
|
||||
}
|
||||
if (
|
||||
this._manifest.integration_type &&
|
||||
!["device", "hub", "service"].includes(this._manifest.integration_type)
|
||||
|
||||
+5
-46
@@ -16,12 +16,14 @@ import "../../../../../components/item/ha-list-item-base";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-base";
|
||||
import type {
|
||||
BluetoothAdapterDevice,
|
||||
BluetoothAllocationsData,
|
||||
BluetoothScannerState,
|
||||
BluetoothScannersDetails,
|
||||
HaScannerType,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
subscribeBluetoothScannerState,
|
||||
@@ -176,52 +178,11 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothDevices = memoizeOne(
|
||||
(devices: HomeAssistant["devices"], configEntries: ConfigEntry[]) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const disabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find(
|
||||
(c) => c[0] === "bluetooth"
|
||||
);
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
}
|
||||
);
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const { enabledDevices, disabledDevices, disabledEntriesWithoutDevice } =
|
||||
this._getBluetoothDevices(this.hass.devices, this._configEntries);
|
||||
this._getBluetoothAdapters(this.hass.devices, this._configEntries);
|
||||
|
||||
return html`
|
||||
<hass-subpage
|
||||
@@ -301,9 +262,7 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderAdaptersList(
|
||||
devices: { device: DeviceRegistryEntry; entry: ConfigEntry }[]
|
||||
) {
|
||||
private _renderAdaptersList(devices: BluetoothAdapterDevice[]) {
|
||||
if (devices.length === 0) {
|
||||
return html`<ha-list-item-base>
|
||||
<div slot="headline">
|
||||
|
||||
+122
-49
@@ -11,18 +11,24 @@ import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import "../../../../../components/animation/ha-fade-in";
|
||||
import "../../../../../components/ha-alert";
|
||||
import "../../../../../components/ha-button";
|
||||
import "../../../../../components/ha-card";
|
||||
import "../../../../../components/ha-icon-next";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-nav";
|
||||
import "../../../../../components/skeleton/ha-skeleton";
|
||||
import "../../../../../components/skeleton/ha-skeleton-text";
|
||||
import type {
|
||||
BluetoothAllocationsData,
|
||||
BluetoothDeviceData,
|
||||
BluetoothScannerState,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothAdvertisements,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
@@ -34,6 +40,7 @@ import "../../../../../layouts/hass-subpage";
|
||||
import { haStyle } from "../../../../../resources/styles";
|
||||
import type { HomeAssistant, Route } from "../../../../../types";
|
||||
import { brandsUrl } from "../../../../../util/brands-url";
|
||||
import { getWsErrorMessage } from "../../../../../util/ws-error";
|
||||
|
||||
@customElement("bluetooth-config-dashboard")
|
||||
export class BluetoothConfigDashboard extends LitElement {
|
||||
@@ -45,7 +52,9 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
|
||||
@property({ attribute: "is-wide", type: Boolean }) public isWide = false;
|
||||
|
||||
@state() private _configEntries: ConfigEntry[] = [];
|
||||
@state() private _configEntries?: ConfigEntry[];
|
||||
|
||||
@state() private _configEntriesError?: string;
|
||||
|
||||
@state() private _connectionAllocationData: BluetoothAllocationsData[] = [];
|
||||
|
||||
@@ -69,11 +78,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async _loadConfigEntries(): Promise<void> {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
}
|
||||
private _loadConfigEntries = async (): Promise<void> => {
|
||||
this._configEntriesError = undefined;
|
||||
try {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
this._configEntriesError =
|
||||
getWsErrorMessage(err) || this.hass.localize("ui.common.unknown_error");
|
||||
}
|
||||
};
|
||||
|
||||
private async _subscribeBluetoothConnectionAllocations(): Promise<void> {
|
||||
if (this._unsubConnectionAllocations) {
|
||||
@@ -131,11 +146,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const enabledEntries = this._configEntries.filter(
|
||||
(e) => e.disabled_by === null
|
||||
);
|
||||
const adapterCount = enabledEntries.length;
|
||||
// The device registry is null until it has loaded.
|
||||
const adapterCount =
|
||||
this._configEntries && this.hass.devices
|
||||
? this._getBluetoothAdapters(this.hass.devices, this._configEntries)
|
||||
.enabledDevices.length
|
||||
: undefined;
|
||||
const error = this._configEntriesError;
|
||||
const loading = adapterCount === undefined && !error;
|
||||
const totalSlots = this._connectionAllocationData.reduce(
|
||||
(sum, a) => sum + a.slots,
|
||||
0
|
||||
@@ -163,40 +184,67 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
back-path="/config/connectivity"
|
||||
>
|
||||
<div class="container">
|
||||
<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>
|
||||
<div class="details">
|
||||
${this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>
|
||||
${
|
||||
error
|
||||
? html`<ha-alert alert-type="error" class="content">
|
||||
${error}
|
||||
<ha-button
|
||||
slot="action"
|
||||
appearance="plain"
|
||||
@click=${this._loadConfigEntries}
|
||||
>
|
||||
${this.hass.localize("ui.common.retry")}
|
||||
</ha-button>
|
||||
</ha-alert>`
|
||||
: html`<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
${
|
||||
loading
|
||||
? html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton
|
||||
class="status-icon"
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton>
|
||||
</ha-fade-in>`
|
||||
: html`<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>`
|
||||
}
|
||||
<div class="details">
|
||||
${
|
||||
loading
|
||||
? this._renderTextSkeleton()
|
||||
: this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)
|
||||
}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>`
|
||||
}
|
||||
|
||||
<ha-card class="network-card">
|
||||
<div class="card-header">
|
||||
@@ -224,10 +272,17 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
.path=${mdiAccessPoint}
|
||||
></ha-svg-icon>
|
||||
<div slot="headline">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)}
|
||||
${
|
||||
// A link needs its name, so no skeleton while loading
|
||||
adapterCount === undefined
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapter_info_title"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>
|
||||
@@ -268,6 +323,15 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderTextSkeleton() {
|
||||
return html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton-text
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton-text>
|
||||
</ha-fade-in>`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
@@ -276,7 +340,9 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
padding: var(--ha-space-2) var(--ha-content-gutter) var(--ha-space-4);
|
||||
}
|
||||
|
||||
ha-card {
|
||||
ha-card,
|
||||
ha-alert {
|
||||
display: block;
|
||||
margin: 0px auto var(--ha-space-4);
|
||||
max-width: var(--ha-content-width-narrow);
|
||||
}
|
||||
@@ -326,6 +392,13 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
--icon-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.network-status div.heading .status-icon {
|
||||
display: block;
|
||||
width: var(--ha-space-10);
|
||||
height: var(--ha-space-10);
|
||||
--ha-skeleton-border-radius: var(--ha-border-radius-2xl);
|
||||
}
|
||||
|
||||
.network-status div.heading .icon.online {
|
||||
--icon-color: var(--success-color);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mdiArrowDown, mdiArrowUp, mdiMenuDown } from "@mdi/js";
|
||||
import type { TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
@@ -8,7 +9,10 @@ import { formatDateTime } from "../../../common/datetime/format_date_time";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import { consumeLocalize } from "../../../common/decorators/consume-context-entry";
|
||||
import { transform } from "../../../common/decorators/transform";
|
||||
import type { HASSDomCurrentTargetEvent } from "../../../common/dom/fire_event";
|
||||
import type {
|
||||
HASSDomCurrentTargetEvent,
|
||||
HASSDomEvent,
|
||||
} from "../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { formatNumber } from "../../../common/number/format_number";
|
||||
@@ -17,13 +21,20 @@ import "../../../components/data-table/ha-data-table";
|
||||
import type {
|
||||
DataTableColumnContainer,
|
||||
DataTableRowData,
|
||||
SortingChangedEvent,
|
||||
SortingDirection,
|
||||
} from "../../../components/data-table/ha-data-table";
|
||||
import "../../../components/chips/ha-assist-chip";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/ha-card";
|
||||
import "../../../components/ha-dropdown";
|
||||
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
|
||||
import "../../../components/ha-dropdown-item";
|
||||
import "../../../components/ha-segmented-bar";
|
||||
import type { Segment } from "../../../components/ha-segmented-bar";
|
||||
import "../../../components/ha-spinner";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import {
|
||||
configContext,
|
||||
fullEntitiesContext,
|
||||
@@ -167,6 +178,10 @@ export class StorageDatabaseCard extends LitElement {
|
||||
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||
private _entityRegistry: EntityRegistryEntry[] = [];
|
||||
|
||||
@state() private _sortColumn?: string;
|
||||
|
||||
@state() private _sortDirection: SortingDirection = null;
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const usage = this.usage;
|
||||
return html`
|
||||
@@ -204,6 +219,7 @@ export class StorageDatabaseCard extends LitElement {
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
${usage ? this._renderTable(usage) : nothing}
|
||||
<div class="card-actions">
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
@@ -270,15 +286,25 @@ export class StorageDatabaseCard extends LitElement {
|
||||
></ha-segmented-bar>`
|
||||
: nothing
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderTable(usage: RecorderDatabaseUsage) {
|
||||
const columns = this._columns(
|
||||
this._localize,
|
||||
this._locale,
|
||||
this.narrow,
|
||||
usage.tables !== null,
|
||||
this._sortColumn
|
||||
);
|
||||
return html`
|
||||
<div class="table">
|
||||
<ha-data-table
|
||||
.narrow=${this.narrow}
|
||||
.columns=${this._columns(
|
||||
this._localize,
|
||||
this._locale,
|
||||
this.narrow,
|
||||
usage.tables !== null
|
||||
)}
|
||||
.columns=${columns}
|
||||
.sortColumn=${this._sortColumn}
|
||||
.sortDirection=${this._sortDirection}
|
||||
@sorting-changed=${this._sortingChanged}
|
||||
.data=${this._rows(usage, this._entityRegistry, this._localize)}
|
||||
.searchLabel=${this._localize(
|
||||
"ui.panel.config.storage.database.search"
|
||||
@@ -286,7 +312,9 @@ export class StorageDatabaseCard extends LitElement {
|
||||
.noDataText=${this._localize(
|
||||
"ui.panel.config.storage.database.no_entities"
|
||||
)}
|
||||
></ha-data-table>
|
||||
>
|
||||
${this.narrow ? this._renderSortMenu(columns) : nothing}
|
||||
</ha-data-table>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -371,85 +399,158 @@ export class StorageDatabaseCard extends LitElement {
|
||||
localize: LocalizeFunc,
|
||||
locale: FrontendLocaleData,
|
||||
narrow: boolean,
|
||||
hasSizes: boolean
|
||||
): DataTableColumnContainer<EntityUsageRow> => ({
|
||||
name: {
|
||||
title: localize("ui.panel.config.storage.database.columns.entity"),
|
||||
main: true,
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
flex: 3,
|
||||
template: (row) => {
|
||||
const content = html`${row.name}
|
||||
${
|
||||
row.id !== UNKNOWN_ROW_ID && row.name !== row.id
|
||||
? html`<div class="secondary">${row.id}</div>`
|
||||
: nothing
|
||||
}`;
|
||||
// Rendered inside the data table, which styles .row-button.
|
||||
return row.hasSettings
|
||||
? html`<button
|
||||
type="button"
|
||||
class="row-button"
|
||||
data-entity-id=${row.id}
|
||||
@click=${this._openSettings}
|
||||
>
|
||||
${content}
|
||||
</button>`
|
||||
: content;
|
||||
hasSizes: boolean,
|
||||
sortColumn: string | undefined
|
||||
): DataTableColumnContainer<EntityUsageRow> => {
|
||||
// Narrow screens show one number beside the name: the sorted one.
|
||||
const narrowColumn =
|
||||
sortColumn && sortColumn !== "name"
|
||||
? sortColumn
|
||||
: hasSizes
|
||||
? "bytes"
|
||||
: "states";
|
||||
return {
|
||||
name: {
|
||||
title: localize("ui.panel.config.storage.database.columns.entity"),
|
||||
main: true,
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
flex: 3,
|
||||
template: (row) => {
|
||||
const content = html`${row.name}
|
||||
${
|
||||
row.id !== UNKNOWN_ROW_ID && row.name !== row.id
|
||||
? html`<div class="secondary">${row.id}</div>`
|
||||
: nothing
|
||||
}`;
|
||||
// Rendered inside the data table, which styles .row-button.
|
||||
return row.hasSettings
|
||||
? html`<button
|
||||
type="button"
|
||||
class="row-button"
|
||||
data-entity-id=${row.id}
|
||||
@click=${this._openSettings}
|
||||
>
|
||||
${content}
|
||||
</button>`
|
||||
: content;
|
||||
},
|
||||
},
|
||||
},
|
||||
id: {
|
||||
title: localize("ui.panel.config.storage.database.columns.entity_id"),
|
||||
filterable: true,
|
||||
hidden: true,
|
||||
},
|
||||
states: {
|
||||
title: localize("ui.panel.config.storage.database.columns.states"),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
// Without sizes the rows are sorted by states instead.
|
||||
direction: hasSizes ? undefined : "desc",
|
||||
hidden: narrow && hasSizes,
|
||||
showNarrow: !hasSizes,
|
||||
template: (row) => formatNumber(row.states, locale),
|
||||
},
|
||||
statistics: {
|
||||
title: localize("ui.panel.config.storage.database.columns.statistics"),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
hidden: narrow,
|
||||
template: (row) => formatNumber(row.statistics, locale),
|
||||
},
|
||||
statistics_short_term: {
|
||||
title: localize(
|
||||
"ui.panel.config.storage.database.columns.statistics_short_term"
|
||||
),
|
||||
type: "numeric",
|
||||
minWidth: "130px",
|
||||
maxWidth: "130px",
|
||||
sortable: true,
|
||||
hidden: narrow,
|
||||
template: (row) => formatNumber(row.statistics_short_term, locale),
|
||||
},
|
||||
bytes: {
|
||||
title: localize("ui.panel.config.storage.database.columns.size"),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
direction: hasSizes ? "desc" : undefined,
|
||||
hidden: !hasSizes,
|
||||
showNarrow: hasSizes,
|
||||
template: (row) => bytesToString(row.bytes ?? 0),
|
||||
},
|
||||
})
|
||||
id: {
|
||||
title: localize("ui.panel.config.storage.database.columns.entity_id"),
|
||||
filterable: true,
|
||||
hidden: true,
|
||||
},
|
||||
states: {
|
||||
title: localize("ui.panel.config.storage.database.columns.states"),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
// Without sizes the rows are sorted by states instead.
|
||||
direction: hasSizes ? undefined : "desc",
|
||||
showNarrow: narrow && narrowColumn === "states",
|
||||
template: (row) => formatNumber(row.states, locale),
|
||||
},
|
||||
statistics: {
|
||||
title: localize(
|
||||
"ui.panel.config.storage.database.columns.statistics"
|
||||
),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
showNarrow: narrow && narrowColumn === "statistics",
|
||||
template: (row) => formatNumber(row.statistics, locale),
|
||||
},
|
||||
statistics_short_term: {
|
||||
title: localize(
|
||||
"ui.panel.config.storage.database.columns.statistics_short_term"
|
||||
),
|
||||
type: "numeric",
|
||||
minWidth: "130px",
|
||||
maxWidth: "130px",
|
||||
sortable: true,
|
||||
showNarrow: narrow && narrowColumn === "statistics_short_term",
|
||||
template: (row) => formatNumber(row.statistics_short_term, locale),
|
||||
},
|
||||
bytes: {
|
||||
title: localize("ui.panel.config.storage.database.columns.size"),
|
||||
type: "numeric",
|
||||
minWidth: "100px",
|
||||
maxWidth: "100px",
|
||||
sortable: true,
|
||||
direction: hasSizes ? "desc" : undefined,
|
||||
hidden: !hasSizes,
|
||||
showNarrow: narrow && narrowColumn === "bytes",
|
||||
template: (row) => bytesToString(row.bytes ?? 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
// Replaces the column headers on narrow screens, like the list pages do.
|
||||
private _renderSortMenu(columns: DataTableColumnContainer<EntityUsageRow>) {
|
||||
const sortColumn = this._sortColumn ? columns[this._sortColumn] : undefined;
|
||||
return html`
|
||||
<div slot="header-row" class="narrow-header-row">
|
||||
<ha-dropdown @wa-select=${this._handleSortBy}>
|
||||
<ha-assist-chip
|
||||
slot="trigger"
|
||||
.label=${this._localize(
|
||||
"ui.components.subpage-data-table.sort_by",
|
||||
{
|
||||
sortColumn: sortColumn ? ` ${sortColumn.title}` : "",
|
||||
}
|
||||
)}
|
||||
>
|
||||
<ha-svg-icon
|
||||
slot="trailing-icon"
|
||||
.path=${mdiMenuDown}
|
||||
></ha-svg-icon>
|
||||
</ha-assist-chip>
|
||||
${Object.entries(columns).map(([id, column]) =>
|
||||
column.sortable && !column.hidden
|
||||
? html`<ha-dropdown-item
|
||||
.value=${id}
|
||||
.selected=${id === this._sortColumn}
|
||||
>
|
||||
${
|
||||
id === this._sortColumn
|
||||
? html`<ha-svg-icon
|
||||
slot="details"
|
||||
.path=${
|
||||
this._sortDirection === "desc"
|
||||
? mdiArrowDown
|
||||
: mdiArrowUp
|
||||
}
|
||||
></ha-svg-icon>`
|
||||
: nothing
|
||||
}
|
||||
${column.title}
|
||||
</ha-dropdown-item>`
|
||||
: nothing
|
||||
)}
|
||||
</ha-dropdown>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private _sortingChanged(ev: HASSDomEvent<SortingChangedEvent>) {
|
||||
this._sortDirection = ev.detail.direction;
|
||||
this._sortColumn = ev.detail.direction ? ev.detail.column : undefined;
|
||||
}
|
||||
|
||||
private _handleSortBy(ev: HaDropdownSelectEvent) {
|
||||
ev.preventDefault(); // keep the dropdown open
|
||||
const column = ev.detail.item.value;
|
||||
this._sortDirection =
|
||||
column === this._sortColumn && this._sortDirection === "asc"
|
||||
? "desc"
|
||||
: "asc";
|
||||
this._sortColumn = column;
|
||||
}
|
||||
|
||||
private _analyze() {
|
||||
fireEvent(this, "database-analyze");
|
||||
}
|
||||
@@ -508,6 +609,17 @@ export class StorageDatabaseCard extends LitElement {
|
||||
--data-table-row-height: 44px;
|
||||
height: 100%;
|
||||
}
|
||||
.narrow-header-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding-inline: var(--ha-space-4);
|
||||
}
|
||||
ha-assist-chip {
|
||||
--ha-assist-chip-container-shape: 10px;
|
||||
--ha-assist-chip-container-color: var(--card-background-color);
|
||||
--ha-assist-chip-trailing-space: 8px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,13 @@ import {
|
||||
import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { formatDateTimeWithSeconds } from "../../../../common/datetime/format_date_time";
|
||||
import "../../../../components/ha-control-select-menu";
|
||||
import type { SelectOption } from "../../../../components/ha-control-select-menu";
|
||||
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
|
||||
import type { FrontendLocaleData } from "../../../../data/translation";
|
||||
import type {
|
||||
PipelineRunEvent,
|
||||
AssistRunListing,
|
||||
@@ -79,20 +83,20 @@ export class AssistPipelineDebug extends LitElement {
|
||||
@click=${this._pickOlderRun}
|
||||
.path=${mdiRayEndArrow}
|
||||
></ha-icon-button>
|
||||
<select .value=${this._runId} @change=${this._pickRun}>
|
||||
${repeat(
|
||||
this._runs,
|
||||
(run) => run.pipeline_run_id,
|
||||
(run) =>
|
||||
html`<option value=${run.pipeline_run_id}>
|
||||
${formatDateTimeWithSeconds(
|
||||
new Date(run.timestamp),
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}
|
||||
</option>`
|
||||
<ha-control-select-menu
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.run"
|
||||
)}
|
||||
</select>
|
||||
hide-label
|
||||
show-arrow
|
||||
.value=${this._runId}
|
||||
.options=${this._runOptions(
|
||||
this._runs,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}
|
||||
@wa-select=${this._pickRun}
|
||||
></ha-control-select-menu>
|
||||
<ha-icon-button
|
||||
.disabled=${this._runs[0].pipeline_run_id === this._runId}
|
||||
.label=${this.hass.localize(
|
||||
@@ -254,8 +258,27 @@ export class AssistPipelineDebug extends LitElement {
|
||||
this._runId = this._runs![curIndex - 1].pipeline_run_id;
|
||||
}
|
||||
|
||||
private _pickRun(ev) {
|
||||
this._runId = ev.target.value;
|
||||
private _runOptions = memoizeOne(
|
||||
(
|
||||
runs: AssistRunListing[],
|
||||
locale: FrontendLocaleData,
|
||||
config: HassConfig
|
||||
): SelectOption[] =>
|
||||
runs.map((run) => ({
|
||||
value: run.pipeline_run_id,
|
||||
label: formatDateTimeWithSeconds(
|
||||
new Date(run.timestamp),
|
||||
locale,
|
||||
config
|
||||
),
|
||||
}))
|
||||
);
|
||||
|
||||
private _pickRun(ev: HaDropdownSelectEvent) {
|
||||
const runId = ev.detail.item?.value;
|
||||
if (runId) {
|
||||
this._runId = runId;
|
||||
}
|
||||
}
|
||||
|
||||
static styles = [
|
||||
@@ -270,6 +293,13 @@ export class AssistPipelineDebug extends LitElement {
|
||||
border-bottom: var(--app-header-border-bottom, none);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.toolbar ha-control-select-menu {
|
||||
min-width: min(
|
||||
240px,
|
||||
calc(100% - 2 * var(--ha-icon-button-size, 48px))
|
||||
);
|
||||
--control-select-menu-height: 40px;
|
||||
}
|
||||
.content {
|
||||
padding: 24px 0 32px;
|
||||
max-width: var(--ha-content-width-narrow);
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { live } from "lit/directives/live";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import {
|
||||
consumeEntityState,
|
||||
@@ -139,7 +140,7 @@ class HuiNumericInputCardFeature
|
||||
return html`
|
||||
<ha-control-number-buttons
|
||||
.label=${label}
|
||||
.value=${value}
|
||||
.value=${live(value)}
|
||||
.min=${stateObj.attributes.min}
|
||||
.max=${stateObj.attributes.max}
|
||||
.step=${stateObj.attributes.step}
|
||||
@@ -153,7 +154,7 @@ class HuiNumericInputCardFeature
|
||||
return html`
|
||||
<ha-control-slider
|
||||
.label=${label}
|
||||
.value=${value}
|
||||
.value=${live(value)}
|
||||
.min=${stateObj.attributes.min}
|
||||
.max=${stateObj.attributes.max}
|
||||
.step=${stateObj.attributes.step}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import durationToSeconds from "../../../common/datetime/duration_to_seconds";
|
||||
import { consumeEntityState } from "../../../common/decorators/consume-context-entry";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import type { LovelaceCardFeature } from "../types";
|
||||
import { cardFeatureStyles } from "./common/card-feature-styles";
|
||||
import type {
|
||||
LovelaceCardFeatureContext,
|
||||
TimerProgressCardFeatureConfig,
|
||||
} from "./types";
|
||||
import { TimerRemainingTimeController } from "../../../common/controllers/timer-remaining-time-controller";
|
||||
import { reducedMotionContext } from "../../../data/context";
|
||||
|
||||
export const supportsTimerProgressCardFeature = (
|
||||
hass: HomeAssistant,
|
||||
context: LovelaceCardFeatureContext
|
||||
) => {
|
||||
const stateObj = context.entity_id
|
||||
? hass.states[context.entity_id]
|
||||
: undefined;
|
||||
return !!stateObj && computeDomain(stateObj.entity_id) === "timer";
|
||||
};
|
||||
|
||||
@customElement("hui-timer-progress-card-feature")
|
||||
class HuiTimerProgressCardFeature
|
||||
extends LitElement
|
||||
implements LovelaceCardFeature
|
||||
{
|
||||
@property({ attribute: false }) public context?: LovelaceCardFeatureContext;
|
||||
|
||||
@state()
|
||||
@consumeEntityState({ entityIdPath: ["context", "entity_id"] })
|
||||
private _stateObj?: HassEntity;
|
||||
|
||||
@state()
|
||||
@consume({ context: reducedMotionContext, subscribe: true })
|
||||
private _reducedMotion = false;
|
||||
|
||||
@state() private _config?: TimerProgressCardFeatureConfig;
|
||||
private _timeRemaining = new TimerRemainingTimeController(this);
|
||||
private _prevRatio = 0;
|
||||
private _animate = false;
|
||||
|
||||
static getStubConfig(): TimerProgressCardFeatureConfig {
|
||||
return { type: "timer-progress" };
|
||||
}
|
||||
|
||||
public setConfig(config: TimerProgressCardFeatureConfig): void {
|
||||
if (!config) {
|
||||
throw new Error("Invalid configuration");
|
||||
}
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
protected update(changedProps: PropertyValues): void {
|
||||
if (changedProps.has("_stateObj")) {
|
||||
this._timeRemaining.setStateObj(this._stateObj);
|
||||
}
|
||||
if (this._stateObj) {
|
||||
const ratio = this._ratio(this._stateObj);
|
||||
this._animate =
|
||||
!this._reducedMotion &&
|
||||
this._stateObj.state === "active" &&
|
||||
ratio <= this._prevRatio;
|
||||
this._prevRatio = ratio;
|
||||
}
|
||||
super.update(changedProps);
|
||||
}
|
||||
|
||||
private _ratio(stateObj: HassEntity, offset = 0): number {
|
||||
const { duration } = stateObj.attributes;
|
||||
const total =
|
||||
typeof duration === "string" ? durationToSeconds(duration) : 0;
|
||||
if (!total || stateObj.state === "idle") {
|
||||
return 0;
|
||||
}
|
||||
const left = (this._timeRemaining.timeRemaining ?? 0) - offset;
|
||||
return Math.min(Math.max(left / total, 0), 1);
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (
|
||||
!this._config ||
|
||||
!this.context ||
|
||||
!this._stateObj ||
|
||||
computeDomain(this._stateObj.entity_id) !== "timer"
|
||||
) {
|
||||
return nothing;
|
||||
}
|
||||
const stateObj = this._stateObj;
|
||||
const ratio = this._ratio(stateObj);
|
||||
const target = this._animate ? this._ratio(stateObj, 1) : ratio;
|
||||
return html`
|
||||
<div
|
||||
class="track"
|
||||
role="progressbar"
|
||||
aria-label=${stateObj.attributes.friendly_name || stateObj.entity_id}
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
aria-valuenow=${Math.round(ratio * 100)}
|
||||
>
|
||||
<div
|
||||
class="bar"
|
||||
style=${styleMap({
|
||||
transform: `scaleX(${target})`,
|
||||
transition: this._animate ? "transform 1s linear" : "none",
|
||||
})}
|
||||
></div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = [
|
||||
cardFeatureStyles,
|
||||
css`
|
||||
:host {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
.track {
|
||||
height: var(--feature-height);
|
||||
border-radius: var(--feature-border-radius);
|
||||
background: color-mix(in srgb, var(--feature-color) 20%, transparent);
|
||||
overflow: hidden;
|
||||
}
|
||||
.bar {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
transform-origin: var(--float-start, left);
|
||||
background: var(--feature-color);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"hui-timer-progress-card-feature": HuiTimerProgressCardFeature;
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import { supportsTargetHumidityCardFeature } from "./hui-target-humidity-card-fe
|
||||
import { supportsTargetTemperatureCardFeature } from "./hui-target-temperature-card-feature";
|
||||
import { supportsTimerActionsCardFeature } from "./hui-timer-actions-card-feature";
|
||||
import { supportsTimerPresetsCardFeature } from "./hui-timer-presets-card-feature";
|
||||
import { supportsTimerProgressCardFeature } from "./hui-timer-progress-card-feature";
|
||||
import { supportsToggleCardFeature } from "./hui-toggle-card-feature";
|
||||
import { supportsTrendGraphCardFeature } from "./hui-trend-graph-card-feature";
|
||||
import { supportsUpdateActionsCardFeature } from "./hui-update-actions-card-feature";
|
||||
@@ -110,6 +111,7 @@ export const UI_FEATURE_TYPES = [
|
||||
"target-temperature",
|
||||
"timer-actions",
|
||||
"timer-presets",
|
||||
"timer-progress",
|
||||
"toggle",
|
||||
"update-actions",
|
||||
"vacuum-commands",
|
||||
@@ -169,6 +171,7 @@ export const SUPPORTS_FEATURE_TYPES: Record<UiFeatureType, SupportsFeature> = {
|
||||
"temperature-forecast": supportsTemperatureForecastCardFeature,
|
||||
"timer-actions": supportsTimerActionsCardFeature,
|
||||
"timer-presets": supportsTimerPresetsCardFeature,
|
||||
"timer-progress": supportsTimerProgressCardFeature,
|
||||
toggle: supportsToggleCardFeature,
|
||||
"update-actions": supportsUpdateActionsCardFeature,
|
||||
"vacuum-commands": supportsVacuumCommandsCardFeature,
|
||||
|
||||
@@ -237,6 +237,10 @@ export interface TimerPresetsCardFeatureConfig {
|
||||
style?: "buttons" | "dropdown";
|
||||
}
|
||||
|
||||
export interface TimerProgressCardFeatureConfig {
|
||||
type: "timer-progress";
|
||||
}
|
||||
|
||||
export interface WaterHeaterOperationModesCardFeatureConfig {
|
||||
type: "water-heater-operation-modes";
|
||||
style?: "dropdown" | "icons";
|
||||
@@ -406,6 +410,7 @@ export type LovelaceCardFeatureConfig =
|
||||
| TargetTemperatureCardFeatureConfig
|
||||
| TimerActionsCardFeatureConfig
|
||||
| TimerPresetsCardFeatureConfig
|
||||
| TimerProgressCardFeatureConfig
|
||||
| ToggleCardFeatureConfig
|
||||
| UpdateActionsCardFeatureConfig
|
||||
| VacuumCommandsCardFeatureConfig
|
||||
|
||||
@@ -84,7 +84,7 @@ const DOMAIN_VARIANTS: Record<string, TileVariant[]> = {
|
||||
],
|
||||
alarm_control_panel: [TILE_VARIANT, ["alarm-modes"]],
|
||||
counter: [TILE_VARIANT, ["counter-actions"]],
|
||||
timer: [TILE_VARIANT, ["timer-actions"]],
|
||||
timer: [TILE_VARIANT, ["timer-actions"], ["timer-progress"]],
|
||||
input_select: SELECT_VARIANTS,
|
||||
select: SELECT_VARIANTS,
|
||||
input_number: NUMERIC_INPUT_VARIANTS,
|
||||
|
||||
@@ -14,6 +14,7 @@ import { consume } from "../../../../common/decorators/consume";
|
||||
import { formatNumberWithUnit } from "../../../../common/number/format_number";
|
||||
import "../../../../components/chart/ha-chart-base";
|
||||
import "../../../../components/chart/ha-chart-tooltip-marker";
|
||||
import { wrapLitTooltipFormatter } from "../../../../components/chart/lit-tooltip-formatter";
|
||||
import {
|
||||
formattersContext,
|
||||
internationalizationContext,
|
||||
@@ -251,6 +252,23 @@ export class HuiEnergyDevicesGraphCard
|
||||
<div style="direction:ltr; display: inline;">${value}</div>`;
|
||||
};
|
||||
|
||||
private _renderLabelTooltip = wrapLitTooltipFormatter(
|
||||
(params: { value: string }) => {
|
||||
const series = this._chartData[0];
|
||||
const item = (series?.data as any[] | undefined)?.find(
|
||||
(d) => d.id === params.value
|
||||
);
|
||||
return item
|
||||
? this._renderTooltip({
|
||||
name: item.name,
|
||||
value: item.value,
|
||||
color: item.itemStyle.color,
|
||||
seriesName: series.name,
|
||||
})
|
||||
: nothing;
|
||||
}
|
||||
);
|
||||
|
||||
private _createOptions = memoizeOne(
|
||||
(
|
||||
data: (BarSeriesOption | PieSeriesOption)[],
|
||||
@@ -287,6 +305,12 @@ export class HuiEnergyDevicesGraphCard
|
||||
type: "category",
|
||||
inverse: true,
|
||||
triggerEvent: true,
|
||||
// ECharts types only list `show`, but the label tooltip takes the
|
||||
// formatter too
|
||||
tooltip: {
|
||||
show: true,
|
||||
formatter: this._renderLabelTooltip,
|
||||
} as { show: boolean },
|
||||
// take order from data
|
||||
data: data[0]?.data?.map((d: any) => d.name),
|
||||
axisLabel: {
|
||||
|
||||
@@ -89,10 +89,10 @@ export class HuiDateCard extends LitElement implements LovelaceCard {
|
||||
case "large":
|
||||
return {
|
||||
min_rows: 2,
|
||||
rows: 2,
|
||||
rows: 3,
|
||||
max_rows: 4,
|
||||
min_columns: 6,
|
||||
columns: 6,
|
||||
columns: 12,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import { mdiDotsVertical } from "@mdi/js";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
@@ -25,13 +25,13 @@ import type { HumidifierCardConfig } from "./types";
|
||||
|
||||
@customElement("hui-humidifier-card")
|
||||
export class HuiHumidifierCard extends LitElement implements LovelaceCard {
|
||||
@query(".container") private _container?: HTMLElement;
|
||||
|
||||
// Observe .container, not the host: in a sections view the host keeps its
|
||||
// size when the entity appears and the warning is replaced by the control.
|
||||
private _resizeController = new ResizeController(this, {
|
||||
callback: (entries) => {
|
||||
const container = entries[0]?.target.shadowRoot?.querySelector(
|
||||
".container"
|
||||
) as HTMLElement | undefined;
|
||||
return container?.clientHeight;
|
||||
},
|
||||
target: null,
|
||||
callback: () => this._container?.clientHeight,
|
||||
});
|
||||
|
||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||
@@ -142,7 +142,7 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {
|
||||
return html`
|
||||
<ha-card role="group" aria-labelledby="title">
|
||||
<p class="title" id="title">${name}</p>
|
||||
<div class="container">
|
||||
<div class="container" ${this._resizeController.target()}>
|
||||
<ha-state-control-humidifier-humidity
|
||||
style=${styleMap({
|
||||
maxWidth: controlMaxWidth,
|
||||
|
||||
@@ -846,10 +846,8 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
||||
|
||||
.narrow ha-icon-button[action="media_play"],
|
||||
.narrow ha-icon-button[action="media_play_pause"],
|
||||
.narrow
|
||||
ha-icon-button[action="media_pause"]
|
||||
.narrow
|
||||
ha-icon-button[action="media_stop"] {
|
||||
.narrow ha-icon-button[action="media_pause"],
|
||||
.narrow ha-icon-button[action="media_stop"] {
|
||||
--ha-icon-button-size: 50px;
|
||||
--mdc-icon-size: 36px;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
ha-icon-button {
|
||||
--ha-icon-button-size: 40px;
|
||||
--disabled-text-color: currentColor;
|
||||
--ha-color-on-disabled-quiet: currentColor;
|
||||
color: var(--ha-picture-icon-button-color, #a9a9a9);
|
||||
}
|
||||
ha-icon-button.state-on {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import { mdiDotsVertical } from "@mdi/js";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
@@ -26,13 +26,13 @@ import type { ThermostatCardConfig } from "./types";
|
||||
|
||||
@customElement("hui-thermostat-card")
|
||||
export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
||||
@query(".container") private _container?: HTMLElement;
|
||||
|
||||
// Observe .container, not the host: in a sections view the host keeps its
|
||||
// size when the entity appears and the warning is replaced by the control.
|
||||
private _resizeController = new ResizeController(this, {
|
||||
callback: (entries) => {
|
||||
const container = entries[0]?.target.shadowRoot?.querySelector(
|
||||
".container"
|
||||
) as HTMLElement | undefined;
|
||||
return container?.clientHeight;
|
||||
},
|
||||
target: null,
|
||||
callback: () => this._container?.clientHeight,
|
||||
});
|
||||
|
||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||
@@ -141,7 +141,7 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
|
||||
return html`
|
||||
<ha-card role="group" aria-labelledby="title">
|
||||
<p class="title" id="title">${name}</p>
|
||||
<div class="container">
|
||||
<div class="container" ${this._resizeController.target()}>
|
||||
${
|
||||
domain === "water_heater"
|
||||
? html` <ha-state-control-water_heater-temperature
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
} from "../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import parseAspectRatio from "../../../common/util/parse-aspect-ratio";
|
||||
import "../../../components/camera/ha-camera-placeholder";
|
||||
import "../../../components/ha-camera-stream";
|
||||
import type { HaCameraStream } from "../../../components/ha-camera-stream";
|
||||
import "../../../components/ha-spinner";
|
||||
@@ -135,6 +136,12 @@ export class HuiImage extends LitElement {
|
||||
|
||||
if (this._shouldStartCameraUpdates(oldHass)) {
|
||||
this._startIntersectionObserver();
|
||||
} else if (
|
||||
this._cameraBecameAvailable(oldHass) &&
|
||||
this._imageVisible &&
|
||||
this.cameraView !== "live"
|
||||
) {
|
||||
this._updateCameraImageSrc();
|
||||
} else if (!this.hass!.connected) {
|
||||
this._stopUpdateCameraInterval();
|
||||
this._stopIntersectionObserver();
|
||||
@@ -264,6 +271,13 @@ export class HuiImage extends LitElement {
|
||||
// Snapshots load only once the card is on screen; skip the spinner until then.
|
||||
const showSpinner = !this.cameraImage || this._imageVisible;
|
||||
|
||||
const cameraUnavailable = this._cameraUnavailable();
|
||||
const placeholderHeight = !useRatio
|
||||
? this._lastImageHeight
|
||||
? `${this._lastImageHeight}px`
|
||||
: "100%"
|
||||
: undefined;
|
||||
|
||||
return html`
|
||||
<div
|
||||
style=${styleMap({
|
||||
@@ -288,71 +302,66 @@ export class HuiImage extends LitElement {
|
||||
})}"
|
||||
>
|
||||
${
|
||||
this.cameraImage && this.cameraView === "live"
|
||||
? html`
|
||||
<ha-camera-stream
|
||||
muted
|
||||
.stateObj=${cameraObj}
|
||||
.fitMode=${this.fitMode}
|
||||
.aspectRatio=${
|
||||
this._ratio ? this._ratio.w / this._ratio.h : undefined
|
||||
}
|
||||
@load=${this._onVideoLoad}
|
||||
></ha-camera-stream>
|
||||
`
|
||||
: imageSrc === undefined
|
||||
? nothing
|
||||
: html`
|
||||
<img
|
||||
id="image"
|
||||
src=${this._reconnectImg ? nothing : live(imageSrc)}
|
||||
alt=${this.entity || ""}
|
||||
@error=${this._onImageError}
|
||||
@load=${this._onImageLoad}
|
||||
style=${styleMap({
|
||||
display:
|
||||
useRatio || this._loadState === LoadState.Loaded
|
||||
? "block"
|
||||
: "none",
|
||||
})}
|
||||
/>
|
||||
cameraUnavailable
|
||||
? nothing
|
||||
: this.cameraImage && this.cameraView === "live"
|
||||
? html`
|
||||
<ha-camera-stream
|
||||
muted
|
||||
.stateObj=${cameraObj}
|
||||
.fitMode=${this.fitMode}
|
||||
.aspectRatio=${
|
||||
this._ratio ? this._ratio.w / this._ratio.h : undefined
|
||||
}
|
||||
@load=${this._onVideoLoad}
|
||||
></ha-camera-stream>
|
||||
`
|
||||
: imageSrc === undefined
|
||||
? nothing
|
||||
: html`
|
||||
<img
|
||||
id="image"
|
||||
src=${this._reconnectImg ? nothing : live(imageSrc)}
|
||||
alt=${this.entity || ""}
|
||||
@error=${this._onImageError}
|
||||
@load=${this._onImageLoad}
|
||||
style=${styleMap({
|
||||
display:
|
||||
useRatio || this._loadState === LoadState.Loaded
|
||||
? "block"
|
||||
: "none",
|
||||
})}
|
||||
/>
|
||||
`
|
||||
}
|
||||
${
|
||||
this._loadState === LoadState.Error
|
||||
? html`<div
|
||||
id="brokenImage"
|
||||
style=${styleMap({
|
||||
height: !useRatio
|
||||
? this._lastImageHeight
|
||||
? `${this._lastImageHeight}px`
|
||||
: "100%"
|
||||
: undefined,
|
||||
})}
|
||||
></div>`
|
||||
: this.cameraView !== "live" &&
|
||||
(imageSrc === undefined ||
|
||||
this._loadState === LoadState.Loading)
|
||||
this.cameraImage &&
|
||||
(cameraUnavailable || this._loadState === LoadState.Error)
|
||||
? html`<ha-camera-placeholder
|
||||
style=${styleMap({ height: placeholderHeight })}
|
||||
></ha-camera-placeholder>`
|
||||
: this._loadState === LoadState.Error
|
||||
? html`<div
|
||||
class="progress-container"
|
||||
style=${styleMap({
|
||||
height: !useRatio
|
||||
? this._lastImageHeight
|
||||
? `${this._lastImageHeight}px`
|
||||
: "100%"
|
||||
: undefined,
|
||||
})}
|
||||
>
|
||||
${
|
||||
showSpinner
|
||||
? html`<ha-spinner
|
||||
class="render-spinner"
|
||||
size="small"
|
||||
></ha-spinner>`
|
||||
: nothing
|
||||
}
|
||||
</div>`
|
||||
: ""
|
||||
id="brokenImage"
|
||||
style=${styleMap({ height: placeholderHeight })}
|
||||
></div>`
|
||||
: this.cameraView !== "live" &&
|
||||
(imageSrc === undefined ||
|
||||
this._loadState === LoadState.Loading)
|
||||
? html`<div
|
||||
class="progress-container"
|
||||
style=${styleMap({ height: placeholderHeight })}
|
||||
>
|
||||
${
|
||||
showSpinner
|
||||
? html`<ha-spinner
|
||||
class="render-spinner"
|
||||
size="small"
|
||||
></ha-spinner>`
|
||||
: nothing
|
||||
}
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
</div>
|
||||
`;
|
||||
@@ -366,6 +375,18 @@ export class HuiImage extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
private _cameraUnavailable(hass = this.hass): boolean {
|
||||
return Boolean(
|
||||
this.cameraImage && hass?.states[this.cameraImage]?.state === UNAVAILABLE
|
||||
);
|
||||
}
|
||||
|
||||
private _cameraBecameAvailable(oldHass?: HomeAssistant): boolean {
|
||||
return Boolean(
|
||||
oldHass && this._cameraUnavailable(oldHass) && !this._cameraUnavailable()
|
||||
);
|
||||
}
|
||||
|
||||
private _startIntersectionObserver(): void {
|
||||
if (!this._intersectionObserver) {
|
||||
this._intersectionObserver = new IntersectionObserver(
|
||||
@@ -434,7 +455,8 @@ export class HuiImage extends LitElement {
|
||||
}
|
||||
|
||||
private async _updateCameraImageSrc(): Promise<void> {
|
||||
if (!this.hass || !this.cameraImage) {
|
||||
// Its picture can't load, a placeholder shows instead
|
||||
if (!this.hass || !this.cameraImage || this._cameraUnavailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -525,7 +547,8 @@ export class HuiImage extends LitElement {
|
||||
}
|
||||
|
||||
.ratio img,
|
||||
.ratio div {
|
||||
.ratio div,
|
||||
.ratio ha-camera-placeholder {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
@@ -537,6 +560,10 @@ export class HuiImage extends LitElement {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
ha-camera-placeholder {
|
||||
background-color: var(--ha-color-fill-neutral-normal-resting);
|
||||
}
|
||||
|
||||
#brokenImage {
|
||||
background: grey url("/static/images/image-broken.svg") center/36px
|
||||
no-repeat;
|
||||
|
||||
@@ -38,6 +38,7 @@ import "../card-features/hui-target-humidity-card-feature";
|
||||
import "../card-features/hui-target-temperature-card-feature";
|
||||
import "../card-features/hui-timer-actions-card-feature";
|
||||
import "../card-features/hui-timer-presets-card-feature";
|
||||
import "../card-features/hui-timer-progress-card-feature";
|
||||
import "../card-features/hui-toggle-card-feature";
|
||||
import "../card-features/hui-update-actions-card-feature";
|
||||
import "../card-features/hui-vacuum-commands-card-feature";
|
||||
@@ -104,6 +105,7 @@ const TYPES = new Set<LovelaceCardFeatureConfig["type"]>([
|
||||
"temperature-forecast",
|
||||
"timer-actions",
|
||||
"timer-presets",
|
||||
"timer-progress",
|
||||
"toggle",
|
||||
"update-actions",
|
||||
"vacuum-commands",
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
|
||||
import {
|
||||
mdiClose,
|
||||
mdiFullscreen,
|
||||
mdiFullscreenExit,
|
||||
mdiHelpCircleOutline,
|
||||
} from "@mdi/js";
|
||||
import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
@@ -68,6 +73,8 @@ export class HuiDialogEditBadge
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
@state() private _badgeConfig?: LovelaceBadgeConfig;
|
||||
|
||||
@state() private _saving = false;
|
||||
@@ -195,6 +202,8 @@ export class HuiDialogEditBadge
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@closed=${this._dialogClosed}
|
||||
@@ -205,12 +214,18 @@ export class HuiDialogEditBadge
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<span
|
||||
slot="headerTitle"
|
||||
class="title-enlargeable"
|
||||
@click=${this._enlarge}
|
||||
>${heading}</span
|
||||
>
|
||||
<span slot="headerTitle">${heading}</span>
|
||||
<ha-icon-button
|
||||
slot="headerActionItems"
|
||||
class="enlarge"
|
||||
.path=${this.large ? mdiFullscreenExit : mdiFullscreen}
|
||||
.label=${this.hass.localize(
|
||||
this.large
|
||||
? "ui.panel.lovelace.editor.edit_badge.shrink"
|
||||
: "ui.panel.lovelace.editor.edit_badge.enlarge"
|
||||
)}
|
||||
@click=${this._toggleLarge}
|
||||
></ha-icon-button>
|
||||
${
|
||||
this._documentationURL !== undefined
|
||||
? html`
|
||||
@@ -304,10 +319,14 @@ export class HuiDialogEditBadge
|
||||
`;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this.large = !this.large;
|
||||
});
|
||||
private _toggleLarge() {
|
||||
this._animateWidth = true;
|
||||
this.large = !this.large;
|
||||
}
|
||||
|
||||
// The code editor's fullscreen changes the height at once, so the width must not lag behind
|
||||
private _stopWidthAnimation() {
|
||||
this._animateWidth = false;
|
||||
}
|
||||
|
||||
private _ignoreKeydown(ev: KeyboardEvent) {
|
||||
@@ -494,8 +513,18 @@ export class HuiDialogEditBadge
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
.title-enlargeable {
|
||||
display: block;
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
max-width var(--ha-animation-duration-normal) ease-out;
|
||||
}
|
||||
ha-dialog[fullscreen] .enlarge {
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 999px) {
|
||||
.enlarge {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -504,7 +504,7 @@ export class HaGridLayoutSlider extends LitElement {
|
||||
left 180ms ease-in-out,
|
||||
bottom 180ms ease-in-out;
|
||||
--handle-spacing: calc(2 * var(--handle-margin) + var(--handle-size));
|
||||
--slider-tooltip-margin: 0px;
|
||||
--slider-tooltip-margin: var(--ha-space-1);
|
||||
--slider-tooltip-range: 100%;
|
||||
--slider-tooltip-offset: 0px;
|
||||
--slider-tooltip-position: calc(
|
||||
|
||||
@@ -420,7 +420,7 @@ export class HuiCardLayoutEditor extends LitElement {
|
||||
}
|
||||
ha-grid-size-picker {
|
||||
display: block;
|
||||
margin: 16px auto;
|
||||
margin: var(--ha-space-4) auto;
|
||||
direction: ltr;
|
||||
}
|
||||
`,
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
|
||||
import {
|
||||
mdiClose,
|
||||
mdiFullscreen,
|
||||
mdiFullscreenExit,
|
||||
mdiHelpCircleOutline,
|
||||
} from "@mdi/js";
|
||||
import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
@@ -76,6 +81,8 @@ export class HuiDialogEditCard
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
@state() private _cardConfig?: LovelaceCardConfig;
|
||||
|
||||
@state() private _sectionConfig?: LovelaceSectionConfig;
|
||||
@@ -207,6 +214,8 @@ export class HuiDialogEditCard
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@closed=${this._dialogClosed}
|
||||
@@ -217,12 +226,18 @@ export class HuiDialogEditCard
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<span
|
||||
slot="headerTitle"
|
||||
class="title-enlargeable"
|
||||
@click=${this._enlarge}
|
||||
>${heading}</span
|
||||
>
|
||||
<span slot="headerTitle">${heading}</span>
|
||||
<ha-icon-button
|
||||
slot="headerActionItems"
|
||||
class="enlarge"
|
||||
.path=${this.large ? mdiFullscreenExit : mdiFullscreen}
|
||||
.label=${this.hass.localize(
|
||||
this.large
|
||||
? "ui.panel.lovelace.editor.edit_card.shrink"
|
||||
: "ui.panel.lovelace.editor.edit_card.enlarge"
|
||||
)}
|
||||
@click=${this._toggleLarge}
|
||||
></ha-icon-button>
|
||||
${
|
||||
this._documentationURL !== undefined
|
||||
? html`
|
||||
@@ -330,10 +345,14 @@ export class HuiDialogEditCard
|
||||
`;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this.large = !this.large;
|
||||
});
|
||||
private _toggleLarge() {
|
||||
this._animateWidth = true;
|
||||
this.large = !this.large;
|
||||
}
|
||||
|
||||
// The code editor's fullscreen changes the height at once, so the width must not lag behind
|
||||
private _stopWidthAnimation() {
|
||||
this._animateWidth = false;
|
||||
}
|
||||
|
||||
private _ignoreKeydown(ev: KeyboardEvent) {
|
||||
@@ -576,8 +595,18 @@ export class HuiDialogEditCard
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
.title-enlargeable {
|
||||
display: block;
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
max-width var(--ha-animation-duration-normal) ease-out;
|
||||
}
|
||||
ha-dialog[fullscreen] .enlarge {
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 999px) {
|
||||
.enlarge {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -67,6 +67,7 @@ import { supportsTargetHumidityCardFeature } from "../../card-features/hui-targe
|
||||
import { supportsTargetTemperatureCardFeature } from "../../card-features/hui-target-temperature-card-feature";
|
||||
import { supportsTimerActionsCardFeature } from "../../card-features/hui-timer-actions-card-feature";
|
||||
import { supportsTimerPresetsCardFeature } from "../../card-features/hui-timer-presets-card-feature";
|
||||
import { supportsTimerProgressCardFeature } from "../../card-features/hui-timer-progress-card-feature";
|
||||
import { supportsToggleCardFeature } from "../../card-features/hui-toggle-card-feature";
|
||||
import { supportsTrendGraphCardFeature } from "../../card-features/hui-trend-graph-card-feature";
|
||||
import { supportsUpdateActionsCardFeature } from "../../card-features/hui-update-actions-card-feature";
|
||||
@@ -136,6 +137,7 @@ const UI_FEATURE_TYPES = [
|
||||
"temperature-forecast",
|
||||
"timer-actions",
|
||||
"timer-presets",
|
||||
"timer-progress",
|
||||
"toggle",
|
||||
"update-actions",
|
||||
"vacuum-commands",
|
||||
@@ -239,6 +241,7 @@ const SUPPORTS_FEATURE_TYPES: Record<
|
||||
"temperature-forecast": supportsTemperatureForecastCardFeature,
|
||||
"timer-actions": supportsTimerActionsCardFeature,
|
||||
"timer-presets": supportsTimerPresetsCardFeature,
|
||||
"timer-progress": supportsTimerProgressCardFeature,
|
||||
toggle: supportsToggleCardFeature,
|
||||
"update-actions": supportsUpdateActionsCardFeature,
|
||||
"vacuum-commands": supportsVacuumCommandsCardFeature,
|
||||
|
||||
@@ -96,8 +96,6 @@ export class HuiDialogEditSection
|
||||
|
||||
@property({ attribute: false }) public lovelace?: Lovelace;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public large = false;
|
||||
|
||||
@state() private _params?: EditSectionDialogParams;
|
||||
|
||||
@state() private _config?: LovelaceSectionRawConfig;
|
||||
@@ -114,6 +112,8 @@ export class HuiDialogEditSection
|
||||
|
||||
@state() private _yamlError = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
@storage({
|
||||
key: "dashboardSectionPreviewMode",
|
||||
state: true,
|
||||
@@ -177,7 +177,7 @@ export class HuiDialogEditSection
|
||||
|
||||
private _dialogClosed(): void {
|
||||
this._params = undefined;
|
||||
this.large = false;
|
||||
this._animateWidth = false;
|
||||
this._yamlMode = false;
|
||||
this._config = undefined;
|
||||
this._currTab = TABS[0];
|
||||
@@ -202,8 +202,14 @@ export class HuiDialogEditSection
|
||||
? "tab-appearance"
|
||||
: this._currTab;
|
||||
|
||||
// YAML mode accepts any value, and the dialog width depends on it
|
||||
const configColumnSpan = this._config.column_span;
|
||||
const columnSpan = Math.min(
|
||||
this._config.column_span ?? DEFAULT_SECTION_COLUMN_SPAN,
|
||||
typeof configColumnSpan === "number" &&
|
||||
Number.isInteger(configColumnSpan) &&
|
||||
configColumnSpan >= 1
|
||||
? configColumnSpan
|
||||
: DEFAULT_SECTION_COLUMN_SPAN,
|
||||
this._viewConfig?.max_columns || DEFAULT_MAX_COLUMNS
|
||||
);
|
||||
const singleColumn = columnSpan === 1;
|
||||
@@ -258,7 +264,10 @@ export class HuiDialogEditSection
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
width="large"
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
style=${styleMap({ "--preview-column-span": previewColumnSpan })}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@closed=${this._dialogClosed}
|
||||
@@ -269,12 +278,7 @@ export class HuiDialogEditSection
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<span
|
||||
slot="headerTitle"
|
||||
class="title-enlargeable"
|
||||
@click=${this._enlarge}
|
||||
>${heading}</span
|
||||
>
|
||||
<span slot="headerTitle">${heading}</span>
|
||||
${
|
||||
this._params.newSection
|
||||
? nothing
|
||||
@@ -454,6 +458,7 @@ export class HuiDialogEditSection
|
||||
ev: ValueChangedEvent<LovelaceSectionRawConfig>
|
||||
): void {
|
||||
ev.stopPropagation();
|
||||
this._animateWidth = true;
|
||||
this._config = ev.detail.value;
|
||||
this._updateDirtyState(this._config!);
|
||||
}
|
||||
@@ -494,15 +499,15 @@ export class HuiDialogEditSection
|
||||
}
|
||||
|
||||
private _previewModeClicked(ev: Event) {
|
||||
this._animateWidth = true;
|
||||
this._storedPreviewMode = (
|
||||
ev.currentTarget as HTMLElement & { mode: PreviewMode }
|
||||
).mode;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this.large = !this.large;
|
||||
});
|
||||
// The code editor's fullscreen changes the height at once, so the width must not lag behind
|
||||
private _stopWidthAnimation() {
|
||||
this._animateWidth = false;
|
||||
}
|
||||
|
||||
private _handleTabChanged(ev: CustomEvent): void {
|
||||
@@ -737,6 +742,18 @@ export class HuiDialogEditSection
|
||||
|
||||
ha-dialog {
|
||||
--dialog-content-padding: var(--ha-space-2);
|
||||
--preview-column-width: 390px;
|
||||
--preview-width: calc(
|
||||
var(--preview-column-span) * var(--preview-column-width) +
|
||||
(var(--preview-column-span) - 1) *
|
||||
var(--ha-view-sections-column-gap, 32px)
|
||||
);
|
||||
}
|
||||
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
max-width var(--ha-animation-duration-normal) ease-out;
|
||||
}
|
||||
|
||||
.content {
|
||||
@@ -752,29 +769,18 @@ export class HuiDialogEditSection
|
||||
}
|
||||
}
|
||||
|
||||
@media all and (min-width: 451px) and (min-height: 501px) {
|
||||
:host([large]) .content {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.content .preview-frame {
|
||||
padding: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.content .section-preview {
|
||||
--preview-column-width: 390px;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
max-width: var(--preview-column-width);
|
||||
}
|
||||
.content .section-preview.wide {
|
||||
max-width: none;
|
||||
width: calc(
|
||||
var(--column-span) * var(--preview-column-width) +
|
||||
(var(--column-span) - 1) *
|
||||
var(--ha-view-sections-column-gap, 32px)
|
||||
);
|
||||
width: var(--preview-width);
|
||||
}
|
||||
.preview-header {
|
||||
display: flex;
|
||||
@@ -828,19 +834,28 @@ export class HuiDialogEditSection
|
||||
}
|
||||
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog {
|
||||
--editor-column-width: 520px;
|
||||
/* Plus the paddings of the preview and the dialog */
|
||||
--ha-dialog-width-lg: calc(
|
||||
var(--editor-column-width) + var(--preview-width) + 28px + 2 *
|
||||
var(--dialog-content-padding)
|
||||
);
|
||||
}
|
||||
.content {
|
||||
flex-direction: row;
|
||||
max-height: var(--code-mirror-max-height);
|
||||
}
|
||||
.content > .element-editor {
|
||||
box-sizing: border-box;
|
||||
flex: 0 1 var(--editor-column-width);
|
||||
padding-inline-end: var(--ha-space-4);
|
||||
max-width: 500px;
|
||||
}
|
||||
.content > .element-preview {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
.content > .element-editor,
|
||||
.content > .element-preview {
|
||||
flex-basis: 0;
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
min-width: 0;
|
||||
height: auto;
|
||||
}
|
||||
@@ -889,9 +904,6 @@ export class HuiDialogEditSection
|
||||
margin-inline-end: auto;
|
||||
margin-inline-start: initial;
|
||||
}
|
||||
.title-enlargeable {
|
||||
display: block;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { live } from "lit/directives/live";
|
||||
import { debounce } from "../../../common/util/debounce";
|
||||
import "../../../components/ha-slider";
|
||||
import "../../../components/input/ha-input";
|
||||
@@ -88,7 +89,7 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
||||
.step=${Number(stateObj.attributes.step)}
|
||||
.min=${Number(stateObj.attributes.min)}
|
||||
.max=${Number(stateObj.attributes.max)}
|
||||
.value=${Number(stateObj.state)}
|
||||
.value=${live(Number(stateObj.state))}
|
||||
@change=${this._selectedValueChanged}
|
||||
></ha-slider>
|
||||
<span class="state">
|
||||
@@ -111,7 +112,7 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
||||
.step=${Number(stateObj.attributes.step)}
|
||||
.min=${Number(stateObj.attributes.min)}
|
||||
.max=${Number(stateObj.attributes.max)}
|
||||
.value=${Number(stateObj.state).toString()}
|
||||
.value=${live(Number(stateObj.state).toString())}
|
||||
type="number"
|
||||
@change=${this._selectedValueChanged}
|
||||
>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import "../../../components/ha-button";
|
||||
@@ -29,7 +29,7 @@ const EMPTY_STATE_OBJ = {
|
||||
|
||||
@customElement("hui-button-row")
|
||||
export class HuiButtonRow extends LitElement implements LovelaceRow {
|
||||
public hass?: HomeAssistant;
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
|
||||
@state() private _config?: ButtonRowConfig;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { mdiCheckCircle, mdiDownload, mdiStar } from "@mdi/js";
|
||||
import { mdiCheckCircle, mdiDownloadMultiple, mdiStar } from "@mdi/js";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
@@ -160,7 +160,7 @@ export class HaMarketplaceDiscover extends LitElement {
|
||||
${
|
||||
repository.downloads
|
||||
? html`<span>
|
||||
<ha-svg-icon .path=${mdiDownload}></ha-svg-icon>
|
||||
<ha-svg-icon .path=${mdiDownloadMultiple}></ha-svg-icon>
|
||||
${formatNumber(repository.downloads, locale, compact)}
|
||||
</span>`
|
||||
: nothing
|
||||
|
||||
@@ -138,10 +138,13 @@ export const statusesOfTab = (
|
||||
tab === "installed" ? INSTALLED_STATUS_ORDER : STATUS_ORDER;
|
||||
|
||||
// The filters are kept for every tab. A status picked on another tab that this
|
||||
// one can't list is left out here, instead of leaving the table empty.
|
||||
// one can't list is left out here, instead of leaving the table empty. So is
|
||||
// an integration category nothing on this tab is in, when the ones it lists
|
||||
// are given. Before the repositories load it lists none, so the URL keeps them.
|
||||
export const filtersOfTab = (
|
||||
filters: RepositoryFilters,
|
||||
tab: MarketplaceTab
|
||||
tab: MarketplaceTab,
|
||||
integrationCategories?: readonly string[]
|
||||
): RepositoryFilters => {
|
||||
const statuses: readonly string[] = statusesOfTab(tab);
|
||||
|
||||
@@ -150,25 +153,31 @@ export const filtersOfTab = (
|
||||
[STATUS_FILTER]: filters[STATUS_FILTER]?.filter((status) =>
|
||||
statuses.includes(status)
|
||||
),
|
||||
[INTEGRATION_CATEGORY_FILTER]: integrationCategories
|
||||
? filters[INTEGRATION_CATEGORY_FILTER]?.filter((slug) =>
|
||||
integrationCategories.includes(slug)
|
||||
)
|
||||
: filters[INTEGRATION_CATEGORY_FILTER],
|
||||
};
|
||||
};
|
||||
|
||||
// The status pane only sends what this tab lists, so statuses picked on another
|
||||
// tab that this one can't list are kept for when that tab is opened again
|
||||
// A pane only sends what it lists, so what was picked on another tab that this
|
||||
// one can't list is kept for when that tab is opened again
|
||||
export const paneFilterOfTab = (
|
||||
previous: string[] | undefined,
|
||||
listed: readonly string[],
|
||||
picked: string[] = []
|
||||
): string[] => [
|
||||
...(previous?.filter((value) => !listed.includes(value)) ?? []),
|
||||
...picked,
|
||||
];
|
||||
|
||||
export const statusFilterOfTab = (
|
||||
filters: RepositoryFilters,
|
||||
tab: MarketplaceTab,
|
||||
picked: string[] = []
|
||||
): string[] => {
|
||||
const statuses: readonly string[] = statusesOfTab(tab);
|
||||
|
||||
return [
|
||||
...(filters[STATUS_FILTER]?.filter(
|
||||
(status) => !statuses.includes(status)
|
||||
) ?? []),
|
||||
...picked,
|
||||
];
|
||||
};
|
||||
picked?: string[]
|
||||
): string[] =>
|
||||
paneFilterOfTab(filters[STATUS_FILTER], statusesOfTab(tab), picked);
|
||||
|
||||
const matchesFilters = (
|
||||
repository: RepositoryBase,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
mdiCheckCircleOutline,
|
||||
mdiCompassOutline,
|
||||
mdiDotsVertical,
|
||||
mdiDownload,
|
||||
mdiDownloadMultiple,
|
||||
mdiLinkPlus,
|
||||
mdiOpenInNew,
|
||||
mdiStar,
|
||||
@@ -100,6 +100,7 @@ import {
|
||||
filterRepositories,
|
||||
filtersOfTab,
|
||||
marketplaceUpdateEntityIds,
|
||||
paneFilterOfTab,
|
||||
skippedUpdateRepositories,
|
||||
SOURCE_FILTER,
|
||||
SOURCE_ORDER,
|
||||
@@ -345,15 +346,7 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const marketplaceRepositories = this._applySkippedUpdates(
|
||||
this.marketplace.repositories,
|
||||
this._skippedUpdateRepositories(
|
||||
this._marketplaceUpdateEntityIds,
|
||||
this._entities,
|
||||
this._devices,
|
||||
this._states ?? {}
|
||||
)
|
||||
);
|
||||
const marketplaceRepositories = this._marketplaceRepositories();
|
||||
const tabs = this._tabs(
|
||||
this._i18n.localize,
|
||||
marketplaceRepositories.filter((repository) => repository.pending_upgrade)
|
||||
@@ -374,19 +367,22 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
</hass-tabs-subpage>`;
|
||||
}
|
||||
|
||||
const filters = this._filtersOfTab(this._filters, this.tab);
|
||||
const tabRepositories = this._repositoriesOfTab(
|
||||
marketplaceRepositories,
|
||||
this.tab
|
||||
);
|
||||
const integrationCategoryStates = this._tabIntegrationCategoryStates();
|
||||
const filters = this._filtersOfTab(
|
||||
this._filters,
|
||||
this.tab,
|
||||
this._stateValues(integrationCategoryStates)
|
||||
);
|
||||
const repositories = this._filterRepositories(
|
||||
this._repositoriesOfTab(marketplaceRepositories, this.tab),
|
||||
tabRepositories,
|
||||
this._i18n.localize,
|
||||
filters
|
||||
);
|
||||
|
||||
const integrationCategoryStates = this._integrationCategoryStates(
|
||||
this.marketplace.repositories,
|
||||
this._i18n.localize,
|
||||
this._integrationCategoryIcons
|
||||
);
|
||||
|
||||
return html`<hass-tabs-subpage-data-table
|
||||
.tabs=${tabs}
|
||||
.columns=${this._columns(
|
||||
@@ -506,7 +502,7 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
.label=${this._i18n.localize(
|
||||
"ui.panel.marketplace.filters.integration_category"
|
||||
)}
|
||||
.value=${this._filters[INTEGRATION_CATEGORY_FILTER]}
|
||||
.value=${filters[INTEGRATION_CATEGORY_FILTER]}
|
||||
.states=${integrationCategoryStates}
|
||||
.narrow=${this.narrow}
|
||||
@data-table-filter-changed=${this._integrationCategoryFilterChanged}
|
||||
@@ -591,6 +587,18 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
|
||||
private _tabs = memoize(marketplaceTabs);
|
||||
|
||||
private _marketplaceRepositories(): MarketplaceRepository[] {
|
||||
return this._applySkippedUpdates(
|
||||
this.marketplace.repositories,
|
||||
this._skippedUpdateRepositories(
|
||||
this._marketplaceUpdateEntityIds,
|
||||
this._entities,
|
||||
this._devices,
|
||||
this._states ?? {}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private _repositoriesOfTab = memoize(repositoriesOfTab);
|
||||
|
||||
private _skippedUpdateRepositories = memoize(skippedUpdateRepositories);
|
||||
@@ -607,6 +615,10 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
|
||||
private _filtersOfTab = memoize(filtersOfTab);
|
||||
|
||||
private _stateValues = memoize((options: { value: string }[]) =>
|
||||
options.map((option) => option.value)
|
||||
);
|
||||
|
||||
private _columns = memoize(
|
||||
(
|
||||
localizeFunc: LocalizeFunc,
|
||||
@@ -662,7 +674,7 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
|
||||
return html`${
|
||||
narrow
|
||||
? html`<ha-svg-icon .path=${mdiDownload}></ha-svg-icon>`
|
||||
? html`<ha-svg-icon .path=${mdiDownloadMultiple}></ha-svg-icon>`
|
||||
: nothing
|
||||
}${formatNumber(repository.downloads, this._i18n.locale, compact)}`;
|
||||
},
|
||||
@@ -1123,6 +1135,14 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
}
|
||||
);
|
||||
|
||||
private _tabIntegrationCategoryStates() {
|
||||
return this._integrationCategoryStates(
|
||||
this._repositoriesOfTab(this._marketplaceRepositories(), this.tab),
|
||||
this._i18n.localize,
|
||||
this._integrationCategoryIcons
|
||||
);
|
||||
}
|
||||
|
||||
private _sourceStates = memoize((localize: LocalizeFunc) =>
|
||||
SOURCE_ORDER.map((source) => ({
|
||||
value: source,
|
||||
@@ -1219,15 +1239,24 @@ export class HaMarketplaceDashboard extends LitElement {
|
||||
private _integrationCategoryFilterChanged(
|
||||
ev: CustomEvent<{ value: string[] }>
|
||||
) {
|
||||
const listed = this._stateValues(this._tabIntegrationCategoryStates());
|
||||
const filters = {
|
||||
...this._filters,
|
||||
[INTEGRATION_CATEGORY_FILTER]: ev.detail.value,
|
||||
[INTEGRATION_CATEGORY_FILTER]: paneFilterOfTab(
|
||||
this._filters[INTEGRATION_CATEGORY_FILTER],
|
||||
listed,
|
||||
ev.detail.value
|
||||
),
|
||||
};
|
||||
|
||||
if (this._isUserChange(filters)) {
|
||||
this._storageFilters = {
|
||||
...this._storageFilters,
|
||||
[INTEGRATION_CATEGORY_FILTER]: ev.detail.value,
|
||||
[INTEGRATION_CATEGORY_FILTER]: paneFilterOfTab(
|
||||
this._storageFilters[INTEGRATION_CATEGORY_FILTER],
|
||||
listed,
|
||||
ev.detail.value
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ import {
|
||||
mdiAccountGroup,
|
||||
mdiAlertCircleOutline,
|
||||
mdiArrowUpBoldCircleOutline,
|
||||
mdiBug,
|
||||
mdiCheckCircle,
|
||||
mdiCheckCircleOutline,
|
||||
mdiDotsVertical,
|
||||
mdiDownload,
|
||||
mdiGithub,
|
||||
mdiDownloadMultiple,
|
||||
mdiPackageVariantClosed,
|
||||
mdiRestart,
|
||||
mdiStar,
|
||||
mdiTestTube,
|
||||
@@ -58,7 +57,7 @@ import type { UpdateEntity } from "../../../data/update";
|
||||
import { latestVersionIsSkipped } from "../../../data/update";
|
||||
import { showConfigFlowDialog } from "../../../dialogs/config-flow/show-dialog-config-flow";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import { showRestartDialog } from "../../../dialogs/restart/show-dialog-restart";
|
||||
import { showRestartConfirmation } from "../../../dialogs/restart/show-restart-confirmation";
|
||||
import "../../../layouts/hass-error-screen";
|
||||
import "../../../layouts/hass-loading-screen";
|
||||
import "../../../layouts/hass-subpage";
|
||||
@@ -175,6 +174,8 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
@consume({ context: connectionContext, subscribe: true })
|
||||
private _connection!: ContextType<typeof connectionContext>;
|
||||
|
||||
@state() private _confirmingRestart = false;
|
||||
|
||||
@state() private _integrationCategoryIcons?: IntegrationCategoryIcons;
|
||||
|
||||
@state()
|
||||
@@ -197,13 +198,12 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
|
||||
private _settingPreReleases = new Set<string>();
|
||||
|
||||
private _loadingIntegrationCategoryIcons = false;
|
||||
|
||||
protected async firstUpdated(
|
||||
changedProperties: PropertyValues<this>
|
||||
): Promise<void> {
|
||||
super.firstUpdated(changedProperties);
|
||||
getIntegrationCategoryIcons(this._connection.connection).then((icons) => {
|
||||
this._integrationCategoryIcons = icons;
|
||||
});
|
||||
await this._loadRepository();
|
||||
}
|
||||
|
||||
@@ -324,24 +324,29 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
this._fetchRepository(existing.id);
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues<this>): void {
|
||||
protected willUpdate(changedProps: PropertyValues): void {
|
||||
super.willUpdate(changedProps);
|
||||
|
||||
// The router reuses this element when going from one repository to
|
||||
// another, the first one is loaded by firstUpdated.
|
||||
const previousRoute = changedProps.get("route");
|
||||
const previousRoute = changedProps.get("route") as Route | undefined;
|
||||
if (
|
||||
!this.hasUpdated ||
|
||||
!previousRoute ||
|
||||
repositoryIdFromRoute(previousRoute) === repositoryIdFromRoute(this.route)
|
||||
this.hasUpdated &&
|
||||
previousRoute &&
|
||||
repositoryIdFromRoute(previousRoute) !== repositoryIdFromRoute(this.route)
|
||||
) {
|
||||
return;
|
||||
this._repository = undefined;
|
||||
this._error = undefined;
|
||||
this._refreshError = undefined;
|
||||
this._loadRepositoryFromRoute();
|
||||
}
|
||||
|
||||
this._repository = undefined;
|
||||
this._error = undefined;
|
||||
this._refreshError = undefined;
|
||||
this._loadRepositoryFromRoute();
|
||||
if (
|
||||
changedProps.has("_repository") &&
|
||||
this._repository?.integration_categories?.length
|
||||
) {
|
||||
this._loadIntegrationCategoryIcons();
|
||||
}
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>): void {
|
||||
@@ -396,6 +401,24 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
// Only integrations have categories, other repositories don't need them
|
||||
private async _loadIntegrationCategoryIcons(): Promise<void> {
|
||||
if (
|
||||
this._integrationCategoryIcons ||
|
||||
this._loadingIntegrationCategoryIcons
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this._loadingIntegrationCategoryIcons = true;
|
||||
try {
|
||||
this._integrationCategoryIcons = await getIntegrationCategoryIcons(
|
||||
this._connection.connection
|
||||
);
|
||||
} finally {
|
||||
this._loadingIntegrationCategoryIcons = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _loadRepositoryFromRoute(): void {
|
||||
const repositoryId = repositoryIdFromRoute(this.route);
|
||||
if (!repositoryId) {
|
||||
@@ -684,13 +707,12 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
if (!repository.installed) {
|
||||
return {
|
||||
kind: "available",
|
||||
icon: mdiDownload,
|
||||
icon: mdiPackageVariantClosed,
|
||||
title: localize("ui.panel.marketplace.repository.status.not_installed"),
|
||||
detail: localize("ui.panel.marketplace.repository.status.available", {
|
||||
version: repository.available_version,
|
||||
}),
|
||||
action: this._installButton(
|
||||
mdiDownload,
|
||||
localize("ui.panel.marketplace.common.install")
|
||||
),
|
||||
};
|
||||
@@ -712,11 +734,7 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
installed: repository.installed_version,
|
||||
version: repository.available_version,
|
||||
}),
|
||||
action: this._installButton(
|
||||
mdiArrowUpBoldCircleOutline,
|
||||
localize("ui.common.update"),
|
||||
this._update
|
||||
),
|
||||
action: this._installButton(localize("ui.common.update"), this._update),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -733,9 +751,9 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
action: html`<ha-button
|
||||
variant="warning"
|
||||
appearance="filled"
|
||||
.loading=${this._confirmingRestart}
|
||||
@click=${this._restart}
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${mdiRestart}></ha-svg-icon>
|
||||
${localize("ui.panel.marketplace.repository.next_step.restart_button")}
|
||||
</ha-button>`,
|
||||
};
|
||||
@@ -778,12 +796,10 @@ export class HaMarketplaceRepositoryDashboard extends LitElement {
|
||||
}
|
||||
|
||||
private _installButton(
|
||||
icon: string,
|
||||
label: string,
|
||||
handler: () => void = this._installRepositoryDialog
|
||||
) {
|
||||
return html`<ha-button appearance="filled" @click=${handler}>
|
||||
<ha-svg-icon slot="start" .path=${icon}></ha-svg-icon>
|
||||
${label}
|
||||
</ha-button>`;
|
||||
}
|
||||
@@ -916,7 +932,6 @@ type: module</pre>`,
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${mdiGithub}></ha-svg-icon>
|
||||
${localize("ui.panel.marketplace.repository.details.source_code")}
|
||||
</ha-button>
|
||||
<ha-button
|
||||
@@ -925,7 +940,6 @@ type: module</pre>`,
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${mdiBug}></ha-svg-icon>
|
||||
${localize("ui.panel.marketplace.repository.details.issue_tracker")}
|
||||
</ha-button>
|
||||
</div>
|
||||
@@ -1005,7 +1019,7 @@ type: module</pre>`,
|
||||
}
|
||||
if (repository.downloads) {
|
||||
signals.push({
|
||||
icon: mdiDownload,
|
||||
icon: mdiDownloadMultiple,
|
||||
text: localize("ui.panel.marketplace.repository.community.downloads", {
|
||||
number: repository.downloads,
|
||||
count: html`<strong
|
||||
@@ -1070,8 +1084,20 @@ type: module</pre>`,
|
||||
this._installRepositoryDialog();
|
||||
}
|
||||
|
||||
private _restart() {
|
||||
showRestartDialog(this);
|
||||
private async _restart() {
|
||||
if (this._confirmingRestart) {
|
||||
return;
|
||||
}
|
||||
this._confirmingRestart = true;
|
||||
try {
|
||||
await showRestartConfirmation(this, {
|
||||
localize: this._i18n.localize,
|
||||
connection: this._connection.connection,
|
||||
callService: this._api.callService,
|
||||
});
|
||||
} finally {
|
||||
this._confirmingRestart = false;
|
||||
}
|
||||
}
|
||||
|
||||
private _setUp() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { mdiGithub } from "@mdi/js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
@@ -10,6 +11,7 @@ import "../../../components/ha-dialog";
|
||||
import "../../../components/ha-dialog-footer";
|
||||
import "../../../components/ha-form/ha-form";
|
||||
import type { HaFormSchema } from "../../../components/ha-form/types";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import "../../../components/progress/ha-progress-bar";
|
||||
import { apiContext, internationalizationContext } from "../../../data/context";
|
||||
import type { RepositoryType } from "../../../data/marketplace/repository";
|
||||
@@ -79,6 +81,7 @@ export class DialogMarketplaceCustomRepositories extends DialogMixin<Marketplace
|
||||
this._githubConnected
|
||||
? nothing
|
||||
: html`<ha-alert alert-type="info">
|
||||
<ha-svg-icon slot="icon" .path=${mdiGithub}></ha-svg-icon>
|
||||
${this._i18n.localize(
|
||||
"ui.panel.marketplace.dialog_custom_repositories.github_needed"
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { mdiSwapHorizontal, mdiUpdate } from "@mdi/js";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
@@ -21,6 +22,7 @@ import {
|
||||
type PickerComboBoxItem,
|
||||
} from "../../../components/ha-picker-combo-box";
|
||||
import "../../../components/ha-spinner";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import "../../../components/progress/ha-progress-bar";
|
||||
|
||||
import { relativeTime } from "../../../common/datetime/relative_time";
|
||||
@@ -259,6 +261,7 @@ export class DialogMarketplaceInstall extends DialogMixin<MarketplaceInstallDial
|
||||
{ domain: repository.domain }
|
||||
)}
|
||||
>
|
||||
<ha-svg-icon slot="icon" .path=${mdiSwapHorizontal}></ha-svg-icon>
|
||||
${this._i18n.localize(
|
||||
"ui.panel.marketplace.dialog_install.replaces_built_in_warning",
|
||||
{ repository: repository.name, domain: repository.domain }
|
||||
@@ -281,6 +284,7 @@ export class DialogMarketplaceInstall extends DialogMixin<MarketplaceInstallDial
|
||||
${
|
||||
tooNew
|
||||
? html`<ha-alert alert-type="warning">
|
||||
<ha-svg-icon slot="icon" .path=${mdiUpdate}></ha-svg-icon>
|
||||
${installBlockedReason(this._i18n.localize, repository)}
|
||||
${this._i18n.localize(
|
||||
"ui.panel.marketplace.dialog_install.older_version_hint"
|
||||
|
||||
@@ -3,6 +3,7 @@ import { mdiMinus, mdiPlus, mdiWaterPercent } from "@mdi/js";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { keyed } from "lit/directives/keyed";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import type { HASSDomEvent } from "../../common/dom/fire_event";
|
||||
@@ -52,6 +53,8 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
|
||||
@state() private _targetHumidity?: number;
|
||||
|
||||
@state() private _changingHumidity?: number;
|
||||
|
||||
private _sizeController = createStateControlCircularSliderController(this);
|
||||
|
||||
private _pendingSync = new PendingValueSync();
|
||||
@@ -61,7 +64,11 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
if (!changedProp.has("stateObj")) {
|
||||
return;
|
||||
}
|
||||
if (this.stateObj.state === UNAVAILABLE) {
|
||||
this._changingHumidity = undefined;
|
||||
}
|
||||
if (changedProp.get("stateObj")?.entity_id !== this.stateObj.entity_id) {
|
||||
this._changingHumidity = undefined;
|
||||
this._debouncedCallService.cancel();
|
||||
this._pendingSync.reset();
|
||||
this._syncTargetHumidity();
|
||||
@@ -71,6 +78,9 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
}
|
||||
|
||||
private _syncTargetHumidity() {
|
||||
if (this.stateObj.attributes.humidity !== this._targetHumidity) {
|
||||
this._changingHumidity = undefined;
|
||||
}
|
||||
this._targetHumidity = this.stateObj.attributes.humidity;
|
||||
}
|
||||
|
||||
@@ -96,8 +106,11 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
|
||||
private _valueChanging(ev: HASSDomEvent<HASSDomEvents["value-changing"]>) {
|
||||
const { value } = ev.detail;
|
||||
if (typeof value !== "number" || isNaN(value)) return;
|
||||
this._targetHumidity = value;
|
||||
if (typeof value !== "number" || isNaN(value)) {
|
||||
this._changingHumidity = undefined;
|
||||
return;
|
||||
}
|
||||
this._changingHumidity = value;
|
||||
}
|
||||
|
||||
private _debouncedCallService = debounce(() => this._callService(), 1000);
|
||||
@@ -212,6 +225,10 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return keyed(this.stateObj.entity_id, this._renderControl());
|
||||
}
|
||||
|
||||
private _renderControl() {
|
||||
const supportsTargetHumidity = supportsFeature(
|
||||
this.stateObj,
|
||||
ClimateEntityFeature.TARGET_HUMIDITY
|
||||
@@ -264,7 +281,8 @@ export class HaStateControlClimateHumidity extends LitElement {
|
||||
>
|
||||
</ha-control-circular-slider>
|
||||
<div class="info">
|
||||
${this._renderLabel()} ${this._renderTarget(targetHumidity)}
|
||||
${this._renderLabel()}
|
||||
${this._renderTarget(this._changingHumidity ?? targetHumidity)}
|
||||
${this._renderCurrentHumidity(
|
||||
this.stateObj.attributes.current_humidity
|
||||
)}
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { keyed } from "lit/directives/keyed";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { UNIT_F } from "../../common/const";
|
||||
@@ -81,6 +82,8 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
|
||||
@state() private _targetTemperature: Partial<Record<Target, number>> = {};
|
||||
|
||||
@state() private _changingTemperature: Partial<Record<Target, number>> = {};
|
||||
|
||||
@state() private _selectTargetTemperature: Target = "low";
|
||||
|
||||
private _sizeController = createStateControlCircularSliderController(this);
|
||||
@@ -92,7 +95,11 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
if (!changedProp.has("stateObj")) {
|
||||
return;
|
||||
}
|
||||
if (this.stateObj.state === UNAVAILABLE) {
|
||||
this._changingTemperature = {};
|
||||
}
|
||||
if (changedProp.get("stateObj")?.entity_id !== this.stateObj.entity_id) {
|
||||
this._changingTemperature = {};
|
||||
this._debouncedCallService.cancel();
|
||||
this._pendingSync.reset();
|
||||
this._syncTargetTemperature();
|
||||
@@ -102,11 +109,20 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
}
|
||||
|
||||
private _syncTargetTemperature() {
|
||||
this._targetTemperature = {
|
||||
const targetTemperature: Partial<Record<Target, number>> = {
|
||||
value: this.stateObj.attributes.temperature,
|
||||
low: this.stateObj.attributes.target_temp_low,
|
||||
high: this.stateObj.attributes.target_temp_high,
|
||||
};
|
||||
if (
|
||||
(Object.keys(this._changingTemperature) as Target[]).some(
|
||||
(target) =>
|
||||
targetTemperature[target] !== this._targetTemperature[target]
|
||||
)
|
||||
) {
|
||||
this._changingTemperature = {};
|
||||
}
|
||||
this._targetTemperature = targetTemperature;
|
||||
}
|
||||
|
||||
private get _step() {
|
||||
@@ -127,27 +143,31 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
private _valueChanged(ev: HASSDomEvent<HASSDomEvents["value-changed"]>) {
|
||||
const { value } = ev.detail;
|
||||
if (typeof value !== "number" || isNaN(value)) return;
|
||||
const target = ev.type.replace("-changed", "");
|
||||
const target = ev.type.replace("-changed", "") as Target;
|
||||
this._targetTemperature = {
|
||||
...this._targetTemperature,
|
||||
[target]: value,
|
||||
[target]: this._clampToRange(target, value),
|
||||
};
|
||||
this._selectTargetTemperature = target as Target;
|
||||
this._selectTargetTemperature = target;
|
||||
this._debouncedCallService.cancel();
|
||||
this._callService(target);
|
||||
}
|
||||
|
||||
private _valueChanging(ev: HASSDomEvent<HASSDomEvents["value-changing"]>) {
|
||||
const { value } = ev.detail;
|
||||
if (typeof value !== "number" || isNaN(value)) return;
|
||||
if (typeof value !== "number" || isNaN(value)) {
|
||||
this._changingTemperature = {};
|
||||
return;
|
||||
}
|
||||
const target = ev.type.replace("-changing", "");
|
||||
this._targetTemperature = {
|
||||
...this._targetTemperature,
|
||||
[target]: value,
|
||||
};
|
||||
this._changingTemperature = { [target]: value };
|
||||
this._selectTargetTemperature = target as Target;
|
||||
}
|
||||
|
||||
private get _displayedTemperature() {
|
||||
return { ...this._targetTemperature, ...this._changingTemperature };
|
||||
}
|
||||
|
||||
private _debouncedCallService = debounce(
|
||||
(target: Target) => this._callService(target),
|
||||
1000
|
||||
@@ -180,21 +200,25 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
let temp = this._targetTemperature[target] ?? defaultValue;
|
||||
temp += step;
|
||||
temp = clamp(temp, this._min, this._max);
|
||||
if (target === "high" && this._targetTemperature.low != null) {
|
||||
temp = clamp(temp, this._targetTemperature.low, this._max);
|
||||
}
|
||||
if (target === "low" && this._targetTemperature.high != null) {
|
||||
temp = clamp(temp, this._min, this._targetTemperature.high);
|
||||
}
|
||||
|
||||
this._targetTemperature = {
|
||||
...this._targetTemperature,
|
||||
[target]: temp,
|
||||
[target]: this._clampToRange(target, temp),
|
||||
};
|
||||
this._pendingSync.schedule();
|
||||
this._debouncedCallService(target);
|
||||
}
|
||||
|
||||
private _clampToRange(target: Target, temp: number) {
|
||||
if (target === "high" && this._targetTemperature.low != null) {
|
||||
return clamp(temp, this._targetTemperature.low, this._max);
|
||||
}
|
||||
if (target === "low" && this._targetTemperature.high != null) {
|
||||
return clamp(temp, this._min, this._targetTemperature.high);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
private _handleSelectTemp(ev) {
|
||||
const target = ev.currentTarget.target as Target;
|
||||
this._selectTargetTemperature = target;
|
||||
@@ -354,7 +378,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
}
|
||||
|
||||
if (this._supportsTargetTemperature && !this.showCurrentAsPrimary) {
|
||||
return this._renderTarget(this._targetTemperature.value!, "big");
|
||||
return this._renderTarget(this._displayedTemperature.value!, "big");
|
||||
}
|
||||
|
||||
if (this._supportsTargetTemperatureRange && !this.showCurrentAsPrimary) {
|
||||
@@ -374,7 +398,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
"target_temp_low"
|
||||
)}
|
||||
</span>
|
||||
${this._renderTarget(this._targetTemperature.low!, "big")}
|
||||
${this._renderTarget(this._displayedTemperature.low!, "big")}
|
||||
</button>
|
||||
<button
|
||||
@click=${this._handleSelectTemp}
|
||||
@@ -390,7 +414,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
"target_temp_high"
|
||||
)}
|
||||
</span>
|
||||
${this._renderTarget(this._targetTemperature.high!, "big")}
|
||||
${this._renderTarget(this._displayedTemperature.high!, "big")}
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
@@ -427,7 +451,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
return html`
|
||||
<p class="label secondary">
|
||||
<ha-svg-icon .path=${mdiThermostat}></ha-svg-icon>
|
||||
${this._renderTarget(this._targetTemperature.value!, "normal")}
|
||||
${this._renderTarget(this._displayedTemperature.value!, "normal")}
|
||||
</p>
|
||||
`;
|
||||
}
|
||||
@@ -450,7 +474,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
"target_temp_low"
|
||||
)}
|
||||
</span>
|
||||
${this._renderTarget(this._targetTemperature.low!, "normal", true)}
|
||||
${this._renderTarget(this._displayedTemperature.low!, "normal", true)}
|
||||
</button>
|
||||
<span>·</span>
|
||||
<button
|
||||
@@ -467,7 +491,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
"target_temp_high"
|
||||
)}
|
||||
</span>
|
||||
${this._renderTarget(this._targetTemperature.high!, "normal", true)}
|
||||
${this._renderTarget(this._displayedTemperature.high!, "normal", true)}
|
||||
</button>
|
||||
</p>
|
||||
`;
|
||||
@@ -503,6 +527,10 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return keyed(this.stateObj.entity_id, this._renderControl());
|
||||
}
|
||||
|
||||
private _renderControl() {
|
||||
const mode = this.stateObj.state;
|
||||
const action = this.stateObj.attributes.hvac_action;
|
||||
const active = stateActive(this.stateObj);
|
||||
@@ -549,7 +577,7 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
.preventInteractionOnScroll=${this.preventInteractionOnScroll}
|
||||
.inactive=${!active}
|
||||
.mode=${sliderMode}
|
||||
.value=${this._targetTemperature.value}
|
||||
.value=${this._displayedTemperature.value}
|
||||
.min=${this._min}
|
||||
.max=${this._max}
|
||||
.step=${this._step}
|
||||
@@ -585,8 +613,8 @@ export class HaStateControlClimateTemperature extends LitElement {
|
||||
.preventInteractionOnScroll=${this.preventInteractionOnScroll}
|
||||
.inactive=${!active}
|
||||
dual
|
||||
.low=${this._targetTemperature.low}
|
||||
.high=${this._targetTemperature.high}
|
||||
.low=${this._displayedTemperature.low}
|
||||
.high=${this._displayedTemperature.high}
|
||||
.min=${this._min}
|
||||
.max=${this._max}
|
||||
.step=${this._step}
|
||||
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
coverCurrentValue,
|
||||
coverHasTiltControls,
|
||||
coverModeAttribute,
|
||||
coverSupportsPosition,
|
||||
coverSupportsSetValue,
|
||||
coverSupportsTiltPosition,
|
||||
coverTiltOpenness,
|
||||
@@ -78,6 +77,17 @@ const pillHandle = (cx: number, cy: number, vertical: boolean) =>
|
||||
const swipeResistance = (distance: number) =>
|
||||
SWIPE_RESISTANCE * (1 - Math.exp(-Math.max(0, distance) / 30));
|
||||
|
||||
const OPEN_CLOSE_FEATURES: Record<
|
||||
CoverControlMode,
|
||||
Record<CoverSwipe["action"], CoverEntityFeature>
|
||||
> = {
|
||||
position: { open: CoverEntityFeature.OPEN, close: CoverEntityFeature.CLOSE },
|
||||
tilt: {
|
||||
open: CoverEntityFeature.OPEN_TILT,
|
||||
close: CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
};
|
||||
|
||||
const modeSprings = (): ModeSprings => ({
|
||||
position: new PercentSpring(),
|
||||
tilt: new PercentSpring(),
|
||||
@@ -190,11 +200,11 @@ export class HaStateControlCover extends LitElement {
|
||||
}
|
||||
|
||||
private get _openCloseOnly(): boolean {
|
||||
const features = OPEN_CLOSE_FEATURES[this.mode];
|
||||
return (
|
||||
this.mode === "position" &&
|
||||
!coverSupportsPosition(this.stateObj) &&
|
||||
(supportsFeature(this.stateObj, CoverEntityFeature.OPEN) ||
|
||||
supportsFeature(this.stateObj, CoverEntityFeature.CLOSE))
|
||||
!this._canSetValue &&
|
||||
(supportsFeature(this.stateObj, features.open) ||
|
||||
supportsFeature(this.stateObj, features.close))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,7 +218,9 @@ export class HaStateControlCover extends LitElement {
|
||||
private get _interactive(): boolean {
|
||||
return (
|
||||
this.stateObj.state !== UNAVAILABLE &&
|
||||
(this._canSetValue || (this._openCloseOnly && !this._valueUnknown))
|
||||
(this._canSetValue ||
|
||||
(this._openCloseOnly &&
|
||||
coverCurrentValue(this.stateObj, this.mode) !== undefined))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -412,11 +424,7 @@ export class HaStateControlCover extends LitElement {
|
||||
}
|
||||
|
||||
private _swipeAction(): CoverSwipe["action"] {
|
||||
const end =
|
||||
this.request?.mode === "position"
|
||||
? this.request.value
|
||||
: this._drawingGoal("position");
|
||||
return end >= 50 ? "close" : "open";
|
||||
return this._handleGoal(this.mode) >= 50 ? "close" : "open";
|
||||
}
|
||||
|
||||
private _startSwipe(
|
||||
@@ -424,14 +432,10 @@ export class HaStateControlCover extends LitElement {
|
||||
shape: CoverShape,
|
||||
startPointer: number
|
||||
) {
|
||||
const mode = this.mode;
|
||||
const action = this._swipeAction();
|
||||
const closing = action === "close";
|
||||
if (
|
||||
!supportsFeature(
|
||||
this.stateObj,
|
||||
closing ? CoverEntityFeature.CLOSE : CoverEntityFeature.OPEN
|
||||
)
|
||||
) {
|
||||
if (!supportsFeature(this.stateObj, OPEN_CLOSE_FEATURES[mode][action])) {
|
||||
return;
|
||||
}
|
||||
const direction = closing ? -1 : 1;
|
||||
@@ -462,13 +466,13 @@ export class HaStateControlCover extends LitElement {
|
||||
const passedHalfway = Boolean(this._drag?.swipe?.passedHalfway);
|
||||
this._setDrag(undefined);
|
||||
if (passedHalfway) {
|
||||
fireEvent(this, "cover-command", { mode: "position", action });
|
||||
fireEvent(this, "cover-command", { mode, action });
|
||||
}
|
||||
},
|
||||
tap: (e) => {
|
||||
const pointer = this._pointerValue(e, shape);
|
||||
if (pointer !== undefined && pointer >= 50 !== closing) {
|
||||
fireEvent(this, "cover-command", { mode: "position", action });
|
||||
fireEvent(this, "cover-command", { mode, action });
|
||||
}
|
||||
},
|
||||
cancel: () => this._setDrag(undefined),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { mdiMinus, mdiPlus, mdiThermostat, mdiWaterPercent } from "@mdi/js";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { keyed } from "lit/directives/keyed";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
@@ -57,6 +58,8 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
|
||||
@state() private _targetHumidity?: number;
|
||||
|
||||
@state() private _changingHumidity?: number;
|
||||
|
||||
private _sizeController = createStateControlCircularSliderController(this);
|
||||
|
||||
private _pendingSync = new PendingValueSync();
|
||||
@@ -66,7 +69,11 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
if (!changedProp.has("stateObj")) {
|
||||
return;
|
||||
}
|
||||
if (this.stateObj.state === UNAVAILABLE) {
|
||||
this._changingHumidity = undefined;
|
||||
}
|
||||
if (changedProp.get("stateObj")?.entity_id !== this.stateObj.entity_id) {
|
||||
this._changingHumidity = undefined;
|
||||
this._debouncedCallService.cancel();
|
||||
this._pendingSync.reset();
|
||||
this._syncTargetHumidity();
|
||||
@@ -76,6 +83,9 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
}
|
||||
|
||||
private _syncTargetHumidity() {
|
||||
if (this.stateObj.attributes.humidity !== this._targetHumidity) {
|
||||
this._changingHumidity = undefined;
|
||||
}
|
||||
this._targetHumidity = this.stateObj.attributes.humidity;
|
||||
}
|
||||
|
||||
@@ -101,8 +111,11 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
|
||||
private _valueChanging(ev: HASSDomEvent<HASSDomEvents["value-changing"]>) {
|
||||
const { value } = ev.detail;
|
||||
if (typeof value !== "number" || isNaN(value)) return;
|
||||
this._targetHumidity = value;
|
||||
if (typeof value !== "number" || isNaN(value)) {
|
||||
this._changingHumidity = undefined;
|
||||
return;
|
||||
}
|
||||
this._changingHumidity = value;
|
||||
}
|
||||
|
||||
private _debouncedCallService = debounce(() => this._callService(), 1000);
|
||||
@@ -200,7 +213,10 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
}
|
||||
|
||||
if (this._targetHumidity != null && !this.showCurrentAsPrimary) {
|
||||
return this._renderTarget(this._targetHumidity!, "big");
|
||||
return this._renderTarget(
|
||||
this._changingHumidity ?? this._targetHumidity,
|
||||
"big"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.stateObj.state !== UNAVAILABLE) {
|
||||
@@ -234,7 +250,10 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
return html`
|
||||
<p class="label">
|
||||
<ha-svg-icon .path=${mdiThermostat}></ha-svg-icon>
|
||||
${this._renderCurrent(this._targetHumidity, "normal")}
|
||||
${this._renderCurrent(
|
||||
this._changingHumidity ?? this._targetHumidity,
|
||||
"normal"
|
||||
)}
|
||||
</p>
|
||||
`;
|
||||
}
|
||||
@@ -299,6 +318,10 @@ export class HaStateControlHumidifierHumidity extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return keyed(this.stateObj.entity_id, this._renderControl());
|
||||
}
|
||||
|
||||
private _renderControl() {
|
||||
const stateColor = stateColorCss(this.stateObj);
|
||||
const active = stateActive(this.stateObj);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { mdiMinus, mdiPlus } from "@mdi/js";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { keyed } from "lit/directives/keyed";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { UNIT_F } from "../../common/const";
|
||||
@@ -60,6 +61,8 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
|
||||
@state() private _targetTemperature?: number;
|
||||
|
||||
@state() private _changingTemperature?: number;
|
||||
|
||||
private _sizeController = createStateControlCircularSliderController(this);
|
||||
|
||||
private _pendingSync = new PendingValueSync();
|
||||
@@ -69,7 +72,11 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
if (!changedProp.has("stateObj")) {
|
||||
return;
|
||||
}
|
||||
if (this.stateObj.state === UNAVAILABLE) {
|
||||
this._changingTemperature = undefined;
|
||||
}
|
||||
if (changedProp.get("stateObj")?.entity_id !== this.stateObj.entity_id) {
|
||||
this._changingTemperature = undefined;
|
||||
this._debouncedCallService.cancel();
|
||||
this._pendingSync.reset();
|
||||
this._syncTargetTemperature();
|
||||
@@ -79,6 +86,9 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
}
|
||||
|
||||
private _syncTargetTemperature() {
|
||||
if (this.stateObj.attributes.temperature !== this._targetTemperature) {
|
||||
this._changingTemperature = undefined;
|
||||
}
|
||||
this._targetTemperature = this.stateObj.attributes.temperature;
|
||||
}
|
||||
|
||||
@@ -107,8 +117,11 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
|
||||
private _valueChanging(ev: HASSDomEvent<HASSDomEvents["value-changing"]>) {
|
||||
const { value } = ev.detail;
|
||||
if (typeof value !== "number" || isNaN(value)) return;
|
||||
this._targetTemperature = value;
|
||||
if (typeof value !== "number" || isNaN(value)) {
|
||||
this._changingTemperature = undefined;
|
||||
return;
|
||||
}
|
||||
this._changingTemperature = value;
|
||||
}
|
||||
|
||||
private _debouncedCallService = debounce(() => this._callService(), 1000);
|
||||
@@ -231,6 +244,10 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return keyed(this.stateObj.entity_id, this._renderControl());
|
||||
}
|
||||
|
||||
private _renderControl() {
|
||||
const supportsTargetTemperature = supportsFeature(
|
||||
this.stateObj,
|
||||
WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
||||
@@ -271,7 +288,9 @@ export class HaStateControlWaterHeaterTemperature extends LitElement {
|
||||
</ha-control-circular-slider>
|
||||
<div class="info">
|
||||
${this._renderLabel()}
|
||||
${this._renderTargetTemperature(this._targetTemperature)}
|
||||
${this._renderTargetTemperature(
|
||||
this._changingTemperature ?? this._targetTemperature
|
||||
)}
|
||||
${this._renderCurrentTemperature(
|
||||
this.stateObj.attributes.current_temperature
|
||||
)}
|
||||
|
||||
@@ -28,12 +28,20 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
|
||||
private _startupToastKey?: string;
|
||||
|
||||
private _startupDetailsOpen = false;
|
||||
|
||||
private _disconnectedTimeout?: number;
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
super.firstUpdated(changedProps);
|
||||
// Need to load in advance because when disconnected, can't dynamically load code.
|
||||
setTimeout(() => import("../managers/notification-manager"), 5000);
|
||||
this.addEventListener("dialog-closed", (ev) => {
|
||||
if (ev.detail.dialog === "dialog-startup-progress") {
|
||||
this._startupDetailsOpen = false;
|
||||
this._updateStartupProgress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updated(changedProperties: PropertyValues<this>) {
|
||||
@@ -135,6 +143,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
// Wait until the translations are available.
|
||||
if (
|
||||
!this._startupProgressVisible ||
|
||||
this._startupDetailsOpen ||
|
||||
!this.hass!.localize("ui.startup_progress.starting")
|
||||
) {
|
||||
return;
|
||||
@@ -163,13 +172,19 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
? {
|
||||
text: { translationKey: "ui.startup_progress.details" },
|
||||
icon: mdiInformationOutline,
|
||||
keepOpen: true,
|
||||
action: () => showStartupProgressDialog(this),
|
||||
action: () => this._showStartupDetails(),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Toasts always show above dialogs, so the toast is hidden while the details are open.
|
||||
private _showStartupDetails() {
|
||||
this._startupDetailsOpen = true;
|
||||
this._startupToastKey = undefined;
|
||||
showStartupProgressDialog(this);
|
||||
}
|
||||
|
||||
// Keeps the subscription, so the completion toast still reflects late failures.
|
||||
private _hideStartupProgress() {
|
||||
this._startupProgressVisible = false;
|
||||
@@ -193,6 +208,9 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
);
|
||||
this._hideStartupProgress();
|
||||
this._unsubscribeBootstrapProgress();
|
||||
if (this._startupDetailsOpen) {
|
||||
return;
|
||||
}
|
||||
const issues = failed.length;
|
||||
showToast(this, {
|
||||
id: SERVER_STARTUP_TOAST_ID,
|
||||
@@ -205,7 +223,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
action: this.hass!.user?.is_admin
|
||||
? {
|
||||
text: this.hass!.localize("ui.notification_toast.details"),
|
||||
action: () => showStartupProgressDialog(this),
|
||||
action: () => this._showStartupDetails(),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
Loaded 100 of 115 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user