mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-15 04:09:25 +00:00
Compare commits
127 Commits
20240809.0
...
card_edito
Author | SHA1 | Date | |
---|---|---|---|
![]() |
76380c189b | ||
![]() |
c8b7f373c3 | ||
![]() |
4f2652abd2 | ||
![]() |
6d8b7f6995 | ||
![]() |
bbf8a8e3e7 | ||
![]() |
14308c9057 | ||
![]() |
b87f44ff74 | ||
![]() |
36540aa8fb | ||
![]() |
bde2fd8202 | ||
![]() |
e5327c0903 | ||
![]() |
1a0ca1b78f | ||
![]() |
ed141b1d12 | ||
![]() |
5a7a71c551 | ||
![]() |
f09e0d187b | ||
![]() |
7f6325fa5e | ||
![]() |
de292a8143 | ||
![]() |
84b2005844 | ||
![]() |
0d93432a2c | ||
![]() |
8bc9927ee2 | ||
![]() |
484bed4dab | ||
![]() |
3d7e243707 | ||
![]() |
f8a432c89e | ||
![]() |
d484b2f63d | ||
![]() |
30d9186031 | ||
![]() |
cd74367acc | ||
![]() |
618cd9d9e5 | ||
![]() |
0ff2f1bf75 | ||
![]() |
d28f1f07e7 | ||
![]() |
6aa5bc2d8b | ||
![]() |
76fc0c7ab1 | ||
![]() |
7aa7019386 | ||
![]() |
b69f0964c9 | ||
![]() |
2f9b6d000b | ||
![]() |
94f186c436 | ||
![]() |
449f858ac8 | ||
![]() |
91a2f2cf24 | ||
![]() |
2c975d4f41 | ||
![]() |
ab534933fc | ||
![]() |
e353aaa339 | ||
![]() |
020904f8f6 | ||
![]() |
fa8b3f006d | ||
![]() |
d9ce20992c | ||
![]() |
a09f44dcd2 | ||
![]() |
c709059c00 | ||
![]() |
5613df1d01 | ||
![]() |
d8013a4db9 | ||
![]() |
216dbc4d41 | ||
![]() |
c40751dadd | ||
![]() |
f58d3ad670 | ||
![]() |
682f5345cc | ||
![]() |
a69771c1f8 | ||
![]() |
22de449dda | ||
![]() |
05a27b9399 | ||
![]() |
32083ea13d | ||
![]() |
18210f35b5 | ||
![]() |
362a6f46fe | ||
![]() |
1c9d411d3a | ||
![]() |
6d84523456 | ||
![]() |
2a18706a13 | ||
![]() |
87b58b0bbd | ||
![]() |
3ebb268b57 | ||
![]() |
2df097cd1b | ||
![]() |
8349e47c17 | ||
![]() |
4913932c97 | ||
![]() |
19f057a51b | ||
![]() |
c556742ff4 | ||
![]() |
8b5f731d0c | ||
![]() |
9568677926 | ||
![]() |
93ee5de1b4 | ||
![]() |
2f68ee0efc | ||
![]() |
5a229e3c88 | ||
![]() |
7c5f947865 | ||
![]() |
e9cbd54979 | ||
![]() |
cf55824899 | ||
![]() |
395586ddeb | ||
![]() |
9c48dbf232 | ||
![]() |
00eb820e36 | ||
![]() |
6b99cda982 | ||
![]() |
9bde0e876d | ||
![]() |
9482fcb04b | ||
![]() |
883ad58f52 | ||
![]() |
11ace6002a | ||
![]() |
c416daeb92 | ||
![]() |
061521a979 | ||
![]() |
d3f73baa36 | ||
![]() |
3037bf494c | ||
![]() |
b4dd953128 | ||
![]() |
430a28f350 | ||
![]() |
0eacf3fdac | ||
![]() |
7f9bf69a08 | ||
![]() |
32cca9e30c | ||
![]() |
d7d62307b8 | ||
![]() |
12bfa5dab2 | ||
![]() |
c0a728bc66 | ||
![]() |
19e8667349 | ||
![]() |
f3688b95d4 | ||
![]() |
01f692f05c | ||
![]() |
d652f6382d | ||
![]() |
c0f96d9473 | ||
![]() |
f1a2af24b3 | ||
![]() |
8501098bd1 | ||
![]() |
a235f76985 | ||
![]() |
968c0de141 | ||
![]() |
77d8aff1f4 | ||
![]() |
5e486d9cf0 | ||
![]() |
f730761b3f | ||
![]() |
46fc9c1a33 | ||
![]() |
8ed68bf295 | ||
![]() |
5622180d42 | ||
![]() |
ef1f9b371d | ||
![]() |
0b79684cf1 | ||
![]() |
bc68d8df11 | ||
![]() |
ebbade2fb7 | ||
![]() |
2b5f778f2e | ||
![]() |
91fc2383cb | ||
![]() |
1080a8c961 | ||
![]() |
6144049f8c | ||
![]() |
4ad3ad6e93 | ||
![]() |
16e84296da | ||
![]() |
3e1ea8d236 | ||
![]() |
8c9996fc81 | ||
![]() |
336b5fb547 | ||
![]() |
3f0f3affb6 | ||
![]() |
6754b8893b | ||
![]() |
6ec4323c76 | ||
![]() |
20408392d2 | ||
![]() |
b030a5d1f0 |
4
.github/workflows/ci.yaml
vendored
4
.github/workflows/ci.yaml
vendored
@@ -89,7 +89,7 @@ jobs:
|
||||
env:
|
||||
IS_TEST: "true"
|
||||
- name: Upload bundle stats
|
||||
uses: actions/upload-artifact@v4.3.5
|
||||
uses: actions/upload-artifact@v4.4.0
|
||||
with:
|
||||
name: frontend-bundle-stats
|
||||
path: build/stats/*.json
|
||||
@@ -113,7 +113,7 @@ jobs:
|
||||
env:
|
||||
IS_TEST: "true"
|
||||
- name: Upload bundle stats
|
||||
uses: actions/upload-artifact@v4.3.5
|
||||
uses: actions/upload-artifact@v4.4.0
|
||||
with:
|
||||
name: supervisor-bundle-stats
|
||||
path: build/stats/*.json
|
||||
|
4
.github/workflows/nightly.yaml
vendored
4
.github/workflows/nightly.yaml
vendored
@@ -57,14 +57,14 @@ jobs:
|
||||
run: tar -czvf translations.tar.gz translations
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4.3.5
|
||||
uses: actions/upload-artifact@v4.4.0
|
||||
with:
|
||||
name: wheels
|
||||
path: dist/home_assistant_frontend*.whl
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload translations
|
||||
uses: actions/upload-artifact@v4.3.5
|
||||
uses: actions/upload-artifact@v4.4.0
|
||||
with:
|
||||
name: translations
|
||||
path: translations.tar.gz
|
||||
|
2
.github/workflows/relative-ci.yaml
vendored
2
.github/workflows/relative-ci.yaml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Send bundle stats and build information to RelativeCI
|
||||
uses: relative-ci/agent-action@v2.1.11
|
||||
uses: relative-ci/agent-action@v2.1.12
|
||||
with:
|
||||
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
||||
token: ${{ github.token }}
|
||||
|
@@ -1,16 +1,7 @@
|
||||
diff --git a/modular/sortable.core.esm.js b/modular/sortable.core.esm.js
|
||||
index 93ba17509e2e8583ab241fea6845fbe714c584a2..de0651ddb5dced30d36f7d764da0dd0b441f523f 100644
|
||||
index 8b5e49b011713c8859c669069fbe85ce53974e1d..6a0afc92787157b8a31c38cc5f67dfa526090a00 100644
|
||||
--- a/modular/sortable.core.esm.js
|
||||
+++ b/modular/sortable.core.esm.js
|
||||
@@ -1461,7 +1461,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
}
|
||||
target = parent; // store last element
|
||||
}
|
||||
- /* jshint boss:true */ while (parent = parent.parentNode);
|
||||
+ /* jshint boss:true */ while (parent = parent.parentNode || parent.getRootNode().host);
|
||||
}
|
||||
_unhideGhostForTarget();
|
||||
}
|
||||
@@ -1781,11 +1781,16 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
}
|
||||
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
|
||||
@@ -33,7 +24,7 @@ index 93ba17509e2e8583ab241fea6845fbe714c584a2..de0651ddb5dced30d36f7d764da0dd0b
|
||||
}
|
||||
parentEl = el; // actualization
|
||||
|
||||
@@ -1802,7 +1807,13 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
@@ -1802,7 +1807,12 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
targetRect = getRect(target);
|
||||
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
|
||||
capture();
|
||||
@@ -44,11 +35,10 @@ index 93ba17509e2e8583ab241fea6845fbe714c584a2..de0651ddb5dced30d36f7d764da0dd0b
|
||||
+ catch(err) {
|
||||
+ return completed(false);
|
||||
+ }
|
||||
+
|
||||
parentEl = el; // actualization
|
||||
|
||||
changed();
|
||||
@@ -1849,12 +1860,17 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
@@ -1849,10 +1859,15 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
||||
_silent = true;
|
||||
setTimeout(_unsilent, 30);
|
||||
capture();
|
||||
@@ -56,8 +46,6 @@ index 93ba17509e2e8583ab241fea6845fbe714c584a2..de0651ddb5dced30d36f7d764da0dd0b
|
||||
- el.appendChild(dragEl);
|
||||
- } else {
|
||||
- target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
|
||||
- }
|
||||
|
||||
+ try {
|
||||
+ if (after && !nextSibling) {
|
||||
+ el.appendChild(dragEl);
|
||||
@@ -67,7 +55,6 @@ index 93ba17509e2e8583ab241fea6845fbe714c584a2..de0651ddb5dced30d36f7d764da0dd0b
|
||||
+ }
|
||||
+ catch(err) {
|
||||
+ return completed(false);
|
||||
+ }
|
||||
}
|
||||
|
||||
// Undo chrome's scroll adjustment (has no effect on other browsers)
|
||||
if (scrolledPastTop) {
|
||||
scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
|
File diff suppressed because one or more lines are too long
@@ -6,4 +6,4 @@ enableGlobalCache: false
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
yarnPath: .yarn/releases/yarn-4.4.0.cjs
|
||||
yarnPath: .yarn/releases/yarn-4.4.1.cjs
|
||||
|
@@ -15,23 +15,29 @@ const brotliOptions = {
|
||||
};
|
||||
const zopfliOptions = { threshold: 150 };
|
||||
|
||||
const compressDistBrotli = (rootDir, modernDir) =>
|
||||
const compressDistBrotli = (rootDir, modernDir, compressServiceWorker = true) =>
|
||||
gulp
|
||||
.src([`${modernDir}/**/${filesGlob}`, `${rootDir}/sw-modern.js`], {
|
||||
base: rootDir,
|
||||
})
|
||||
.src(
|
||||
[
|
||||
`${modernDir}/**/${filesGlob}`,
|
||||
compressServiceWorker ? `${rootDir}/sw-modern.js` : undefined,
|
||||
].filter(Boolean),
|
||||
{
|
||||
base: rootDir,
|
||||
}
|
||||
)
|
||||
.pipe(brotli(brotliOptions))
|
||||
.pipe(gulp.dest(rootDir));
|
||||
|
||||
const compressDistZopfli = (rootDir, modernDir) =>
|
||||
const compressDistZopfli = (rootDir, modernDir, compressModern = false) =>
|
||||
gulp
|
||||
.src(
|
||||
[
|
||||
`${rootDir}/**/${filesGlob}`,
|
||||
`!${modernDir}/**/${filesGlob}`,
|
||||
compressModern ? undefined : `!${modernDir}/**/${filesGlob}`,
|
||||
`!${rootDir}/{sw-modern,service_worker}.js`,
|
||||
`${rootDir}/{authorize,onboarding}.html`,
|
||||
],
|
||||
].filter(Boolean),
|
||||
{ base: rootDir }
|
||||
)
|
||||
.pipe(zopfli(zopfliOptions))
|
||||
@@ -40,12 +46,20 @@ const compressDistZopfli = (rootDir, modernDir) =>
|
||||
const compressAppBrotli = () =>
|
||||
compressDistBrotli(paths.app_output_root, paths.app_output_latest);
|
||||
const compressHassioBrotli = () =>
|
||||
compressDistBrotli(paths.hassio_output_root, paths.hassio_output_latest);
|
||||
compressDistBrotli(
|
||||
paths.hassio_output_root,
|
||||
paths.hassio_output_latest,
|
||||
false
|
||||
);
|
||||
|
||||
const compressAppZopfli = () =>
|
||||
compressDistZopfli(paths.app_output_root, paths.app_output_latest);
|
||||
const compressHassioZopfli = () =>
|
||||
compressDistZopfli(paths.hassio_output_root, paths.hassio_output_latest);
|
||||
compressDistZopfli(
|
||||
paths.hassio_output_root,
|
||||
paths.hassio_output_latest,
|
||||
true
|
||||
);
|
||||
|
||||
gulp.task("compress-app", gulp.parallel(compressAppBrotli, compressAppZopfli));
|
||||
gulp.task(
|
||||
|
@@ -1,35 +1,76 @@
|
||||
// Tasks to generate entry HTML
|
||||
|
||||
import { getUserAgentRegex } from "browserslist-useragent-regexp";
|
||||
import {
|
||||
applyVersionsToRegexes,
|
||||
compileRegex,
|
||||
getPreUserAgentRegexes,
|
||||
} from "browserslist-useragent-regexp";
|
||||
import fs from "fs-extra";
|
||||
import gulp from "gulp";
|
||||
import { minify } from "html-minifier-terser";
|
||||
import template from "lodash.template";
|
||||
import path from "path";
|
||||
import { dirname, extname, resolve } from "node:path";
|
||||
import { htmlMinifierOptions, terserOptions } from "../bundle.cjs";
|
||||
import env from "../env.cjs";
|
||||
import paths from "../paths.cjs";
|
||||
|
||||
// macOS companion app has no way to obtain the Safari version used by WKWebView,
|
||||
// and it is not in the default user agent string. So we add an additional regex
|
||||
// to serve modern based on a minimum macOS version. We take the minimum Safari
|
||||
// major version from browserslist and manually map that to a supported macOS
|
||||
// version. Note this assumes the user has kept Safari updated.
|
||||
const HA_MACOS_REGEX =
|
||||
/Home Assistant\/[\d.]+ \(.+; macOS (\d+)\.(\d+)(?:\.(\d+))?\)/;
|
||||
const SAFARI_TO_MACOS = {
|
||||
15: [10, 15, 0],
|
||||
16: [11, 0, 0],
|
||||
17: [12, 0, 0],
|
||||
18: [13, 0, 0],
|
||||
};
|
||||
|
||||
const getCommonTemplateVars = () => {
|
||||
const browserRegexes = getPreUserAgentRegexes({
|
||||
env: "modern",
|
||||
allowHigherVersions: true,
|
||||
mobileToDesktop: true,
|
||||
throwOnMissing: true,
|
||||
});
|
||||
const minSafariVersion = browserRegexes.find(
|
||||
(regex) => regex.family === "safari"
|
||||
)?.matchedVersions[0][0];
|
||||
const minMacOSVersion = SAFARI_TO_MACOS[minSafariVersion];
|
||||
if (!minMacOSVersion) {
|
||||
throw Error(
|
||||
`Could not find minimum MacOS version for Safari ${minSafariVersion}.`
|
||||
);
|
||||
}
|
||||
const haMacOSRegex = applyVersionsToRegexes(
|
||||
[
|
||||
{
|
||||
family: "ha_macos",
|
||||
regex: HA_MACOS_REGEX,
|
||||
matchedVersions: [minMacOSVersion],
|
||||
requestVersions: [minMacOSVersion],
|
||||
},
|
||||
],
|
||||
{ ignorePatch: true, allowHigherVersions: true }
|
||||
);
|
||||
return {
|
||||
useRollup: env.useRollup(),
|
||||
useWDS: env.useWDS(),
|
||||
modernRegex: compileRegex(browserRegexes.concat(haMacOSRegex)).toString(),
|
||||
};
|
||||
};
|
||||
|
||||
const renderTemplate = (templateFile, data = {}) => {
|
||||
const compiled = template(
|
||||
fs.readFileSync(templateFile, { encoding: "utf-8" })
|
||||
);
|
||||
return compiled({
|
||||
...data,
|
||||
useRollup: env.useRollup(),
|
||||
useWDS: env.useWDS(),
|
||||
modernRegex: getUserAgentRegex({
|
||||
env: "modern",
|
||||
allowHigherVersions: true,
|
||||
mobileToDesktop: true,
|
||||
throwOnMissing: true,
|
||||
}).toString(),
|
||||
// Resolve any child/nested templates relative to the parent and pass the same data
|
||||
renderTemplate: (childTemplate) =>
|
||||
renderTemplate(
|
||||
path.resolve(path.dirname(templateFile), childTemplate),
|
||||
data
|
||||
),
|
||||
renderTemplate(resolve(dirname(templateFile), childTemplate), data),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -63,10 +104,12 @@ const genPagesDevTask =
|
||||
publicRoot = ""
|
||||
) =>
|
||||
async () => {
|
||||
const commonVars = getCommonTemplateVars();
|
||||
for (const [page, entries] of Object.entries(pageEntries)) {
|
||||
const content = renderTemplate(
|
||||
path.resolve(inputRoot, inputSub, `${page}.template`),
|
||||
resolve(inputRoot, inputSub, `${page}.template`),
|
||||
{
|
||||
...commonVars,
|
||||
latestEntryJS: entries.map((entry) =>
|
||||
useWDS
|
||||
? `http://localhost:8000/src/entrypoints/${entry}.ts`
|
||||
@@ -81,7 +124,7 @@ const genPagesDevTask =
|
||||
es5CustomPanelJS: `${publicRoot}/frontend_es5/custom-panel.js`,
|
||||
}
|
||||
);
|
||||
fs.outputFileSync(path.resolve(outputRoot, page), content);
|
||||
fs.outputFileSync(resolve(outputRoot, page), content);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -98,16 +141,18 @@ const genPagesProdTask =
|
||||
) =>
|
||||
async () => {
|
||||
const latestManifest = fs.readJsonSync(
|
||||
path.resolve(outputLatest, "manifest.json")
|
||||
resolve(outputLatest, "manifest.json")
|
||||
);
|
||||
const es5Manifest = outputES5
|
||||
? fs.readJsonSync(path.resolve(outputES5, "manifest.json"))
|
||||
? fs.readJsonSync(resolve(outputES5, "manifest.json"))
|
||||
: {};
|
||||
const commonVars = getCommonTemplateVars();
|
||||
const minifiedHTML = [];
|
||||
for (const [page, entries] of Object.entries(pageEntries)) {
|
||||
const content = renderTemplate(
|
||||
path.resolve(inputRoot, inputSub, `${page}.template`),
|
||||
resolve(inputRoot, inputSub, `${page}.template`),
|
||||
{
|
||||
...commonVars,
|
||||
latestEntryJS: entries.map((entry) => latestManifest[`${entry}.js`]),
|
||||
es5EntryJS: entries.map((entry) => es5Manifest[`${entry}.js`]),
|
||||
latestCustomPanelJS: latestManifest["custom-panel.js"],
|
||||
@@ -115,8 +160,8 @@ const genPagesProdTask =
|
||||
}
|
||||
);
|
||||
minifiedHTML.push(
|
||||
minifyHtml(content, path.extname(page)).then((minified) =>
|
||||
fs.outputFileSync(path.resolve(outputRoot, page), minified)
|
||||
minifyHtml(content, extname(page)).then((minified) =>
|
||||
fs.outputFileSync(resolve(outputRoot, page), minified)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -532,15 +532,6 @@ export default {
|
||||
last_changed: "2018-07-19T10:44:46.200946+00:00",
|
||||
last_updated: "2018-07-19T10:44:46.200946+00:00",
|
||||
},
|
||||
"mailbox.demomailbox": {
|
||||
entity_id: "mailbox.demomailbox",
|
||||
state: "10",
|
||||
attributes: {
|
||||
friendly_name: "DemoMailbox",
|
||||
},
|
||||
last_changed: "2018-07-19T10:45:16.555210+00:00",
|
||||
last_updated: "2018-07-19T10:45:16.555210+00:00",
|
||||
},
|
||||
"input_select.living_room_preset": {
|
||||
entity_id: "input_select.living_room_preset",
|
||||
state: "Visitors",
|
||||
|
@@ -11,7 +11,6 @@ import { mockHassioSupervisor } from "../../../../demo/src/stubs/hassio_supervis
|
||||
import type { ConditionWithShorthand } from "../../../../src/data/automation";
|
||||
import "../../../../src/panels/config/automation/condition/ha-automation-condition";
|
||||
import { HaDeviceCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-device";
|
||||
import { HaLogicalCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-logical";
|
||||
import HaNumericStateCondition from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-numeric_state";
|
||||
import { HaStateCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-state";
|
||||
import { HaSunCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-sun";
|
||||
@@ -19,62 +18,67 @@ import { HaTemplateCondition } from "../../../../src/panels/config/automation/co
|
||||
import { HaTimeCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-time";
|
||||
import { HaTriggerCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-trigger";
|
||||
import { HaZoneCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-zone";
|
||||
import { HaAndCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-and";
|
||||
import { HaOrCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-or";
|
||||
import { HaNotCondition } from "../../../../src/panels/config/automation/condition/types/ha-automation-condition-not";
|
||||
|
||||
const SCHEMAS: { name: string; conditions: ConditionWithShorthand[] }[] = [
|
||||
{
|
||||
name: "State",
|
||||
conditions: [{ condition: "state", ...HaStateCondition.defaultConfig }],
|
||||
conditions: [{ ...HaStateCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Numeric State",
|
||||
conditions: [
|
||||
{ condition: "numeric_state", ...HaNumericStateCondition.defaultConfig },
|
||||
],
|
||||
conditions: [{ ...HaNumericStateCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Sun",
|
||||
conditions: [{ condition: "sun", ...HaSunCondition.defaultConfig }],
|
||||
conditions: [{ ...HaSunCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Zone",
|
||||
conditions: [{ condition: "zone", ...HaZoneCondition.defaultConfig }],
|
||||
conditions: [{ ...HaZoneCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Time",
|
||||
conditions: [{ condition: "time", ...HaTimeCondition.defaultConfig }],
|
||||
conditions: [{ ...HaTimeCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Template",
|
||||
conditions: [
|
||||
{ condition: "template", ...HaTemplateCondition.defaultConfig },
|
||||
],
|
||||
conditions: [{ ...HaTemplateCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Device",
|
||||
conditions: [{ condition: "device", ...HaDeviceCondition.defaultConfig }],
|
||||
conditions: [{ ...HaDeviceCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "And",
|
||||
conditions: [{ condition: "and", ...HaLogicalCondition.defaultConfig }],
|
||||
conditions: [{ ...HaAndCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Or",
|
||||
conditions: [{ condition: "or", ...HaLogicalCondition.defaultConfig }],
|
||||
conditions: [{ ...HaOrCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Not",
|
||||
conditions: [{ condition: "not", ...HaLogicalCondition.defaultConfig }],
|
||||
conditions: [{ ...HaNotCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Trigger",
|
||||
conditions: [{ condition: "trigger", ...HaTriggerCondition.defaultConfig }],
|
||||
conditions: [{ ...HaTriggerCondition.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Shorthand",
|
||||
conditions: [
|
||||
{ and: HaLogicalCondition.defaultConfig.conditions },
|
||||
{ or: HaLogicalCondition.defaultConfig.conditions },
|
||||
{ not: HaLogicalCondition.defaultConfig.conditions },
|
||||
{
|
||||
...HaAndCondition.defaultConfig,
|
||||
},
|
||||
{
|
||||
...HaOrCondition.defaultConfig,
|
||||
},
|
||||
{
|
||||
...HaNotCondition.defaultConfig,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
@@ -30,55 +30,48 @@ import { HaConversationTrigger } from "../../../../src/panels/config/automation/
|
||||
const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
||||
{
|
||||
name: "State",
|
||||
triggers: [{ platform: "state", ...HaStateTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaStateTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "MQTT",
|
||||
triggers: [{ platform: "mqtt", ...HaMQTTTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaMQTTTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "GeoLocation",
|
||||
triggers: [
|
||||
{ platform: "geo_location", ...HaGeolocationTrigger.defaultConfig },
|
||||
],
|
||||
triggers: [{ ...HaGeolocationTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Home Assistant",
|
||||
triggers: [{ platform: "homeassistant", ...HaHassTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaHassTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Numeric State",
|
||||
triggers: [
|
||||
{ platform: "numeric_state", ...HaNumericStateTrigger.defaultConfig },
|
||||
],
|
||||
triggers: [{ ...HaNumericStateTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Sun",
|
||||
triggers: [{ platform: "sun", ...HaSunTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaSunTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Time Pattern",
|
||||
triggers: [
|
||||
{ platform: "time_pattern", ...HaTimePatternTrigger.defaultConfig },
|
||||
],
|
||||
triggers: [{ ...HaTimePatternTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Webhook",
|
||||
triggers: [{ platform: "webhook", ...HaWebhookTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaWebhookTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Persistent Notification",
|
||||
triggers: [
|
||||
{
|
||||
platform: "persistent_notification",
|
||||
...HaPersistentNotificationTrigger.defaultConfig,
|
||||
},
|
||||
],
|
||||
@@ -86,37 +79,37 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
||||
|
||||
{
|
||||
name: "Zone",
|
||||
triggers: [{ platform: "zone", ...HaZoneTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaZoneTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Tag",
|
||||
triggers: [{ platform: "tag", ...HaTagTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaTagTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Time",
|
||||
triggers: [{ platform: "time", ...HaTimeTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaTimeTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Template",
|
||||
triggers: [{ platform: "template", ...HaTemplateTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaTemplateTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Event",
|
||||
triggers: [{ platform: "event", ...HaEventTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaEventTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Device Trigger",
|
||||
triggers: [{ platform: "device", ...HaDeviceTrigger.defaultConfig }],
|
||||
triggers: [{ ...HaDeviceTrigger.defaultConfig }],
|
||||
},
|
||||
{
|
||||
name: "Sentence",
|
||||
triggers: [
|
||||
{ platform: "conversation", ...HaConversationTrigger.defaultConfig },
|
||||
{ ...HaConversationTrigger.defaultConfig },
|
||||
{
|
||||
platform: "conversation",
|
||||
command: ["Turn on the lights", "Turn the lights on"],
|
||||
|
@@ -64,6 +64,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
{
|
||||
area_id: "backyard",
|
||||
@@ -86,6 +87,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
{
|
||||
area_id: null,
|
||||
@@ -108,6 +110,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
];
|
||||
|
||||
|
@@ -64,6 +64,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
{
|
||||
area_id: "backyard",
|
||||
@@ -86,6 +87,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
{
|
||||
area_id: null,
|
||||
@@ -108,6 +110,7 @@ const DEVICES: DeviceRegistryEntry[] = [
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
];
|
||||
|
||||
|
3
gallery/src/pages/misc/ha-markdown.markdown
Normal file
3
gallery/src/pages/misc/ha-markdown.markdown
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Markdown
|
||||
---
|
93
gallery/src/pages/misc/ha-markdown.ts
Normal file
93
gallery/src/pages/misc/ha-markdown.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { css, html, LitElement } from "lit";
|
||||
import "../../../../src/components/ha-card";
|
||||
import "../../../../src/components/ha-markdown";
|
||||
|
||||
import { customElement } from "lit/decorators";
|
||||
|
||||
interface MarkdownContent {
|
||||
content: string;
|
||||
breaks: boolean;
|
||||
allowSvg: boolean;
|
||||
lazyImages: boolean;
|
||||
}
|
||||
|
||||
const mdContentwithDefaults = (md: Partial<MarkdownContent>) =>
|
||||
({
|
||||
breaks: false,
|
||||
allowSvg: false,
|
||||
lazyImages: false,
|
||||
...md,
|
||||
}) as MarkdownContent;
|
||||
|
||||
const generateContent = (md) => `
|
||||
\`\`\`json
|
||||
${JSON.stringify({ ...md, content: undefined })}
|
||||
\`\`\`
|
||||
|
||||
---
|
||||
|
||||
${md.content}
|
||||
`;
|
||||
|
||||
const markdownContents: MarkdownContent[] = [
|
||||
mdContentwithDefaults({
|
||||
content: "_Hello_ **there** 👋, ~~nice~~ of you ||to|| show up.",
|
||||
}),
|
||||
...[true, false].map((breaks) =>
|
||||
mdContentwithDefaults({
|
||||
breaks,
|
||||
content: `
|
||||

|
||||

|
||||
|
||||
> [!TIP]
|
||||
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dictum quis ante eu eleifend. Integer sed [consectetur est, nec elementum magna](#). Fusce lobortis lectus ac rutrum tincidunt. Quisque suscipit gravida ante, in convallis risus vulputate non.
|
||||
|
||||
key | description
|
||||
-- | --
|
||||
lorem | ipsum
|
||||
|
||||
- list item 1
|
||||
- list item 2
|
||||
|
||||
|
||||
`,
|
||||
})
|
||||
),
|
||||
];
|
||||
|
||||
@customElement("demo-misc-ha-markdown")
|
||||
export class DemoMiscMarkdown extends LitElement {
|
||||
protected render() {
|
||||
return html`
|
||||
<div class="container">
|
||||
${markdownContents.map(
|
||||
(md) =>
|
||||
html`<ha-card>
|
||||
<ha-markdown
|
||||
.content=${generateContent(md)}
|
||||
.breaks=${md.breaks}
|
||||
.allowSvg=${md.allowSvg}
|
||||
.lazyImages=${md.lazyImages}
|
||||
></ha-markdown>
|
||||
</ha-card>`
|
||||
)}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles() {
|
||||
return css`
|
||||
ha-card {
|
||||
margin: 12px;
|
||||
padding: 12px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"demo-misc-ha-markdown": DemoMiscMarkdown;
|
||||
}
|
||||
}
|
@@ -232,6 +232,7 @@ const createDeviceRegistryEntries = (
|
||||
labels: [],
|
||||
created_at: 0,
|
||||
modified_at: 0,
|
||||
primary_config_entry: null,
|
||||
},
|
||||
];
|
||||
|
||||
|
56
package.json
56
package.json
@@ -25,15 +25,15 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.25.0",
|
||||
"@babel/runtime": "7.25.6",
|
||||
"@braintree/sanitize-url": "7.1.0",
|
||||
"@codemirror/autocomplete": "6.18.0",
|
||||
"@codemirror/commands": "6.6.0",
|
||||
"@codemirror/commands": "6.6.1",
|
||||
"@codemirror/language": "6.10.2",
|
||||
"@codemirror/legacy-modes": "6.4.0",
|
||||
"@codemirror/legacy-modes": "6.4.1",
|
||||
"@codemirror/search": "6.5.6",
|
||||
"@codemirror/state": "6.4.1",
|
||||
"@codemirror/view": "6.30.0",
|
||||
"@codemirror/view": "6.33.0",
|
||||
"@egjs/hammerjs": "2.0.17",
|
||||
"@formatjs/intl-datetimeformat": "6.12.5",
|
||||
"@formatjs/intl-displaynames": "6.6.8",
|
||||
@@ -49,7 +49,7 @@
|
||||
"@fullcalendar/list": "6.1.15",
|
||||
"@fullcalendar/luxon3": "6.1.15",
|
||||
"@fullcalendar/timegrid": "6.1.15",
|
||||
"@lezer/highlight": "1.2.0",
|
||||
"@lezer/highlight": "1.2.1",
|
||||
"@lit-labs/context": "0.4.1",
|
||||
"@lit-labs/motion": "1.0.7",
|
||||
"@lit-labs/observers": "2.0.2",
|
||||
@@ -80,7 +80,7 @@
|
||||
"@material/mwc-top-app-bar": "0.27.0",
|
||||
"@material/mwc-top-app-bar-fixed": "0.27.0",
|
||||
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
|
||||
"@material/web": "2.0.0",
|
||||
"@material/web": "2.1.0",
|
||||
"@mdi/js": "7.4.47",
|
||||
"@mdi/svg": "7.4.47",
|
||||
"@polymer/paper-item": "3.0.1",
|
||||
@@ -88,8 +88,8 @@
|
||||
"@polymer/paper-tabs": "3.1.0",
|
||||
"@polymer/polymer": "3.5.1",
|
||||
"@thomasloven/round-slider": "0.6.0",
|
||||
"@vaadin/combo-box": "24.4.5",
|
||||
"@vaadin/vaadin-themable-mixin": "24.4.5",
|
||||
"@vaadin/combo-box": "24.4.7",
|
||||
"@vaadin/vaadin-themable-mixin": "24.4.7",
|
||||
"@vibrant/color": "3.2.1-alpha.1",
|
||||
"@vibrant/core": "3.2.1-alpha.1",
|
||||
"@vibrant/quantizer-mmcq": "3.2.1-alpha.1",
|
||||
@@ -97,10 +97,10 @@
|
||||
"@webcomponents/scoped-custom-element-registry": "0.0.9",
|
||||
"@webcomponents/webcomponentsjs": "2.8.0",
|
||||
"app-datepicker": "5.1.1",
|
||||
"chart.js": "4.4.3",
|
||||
"chart.js": "4.4.4",
|
||||
"color-name": "2.0.0",
|
||||
"comlink": "4.4.1",
|
||||
"core-js": "3.38.0",
|
||||
"core-js": "3.38.1",
|
||||
"cropperjs": "1.6.2",
|
||||
"date-fns": "3.6.0",
|
||||
"date-fns-tz": "3.1.3",
|
||||
@@ -118,7 +118,7 @@
|
||||
"leaflet-draw": "1.0.4",
|
||||
"lit": "2.8.0",
|
||||
"luxon": "3.5.0",
|
||||
"marked": "13.0.3",
|
||||
"marked": "14.1.1",
|
||||
"memoize-one": "6.0.0",
|
||||
"node-vibrant": "3.2.1-alpha.1",
|
||||
"proxy-polyfill": "0.3.2",
|
||||
@@ -127,10 +127,10 @@
|
||||
"qrcode": "1.5.4",
|
||||
"roboto-fontface": "0.10.0",
|
||||
"rrule": "2.8.1",
|
||||
"sortablejs": "1.15.2",
|
||||
"sortablejs": "1.15.3",
|
||||
"stacktrace-js": "2.0.2",
|
||||
"superstruct": "2.0.2",
|
||||
"tinykeys": "2.1.0",
|
||||
"tinykeys": "3.0.0",
|
||||
"tsparticles-engine": "2.12.0",
|
||||
"tsparticles-preset-links": "2.12.0",
|
||||
"ua-parser-js": "1.0.38",
|
||||
@@ -152,15 +152,15 @@
|
||||
"@babel/core": "7.25.2",
|
||||
"@babel/helper-define-polyfill-provider": "0.6.2",
|
||||
"@babel/plugin-proposal-decorators": "7.24.7",
|
||||
"@babel/plugin-transform-runtime": "7.24.7",
|
||||
"@babel/preset-env": "7.25.3",
|
||||
"@babel/plugin-transform-runtime": "7.25.4",
|
||||
"@babel/preset-env": "7.25.4",
|
||||
"@babel/preset-typescript": "7.24.7",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.14.0",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.15.0",
|
||||
"@koa/cors": "5.0.0",
|
||||
"@lokalise/node-api": "12.7.0",
|
||||
"@octokit/auth-oauth-device": "7.1.1",
|
||||
"@octokit/plugin-retry": "7.1.1",
|
||||
"@octokit/rest": "21.0.1",
|
||||
"@octokit/rest": "21.0.2",
|
||||
"@open-wc/dev-server-hmr": "0.1.4",
|
||||
"@rollup/plugin-babel": "6.0.4",
|
||||
"@rollup/plugin-commonjs": "26.0.1",
|
||||
@@ -168,7 +168,7 @@
|
||||
"@rollup/plugin-node-resolve": "15.2.3",
|
||||
"@rollup/plugin-replace": "5.0.7",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||
"@types/chromecast-caf-receiver": "6.0.16",
|
||||
"@types/chromecast-caf-receiver": "6.0.17",
|
||||
"@types/chromecast-caf-sender": "1.0.10",
|
||||
"@types/color-name": "1.1.4",
|
||||
"@types/glob": "8.1.0",
|
||||
@@ -198,12 +198,12 @@
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-airbnb-typescript": "18.0.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"eslint-import-resolver-webpack": "0.13.8",
|
||||
"eslint-plugin-import": "2.29.1",
|
||||
"eslint-import-resolver-webpack": "0.13.9",
|
||||
"eslint-plugin-import": "2.30.0",
|
||||
"eslint-plugin-lit": "1.14.0",
|
||||
"eslint-plugin-lit-a11y": "4.1.4",
|
||||
"eslint-plugin-unused-imports": "4.0.1",
|
||||
"eslint-plugin-wc": "2.1.0",
|
||||
"eslint-plugin-unused-imports": "4.1.3",
|
||||
"eslint-plugin-wc": "2.1.1",
|
||||
"fancy-log": "2.0.0",
|
||||
"fs-extra": "11.2.0",
|
||||
"glob": "11.0.0",
|
||||
@@ -213,10 +213,10 @@
|
||||
"gulp-rename": "2.0.0",
|
||||
"gulp-zopfli-green": "6.0.2",
|
||||
"html-minifier-terser": "7.2.0",
|
||||
"husky": "9.1.4",
|
||||
"husky": "9.1.5",
|
||||
"instant-mocha": "1.5.2",
|
||||
"jszip": "3.10.1",
|
||||
"lint-staged": "15.2.8",
|
||||
"lint-staged": "15.2.10",
|
||||
"lit-analyzer": "2.0.3",
|
||||
"lodash.merge": "4.6.2",
|
||||
"lodash.template": "4.5.0",
|
||||
@@ -239,9 +239,9 @@
|
||||
"transform-async-modules-webpack-plugin": "1.1.1",
|
||||
"ts-lit-plugin": "2.0.2",
|
||||
"typescript": "5.5.4",
|
||||
"webpack": "5.93.0",
|
||||
"webpack": "5.94.0",
|
||||
"webpack-cli": "5.1.4",
|
||||
"webpack-dev-server": "5.0.4",
|
||||
"webpack-dev-server": "5.1.0",
|
||||
"webpack-manifest-plugin": "5.0.0",
|
||||
"webpack-stats-plugin": "1.1.3",
|
||||
"webpackbar": "6.0.1",
|
||||
@@ -255,8 +255,8 @@
|
||||
"clean-css": "5.3.3",
|
||||
"@lit/reactive-element": "1.6.3",
|
||||
"@fullcalendar/daygrid": "6.1.15",
|
||||
"sortablejs@1.15.2": "patch:sortablejs@npm%3A1.15.2#~/.yarn/patches/sortablejs-npm-1.15.2-73347ae85a.patch",
|
||||
"sortablejs@1.15.3": "patch:sortablejs@npm%3A1.15.3#~/.yarn/patches/sortablejs-npm-1.15.3-3235a8f83b.patch",
|
||||
"leaflet-draw@1.0.4": "patch:leaflet-draw@npm%3A1.0.4#./.yarn/patches/leaflet-draw-npm-1.0.4-0ca0ebcf65.patch"
|
||||
},
|
||||
"packageManager": "yarn@4.4.0"
|
||||
"packageManager": "yarn@4.4.1"
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20240809.0"
|
||||
version = "20240909.1"
|
||||
license = {text = "Apache-2.0"}
|
||||
description = "The Home Assistant frontend"
|
||||
readme = "README.md"
|
||||
|
@@ -40,7 +40,6 @@ import {
|
||||
mdiImageFilterFrames,
|
||||
mdiLightbulb,
|
||||
mdiLightningBolt,
|
||||
mdiMailbox,
|
||||
mdiMapMarkerRadius,
|
||||
mdiMeterGas,
|
||||
mdiMicrophoneMessage,
|
||||
@@ -119,7 +118,6 @@ export const FIXED_DOMAIN_ICONS = {
|
||||
input_text: mdiFormTextbox,
|
||||
lawn_mower: mdiRobotMower,
|
||||
light: mdiLightbulb,
|
||||
mailbox: mdiMailbox,
|
||||
notify: mdiCommentAlert,
|
||||
number: mdiRayVertex,
|
||||
persistent_notification: mdiBell,
|
||||
|
@@ -71,8 +71,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
||||
if (
|
||||
attributes.device_class === "duration" &&
|
||||
attributes.unit_of_measurement &&
|
||||
UNIT_TO_MILLISECOND_CONVERT[attributes.unit_of_measurement] &&
|
||||
entity?.display_precision === undefined
|
||||
UNIT_TO_MILLISECOND_CONVERT[attributes.unit_of_measurement]
|
||||
) {
|
||||
try {
|
||||
return formatDuration(state, attributes.unit_of_measurement);
|
||||
|
@@ -26,7 +26,7 @@ export const FIXED_DOMAIN_STATES = {
|
||||
humidifier: ["on", "off"],
|
||||
input_boolean: ["on", "off"],
|
||||
input_button: [],
|
||||
lawn_mower: ["error", "paused", "mowing", "docked"],
|
||||
lawn_mower: ["error", "paused", "mowing", "returning", "docked"],
|
||||
light: ["on", "off"],
|
||||
lock: [
|
||||
"jammed",
|
||||
|
6
src/components/chart/click_is_touch.ts
Normal file
6
src/components/chart/click_is_touch.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { ChartEvent } from "chart.js";
|
||||
|
||||
export const clickIsTouch = (event: ChartEvent): boolean =>
|
||||
!(event.native instanceof MouseEvent) ||
|
||||
(event.native instanceof PointerEvent &&
|
||||
event.native.pointerType !== "mouse");
|
@@ -16,6 +16,7 @@ import {
|
||||
HaChartBase,
|
||||
MIN_TIME_BETWEEN_UPDATES,
|
||||
} from "./ha-chart-base";
|
||||
import { clickIsTouch } from "./click_is_touch";
|
||||
|
||||
const safeParseFloat = (value) => {
|
||||
const parsed = parseFloat(value);
|
||||
@@ -220,12 +221,7 @@ export class StateHistoryChartLine extends LitElement {
|
||||
// @ts-expect-error
|
||||
locale: numberFormatToLocale(this.hass.locale),
|
||||
onClick: (e: any) => {
|
||||
if (
|
||||
!this.clickForMoreInfo ||
|
||||
!(e.native instanceof MouseEvent) ||
|
||||
(e.native instanceof PointerEvent &&
|
||||
e.native.pointerType !== "mouse")
|
||||
) {
|
||||
if (!this.clickForMoreInfo || clickIsTouch(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,7 @@ import {
|
||||
} from "./ha-chart-base";
|
||||
import type { TimeLineData } from "./timeline-chart/const";
|
||||
import { computeTimelineColor } from "./timeline-chart/timeline-color";
|
||||
import { clickIsTouch } from "./click_is_touch";
|
||||
|
||||
@customElement("state-history-chart-timeline")
|
||||
export class StateHistoryChartTimeline extends LitElement {
|
||||
@@ -224,11 +225,7 @@ export class StateHistoryChartTimeline extends LitElement {
|
||||
// @ts-expect-error
|
||||
locale: numberFormatToLocale(this.hass.locale),
|
||||
onClick: (e: any) => {
|
||||
if (
|
||||
!this.clickForMoreInfo ||
|
||||
!(e.native instanceof MouseEvent) ||
|
||||
(e.native instanceof PointerEvent && e.native.pointerType !== "mouse")
|
||||
) {
|
||||
if (!this.clickForMoreInfo || clickIsTouch(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@ import type {
|
||||
ChartDatasetExtra,
|
||||
HaChartBase,
|
||||
} from "./ha-chart-base";
|
||||
import { clickIsTouch } from "./click_is_touch";
|
||||
|
||||
export const supportedStatTypeMap: Record<StatisticType, StatisticType> = {
|
||||
mean: "mean",
|
||||
@@ -278,11 +279,7 @@ export class StatisticsChart extends LitElement {
|
||||
// @ts-expect-error
|
||||
locale: numberFormatToLocale(this.hass.locale),
|
||||
onClick: (e: any) => {
|
||||
if (
|
||||
!this.clickForMoreInfo ||
|
||||
!(e.native instanceof MouseEvent) ||
|
||||
(e.native instanceof PointerEvent && e.native.pointerType !== "mouse")
|
||||
) {
|
||||
if (!this.clickForMoreInfo || clickIsTouch(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,6 @@ import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { stringCompare } from "../../common/string/compare";
|
||||
import { debounce } from "../../common/util/debounce";
|
||||
import { groupBy } from "../../common/util/group-by";
|
||||
import { nextRender } from "../../common/util/render-status";
|
||||
import { haStyleScrollbar } from "../../resources/styles";
|
||||
import { loadVirtualizer } from "../../resources/virtualizer";
|
||||
import { HomeAssistant } from "../../types";
|
||||
@@ -35,6 +34,7 @@ import "../ha-svg-icon";
|
||||
import "../search-input";
|
||||
import { filterData, sortData } from "./sort-filter";
|
||||
import { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { nextRender } from "../../common/util/render-status";
|
||||
|
||||
export interface RowClickedEvent {
|
||||
id: string;
|
||||
@@ -169,8 +169,6 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
@query("slot[name='header']") private _header!: HTMLSlotElement;
|
||||
|
||||
@state() private _items: DataTableRowData[] = [];
|
||||
|
||||
@state() private _collapsedGroups: string[] = [];
|
||||
|
||||
private _checkableRowsCount?: number;
|
||||
@@ -179,7 +177,9 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
private _sortColumns: SortableColumnContainer = {};
|
||||
|
||||
private curRequest = 0;
|
||||
private _curRequest = 0;
|
||||
|
||||
private _lastUpdate = 0;
|
||||
|
||||
// @ts-ignore
|
||||
@restoreScroll(".scroller") private _savedScrollPos?: number;
|
||||
@@ -206,9 +206,9 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
if (this._items.length) {
|
||||
if (this._filteredData.length) {
|
||||
// Force update of location of rows
|
||||
this._items = [...this._items];
|
||||
this._filteredData = [...this._filteredData];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,16 +291,13 @@ export class HaDataTable extends LitElement {
|
||||
properties.has("columns") ||
|
||||
properties.has("_filter") ||
|
||||
properties.has("sortColumn") ||
|
||||
properties.has("sortDirection") ||
|
||||
properties.has("groupColumn") ||
|
||||
properties.has("groupOrder") ||
|
||||
properties.has("_collapsedGroups")
|
||||
properties.has("sortDirection")
|
||||
) {
|
||||
this._sortFilterData();
|
||||
}
|
||||
|
||||
if (properties.has("selectable") || properties.has("hiddenColumns")) {
|
||||
this._items = [...this._items];
|
||||
this._filteredData = [...this._filteredData];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +464,15 @@ export class HaDataTable extends LitElement {
|
||||
scroller
|
||||
class="mdc-data-table__content scroller ha-scrollbar"
|
||||
@scroll=${this._saveScrollPos}
|
||||
.items=${this._items}
|
||||
.items=${this._groupData(
|
||||
this._filteredData,
|
||||
localize,
|
||||
this.appendRow,
|
||||
this.hasFab,
|
||||
this.groupColumn,
|
||||
this.groupOrder,
|
||||
this._collapsedGroups
|
||||
)}
|
||||
.keyFunction=${this._keyFunction}
|
||||
.renderItem=${renderRow}
|
||||
></lit-virtualizer>
|
||||
@@ -602,8 +607,13 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
private async _sortFilterData() {
|
||||
const startTime = new Date().getTime();
|
||||
this.curRequest++;
|
||||
const curRequest = this.curRequest;
|
||||
const timeBetweenUpdate = startTime - this._lastUpdate;
|
||||
const timeBetweenRequest = startTime - this._curRequest;
|
||||
this._curRequest = startTime;
|
||||
|
||||
const forceUpdate =
|
||||
!this._lastUpdate ||
|
||||
(timeBetweenUpdate > 500 && timeBetweenRequest < 500);
|
||||
|
||||
let filteredData = this.data;
|
||||
if (this._filter) {
|
||||
@@ -614,6 +624,10 @@ export class HaDataTable extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
if (!forceUpdate && this._curRequest !== startTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prom = this.sortColumn
|
||||
? sortData(
|
||||
filteredData,
|
||||
@@ -634,91 +648,103 @@ export class HaDataTable extends LitElement {
|
||||
setTimeout(resolve, 100 - elapsed);
|
||||
});
|
||||
}
|
||||
if (this.curRequest !== curRequest) {
|
||||
|
||||
if (!forceUpdate && this._curRequest !== startTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localize = this.localizeFunc || this.hass.localize;
|
||||
|
||||
if (this.appendRow || this.hasFab || this.groupColumn) {
|
||||
let items = [...data];
|
||||
|
||||
if (this.groupColumn) {
|
||||
const grouped = groupBy(items, (item) => item[this.groupColumn!]);
|
||||
if (grouped.undefined) {
|
||||
// make sure ungrouped items are at the bottom
|
||||
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined;
|
||||
delete grouped.undefined;
|
||||
}
|
||||
const sorted: {
|
||||
[key: string]: DataTableRowData[];
|
||||
} = Object.keys(grouped)
|
||||
.sort((a, b) => {
|
||||
const orderA = this.groupOrder?.indexOf(a) ?? -1;
|
||||
const orderB = this.groupOrder?.indexOf(b) ?? -1;
|
||||
if (orderA !== orderB) {
|
||||
if (orderA === -1) {
|
||||
return 1;
|
||||
}
|
||||
if (orderB === -1) {
|
||||
return -1;
|
||||
}
|
||||
return orderA - orderB;
|
||||
}
|
||||
return stringCompare(
|
||||
["", "-", "—"].includes(a) ? "zzz" : a,
|
||||
["", "-", "—"].includes(b) ? "zzz" : b,
|
||||
this.hass.locale.language
|
||||
);
|
||||
})
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = grouped[key];
|
||||
return obj;
|
||||
}, {});
|
||||
const groupedItems: DataTableRowData[] = [];
|
||||
Object.entries(sorted).forEach(([groupName, rows]) => {
|
||||
groupedItems.push({
|
||||
append: true,
|
||||
content: html`<div
|
||||
class="mdc-data-table__cell group-header"
|
||||
role="cell"
|
||||
.group=${groupName}
|
||||
@click=${this._collapseGroup}
|
||||
>
|
||||
<ha-icon-button
|
||||
.path=${mdiChevronUp}
|
||||
class=${this._collapsedGroups.includes(groupName)
|
||||
? "collapsed"
|
||||
: ""}
|
||||
>
|
||||
</ha-icon-button>
|
||||
${groupName === UNDEFINED_GROUP_KEY
|
||||
? localize("ui.components.data-table.ungrouped")
|
||||
: groupName || ""}
|
||||
</div>`,
|
||||
});
|
||||
if (!this._collapsedGroups.includes(groupName)) {
|
||||
groupedItems.push(...rows);
|
||||
}
|
||||
});
|
||||
items = groupedItems;
|
||||
}
|
||||
|
||||
if (this.appendRow) {
|
||||
items.push({ append: true, content: this.appendRow });
|
||||
}
|
||||
|
||||
if (this.hasFab) {
|
||||
items.push({ empty: true });
|
||||
}
|
||||
|
||||
this._items = items;
|
||||
} else {
|
||||
this._items = data;
|
||||
}
|
||||
this._lastUpdate = startTime;
|
||||
this._filteredData = data;
|
||||
}
|
||||
|
||||
private _groupData = memoizeOne(
|
||||
(
|
||||
data: DataTableRowData[],
|
||||
localize: LocalizeFunc,
|
||||
appendRow,
|
||||
hasFab: boolean,
|
||||
groupColumn: string | undefined,
|
||||
groupOrder: string[] | undefined,
|
||||
collapsedGroups: string[]
|
||||
) => {
|
||||
if (appendRow || hasFab || groupColumn) {
|
||||
let items = [...data];
|
||||
|
||||
if (groupColumn) {
|
||||
const grouped = groupBy(items, (item) => item[groupColumn]);
|
||||
if (grouped.undefined) {
|
||||
// make sure ungrouped items are at the bottom
|
||||
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined;
|
||||
delete grouped.undefined;
|
||||
}
|
||||
const sorted: {
|
||||
[key: string]: DataTableRowData[];
|
||||
} = Object.keys(grouped)
|
||||
.sort((a, b) => {
|
||||
const orderA = groupOrder?.indexOf(a) ?? -1;
|
||||
const orderB = groupOrder?.indexOf(b) ?? -1;
|
||||
if (orderA !== orderB) {
|
||||
if (orderA === -1) {
|
||||
return 1;
|
||||
}
|
||||
if (orderB === -1) {
|
||||
return -1;
|
||||
}
|
||||
return orderA - orderB;
|
||||
}
|
||||
return stringCompare(
|
||||
["", "-", "—"].includes(a) ? "zzz" : a,
|
||||
["", "-", "—"].includes(b) ? "zzz" : b,
|
||||
this.hass.locale.language
|
||||
);
|
||||
})
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = grouped[key];
|
||||
return obj;
|
||||
}, {});
|
||||
const groupedItems: DataTableRowData[] = [];
|
||||
Object.entries(sorted).forEach(([groupName, rows]) => {
|
||||
groupedItems.push({
|
||||
append: true,
|
||||
content: html`<div
|
||||
class="mdc-data-table__cell group-header"
|
||||
role="cell"
|
||||
.group=${groupName}
|
||||
@click=${this._collapseGroup}
|
||||
>
|
||||
<ha-icon-button
|
||||
.path=${mdiChevronUp}
|
||||
class=${collapsedGroups.includes(groupName)
|
||||
? "collapsed"
|
||||
: ""}
|
||||
>
|
||||
</ha-icon-button>
|
||||
${groupName === UNDEFINED_GROUP_KEY
|
||||
? localize("ui.components.data-table.ungrouped")
|
||||
: groupName || ""}
|
||||
</div>`,
|
||||
});
|
||||
if (!collapsedGroups.includes(groupName)) {
|
||||
groupedItems.push(...rows);
|
||||
}
|
||||
});
|
||||
items = groupedItems;
|
||||
}
|
||||
|
||||
if (appendRow) {
|
||||
items.push({ append: true, content: appendRow });
|
||||
}
|
||||
|
||||
if (hasFab) {
|
||||
items.push({ empty: true });
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
);
|
||||
|
||||
private _memFilterData = memoizeOne(
|
||||
(
|
||||
data: DataTableRowData[],
|
||||
@@ -802,8 +828,8 @@ export class HaDataTable extends LitElement {
|
||||
|
||||
private _checkedRowsChanged() {
|
||||
// force scroller to update, change it's items
|
||||
if (this._items.length) {
|
||||
this._items = [...this._items];
|
||||
if (this._filteredData.length) {
|
||||
this._filteredData = [...this._filteredData];
|
||||
}
|
||||
fireEvent(this, "selection-changed", {
|
||||
value: this._checkedRows,
|
||||
|
155
src/components/ha-badge.ts
Normal file
155
src/components/ha-badge.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import "./ha-ripple";
|
||||
|
||||
type BadgeType = "badge" | "button";
|
||||
|
||||
@customElement("ha-badge")
|
||||
export class HaBadge extends LitElement {
|
||||
@property() public type: BadgeType = "badge";
|
||||
|
||||
@property() public label?: string;
|
||||
|
||||
@property({ type: Boolean, attribute: "icon-only" }) iconOnly = false;
|
||||
|
||||
protected render() {
|
||||
const label = this.label;
|
||||
|
||||
return html`
|
||||
<div
|
||||
class="badge ${classMap({
|
||||
"icon-only": this.iconOnly,
|
||||
})}"
|
||||
role=${ifDefined(this.type === "button" ? "button" : undefined)}
|
||||
tabindex=${ifDefined(this.type === "button" ? "0" : undefined)}
|
||||
>
|
||||
<ha-ripple .disabled=${this.type !== "button"}></ha-ripple>
|
||||
<slot name="icon"></slot>
|
||||
${this.iconOnly
|
||||
? nothing
|
||||
: html`<span class="info">
|
||||
${label ? html`<span class="label">${label}</span>` : nothing}
|
||||
<span class="content"><slot></slot></span>
|
||||
</span>`}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
:host {
|
||||
--badge-color: var(--secondary-text-color);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.badge {
|
||||
position: relative;
|
||||
--ha-ripple-color: var(--badge-color);
|
||||
--ha-ripple-hover-opacity: 0.04;
|
||||
--ha-ripple-pressed-opacity: 0.12;
|
||||
transition:
|
||||
box-shadow 180ms ease-in-out,
|
||||
border-color 180ms ease-in-out;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
height: var(--ha-badge-size, 36px);
|
||||
min-width: var(--ha-badge-size, 36px);
|
||||
padding: 0px 12px;
|
||||
box-sizing: border-box;
|
||||
width: auto;
|
||||
border-radius: var(
|
||||
--ha-badge-border-radius,
|
||||
calc(var(--ha-badge-size, 36px) / 2)
|
||||
);
|
||||
background: var(
|
||||
--ha-card-background,
|
||||
var(--card-background-color, white)
|
||||
);
|
||||
-webkit-backdrop-filter: var(--ha-card-backdrop-filter, none);
|
||||
backdrop-filter: var(--ha-card-backdrop-filter, none);
|
||||
border-width: var(--ha-card-border-width, 1px);
|
||||
box-shadow: var(--ha-card-box-shadow, none);
|
||||
border-style: solid;
|
||||
border-color: var(
|
||||
--ha-card-border-color,
|
||||
var(--divider-color, #e0e0e0)
|
||||
);
|
||||
}
|
||||
.badge:focus-visible {
|
||||
--shadow-default: var(--ha-card-box-shadow, 0 0 0 0 transparent);
|
||||
--shadow-focus: 0 0 0 1px var(--badge-color);
|
||||
border-color: var(--badge-color);
|
||||
box-shadow: var(--shadow-default), var(--shadow-focus);
|
||||
}
|
||||
[role="button"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
[role="button"]:focus {
|
||||
outline: none;
|
||||
}
|
||||
.info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
padding-inline-start: initial;
|
||||
text-align: center;
|
||||
font-family: Roboto;
|
||||
}
|
||||
.label {
|
||||
font-size: 10px;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
line-height: 10px;
|
||||
letter-spacing: 0.1px;
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
.content {
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
line-height: 16px;
|
||||
letter-spacing: 0.1px;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
::slotted([slot="icon"]) {
|
||||
--mdc-icon-size: 18px;
|
||||
color: var(--badge-color);
|
||||
line-height: 0;
|
||||
margin-left: -4px;
|
||||
margin-right: 0;
|
||||
margin-inline-start: -4px;
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
::slotted(img[slot="icon"]) {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
overflow: hidden;
|
||||
margin-left: -10px;
|
||||
margin-right: 0;
|
||||
margin-inline-start: -10px;
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
.badge.icon-only {
|
||||
padding: 0;
|
||||
}
|
||||
.badge.icon-only ::slotted([slot="icon"]) {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
margin-inline-start: 0;
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-badge": HaBadge;
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import { Button } from "@material/mwc-button";
|
||||
import { Corner } from "@material/web/menu/menu";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators";
|
||||
import { FOCUS_TARGET } from "../dialogs/make-dialog-manager";
|
||||
@@ -14,8 +15,20 @@ export class HaButtonMenuNew extends LitElement {
|
||||
|
||||
@property() public positioning?: "fixed" | "absolute" | "popover";
|
||||
|
||||
@property({ type: Boolean, attribute: "has-overflow" }) public hasOverflow =
|
||||
false;
|
||||
@property({ type: Boolean, attribute: "no-horizontal-flip" })
|
||||
public noHorizontalFlip = false;
|
||||
|
||||
@property({ type: Boolean, attribute: "no-vertical-flip" })
|
||||
public noVerticalFlip = false;
|
||||
|
||||
@property({ attribute: "anchor-corner" })
|
||||
public anchorCorner: Corner = Corner.END_START;
|
||||
|
||||
@property({ attribute: "menu-corner" })
|
||||
public menuCorner: Corner = Corner.START_START;
|
||||
|
||||
@property({ type: Boolean, attribute: "has-overflow" })
|
||||
public hasOverflow = false;
|
||||
|
||||
@query("ha-menu", true) private _menu!: HaMenu;
|
||||
|
||||
@@ -39,6 +52,10 @@ export class HaButtonMenuNew extends LitElement {
|
||||
<ha-menu
|
||||
.positioning=${this.positioning}
|
||||
.hasOverflow=${this.hasOverflow}
|
||||
.anchorCorner=${this.anchorCorner}
|
||||
.menuCorner=${this.menuCorner}
|
||||
.noVerticalFlip=${this.noVerticalFlip}
|
||||
.noHorizontalFlip=${this.noHorizontalFlip}
|
||||
>
|
||||
<slot></slot>
|
||||
</ha-menu>
|
||||
|
@@ -45,15 +45,35 @@ export class HaConversationAgentPicker extends LitElement {
|
||||
if (!this._agents) {
|
||||
return nothing;
|
||||
}
|
||||
const value =
|
||||
this.value ??
|
||||
(this.required &&
|
||||
(!this.language ||
|
||||
this._agents
|
||||
.find((agent) => agent.id === "homeassistant")
|
||||
?.supported_languages.includes(this.language))
|
||||
? "homeassistant"
|
||||
: NONE);
|
||||
let value = this.value;
|
||||
if (!value && this.required) {
|
||||
// Select Home Assistant conversation agent if it supports the language
|
||||
for (const agent of this._agents) {
|
||||
if (
|
||||
agent.id === "conversation.home_assistant" &&
|
||||
agent.supported_languages.includes(this.language!)
|
||||
) {
|
||||
value = agent.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!value) {
|
||||
// Select the first agent that supports the language
|
||||
for (const agent of this._agents) {
|
||||
if (
|
||||
agent.supported_languages === "*" &&
|
||||
agent.supported_languages.includes(this.language!)
|
||||
) {
|
||||
value = agent.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!value) {
|
||||
value = NONE;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-select
|
||||
.label=${this.label ||
|
||||
|
@@ -68,8 +68,8 @@ export class HaExpansionPanel extends LitElement {
|
||||
></ha-svg-icon>
|
||||
`
|
||||
: ""}
|
||||
<slot name="icons"></slot>
|
||||
</div>
|
||||
<slot name="icons"></slot>
|
||||
</div>
|
||||
<div
|
||||
class="container ${classMap({ expanded: this.expanded })}"
|
||||
|
@@ -95,10 +95,10 @@ export const computeInitialHaFormData = (
|
||||
} else if (
|
||||
"action" in selector ||
|
||||
"trigger" in selector ||
|
||||
"condition" in selector ||
|
||||
"media" in selector ||
|
||||
"target" in selector
|
||||
"condition" in selector
|
||||
) {
|
||||
data[field.name] = [];
|
||||
} else if ("media" in selector || "target" in selector) {
|
||||
data[field.name] = {};
|
||||
} else {
|
||||
throw new Error(
|
||||
|
@@ -21,13 +21,45 @@ export class HaFormExpendable extends LitElement implements HaFormElement {
|
||||
|
||||
@property({ attribute: false }) public computeLabel?: (
|
||||
schema: HaFormSchema,
|
||||
data?: HaFormDataContainer
|
||||
data?: HaFormDataContainer,
|
||||
options?: { path?: string[] }
|
||||
) => string;
|
||||
|
||||
@property({ attribute: false }) public computeHelper?: (
|
||||
schema: HaFormSchema
|
||||
schema: HaFormSchema,
|
||||
options?: { path?: string[] }
|
||||
) => string;
|
||||
|
||||
private _renderDescription() {
|
||||
const description = this.computeHelper?.(this.schema);
|
||||
return description ? html`<p>${description}</p>` : nothing;
|
||||
}
|
||||
|
||||
private _computeLabel = (
|
||||
schema: HaFormSchema,
|
||||
data?: HaFormDataContainer,
|
||||
options?: { path?: string[] }
|
||||
) => {
|
||||
if (!this.computeLabel) return this.computeLabel;
|
||||
|
||||
return this.computeLabel(schema, data, {
|
||||
...options,
|
||||
path: [...(options?.path || []), this.schema.name],
|
||||
});
|
||||
};
|
||||
|
||||
private _computeHelper = (
|
||||
schema: HaFormSchema,
|
||||
options?: { path?: string[] }
|
||||
) => {
|
||||
if (!this.computeHelper) return this.computeHelper;
|
||||
|
||||
return this.computeHelper(schema, {
|
||||
...options,
|
||||
path: [...(options?.path || []), this.schema.name],
|
||||
});
|
||||
};
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
<ha-expansion-panel outlined .expanded=${Boolean(this.schema.expanded)}>
|
||||
@@ -43,16 +75,17 @@ export class HaFormExpendable extends LitElement implements HaFormElement {
|
||||
<ha-svg-icon .path=${this.schema.iconPath}></ha-svg-icon>
|
||||
`
|
||||
: nothing}
|
||||
${this.schema.title}
|
||||
${this.schema.title || this.computeLabel?.(this.schema)}
|
||||
</div>
|
||||
<div class="content">
|
||||
${this._renderDescription()}
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${this.data}
|
||||
.schema=${this.schema.schema}
|
||||
.disabled=${this.disabled}
|
||||
.computeLabel=${this.computeLabel}
|
||||
.computeHelper=${this.computeHelper}
|
||||
.computeLabel=${this._computeLabel}
|
||||
.computeHelper=${this._computeHelper}
|
||||
></ha-form>
|
||||
</div>
|
||||
</ha-expansion-panel>
|
||||
@@ -71,6 +104,9 @@ export class HaFormExpendable extends LitElement implements HaFormElement {
|
||||
.content {
|
||||
padding: 12px;
|
||||
}
|
||||
.content p {
|
||||
margin: 0 0 24px;
|
||||
}
|
||||
ha-expansion-panel {
|
||||
display: block;
|
||||
--expansion-panel-content-padding: 0;
|
||||
|
@@ -31,7 +31,7 @@ const LOAD_ELEMENTS = {
|
||||
};
|
||||
|
||||
const getValue = (obj, item) =>
|
||||
obj ? (!item.name ? obj : obj[item.name]) : null;
|
||||
obj ? (!item.name || item.flatten ? obj : obj[item.name]) : null;
|
||||
|
||||
const getError = (obj, item) => (obj && item.name ? obj[item.name] : null);
|
||||
|
||||
@@ -204,9 +204,10 @@ export class HaForm extends LitElement implements HaFormElement {
|
||||
|
||||
if (ev.target === this) return;
|
||||
|
||||
const newValue = !schema.name
|
||||
? ev.detail.value
|
||||
: { [schema.name]: ev.detail.value };
|
||||
const newValue =
|
||||
!schema.name || ("flatten" in schema && schema.flatten)
|
||||
? ev.detail.value
|
||||
: { [schema.name]: ev.detail.value };
|
||||
|
||||
this.data = {
|
||||
...this.data,
|
||||
|
@@ -31,15 +31,15 @@ export interface HaFormBaseSchema {
|
||||
|
||||
export interface HaFormGridSchema extends HaFormBaseSchema {
|
||||
type: "grid";
|
||||
name: string;
|
||||
flatten?: boolean;
|
||||
column_min_width?: string;
|
||||
schema: readonly HaFormSchema[];
|
||||
}
|
||||
|
||||
export interface HaFormExpandableSchema extends HaFormBaseSchema {
|
||||
type: "expandable";
|
||||
name: "";
|
||||
title: string;
|
||||
flatten?: boolean;
|
||||
title?: string;
|
||||
icon?: string;
|
||||
iconPath?: string;
|
||||
expanded?: boolean;
|
||||
@@ -100,7 +100,7 @@ export type SchemaUnion<
|
||||
SchemaArray extends readonly HaFormSchema[],
|
||||
Schema = SchemaArray[number],
|
||||
> = Schema extends HaFormGridSchema | HaFormExpandableSchema
|
||||
? SchemaUnion<Schema["schema"]>
|
||||
? SchemaUnion<Schema["schema"]> | Schema
|
||||
: Schema;
|
||||
|
||||
export interface HaFormDataContainer {
|
||||
|
@@ -18,9 +18,9 @@ export class HaFormfield extends FormfieldBase {
|
||||
|
||||
return html` <div class="mdc-form-field ${classMap(classes)}">
|
||||
<slot></slot>
|
||||
<label class="mdc-label" @click=${this._labelClick}
|
||||
><slot name="label">${this.label}</slot></label
|
||||
>
|
||||
<label class="mdc-label" @click=${this._labelClick}>
|
||||
<slot name="label">${this.label}</slot>
|
||||
</label>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,13 @@ export class HaFormfield extends FormfieldBase {
|
||||
}
|
||||
.mdc-form-field {
|
||||
align-items: var(--ha-formfield-align-items, center);
|
||||
gap: 4px;
|
||||
}
|
||||
.mdc-form-field > label {
|
||||
direction: var(--direction);
|
||||
margin-inline-start: 0;
|
||||
margin-inline-end: auto;
|
||||
padding-inline-start: 4px;
|
||||
padding-inline-end: 0;
|
||||
padding: 0;
|
||||
}
|
||||
:host([disabled]) label {
|
||||
color: var(--disabled-text-color);
|
||||
|
@@ -1,24 +1,24 @@
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import "./ha-icon-button";
|
||||
import "../panels/lovelace/editor/card-editor/ha-grid-layout-slider";
|
||||
import "./ha-icon-button";
|
||||
|
||||
import { mdiRestore } from "@mdi/js";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { conditionalClamp } from "../common/number/clamp";
|
||||
|
||||
type GridSizeValue = {
|
||||
rows?: number | "auto";
|
||||
columns?: number;
|
||||
};
|
||||
import {
|
||||
CardGridSize,
|
||||
DEFAULT_GRID_SIZE,
|
||||
} from "../panels/lovelace/common/compute-card-grid-size";
|
||||
import { HomeAssistant } from "../types";
|
||||
|
||||
@customElement("ha-grid-size-picker")
|
||||
export class HaGridSizeEditor extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public value?: GridSizeValue;
|
||||
@property({ attribute: false }) public value?: CardGridSize;
|
||||
|
||||
@property({ attribute: false }) public rows = 8;
|
||||
|
||||
@@ -34,7 +34,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public isDefault?: boolean;
|
||||
|
||||
@state() public _localValue?: GridSizeValue = undefined;
|
||||
@state() public _localValue?: CardGridSize = { rows: 1, columns: 1 };
|
||||
|
||||
protected willUpdate(changedProperties) {
|
||||
if (changedProperties.has("value")) {
|
||||
@@ -49,6 +49,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
this.rowMin !== undefined && this.rowMin === this.rowMax;
|
||||
|
||||
const autoHeight = this._localValue?.rows === "auto";
|
||||
const fullWidth = this._localValue?.columns === "full";
|
||||
|
||||
const rowMin = this.rowMin ?? 1;
|
||||
const rowMax = this.rowMax ?? this.rows;
|
||||
@@ -67,7 +68,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
.min=${columnMin}
|
||||
.max=${columnMax}
|
||||
.range=${this.columns}
|
||||
.value=${columnValue}
|
||||
.value=${fullWidth ? this.columns : columnValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
@slider-moved=${this._sliderMoved}
|
||||
.disabled=${disabledColumns}
|
||||
@@ -104,12 +105,12 @@ export class HaGridSizeEditor extends LitElement {
|
||||
`
|
||||
: nothing}
|
||||
<div
|
||||
class="preview"
|
||||
class="preview ${classMap({ "full-width": fullWidth })}"
|
||||
style=${styleMap({
|
||||
"--total-rows": this.rows,
|
||||
"--total-columns": this.columns,
|
||||
"--rows": rowValue,
|
||||
"--columns": columnValue,
|
||||
"--columns": fullWidth ? this.columns : columnValue,
|
||||
})}
|
||||
>
|
||||
<div>
|
||||
@@ -140,12 +141,21 @@ export class HaGridSizeEditor extends LitElement {
|
||||
const cell = ev.currentTarget as HTMLElement;
|
||||
const rows = Number(cell.getAttribute("data-row"));
|
||||
const columns = Number(cell.getAttribute("data-column"));
|
||||
const clampedRow = conditionalClamp(rows, this.rowMin, this.rowMax);
|
||||
const clampedColumn = conditionalClamp(
|
||||
const clampedRow: CardGridSize["rows"] = conditionalClamp(
|
||||
rows,
|
||||
this.rowMin,
|
||||
this.rowMax
|
||||
);
|
||||
let clampedColumn: CardGridSize["columns"] = conditionalClamp(
|
||||
columns,
|
||||
this.columnMin,
|
||||
this.columnMax
|
||||
);
|
||||
|
||||
const currentSize = this.value ?? DEFAULT_GRID_SIZE;
|
||||
if (currentSize.columns === "full" && clampedColumn === this.columns) {
|
||||
clampedColumn = "full";
|
||||
}
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { rows: clampedRow, columns: clampedColumn },
|
||||
});
|
||||
@@ -153,12 +163,23 @@ export class HaGridSizeEditor extends LitElement {
|
||||
|
||||
private _valueChanged(ev) {
|
||||
ev.stopPropagation();
|
||||
const key = ev.currentTarget.id;
|
||||
const newValue = {
|
||||
...this.value,
|
||||
[key]: ev.detail.value,
|
||||
const key = ev.currentTarget.id as "rows" | "columns";
|
||||
const currentSize = this.value ?? DEFAULT_GRID_SIZE;
|
||||
let value = ev.detail.value as CardGridSize[typeof key];
|
||||
|
||||
if (
|
||||
key === "columns" &&
|
||||
currentSize.columns === "full" &&
|
||||
value === this.columns
|
||||
) {
|
||||
value = "full";
|
||||
}
|
||||
|
||||
const newSize = {
|
||||
...currentSize,
|
||||
[key]: value,
|
||||
};
|
||||
fireEvent(this, "value-changed", { value: newValue });
|
||||
fireEvent(this, "value-changed", { value: newSize });
|
||||
}
|
||||
|
||||
private _reset(ev) {
|
||||
@@ -173,11 +194,14 @@ export class HaGridSizeEditor extends LitElement {
|
||||
|
||||
private _sliderMoved(ev) {
|
||||
ev.stopPropagation();
|
||||
const key = ev.currentTarget.id;
|
||||
const value = ev.detail.value;
|
||||
const key = ev.currentTarget.id as "rows" | "columns";
|
||||
const currentSize = this.value ?? DEFAULT_GRID_SIZE;
|
||||
const value = ev.detail.value as CardGridSize[typeof key] | undefined;
|
||||
|
||||
if (value === undefined) return;
|
||||
|
||||
this._localValue = {
|
||||
...this.value,
|
||||
...currentSize,
|
||||
[key]: ev.detail.value,
|
||||
};
|
||||
}
|
||||
@@ -189,7 +213,7 @@ export class HaGridSizeEditor extends LitElement {
|
||||
grid-template-areas:
|
||||
"reset column-slider"
|
||||
"row-slider preview";
|
||||
grid-template-rows: auto 1fr;
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 8px;
|
||||
}
|
||||
@@ -205,17 +229,12 @@ export class HaGridSizeEditor extends LitElement {
|
||||
.preview {
|
||||
position: relative;
|
||||
grid-area: preview;
|
||||
aspect-ratio: 1 / 1.2;
|
||||
}
|
||||
.preview > div {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: relative;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(var(--total-columns), 1fr);
|
||||
grid-template-rows: repeat(var(--total-rows), 1fr);
|
||||
grid-template-rows: repeat(var(--total-rows), 25px);
|
||||
gap: 4px;
|
||||
}
|
||||
.preview .cell {
|
||||
@@ -226,15 +245,23 @@ export class HaGridSizeEditor extends LitElement {
|
||||
opacity: 0.2;
|
||||
cursor: pointer;
|
||||
}
|
||||
.selected {
|
||||
.preview .selected {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
.selected .cell {
|
||||
background-color: var(--primary-color);
|
||||
grid-column: 1 / span var(--columns, 0);
|
||||
grid-row: 1 / span var(--rows, 0);
|
||||
grid-column: 1 / span min(var(--columns, 0), var(--total-columns));
|
||||
grid-row: 1 / span min(var(--rows, 0), var(--total-rows));
|
||||
opacity: 0.5;
|
||||
}
|
||||
.preview.full-width .selected .cell {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
@@ -28,6 +28,11 @@ const LAWN_MOWER_ACTIONS: Partial<
|
||||
service: "start_mowing",
|
||||
feature: LawnMowerEntityFeature.START_MOWING,
|
||||
},
|
||||
returning: {
|
||||
action: "pause",
|
||||
service: "pause",
|
||||
feature: LawnMowerEntityFeature.PAUSE,
|
||||
},
|
||||
paused: {
|
||||
action: "resume_mowing",
|
||||
service: "start_mowing",
|
||||
|
@@ -96,7 +96,25 @@ class HaMarkdownElement extends ReactiveElement {
|
||||
|
||||
haAlertNode.append(
|
||||
...Array.from(node.childNodes)
|
||||
.map((child) => Array.from(child.childNodes))
|
||||
.map((child) => {
|
||||
const arr = Array.from(child.childNodes);
|
||||
if (!this.breaks && arr.length) {
|
||||
// When we are not breaking, the first line of the blockquote is not considered,
|
||||
// so we need to adjust the first child text content
|
||||
const firstChild = arr[0];
|
||||
if (
|
||||
firstChild.nodeType === Node.TEXT_NODE &&
|
||||
firstChild.textContent === gitHubAlertMatch.input &&
|
||||
firstChild.textContent?.includes("\n")
|
||||
) {
|
||||
firstChild.textContent = firstChild.textContent
|
||||
.split("\n")
|
||||
.slice(1)
|
||||
.join("\n");
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
})
|
||||
.reduce((acc, val) => acc.concat(val), [])
|
||||
.filter(
|
||||
(childNode) =>
|
||||
|
22
src/components/ha-outlined-segmented-button-set.ts
Normal file
22
src/components/ha-outlined-segmented-button-set.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { MdOutlinedSegmentedButtonSet } from "@material/web/labs/segmentedbuttonset/outlined-segmented-button-set";
|
||||
import { css } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
|
||||
@customElement("ha-outlined-segmented-button-set")
|
||||
export class HaOutlinedSegmentedButtonSet extends MdOutlinedSegmentedButtonSet {
|
||||
static override styles = [
|
||||
...super.styles,
|
||||
css`
|
||||
:host {
|
||||
--ha-icon-display: block;
|
||||
--md-outlined-segmented-button-container-height: 32px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-outlined-segmented-button-set": HaOutlinedSegmentedButtonSet;
|
||||
}
|
||||
}
|
34
src/components/ha-outlined-segmented-button.ts
Normal file
34
src/components/ha-outlined-segmented-button.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { MdOutlinedSegmentedButton } from "@material/web/labs/segmentedbutton/outlined-segmented-button";
|
||||
import { css } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
|
||||
@customElement("ha-outlined-segmented-button")
|
||||
export class HaOutlinedSegmentedButton extends MdOutlinedSegmentedButton {
|
||||
static override styles = [
|
||||
...super.styles,
|
||||
css`
|
||||
:host {
|
||||
--ha-icon-display: block;
|
||||
--md-outlined-segmented-button-selected-container-color: var(
|
||||
--light-primary-color
|
||||
);
|
||||
--md-outlined-segmented-button-container-height: 32px;
|
||||
--md-outlined-segmented-button-disabled-label-text-color: var(
|
||||
--disabled-text-color
|
||||
);
|
||||
--md-outlined-segmented-button-disabled-icon-color: var(
|
||||
--disabled-text-color
|
||||
);
|
||||
--md-outlined-segmented-button-disabled-outline-color: var(
|
||||
--disabled-text-color
|
||||
);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-outlined-segmented-button": HaOutlinedSegmentedButton;
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { HomeAssistant } from "../../types";
|
||||
@@ -28,10 +28,13 @@ export class HaBooleanSelector extends LitElement {
|
||||
@change=${this._handleChange}
|
||||
.disabled=${this.disabled}
|
||||
></ha-switch>
|
||||
<span slot="label">
|
||||
<p class="primary">${this.label}</p>
|
||||
${this.helper
|
||||
? html`<p class="secondary">${this.helper}</p>`
|
||||
: nothing}
|
||||
</span>
|
||||
</ha-formfield>
|
||||
${this.helper
|
||||
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||
: ""}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -47,10 +50,21 @@ export class HaBooleanSelector extends LitElement {
|
||||
return css`
|
||||
ha-formfield {
|
||||
display: flex;
|
||||
height: 56px;
|
||||
min-height: 56px;
|
||||
align-items: center;
|
||||
--mdc-typography-body2-font-size: 1em;
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
.secondary {
|
||||
direction: var(--direction);
|
||||
padding-top: 4px;
|
||||
box-sizing: border-box;
|
||||
color: var(--secondary-text-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: var(--mdc-typography-body2-font-weight, 400);
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
@@ -162,8 +162,14 @@ export class HaLocationSelector extends LitElement {
|
||||
|
||||
private _computeLabel = (
|
||||
entry: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
): string =>
|
||||
this.hass.localize(`ui.components.selectors.location.${entry.name}`);
|
||||
): string => {
|
||||
if (entry.name) {
|
||||
return this.hass.localize(
|
||||
`ui.components.selectors.location.${entry.name}`
|
||||
);
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
static styles = css`
|
||||
ha-locations-editor {
|
||||
|
@@ -1,4 +1,11 @@
|
||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
html,
|
||||
LitElement,
|
||||
nothing,
|
||||
PropertyValues,
|
||||
} from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
@@ -60,12 +67,12 @@ export class HaNumberSelector extends LitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
${this.label && !isBox
|
||||
? html`${this.label}${this.required ? "*" : ""}`
|
||||
: nothing}
|
||||
<div class="input">
|
||||
${!isBox
|
||||
? html`
|
||||
${this.label
|
||||
? html`${this.label}${this.required ? "*" : ""}`
|
||||
: ""}
|
||||
<ha-slider
|
||||
labeled
|
||||
.min=${this.selector.number!.min}
|
||||
@@ -75,10 +82,11 @@ export class HaNumberSelector extends LitElement {
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
@change=${this._handleSliderChange}
|
||||
.ticks=${this.selector.number?.slider_ticks}
|
||||
>
|
||||
</ha-slider>
|
||||
`
|
||||
: ""}
|
||||
: nothing}
|
||||
<ha-textfield
|
||||
.inputMode=${this.selector.number?.step === "any" ||
|
||||
(this.selector.number?.step ?? 1) % 1 !== 0
|
||||
@@ -105,7 +113,7 @@ export class HaNumberSelector extends LitElement {
|
||||
</div>
|
||||
${!isBox && this.helper
|
||||
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
|
||||
: ""}
|
||||
: nothing}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -141,6 +149,9 @@ export class HaNumberSelector extends LitElement {
|
||||
}
|
||||
ha-slider {
|
||||
flex: 1;
|
||||
margin-right: 16px;
|
||||
margin-inline-end: 16px;
|
||||
margin-inline-start: 0;
|
||||
}
|
||||
ha-textfield {
|
||||
--ha-textfield-input-width: 40px;
|
||||
|
@@ -81,15 +81,16 @@ export class HaTargetSelector extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`<ha-target-picker
|
||||
.hass=${this.hass}
|
||||
.value=${this.value}
|
||||
.helper=${this.helper}
|
||||
.deviceFilter=${this._filterDevices}
|
||||
.entityFilter=${this._filterEntities}
|
||||
.disabled=${this.disabled}
|
||||
.createDomains=${this._createDomains}
|
||||
></ha-target-picker>`;
|
||||
return html` ${this.label ? html`<label>${this.label}</label>` : nothing}
|
||||
<ha-target-picker
|
||||
.hass=${this.hass}
|
||||
.value=${this.value}
|
||||
.helper=${this.helper}
|
||||
.deviceFilter=${this._filterDevices}
|
||||
.entityFilter=${this._filterEntities}
|
||||
.disabled=${this.disabled}
|
||||
.createDomains=${this._createDomains}
|
||||
></ha-target-picker>`;
|
||||
}
|
||||
|
||||
private _filterEntities = (entity: HassEntity): boolean => {
|
||||
|
@@ -82,6 +82,7 @@ export class HaTextSelector extends LitElement {
|
||||
.disabled=${this.disabled}
|
||||
.type=${this._unmaskedPassword ? "text" : this.selector.text?.type}
|
||||
@input=${this._handleChange}
|
||||
@change=${this._handleChange}
|
||||
.label=${this.label || ""}
|
||||
.prefix=${this.selector.text?.prefix}
|
||||
.suffix=${this.selector.text?.type === "password"
|
||||
|
@@ -30,7 +30,7 @@ export class HaTimeSelector extends LitElement {
|
||||
clearable
|
||||
.helper=${this.helper}
|
||||
.label=${this.label}
|
||||
enable-second
|
||||
.enableSecond=${!this.selector.time?.no_second}
|
||||
></ha-time-input>
|
||||
`;
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ import "./ha-service-picker";
|
||||
import "./ha-settings-row";
|
||||
import "./ha-yaml-editor";
|
||||
import type { HaYamlEditor } from "./ha-yaml-editor";
|
||||
import "./ha-service-section-icon";
|
||||
|
||||
const attributeFilter = (values: any[], attribute: any) => {
|
||||
if (typeof attribute === "object") {
|
||||
@@ -496,7 +497,18 @@ export class HaServiceControl extends LitElement {
|
||||
) ||
|
||||
dataField.name ||
|
||||
dataField.key}
|
||||
.secondary=${this._getSectionDescription(
|
||||
dataField,
|
||||
domain,
|
||||
serviceName
|
||||
)}
|
||||
>
|
||||
<ha-service-section-icon
|
||||
slot="icons"
|
||||
.hass=${this.hass}
|
||||
.service=${this._value!.action}
|
||||
.section=${dataField.key}
|
||||
></ha-service-section-icon>
|
||||
${Object.entries(dataField.fields).map(([key, field]) =>
|
||||
this._renderField(
|
||||
{ key, ...field },
|
||||
@@ -517,6 +529,16 @@ export class HaServiceControl extends LitElement {
|
||||
)} `;
|
||||
}
|
||||
|
||||
private _getSectionDescription(
|
||||
dataField: ExtHassService["fields"][number],
|
||||
domain: string | undefined,
|
||||
serviceName: string | undefined
|
||||
) {
|
||||
return this.hass!.localize(
|
||||
`component.${domain}.services.${serviceName}.sections.${dataField.key}.description`
|
||||
);
|
||||
}
|
||||
|
||||
private _renderField = (
|
||||
dataField: ExtHassService["fields"][number],
|
||||
hasOptional: boolean,
|
||||
|
53
src/components/ha-service-section-icon.ts
Normal file
53
src/components/ha-service-section-icon.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { until } from "lit/directives/until";
|
||||
import { HomeAssistant } from "../types";
|
||||
import "./ha-icon";
|
||||
import "./ha-svg-icon";
|
||||
import { serviceSectionIcon } from "../data/icons";
|
||||
|
||||
@customElement("ha-service-section-icon")
|
||||
export class HaServiceSectionIcon extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public service?: string;
|
||||
|
||||
@property() public section?: string;
|
||||
|
||||
@property() public icon?: string;
|
||||
|
||||
protected render() {
|
||||
if (this.icon) {
|
||||
return html`<ha-icon .icon=${this.icon}></ha-icon>`;
|
||||
}
|
||||
|
||||
if (!this.service || !this.section) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
if (!this.hass) {
|
||||
return this._renderFallback();
|
||||
}
|
||||
|
||||
const icon = serviceSectionIcon(this.hass, this.service, this.section).then(
|
||||
(icn) => {
|
||||
if (icn) {
|
||||
return html`<ha-icon .icon=${icn}></ha-icon>`;
|
||||
}
|
||||
return this._renderFallback();
|
||||
}
|
||||
);
|
||||
|
||||
return html`${until(icon)}`;
|
||||
}
|
||||
|
||||
private _renderFallback() {
|
||||
return nothing;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-service-section-icon": HaServiceSectionIcon;
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ export class HaSlider extends MdSlider {
|
||||
--md-sys-color-on-surface: var(--primary-text-color);
|
||||
--md-slider-handle-width: 14px;
|
||||
--md-slider-handle-height: 14px;
|
||||
--md-slider-state-layer-size: 24px;
|
||||
min-width: 100px;
|
||||
min-inline-size: 100px;
|
||||
width: 200px;
|
||||
|
@@ -16,11 +16,10 @@ import { HomeAssistant } from "../types";
|
||||
import "./ha-list-item";
|
||||
import "./ha-select";
|
||||
import type { HaSelect } from "./ha-select";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
|
||||
const NONE = "__NONE_OPTION__";
|
||||
|
||||
const NAME_MAP = { cloud: "Home Assistant Cloud" };
|
||||
|
||||
@customElement("ha-stt-picker")
|
||||
export class HaSTTPicker extends LitElement {
|
||||
@property() public value?: string;
|
||||
@@ -41,13 +40,32 @@ export class HaSTTPicker extends LitElement {
|
||||
if (!this._engines) {
|
||||
return nothing;
|
||||
}
|
||||
const value =
|
||||
this.value ??
|
||||
(this.required
|
||||
? this._engines.find(
|
||||
(engine) => engine.supported_languages?.length !== 0
|
||||
)
|
||||
: NONE);
|
||||
|
||||
let value = this.value;
|
||||
if (!value && this.required) {
|
||||
for (const entity of Object.values(this.hass.entities)) {
|
||||
if (
|
||||
entity.platform === "cloud" &&
|
||||
computeDomain(entity.entity_id) === "stt"
|
||||
) {
|
||||
value = entity.entity_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
for (const sttEngine of this._engines) {
|
||||
if (sttEngine?.supported_languages?.length !== 0) {
|
||||
value = sttEngine.engine_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!value) {
|
||||
value = NONE;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-select
|
||||
.label=${this.label ||
|
||||
@@ -66,12 +84,15 @@ export class HaSTTPicker extends LitElement {
|
||||
</ha-list-item>`
|
||||
: nothing}
|
||||
${this._engines.map((engine) => {
|
||||
let label = engine.engine_id;
|
||||
if (engine.deprecated && engine.engine_id !== value) {
|
||||
return nothing;
|
||||
}
|
||||
let label: string;
|
||||
if (engine.engine_id.includes(".")) {
|
||||
const stateObj = this.hass!.states[engine.engine_id];
|
||||
label = stateObj ? computeStateName(stateObj) : engine.engine_id;
|
||||
} else if (engine.engine_id in NAME_MAP) {
|
||||
label = NAME_MAP[engine.engine_id];
|
||||
} else {
|
||||
label = engine.name || engine.engine_id;
|
||||
}
|
||||
return html`<ha-list-item
|
||||
.value=${engine.engine_id}
|
||||
|
@@ -16,14 +16,10 @@ import { HomeAssistant } from "../types";
|
||||
import "./ha-list-item";
|
||||
import "./ha-select";
|
||||
import type { HaSelect } from "./ha-select";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
|
||||
const NONE = "__NONE_OPTION__";
|
||||
|
||||
const NAME_MAP = {
|
||||
cloud: "Home Assistant Cloud",
|
||||
google_translate: "Google Translate",
|
||||
};
|
||||
|
||||
@customElement("ha-tts-picker")
|
||||
export class HaTTSPicker extends LitElement {
|
||||
@property() public value?: string;
|
||||
@@ -44,13 +40,32 @@ export class HaTTSPicker extends LitElement {
|
||||
if (!this._engines) {
|
||||
return nothing;
|
||||
}
|
||||
const value =
|
||||
this.value ??
|
||||
(this.required
|
||||
? this._engines.find(
|
||||
(engine) => engine.supported_languages?.length !== 0
|
||||
)
|
||||
: NONE);
|
||||
|
||||
let value = this.value;
|
||||
if (!value && this.required) {
|
||||
for (const entity of Object.values(this.hass.entities)) {
|
||||
if (
|
||||
entity.platform === "cloud" &&
|
||||
computeDomain(entity.entity_id) === "tts"
|
||||
) {
|
||||
value = entity.entity_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
for (const ttsEngine of this._engines) {
|
||||
if (ttsEngine?.supported_languages?.length !== 0) {
|
||||
value = ttsEngine.engine_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!value) {
|
||||
value = NONE;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-select
|
||||
.label=${this.label ||
|
||||
@@ -69,12 +84,15 @@ export class HaTTSPicker extends LitElement {
|
||||
</ha-list-item>`
|
||||
: nothing}
|
||||
${this._engines.map((engine) => {
|
||||
let label = engine.engine_id;
|
||||
if (engine.deprecated && engine.engine_id !== value) {
|
||||
return nothing;
|
||||
}
|
||||
let label: string;
|
||||
if (engine.engine_id.includes(".")) {
|
||||
const stateObj = this.hass!.states[engine.engine_id];
|
||||
label = stateObj ? computeStateName(stateObj) : engine.engine_id;
|
||||
} else if (engine.engine_id in NAME_MAP) {
|
||||
label = NAME_MAP[engine.engine_id];
|
||||
} else {
|
||||
label = engine.name || engine.engine_id;
|
||||
}
|
||||
return html`<ha-list-item
|
||||
.value=${engine.engine_id}
|
||||
|
@@ -109,7 +109,7 @@ class HaWebRtcPlayer extends LitElement {
|
||||
let candidates = ""; // Build an Offer SDP string with ice candidates
|
||||
const iceResolver = new Promise<void>((resolve) => {
|
||||
peerConnection.addEventListener("icecandidate", async (event) => {
|
||||
if (!event.candidate) {
|
||||
if (!event.candidate?.candidate) {
|
||||
resolve(); // Gathering complete
|
||||
return;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { IntegrationManifest, IntegrationType } from "./integration";
|
||||
import type { IntegrationType } from "./integration";
|
||||
|
||||
export interface ConfigEntry {
|
||||
entry_id: string;
|
||||
@@ -149,20 +149,19 @@ export const enableConfigEntry = (hass: HomeAssistant, configEntryId: string) =>
|
||||
|
||||
export const sortConfigEntries = (
|
||||
configEntries: ConfigEntry[],
|
||||
manifestLookup: { [domain: string]: IntegrationManifest }
|
||||
primaryConfigEntry: string | null
|
||||
): ConfigEntry[] => {
|
||||
const sortedConfigEntries = [...configEntries];
|
||||
|
||||
const getScore = (entry: ConfigEntry) => {
|
||||
const manifest = manifestLookup[entry.domain] as
|
||||
| IntegrationManifest
|
||||
| undefined;
|
||||
const isHelper = manifest?.integration_type === "helper";
|
||||
return isHelper ? -1 : 1;
|
||||
};
|
||||
|
||||
const configEntriesCompare = (a: ConfigEntry, b: ConfigEntry) =>
|
||||
getScore(b) - getScore(a);
|
||||
|
||||
return sortedConfigEntries.sort(configEntriesCompare);
|
||||
if (!primaryConfigEntry) {
|
||||
return configEntries;
|
||||
}
|
||||
const primaryEntry = configEntries.find(
|
||||
(e) => e.entry_id === primaryConfigEntry
|
||||
);
|
||||
if (!primaryEntry) {
|
||||
return configEntries;
|
||||
}
|
||||
const otherEntries = configEntries.filter(
|
||||
(e) => e.entry_id !== primaryConfigEntry
|
||||
);
|
||||
return [primaryEntry, ...otherEntries];
|
||||
};
|
||||
|
@@ -33,6 +33,7 @@ export interface DeviceRegistryEntry extends RegistryEntry {
|
||||
entry_type: "service" | null;
|
||||
disabled_by: "user" | "integration" | "config_entry" | null;
|
||||
configuration_url: string | null;
|
||||
primary_config_entry: string | null;
|
||||
}
|
||||
|
||||
export interface DeviceEntityDisplayLookup {
|
||||
|
@@ -11,6 +11,7 @@ import {
|
||||
isLastDayOfMonth,
|
||||
} from "date-fns";
|
||||
import { Collection, getCollection } from "home-assistant-js-websocket";
|
||||
import memoizeOne from "memoize-one";
|
||||
import {
|
||||
calcDate,
|
||||
calcDateProperty,
|
||||
@@ -791,3 +792,147 @@ export const getEnergyWaterUnit = (hass: HomeAssistant): string =>
|
||||
|
||||
export const energyStatisticHelpUrl =
|
||||
"/docs/energy/faq/#troubleshooting-missing-entities";
|
||||
|
||||
interface EnergySumData {
|
||||
to_grid?: { [start: number]: number };
|
||||
from_grid?: { [start: number]: number };
|
||||
to_battery?: { [start: number]: number };
|
||||
from_battery?: { [start: number]: number };
|
||||
solar?: { [start: number]: number };
|
||||
}
|
||||
|
||||
interface EnergyConsumptionData {
|
||||
total: { [start: number]: number };
|
||||
}
|
||||
|
||||
export const getSummedData = memoizeOne(
|
||||
(
|
||||
data: EnergyData
|
||||
): { summedData: EnergySumData; compareSummedData?: EnergySumData } => {
|
||||
const summedData = getSummedDataPartial(data);
|
||||
const compareSummedData = data.statsCompare
|
||||
? getSummedDataPartial(data, true)
|
||||
: undefined;
|
||||
return { summedData, compareSummedData };
|
||||
}
|
||||
);
|
||||
|
||||
const getSummedDataPartial = (
|
||||
data: EnergyData,
|
||||
compare?: boolean
|
||||
): EnergySumData => {
|
||||
const statIds: {
|
||||
to_grid?: string[];
|
||||
from_grid?: string[];
|
||||
solar?: string[];
|
||||
to_battery?: string[];
|
||||
from_battery?: string[];
|
||||
} = {};
|
||||
|
||||
for (const source of data.prefs.energy_sources) {
|
||||
if (source.type === "solar") {
|
||||
if (statIds.solar) {
|
||||
statIds.solar.push(source.stat_energy_from);
|
||||
} else {
|
||||
statIds.solar = [source.stat_energy_from];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (source.type === "battery") {
|
||||
if (statIds.to_battery) {
|
||||
statIds.to_battery.push(source.stat_energy_to);
|
||||
statIds.from_battery!.push(source.stat_energy_from);
|
||||
} else {
|
||||
statIds.to_battery = [source.stat_energy_to];
|
||||
statIds.from_battery = [source.stat_energy_from];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (source.type !== "grid") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// grid source
|
||||
for (const flowFrom of source.flow_from) {
|
||||
if (statIds.from_grid) {
|
||||
statIds.from_grid.push(flowFrom.stat_energy_from);
|
||||
} else {
|
||||
statIds.from_grid = [flowFrom.stat_energy_from];
|
||||
}
|
||||
}
|
||||
for (const flowTo of source.flow_to) {
|
||||
if (statIds.to_grid) {
|
||||
statIds.to_grid.push(flowTo.stat_energy_to);
|
||||
} else {
|
||||
statIds.to_grid = [flowTo.stat_energy_to];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const summedData: EnergySumData = {};
|
||||
Object.entries(statIds).forEach(([key, subStatIds]) => {
|
||||
const totalStats: { [start: number]: number } = {};
|
||||
const sets: { [statId: string]: { [start: number]: number } } = {};
|
||||
subStatIds!.forEach((id) => {
|
||||
const stats = compare ? data.statsCompare[id] : data.stats[id];
|
||||
if (!stats) {
|
||||
return;
|
||||
}
|
||||
|
||||
const set = {};
|
||||
stats.forEach((stat) => {
|
||||
if (stat.change === null || stat.change === undefined) {
|
||||
return;
|
||||
}
|
||||
const val = stat.change;
|
||||
// Get total of solar and to grid to calculate the solar energy used
|
||||
totalStats[stat.start] =
|
||||
stat.start in totalStats ? totalStats[stat.start] + val : val;
|
||||
});
|
||||
sets[id] = set;
|
||||
});
|
||||
summedData[key] = totalStats;
|
||||
});
|
||||
|
||||
return summedData;
|
||||
};
|
||||
|
||||
export const computeConsumptionData = memoizeOne(
|
||||
(
|
||||
data: EnergySumData,
|
||||
compareData?: EnergySumData
|
||||
): {
|
||||
consumption: EnergyConsumptionData;
|
||||
compareConsumption?: EnergyConsumptionData;
|
||||
} => {
|
||||
const consumption = computeConsumptionDataPartial(data);
|
||||
const compareConsumption = compareData
|
||||
? computeConsumptionDataPartial(compareData)
|
||||
: undefined;
|
||||
return { consumption, compareConsumption };
|
||||
}
|
||||
);
|
||||
|
||||
const computeConsumptionDataPartial = (
|
||||
data: EnergySumData
|
||||
): EnergyConsumptionData => {
|
||||
const outData: EnergyConsumptionData = { total: {} };
|
||||
|
||||
Object.keys(data).forEach((type) => {
|
||||
Object.keys(data[type]).forEach((start) => {
|
||||
if (outData.total[start] === undefined) {
|
||||
const consumption =
|
||||
(data.from_grid?.[start] || 0) +
|
||||
(data.solar?.[start] || 0) +
|
||||
(data.from_battery?.[start] || 0) -
|
||||
(data.to_grid?.[start] || 0) -
|
||||
(data.to_battery?.[start] || 0);
|
||||
outData.total[start] = consumption;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return outData;
|
||||
};
|
||||
|
@@ -62,7 +62,7 @@ export interface ComponentIcons {
|
||||
}
|
||||
|
||||
interface ServiceIcons {
|
||||
[service: string]: string;
|
||||
[service: string]: { service: string; sections?: { [name: string]: string } };
|
||||
}
|
||||
|
||||
export type IconCategory = "entity" | "entity_component" | "services";
|
||||
@@ -288,7 +288,8 @@ export const serviceIcon = async (
|
||||
const serviceName = computeObjectId(service);
|
||||
const serviceIcons = await getServiceIcons(hass, domain);
|
||||
if (serviceIcons) {
|
||||
icon = serviceIcons[serviceName] as string;
|
||||
const srvceIcon = serviceIcons[serviceName] as ServiceIcons[string];
|
||||
icon = srvceIcon?.service;
|
||||
}
|
||||
if (!icon) {
|
||||
icon = await domainIcon(hass, domain);
|
||||
@@ -296,6 +297,21 @@ export const serviceIcon = async (
|
||||
return icon;
|
||||
};
|
||||
|
||||
export const serviceSectionIcon = async (
|
||||
hass: HomeAssistant,
|
||||
service: string,
|
||||
section: string
|
||||
): Promise<string | undefined> => {
|
||||
const domain = computeDomain(service);
|
||||
const serviceName = computeObjectId(service);
|
||||
const serviceIcons = await getServiceIcons(hass, domain);
|
||||
if (serviceIcons) {
|
||||
const srvceIcon = serviceIcons[serviceName] as ServiceIcons[string];
|
||||
return srvceIcon?.sections?.[section];
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const domainIcon = async (
|
||||
hass: HomeAssistant,
|
||||
domain: string,
|
||||
|
@@ -4,7 +4,12 @@ import {
|
||||
} from "home-assistant-js-websocket";
|
||||
import { UNAVAILABLE } from "./entity";
|
||||
|
||||
export type LawnMowerEntityState = "paused" | "mowing" | "docked" | "error";
|
||||
export type LawnMowerEntityState =
|
||||
| "paused"
|
||||
| "mowing"
|
||||
| "returning"
|
||||
| "docked"
|
||||
| "error";
|
||||
|
||||
export const enum LawnMowerEntityFeature {
|
||||
START_MOWING = 1,
|
||||
|
@@ -13,7 +13,7 @@ export const ensureBadgeConfig = (
|
||||
return {
|
||||
type: "entity",
|
||||
entity: config,
|
||||
display_type: "complete",
|
||||
show_name: true,
|
||||
};
|
||||
}
|
||||
if ("type" in config && config.type) {
|
||||
|
@@ -5,6 +5,8 @@ import type { LovelaceStrategyConfig } from "./strategy";
|
||||
export interface LovelaceBaseSectionConfig {
|
||||
title?: string;
|
||||
visibility?: Condition[];
|
||||
column_span?: number;
|
||||
row_span?: number;
|
||||
}
|
||||
|
||||
export interface LovelaceSectionConfig extends LovelaceBaseSectionConfig {
|
||||
|
@@ -22,7 +22,9 @@ export interface LovelaceBaseViewConfig {
|
||||
visible?: boolean | ShowViewConfig[];
|
||||
subview?: boolean;
|
||||
back_path?: string;
|
||||
max_columns?: number; // Only used for section view, it should move to a section view config type when the views will have dedicated editor.
|
||||
// Only used for section view, it should move to a section view config type when the views will have dedicated editor.
|
||||
max_columns?: number;
|
||||
dense_section_placement?: boolean;
|
||||
}
|
||||
|
||||
export interface LovelaceViewConfig extends LovelaceBaseViewConfig {
|
||||
|
@@ -127,6 +127,12 @@ const tryDescribeAction = <T extends ActionType>(
|
||||
targets.push(
|
||||
computeEntityRegistryName(hass, entityReg) || targetThing
|
||||
);
|
||||
} else if (targetThing === "all") {
|
||||
targets.push(
|
||||
hass.localize(
|
||||
`${actionTranslationBaseKey}.service.description.target_every_entity`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
targets.push(
|
||||
hass.localize(
|
||||
|
@@ -323,6 +323,7 @@ export interface NumberSelector {
|
||||
step?: number | "any";
|
||||
mode?: "box" | "slider";
|
||||
unit_of_measurement?: string;
|
||||
slider_ticks?: boolean;
|
||||
} | null;
|
||||
}
|
||||
|
||||
@@ -427,8 +428,7 @@ export interface ThemeSelector {
|
||||
theme: { include_default?: boolean } | null;
|
||||
}
|
||||
export interface TimeSelector {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
time: {} | null;
|
||||
time: { no_second?: boolean } | null;
|
||||
}
|
||||
|
||||
export interface TriggerSelector {
|
||||
|
@@ -21,6 +21,8 @@ export interface SpeechMetadata {
|
||||
export interface STTEngine {
|
||||
engine_id: string;
|
||||
supported_languages?: string[];
|
||||
name?: string;
|
||||
deprecated: boolean;
|
||||
}
|
||||
|
||||
export const listSTTEngines = (
|
||||
|
@@ -3,6 +3,8 @@ import { HomeAssistant } from "../types";
|
||||
export interface TTSEngine {
|
||||
engine_id: string;
|
||||
supported_languages?: string[];
|
||||
name?: string;
|
||||
deprecated: boolean;
|
||||
}
|
||||
|
||||
export interface TTSVoice {
|
||||
|
@@ -76,17 +76,36 @@ export const showConfigFlowDialog = (
|
||||
: "";
|
||||
},
|
||||
|
||||
renderShowFormStepFieldLabel(hass, step, field) {
|
||||
return hass.localize(
|
||||
`component.${step.handler}.config.step.${step.step_id}.data.${field.name}`
|
||||
renderShowFormStepFieldLabel(hass, step, field, options) {
|
||||
if (field.type === "expandable") {
|
||||
return hass.localize(
|
||||
`component.${step.handler}.config.step.${step.step_id}.sections.${field.name}.name`
|
||||
);
|
||||
}
|
||||
|
||||
const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";
|
||||
|
||||
return (
|
||||
hass.localize(
|
||||
`component.${step.handler}.config.step.${step.step_id}.${prefix}data.${field.name}`
|
||||
) || field.name
|
||||
);
|
||||
},
|
||||
|
||||
renderShowFormStepFieldHelper(hass, step, field) {
|
||||
renderShowFormStepFieldHelper(hass, step, field, options) {
|
||||
if (field.type === "expandable") {
|
||||
return hass.localize(
|
||||
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.sections.${field.name}.description`
|
||||
);
|
||||
}
|
||||
|
||||
const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";
|
||||
|
||||
const description = hass.localize(
|
||||
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.data_description.${field.name}`,
|
||||
`component.${step.translation_domain || step.handler}.config.step.${step.step_id}.${prefix}data_description.${field.name}`,
|
||||
step.description_placeholders
|
||||
);
|
||||
|
||||
return description
|
||||
? html`<ha-markdown breaks .content=${description}></ha-markdown>`
|
||||
: "";
|
||||
|
@@ -49,13 +49,15 @@ export interface FlowConfig {
|
||||
renderShowFormStepFieldLabel(
|
||||
hass: HomeAssistant,
|
||||
step: DataEntryFlowStepForm,
|
||||
field: HaFormSchema
|
||||
field: HaFormSchema,
|
||||
options: { path?: string[]; [key: string]: any }
|
||||
): string;
|
||||
|
||||
renderShowFormStepFieldHelper(
|
||||
hass: HomeAssistant,
|
||||
step: DataEntryFlowStepForm,
|
||||
field: HaFormSchema
|
||||
field: HaFormSchema,
|
||||
options: { path?: string[]; [key: string]: any }
|
||||
): TemplateResult | string;
|
||||
|
||||
renderShowFormStepFieldError(
|
||||
|
@@ -93,15 +93,33 @@ export const showOptionsFlowDialog = (
|
||||
: "";
|
||||
},
|
||||
|
||||
renderShowFormStepFieldLabel(hass, step, field) {
|
||||
return hass.localize(
|
||||
`component.${configEntry.domain}.options.step.${step.step_id}.data.${field.name}`
|
||||
renderShowFormStepFieldLabel(hass, step, field, options) {
|
||||
if (field.type === "expandable") {
|
||||
return hass.localize(
|
||||
`component.${configEntry.domain}.options.step.${step.step_id}.sections.${field.name}.name`
|
||||
);
|
||||
}
|
||||
|
||||
const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";
|
||||
|
||||
return (
|
||||
hass.localize(
|
||||
`component.${configEntry.domain}.options.step.${step.step_id}.${prefix}data.${field.name}`
|
||||
) || field.name
|
||||
);
|
||||
},
|
||||
|
||||
renderShowFormStepFieldHelper(hass, step, field) {
|
||||
renderShowFormStepFieldHelper(hass, step, field, options) {
|
||||
if (field.type === "expandable") {
|
||||
return hass.localize(
|
||||
`component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.sections.${field.name}.description`
|
||||
);
|
||||
}
|
||||
|
||||
const prefix = options?.path?.[0] ? `sections.${options.path[0]}.` : "";
|
||||
|
||||
const description = hass.localize(
|
||||
`component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.data_description.${field.name}`,
|
||||
`component.${step.translation_domain || configEntry.domain}.options.step.${step.step_id}.${prefix}data_description.${field.name}`,
|
||||
step.description_placeholders
|
||||
);
|
||||
return description
|
||||
|
@@ -225,11 +225,24 @@ class StepFlowForm extends LitElement {
|
||||
this._stepData = ev.detail.value;
|
||||
}
|
||||
|
||||
private _labelCallback = (field: HaFormSchema): string =>
|
||||
this.flowConfig.renderShowFormStepFieldLabel(this.hass, this.step, field);
|
||||
private _labelCallback = (field: HaFormSchema, _data, options): string =>
|
||||
this.flowConfig.renderShowFormStepFieldLabel(
|
||||
this.hass,
|
||||
this.step,
|
||||
field,
|
||||
options
|
||||
);
|
||||
|
||||
private _helperCallback = (field: HaFormSchema): string | TemplateResult =>
|
||||
this.flowConfig.renderShowFormStepFieldHelper(this.hass, this.step, field);
|
||||
private _helperCallback = (
|
||||
field: HaFormSchema,
|
||||
options
|
||||
): string | TemplateResult =>
|
||||
this.flowConfig.renderShowFormStepFieldHelper(
|
||||
this.hass,
|
||||
this.step,
|
||||
field,
|
||||
options
|
||||
);
|
||||
|
||||
private _errorCallback = (error: string) =>
|
||||
this.flowConfig.renderShowFormStepFieldError(this.hass, this.step, error);
|
||||
|
@@ -140,10 +140,12 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
|
||||
const controlHA = !this._pipeline
|
||||
? false
|
||||
: supportsFeature(
|
||||
this.hass.states[this._pipeline?.conversation_engine],
|
||||
ConversationEntityFeature.CONTROL
|
||||
);
|
||||
: this.hass.states[this._pipeline?.conversation_engine]
|
||||
? supportsFeature(
|
||||
this.hass.states[this._pipeline?.conversation_engine],
|
||||
ConversationEntityFeature.CONTROL
|
||||
)
|
||||
: true;
|
||||
const supportsMicrophone = AudioRecorder.isSupported;
|
||||
const supportsSTT = this._pipeline?.stt_engine;
|
||||
|
||||
@@ -648,6 +650,7 @@ export class HaVoiceCommandDialog extends LitElement {
|
||||
margin-inline-end: -24px;
|
||||
margin-inline-start: initial;
|
||||
direction: var(--direction);
|
||||
transform: scaleX(var(--scale-direction));
|
||||
}
|
||||
|
||||
.listening-icon[active] {
|
||||
|
@@ -29,7 +29,6 @@ const COMPONENTS = {
|
||||
history: () => import("../panels/history/ha-panel-history"),
|
||||
iframe: () => import("../panels/iframe/ha-panel-iframe"),
|
||||
logbook: () => import("../panels/logbook/ha-panel-logbook"),
|
||||
mailbox: () => import("../panels/mailbox/ha-panel-mailbox"),
|
||||
map: () => import("../panels/map/ha-panel-map"),
|
||||
my: () => import("../panels/my/ha-panel-my"),
|
||||
profile: () => import("../panels/profile/ha-panel-profile"),
|
||||
|
@@ -86,7 +86,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
this._unsubMql = undefined;
|
||||
}
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): ChooseAction {
|
||||
return { choose: [{ conditions: [], sequence: [] }] };
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ export class HaConditionAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ attribute: false }) public action!: Condition;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): Omit<Condition, "state" | "entity_id"> {
|
||||
return { condition: "state" };
|
||||
}
|
||||
|
||||
@@ -87,13 +87,12 @@ export class HaConditionAction extends LitElement implements ActionElement {
|
||||
const elClass = customElements.get(
|
||||
`ha-automation-condition-${type}`
|
||||
) as CustomElementConstructor & {
|
||||
defaultConfig: Omit<Condition, "condition">;
|
||||
defaultConfig: Condition;
|
||||
};
|
||||
|
||||
if (type !== this.action.condition) {
|
||||
fireEvent(this, "value-changed", {
|
||||
value: {
|
||||
condition: type,
|
||||
...elClass.defaultConfig,
|
||||
},
|
||||
});
|
||||
|
@@ -19,7 +19,7 @@ export class HaDelayAction extends LitElement implements ActionElement {
|
||||
|
||||
@state() private _timeData?: HaDurationData;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): DelayAction {
|
||||
return { delay: "" };
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ export class HaDeviceAction extends LitElement {
|
||||
|
||||
private _origAction?: DeviceAction;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): DeviceAction {
|
||||
return {
|
||||
device_id: "",
|
||||
domain: "",
|
||||
|
@@ -21,7 +21,7 @@ export class HaIfAction extends LitElement implements ActionElement {
|
||||
|
||||
@state() private _showElse = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): IfAction {
|
||||
return {
|
||||
if: [],
|
||||
then: [],
|
||||
|
@@ -18,7 +18,7 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ attribute: false }) public action!: ParallelAction;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): ParallelAction {
|
||||
return {
|
||||
parallel: [],
|
||||
};
|
||||
|
@@ -31,7 +31,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ type: Array }) public path?: ItemPath;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): RepeatAction {
|
||||
return { repeat: { count: 2, sequence: [] } };
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ export class HaSequenceAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ attribute: false }) public action!: SequenceAction;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): SequenceAction {
|
||||
return {
|
||||
sequence: [],
|
||||
};
|
||||
|
@@ -52,7 +52,7 @@ export class HaServiceAction extends LitElement implements ActionElement {
|
||||
}
|
||||
);
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): ServiceAction {
|
||||
return { action: "", data: {} };
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ export class HaSetConversationResponseAction
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): SetConversationResponseAction {
|
||||
return { set_conversation_response: "" };
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ export class HaStopAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): StopAction {
|
||||
return { stop: "" };
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ export class HaWaitForTriggerAction
|
||||
|
||||
@property({ attribute: false }) public path?: ItemPath;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): WaitForTriggerAction {
|
||||
return { wait_for_trigger: [] };
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ export class HaWaitAction extends LitElement implements ActionElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): WaitAction {
|
||||
return { wait_template: "", continue_on_timeout: true };
|
||||
}
|
||||
|
||||
|
@@ -207,10 +207,9 @@ export default class HaAutomationCondition extends LitElement {
|
||||
const elClass = customElements.get(
|
||||
`ha-automation-condition-${condition}`
|
||||
) as CustomElementConstructor & {
|
||||
defaultConfig: Omit<Condition, "condition">;
|
||||
defaultConfig: Condition;
|
||||
};
|
||||
conditions = this.conditions.concat({
|
||||
condition: condition as any,
|
||||
...elClass.defaultConfig,
|
||||
});
|
||||
}
|
||||
|
@@ -1,8 +1,16 @@
|
||||
import { customElement } from "lit/decorators";
|
||||
import { HaLogicalCondition } from "./ha-automation-condition-logical";
|
||||
import { LogicalCondition } from "../../../../../data/automation";
|
||||
|
||||
@customElement("ha-automation-condition-and")
|
||||
export class HaAndCondition extends HaLogicalCondition {}
|
||||
export class HaAndCondition extends HaLogicalCondition {
|
||||
public static get defaultConfig(): LogicalCondition {
|
||||
return {
|
||||
condition: "and",
|
||||
conditions: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
|
@@ -36,8 +36,9 @@ export class HaDeviceCondition extends LitElement {
|
||||
|
||||
private _origCondition?: DeviceCondition;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): DeviceCondition {
|
||||
return {
|
||||
condition: "device",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
entity_id: "",
|
||||
|
@@ -7,7 +7,10 @@ import "../ha-automation-condition";
|
||||
import type { ConditionElement } from "../ha-automation-condition-row";
|
||||
|
||||
@customElement("ha-automation-condition-logical")
|
||||
export class HaLogicalCondition extends LitElement implements ConditionElement {
|
||||
export abstract class HaLogicalCondition
|
||||
extends LitElement
|
||||
implements ConditionElement
|
||||
{
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public condition!: LogicalCondition;
|
||||
@@ -16,12 +19,6 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
||||
|
||||
@property({ attribute: false }) public path?: ItemPath;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return {
|
||||
conditions: [],
|
||||
};
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
<ha-automation-condition
|
||||
|
@@ -1,8 +1,16 @@
|
||||
import { customElement } from "lit/decorators";
|
||||
import { HaLogicalCondition } from "./ha-automation-condition-logical";
|
||||
import { LogicalCondition } from "../../../../../data/automation";
|
||||
|
||||
@customElement("ha-automation-condition-not")
|
||||
export class HaNotCondition extends HaLogicalCondition {}
|
||||
export class HaNotCondition extends HaLogicalCondition {
|
||||
public static get defaultConfig(): LogicalCondition {
|
||||
return {
|
||||
condition: "not",
|
||||
conditions: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
|
@@ -20,8 +20,9 @@ export default class HaNumericStateCondition extends LitElement {
|
||||
|
||||
@state() private _inputBelowIsEntity?: boolean;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): NumericStateCondition {
|
||||
return {
|
||||
condition: "numeric_state",
|
||||
entity_id: "",
|
||||
};
|
||||
}
|
||||
|
@@ -1,8 +1,16 @@
|
||||
import { customElement } from "lit/decorators";
|
||||
import { HaLogicalCondition } from "./ha-automation-condition-logical";
|
||||
import { LogicalCondition } from "../../../../../data/automation";
|
||||
|
||||
@customElement("ha-automation-condition-or")
|
||||
export class HaOrCondition extends HaLogicalCondition {}
|
||||
export class HaOrCondition extends HaLogicalCondition {
|
||||
public static get defaultConfig(): LogicalCondition {
|
||||
return {
|
||||
condition: "or",
|
||||
conditions: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
|
@@ -86,8 +86,8 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return { entity_id: "", state: "" };
|
||||
public static get defaultConfig(): StateCondition {
|
||||
return { condition: "state", entity_id: "", state: "" };
|
||||
}
|
||||
|
||||
public shouldUpdate(changedProperties: PropertyValues) {
|
||||
|
@@ -17,8 +17,8 @@ export class HaSunCondition extends LitElement implements ConditionElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return {};
|
||||
public static get defaultConfig(): SunCondition {
|
||||
return { condition: "sun" };
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
|
@@ -13,8 +13,8 @@ export class HaTemplateCondition extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return { value_template: "" };
|
||||
public static get defaultConfig(): TemplateCondition {
|
||||
return { condition: "template", value_template: "" };
|
||||
}
|
||||
|
||||
protected render() {
|
||||
|
@@ -25,8 +25,8 @@ export class HaTimeCondition extends LitElement implements ConditionElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return {};
|
||||
public static get defaultConfig(): TimeCondition {
|
||||
return { condition: "time" };
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
|
@@ -27,8 +27,9 @@ export class HaTriggerCondition extends LitElement {
|
||||
|
||||
private _unsub?: UnsubscribeFunc;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): TriggerCondition {
|
||||
return {
|
||||
condition: "trigger",
|
||||
id: "",
|
||||
};
|
||||
}
|
||||
|
@@ -21,8 +21,9 @@ export class HaZoneCondition extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): ZoneCondition {
|
||||
return {
|
||||
condition: "zone",
|
||||
entity_id: "",
|
||||
zone: "",
|
||||
};
|
||||
|
@@ -143,10 +143,9 @@ export default class HaAutomationTrigger extends LitElement {
|
||||
const elClass = customElements.get(
|
||||
`ha-automation-trigger-${platform}`
|
||||
) as CustomElementConstructor & {
|
||||
defaultConfig: Omit<Trigger, "platform">;
|
||||
defaultConfig: Trigger;
|
||||
};
|
||||
triggers = this.triggers.concat({
|
||||
platform: platform as any,
|
||||
...elClass.defaultConfig,
|
||||
});
|
||||
}
|
||||
|
@@ -69,10 +69,12 @@ export class HaCalendarTrigger extends LitElement implements TriggerElement {
|
||||
] as const
|
||||
);
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): CalendarTrigger {
|
||||
return {
|
||||
platform: "calendar",
|
||||
entity_id: "",
|
||||
event: "start" as CalendarTrigger["event"],
|
||||
offset: 0,
|
||||
offset: "0",
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -25,8 +25,8 @@ export class HaConversationTrigger
|
||||
|
||||
@query("#option_input", true) private _optionInput?: HaTextField;
|
||||
|
||||
public static get defaultConfig(): Omit<ConversationTrigger, "platform"> {
|
||||
return { command: "" };
|
||||
public static get defaultConfig(): ConversationTrigger {
|
||||
return { platform: "conversation", command: "" };
|
||||
}
|
||||
|
||||
protected render() {
|
||||
|
@@ -38,8 +38,9 @@ export class HaDeviceTrigger extends LitElement {
|
||||
|
||||
private _origTrigger?: DeviceTrigger;
|
||||
|
||||
public static get defaultConfig() {
|
||||
public static get defaultConfig(): DeviceTrigger {
|
||||
return {
|
||||
platform: "device",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
entity_id: "",
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user