mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-17 23:10:44 +00:00
Compare commits
45 Commits
calendar-s
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89796e425a | ||
|
|
9c42c8bbc4 | ||
|
|
616237caee | ||
|
|
2d36a0d37f | ||
|
|
1ec432a20f | ||
|
|
afd91b2261 | ||
|
|
cdfb7f914f | ||
|
|
33b0897522 | ||
|
|
5f0cf1b522 | ||
|
|
afb2ad95a4 | ||
|
|
27beab3133 | ||
|
|
435c82489b | ||
|
|
3ba6bf272e | ||
|
|
eec99b2fa3 | ||
|
|
d23e45e410 | ||
|
|
3c82d12609 | ||
|
|
15d67997e7 | ||
|
|
a6dfcb3100 | ||
|
|
26c2369228 | ||
|
|
2eed446492 | ||
|
|
7ebdeab6b2 | ||
|
|
0c35278f51 | ||
|
|
561122f03d | ||
|
|
95311be034 | ||
|
|
1eda44a102 | ||
|
|
d76781eb91 | ||
|
|
82d44e051f | ||
|
|
fdc9f5a3b7 | ||
|
|
ee6c82aba9 | ||
|
|
11d3f5c2ba | ||
|
|
feb68ce373 | ||
|
|
7f9a9de157 | ||
|
|
8e1b6a3d3b | ||
|
|
6e6e5a53e2 | ||
|
|
0408734ec5 | ||
|
|
317519fc08 | ||
|
|
843d79eab4 | ||
|
|
165a757f06 | ||
|
|
ea8b730142 | ||
|
|
e88c97d625 | ||
|
|
7560988b76 | ||
|
|
eecd8077b6 | ||
|
|
cbab5c3f7b | ||
|
|
a5d27c8bb8 | ||
|
|
a6a340b5db |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -36,14 +36,14 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
uses: github/codeql-action/init@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
uses: github/codeql-action/autobuild@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -57,4 +57,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
uses: github/codeql-action/analyze@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
|
||||
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@feb19ddc698445db27401f1490f6ac182da0816f # v3.2.0
|
||||
uses: relative-ci/agent-action@8504826a02078b05756e4c07e380023cc2c4274a # v3.1.0
|
||||
with:
|
||||
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
||||
token: ${{ github.token }}
|
||||
|
||||
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
@@ -55,7 +55,7 @@ jobs:
|
||||
script/release
|
||||
|
||||
- name: Upload release assets
|
||||
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
||||
with:
|
||||
files: |
|
||||
dist/*.whl
|
||||
@@ -108,7 +108,7 @@ jobs:
|
||||
- name: Tar folder
|
||||
run: tar -czf landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz -C landing-page/dist .
|
||||
- name: Upload release asset
|
||||
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
||||
with:
|
||||
files: landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz
|
||||
|
||||
@@ -137,6 +137,6 @@ jobs:
|
||||
- name: Tar folder
|
||||
run: tar -czf hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz -C hassio/build .
|
||||
- name: Upload release asset
|
||||
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
||||
with:
|
||||
files: hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz
|
||||
|
||||
@@ -18,16 +18,16 @@ module.exports.sourceMapURL = () => {
|
||||
module.exports.ignorePackages = () => [];
|
||||
|
||||
// Files from NPM packages that we should replace with empty file
|
||||
module.exports.emptyPackages = ({ isHassioBuild, isLandingPageBuild }) =>
|
||||
module.exports.emptyPackages = ({ isHassioBuild }) =>
|
||||
[
|
||||
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
|
||||
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
|
||||
// Icons in supervisor conflict with icons in HA so we don't load.
|
||||
(isHassioBuild || isLandingPageBuild) &&
|
||||
isHassioBuild &&
|
||||
require.resolve(
|
||||
path.resolve(paths.root_dir, "src/components/ha-icon.ts")
|
||||
),
|
||||
(isHassioBuild || isLandingPageBuild) &&
|
||||
isHassioBuild &&
|
||||
require.resolve(
|
||||
path.resolve(paths.root_dir, "src/components/ha-icon-picker.ts")
|
||||
),
|
||||
@@ -337,7 +337,6 @@ module.exports.config = {
|
||||
publicPath: publicPath(latestBuild),
|
||||
isProdBuild,
|
||||
latestBuild,
|
||||
isLandingPageBuild: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -41,7 +41,6 @@ const createRspackConfig = ({
|
||||
isStatsBuild,
|
||||
isTestBuild,
|
||||
isHassioBuild,
|
||||
isLandingPageBuild,
|
||||
dontHash,
|
||||
}) => {
|
||||
if (!dontHash) {
|
||||
@@ -169,9 +168,7 @@ const createRspackConfig = ({
|
||||
},
|
||||
}),
|
||||
new rspack.NormalModuleReplacementPlugin(
|
||||
new RegExp(
|
||||
bundle.emptyPackages({ isHassioBuild, isLandingPageBuild }).join("|")
|
||||
),
|
||||
new RegExp(bundle.emptyPackages({ isHassioBuild }).join("|")),
|
||||
path.resolve(paths.root_dir, "src/util/empty.js")
|
||||
),
|
||||
!isProdBuild && new LogStartCompilePlugin(),
|
||||
|
||||
38
package.json
38
package.json
@@ -52,7 +52,7 @@
|
||||
"@fullcalendar/list": "6.1.19",
|
||||
"@fullcalendar/luxon3": "6.1.19",
|
||||
"@fullcalendar/timegrid": "6.1.19",
|
||||
"@home-assistant/webawesome": "3.0.0-beta.6.ha.7",
|
||||
"@home-assistant/webawesome": "3.0.0-beta.6.ha.6",
|
||||
"@lezer/highlight": "1.2.3",
|
||||
"@lit-labs/motion": "1.0.9",
|
||||
"@lit-labs/observers": "2.0.6",
|
||||
@@ -81,7 +81,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.4.1",
|
||||
"@material/web": "2.4.0",
|
||||
"@mdi/js": "7.4.47",
|
||||
"@mdi/svg": "7.4.47",
|
||||
"@replit/codemirror-indentation-markers": "6.5.3",
|
||||
@@ -89,8 +89,8 @@
|
||||
"@thomasloven/round-slider": "0.6.0",
|
||||
"@tsparticles/engine": "3.9.1",
|
||||
"@tsparticles/preset-links": "3.2.0",
|
||||
"@vaadin/combo-box": "24.9.5",
|
||||
"@vaadin/vaadin-themable-mixin": "24.9.5",
|
||||
"@vaadin/combo-box": "24.9.2",
|
||||
"@vaadin/vaadin-themable-mixin": "24.9.2",
|
||||
"@vibrant/color": "4.0.0",
|
||||
"@vue/web-component-wrapper": "1.3.0",
|
||||
"@webcomponents/scoped-custom-element-registry": "0.0.10",
|
||||
@@ -111,7 +111,7 @@
|
||||
"fuse.js": "7.1.0",
|
||||
"google-timezones-json": "1.2.0",
|
||||
"gulp-zopfli-green": "6.0.2",
|
||||
"hls.js": "1.6.14",
|
||||
"hls.js": "1.6.13",
|
||||
"home-assistant-js-websocket": "9.5.0",
|
||||
"idb-keyval": "6.2.2",
|
||||
"intl-messageformat": "10.7.18",
|
||||
@@ -122,7 +122,7 @@
|
||||
"lit": "3.3.1",
|
||||
"lit-html": "3.3.1",
|
||||
"luxon": "3.7.2",
|
||||
"marked": "16.4.2",
|
||||
"marked": "16.4.1",
|
||||
"memoize-one": "6.0.0",
|
||||
"node-vibrant": "4.0.3",
|
||||
"object-hash": "3.0.0",
|
||||
@@ -152,13 +152,13 @@
|
||||
"@babel/helper-define-polyfill-provider": "0.6.5",
|
||||
"@babel/plugin-transform-runtime": "7.28.5",
|
||||
"@babel/preset-env": "7.28.5",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.21.6",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.21.5",
|
||||
"@lokalise/node-api": "15.3.1",
|
||||
"@octokit/auth-oauth-device": "8.0.3",
|
||||
"@octokit/plugin-retry": "8.0.3",
|
||||
"@octokit/rest": "22.0.1",
|
||||
"@rsdoctor/rspack-plugin": "1.3.8",
|
||||
"@rspack/core": "1.6.1",
|
||||
"@octokit/auth-oauth-device": "8.0.2",
|
||||
"@octokit/plugin-retry": "8.0.2",
|
||||
"@octokit/rest": "22.0.0",
|
||||
"@rsdoctor/rspack-plugin": "1.3.4",
|
||||
"@rspack/core": "1.5.8",
|
||||
"@rspack/dev-server": "1.1.4",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||
"@types/chromecast-caf-receiver": "6.0.22",
|
||||
@@ -178,12 +178,12 @@
|
||||
"@types/tar": "6.1.13",
|
||||
"@types/ua-parser-js": "0.7.39",
|
||||
"@types/webspeechapi": "0.0.29",
|
||||
"@vitest/coverage-v8": "4.0.8",
|
||||
"@vitest/coverage-v8": "4.0.3",
|
||||
"babel-loader": "10.0.0",
|
||||
"babel-plugin-template-html-minifier": "4.1.0",
|
||||
"browserslist-useragent-regexp": "4.1.3",
|
||||
"del": "8.0.1",
|
||||
"eslint": "9.39.1",
|
||||
"eslint": "9.38.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-import-resolver-webpack": "0.13.10",
|
||||
@@ -201,7 +201,7 @@
|
||||
"gulp-rename": "2.1.0",
|
||||
"html-minifier-terser": "7.2.0",
|
||||
"husky": "9.1.7",
|
||||
"jsdom": "27.1.0",
|
||||
"jsdom": "27.0.1",
|
||||
"jszip": "3.10.1",
|
||||
"lint-staged": "16.2.6",
|
||||
"lit-analyzer": "2.0.3",
|
||||
@@ -213,13 +213,13 @@
|
||||
"rspack-manifest-plugin": "5.1.0",
|
||||
"serve": "14.2.5",
|
||||
"sinon": "21.0.0",
|
||||
"tar": "7.5.2",
|
||||
"tar": "7.5.1",
|
||||
"terser-webpack-plugin": "5.3.14",
|
||||
"ts-lit-plugin": "2.0.2",
|
||||
"typescript": "5.9.3",
|
||||
"typescript-eslint": "8.46.3",
|
||||
"typescript-eslint": "8.46.2",
|
||||
"vite-tsconfig-paths": "5.1.4",
|
||||
"vitest": "4.0.8",
|
||||
"vitest": "4.0.3",
|
||||
"webpack-stats-plugin": "1.1.3",
|
||||
"webpackbar": "7.0.0",
|
||||
"workbox-build": "patch:workbox-build@npm%3A7.1.1#~/.yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch"
|
||||
@@ -231,7 +231,7 @@
|
||||
"clean-css": "5.3.3",
|
||||
"@lit/reactive-element": "2.1.1",
|
||||
"@fullcalendar/daygrid": "6.1.19",
|
||||
"globals": "16.5.0",
|
||||
"globals": "16.4.0",
|
||||
"tslib": "2.8.1",
|
||||
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch"
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20251029.0"
|
||||
version = "20251105.0"
|
||||
license = "Apache-2.0"
|
||||
license-files = ["LICENSE*"]
|
||||
description = "The Home Assistant frontend"
|
||||
|
||||
@@ -119,8 +119,8 @@ type Thresholds = Record<
|
||||
>;
|
||||
|
||||
export const DEFAULT_THRESHOLDS: Thresholds = {
|
||||
second: 59, // seconds to minute
|
||||
minute: 59, // minutes to hour
|
||||
second: 45, // seconds to minute
|
||||
minute: 45, // minutes to hour
|
||||
hour: 22, // hour to day
|
||||
day: 5, // day to week
|
||||
week: 4, // week to months
|
||||
|
||||
@@ -6,8 +6,7 @@ export function downSampleLineData<
|
||||
data: T[] | undefined,
|
||||
maxDetails: number,
|
||||
minX?: number,
|
||||
maxX?: number,
|
||||
useMean = false
|
||||
maxX?: number
|
||||
): T[] {
|
||||
if (!data) {
|
||||
return [];
|
||||
@@ -18,13 +17,15 @@ export function downSampleLineData<
|
||||
const min = minX ?? getPointData(data[0]!)[0];
|
||||
const max = maxX ?? getPointData(data[data.length - 1]!)[0];
|
||||
const step = Math.ceil((max - min) / Math.floor(maxDetails));
|
||||
|
||||
// Group points into frames
|
||||
const frames = new Map<
|
||||
number,
|
||||
{ point: (typeof data)[number]; x: number; y: number }[]
|
||||
{
|
||||
min: { point: (typeof data)[number]; x: number; y: number };
|
||||
max: { point: (typeof data)[number]; x: number; y: number };
|
||||
}
|
||||
>();
|
||||
|
||||
// Group points into frames
|
||||
for (const point of data) {
|
||||
const pointData = getPointData(point);
|
||||
if (!Array.isArray(pointData)) continue;
|
||||
@@ -35,53 +36,28 @@ export function downSampleLineData<
|
||||
const frameIndex = Math.floor((x - min) / step);
|
||||
const frame = frames.get(frameIndex);
|
||||
if (!frame) {
|
||||
frames.set(frameIndex, [{ point, x, y }]);
|
||||
frames.set(frameIndex, { min: { point, x, y }, max: { point, x, y } });
|
||||
} else {
|
||||
frame.push({ point, x, y });
|
||||
if (frame.min.y > y) {
|
||||
frame.min = { point, x, y };
|
||||
}
|
||||
if (frame.max.y < y) {
|
||||
frame.max = { point, x, y };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert frames back to points
|
||||
const result: T[] = [];
|
||||
|
||||
if (useMean) {
|
||||
// Use mean values for each frame
|
||||
for (const [_i, framePoints] of frames) {
|
||||
const sumY = framePoints.reduce((acc, p) => acc + p.y, 0);
|
||||
const meanY = sumY / framePoints.length;
|
||||
const sumX = framePoints.reduce((acc, p) => acc + p.x, 0);
|
||||
const meanX = sumX / framePoints.length;
|
||||
|
||||
const firstPoint = framePoints[0].point;
|
||||
const pointData = getPointData(firstPoint);
|
||||
const meanPoint = (
|
||||
Array.isArray(pointData) ? [meanX, meanY] : { value: [meanX, meanY] }
|
||||
) as T;
|
||||
result.push(meanPoint);
|
||||
for (const [_i, frame] of frames) {
|
||||
// Use min/max points to preserve visual accuracy
|
||||
// The order of the data must be preserved so max may be before min
|
||||
if (frame.min.x > frame.max.x) {
|
||||
result.push(frame.max.point);
|
||||
}
|
||||
} else {
|
||||
// Use min/max values for each frame
|
||||
for (const [_i, framePoints] of frames) {
|
||||
let minPoint = framePoints[0];
|
||||
let maxPoint = framePoints[0];
|
||||
|
||||
for (const p of framePoints) {
|
||||
if (p.y < minPoint.y) {
|
||||
minPoint = p;
|
||||
}
|
||||
if (p.y > maxPoint.y) {
|
||||
maxPoint = p;
|
||||
}
|
||||
}
|
||||
|
||||
// The order of the data must be preserved so max may be before min
|
||||
if (minPoint.x > maxPoint.x) {
|
||||
result.push(maxPoint.point);
|
||||
}
|
||||
result.push(minPoint.point);
|
||||
if (minPoint.x < maxPoint.x) {
|
||||
result.push(maxPoint.point);
|
||||
}
|
||||
result.push(frame.min.point);
|
||||
if (frame.min.x < frame.max.x) {
|
||||
result.push(frame.max.point);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ export const MIN_TIME_BETWEEN_UPDATES = 60 * 5 * 1000;
|
||||
const LEGEND_OVERFLOW_LIMIT = 10;
|
||||
const LEGEND_OVERFLOW_LIMIT_MOBILE = 6;
|
||||
const DOUBLE_TAP_TIME = 300;
|
||||
const RESIZE_ANIMATION_DURATION = 250;
|
||||
|
||||
export type CustomLegendOption = ECOption["legend"] & {
|
||||
type: "custom";
|
||||
@@ -90,8 +91,6 @@ export class HaChartBase extends LitElement {
|
||||
|
||||
private _shouldResizeChart = false;
|
||||
|
||||
private _resizeAnimationDuration?: number;
|
||||
|
||||
// @ts-ignore
|
||||
private _resizeController = new ResizeController(this, {
|
||||
callback: () => {
|
||||
@@ -215,7 +214,6 @@ export class HaChartBase extends LitElement {
|
||||
) {
|
||||
// custom legend changes may require a resize to layout properly
|
||||
this._shouldResizeChart = true;
|
||||
this._resizeAnimationDuration = 250;
|
||||
}
|
||||
} else if (this._isTouchDevice && changedProps.has("_isZoomed")) {
|
||||
chartOptions.dataZoom = this._getDataZoomConfig();
|
||||
@@ -427,7 +425,6 @@ export class HaChartBase extends LitElement {
|
||||
...axis.axisPointer?.handle,
|
||||
show: true,
|
||||
},
|
||||
label: { show: false },
|
||||
},
|
||||
}
|
||||
: axis
|
||||
@@ -628,10 +625,6 @@ export class HaChartBase extends LitElement {
|
||||
}
|
||||
|
||||
private _createTheme(style: CSSStyleDeclaration) {
|
||||
const textBorderColor =
|
||||
style.getPropertyValue("--ha-card-background") ||
|
||||
style.getPropertyValue("--card-background-color");
|
||||
const textBorderWidth = 2;
|
||||
return {
|
||||
color: getAllGraphColors(style),
|
||||
backgroundColor: "transparent",
|
||||
@@ -655,22 +648,22 @@ export class HaChartBase extends LitElement {
|
||||
graph: {
|
||||
label: {
|
||||
color: style.getPropertyValue("--primary-text-color"),
|
||||
textBorderColor,
|
||||
textBorderWidth,
|
||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
||||
textBorderWidth: 2,
|
||||
},
|
||||
},
|
||||
pie: {
|
||||
label: {
|
||||
color: style.getPropertyValue("--primary-text-color"),
|
||||
textBorderColor,
|
||||
textBorderWidth,
|
||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
||||
textBorderWidth: 2,
|
||||
},
|
||||
},
|
||||
sankey: {
|
||||
label: {
|
||||
color: style.getPropertyValue("--primary-text-color"),
|
||||
textBorderColor,
|
||||
textBorderWidth,
|
||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
||||
textBorderWidth: 2,
|
||||
},
|
||||
},
|
||||
categoryAxis: {
|
||||
@@ -984,14 +977,11 @@ export class HaChartBase extends LitElement {
|
||||
private _handleChartRenderFinished = () => {
|
||||
if (this._shouldResizeChart) {
|
||||
this.chart?.resize({
|
||||
animation:
|
||||
this._reducedMotion ||
|
||||
typeof this._resizeAnimationDuration !== "number"
|
||||
? undefined
|
||||
: { duration: this._resizeAnimationDuration },
|
||||
animation: this._reducedMotion
|
||||
? undefined
|
||||
: { duration: RESIZE_ANIMATION_DURATION },
|
||||
});
|
||||
this._shouldResizeChart = false;
|
||||
this._resizeAnimationDuration = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@ import type { EChartsType } from "echarts/core";
|
||||
import type { GraphSeriesOption } from "echarts/charts";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state, query } from "lit/decorators";
|
||||
import type {
|
||||
CallbackDataParams,
|
||||
TopLevelFormatterParams,
|
||||
} from "echarts/types/dist/shared";
|
||||
import type { TopLevelFormatterParams } from "echarts/types/dist/shared";
|
||||
import { mdiFormatTextVariant, mdiGoogleCirclesGroup } from "@mdi/js";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { listenMediaQuery } from "../../common/dom/media_query";
|
||||
@@ -19,7 +16,6 @@ import { deepEqual } from "../../common/util/deep-equal";
|
||||
export interface NetworkNode {
|
||||
id: string;
|
||||
name?: string;
|
||||
context?: string;
|
||||
category?: number;
|
||||
value?: number;
|
||||
symbolSize?: number;
|
||||
@@ -192,25 +188,6 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
||||
label: {
|
||||
show: showLabels,
|
||||
position: "right",
|
||||
formatter: (params: CallbackDataParams) => {
|
||||
const node = params.data as NetworkNode;
|
||||
if (node.context) {
|
||||
return `{primary|${node.name ?? ""}}\n{secondary|${node.context}}`;
|
||||
}
|
||||
return node.name ?? "";
|
||||
},
|
||||
rich: {
|
||||
primary: {
|
||||
fontSize: 12,
|
||||
},
|
||||
secondary: {
|
||||
fontSize: 12,
|
||||
color: getComputedStyle(document.body).getPropertyValue(
|
||||
"--secondary-text-color"
|
||||
),
|
||||
lineHeight: 16,
|
||||
},
|
||||
},
|
||||
},
|
||||
emphasis: {
|
||||
focus: isMobile ? "none" : "adjacency",
|
||||
@@ -248,7 +225,6 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
||||
({
|
||||
id: node.id,
|
||||
name: node.name,
|
||||
context: node.context,
|
||||
category: node.category,
|
||||
value: node.value,
|
||||
symbolSize: node.symbolSize || 30,
|
||||
|
||||
@@ -62,7 +62,6 @@ class HaDataTableLabels extends LitElement {
|
||||
@click=${clickAction ? this._labelClicked : undefined}
|
||||
@keydown=${clickAction ? this._labelClicked : undefined}
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
${label?.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
|
||||
@@ -197,6 +197,9 @@ export class HaDevicePicker extends LitElement {
|
||||
const placeholder =
|
||||
this.placeholder ??
|
||||
this.hass.localize("ui.components.device-picker.placeholder");
|
||||
const notFoundLabel = this.hass.localize(
|
||||
"ui.components.device-picker.no_match"
|
||||
);
|
||||
|
||||
const valueRenderer = this._valueRenderer(this._configEntryLookup);
|
||||
|
||||
@@ -206,10 +209,7 @@ export class HaDevicePicker extends LitElement {
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.searchLabel=${this.searchLabel}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.device-picker.no_devices"
|
||||
)}
|
||||
.notFoundLabel=${notFoundLabel}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
.rowRenderer=${this._rowRenderer}
|
||||
@@ -233,11 +233,6 @@ export class HaDevicePicker extends LitElement {
|
||||
this.value = value;
|
||||
fireEvent(this, "value-changed", { value });
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.device-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -269,6 +269,9 @@ export class HaEntityPicker extends LitElement {
|
||||
const placeholder =
|
||||
this.placeholder ??
|
||||
this.hass.localize("ui.components.entity.entity-picker.placeholder");
|
||||
const notFoundLabel = this.hass.localize(
|
||||
"ui.components.entity.entity-picker.no_match"
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-generic-picker
|
||||
@@ -279,7 +282,7 @@ export class HaEntityPicker extends LitElement {
|
||||
.label=${this.label}
|
||||
.helper=${this.helper}
|
||||
.searchLabel=${this.searchLabel}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.notFoundLabel=${notFoundLabel}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.addButton ? undefined : this.value}
|
||||
.rowRenderer=${this._rowRenderer}
|
||||
@@ -353,11 +356,6 @@ export class HaEntityPicker extends LitElement {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
fireEvent(this, "change");
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.entity.entity-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -271,6 +271,7 @@ export class HaStatisticPicker extends LitElement {
|
||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||
.filter(Boolean)
|
||||
.join(isRTL ? " ◂ " : " ▸ ");
|
||||
const a11yLabel = [deviceName, entityName].filter(Boolean).join(" - ");
|
||||
|
||||
const sortingPrefix = `${TYPE_ORDER.indexOf("entity")}`;
|
||||
output.push({
|
||||
@@ -278,6 +279,7 @@ export class HaStatisticPicker extends LitElement {
|
||||
statistic_id: id,
|
||||
primary,
|
||||
secondary,
|
||||
a11y_label: a11yLabel,
|
||||
stateObj: stateObj,
|
||||
type: "entity",
|
||||
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
||||
@@ -456,6 +458,9 @@ export class HaStatisticPicker extends LitElement {
|
||||
const placeholder =
|
||||
this.placeholder ??
|
||||
this.hass.localize("ui.components.statistic-picker.placeholder");
|
||||
const notFoundLabel = this.hass.localize(
|
||||
"ui.components.statistic-picker.no_match"
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-generic-picker
|
||||
@@ -463,10 +468,7 @@ export class HaStatisticPicker extends LitElement {
|
||||
.autofocus=${this.autofocus}
|
||||
.allowCustomValue=${this.allowCustomEntity}
|
||||
.label=${this.label}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.statistic-picker.no_statistics"
|
||||
)}
|
||||
.notFoundLabel=${notFoundLabel}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
.rowRenderer=${this._rowRenderer}
|
||||
@@ -519,11 +521,6 @@ export class HaStatisticPicker extends LitElement {
|
||||
await this.updateComplete;
|
||||
await this._picker?.open();
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.statistic-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -87,8 +87,6 @@ export class HaAreaPicker extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public required = false;
|
||||
|
||||
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||
|
||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||
|
||||
public async open() {
|
||||
@@ -369,16 +367,14 @@ export class HaAreaPicker extends LitElement {
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.helper=${this.helper}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize("ui.components.area-picker.no_areas")}
|
||||
.disabled=${this.disabled}
|
||||
.required=${this.required}
|
||||
.notFoundLabel=${this.hass.localize(
|
||||
"ui.components.area-picker.no_match"
|
||||
)}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
.getItems=${this._getItems}
|
||||
.getAdditionalItems=${this._getAdditionalItems}
|
||||
.valueRenderer=${valueRenderer}
|
||||
.addButtonLabel=${this.addButtonLabel}
|
||||
@value-changed=${this._valueChanged}
|
||||
>
|
||||
</ha-generic-picker>
|
||||
@@ -426,11 +422,6 @@ export class HaAreaPicker extends LitElement {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
fireEvent(this, "change");
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.area-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -109,10 +109,7 @@ export class HaFilterLabels extends SubscribeMixin(LitElement) {
|
||||
.selected=${(this.value || []).includes(label.label_id)}
|
||||
hasMeta
|
||||
>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon
|
||||
slot="icon"
|
||||
|
||||
@@ -383,9 +383,8 @@ export class HaFloorPicker extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.floor-picker.no_floors"
|
||||
.notFoundLabel=${this.hass.localize(
|
||||
"ui.components.floor-picker.no_match"
|
||||
)}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
@@ -445,11 +444,6 @@ export class HaFloorPicker extends LitElement {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
fireEvent(this, "change");
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.floor-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { HomeAssistant } from "../types";
|
||||
import "./ha-bottom-sheet";
|
||||
import "./ha-button";
|
||||
import "./ha-combo-box-item";
|
||||
import "./ha-icon-button";
|
||||
import "./ha-input-helper-text";
|
||||
import "./ha-picker-combo-box";
|
||||
import type {
|
||||
@@ -25,6 +26,9 @@ import "./ha-svg-icon";
|
||||
export class HaGenericPicker extends LitElement {
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
|
||||
// eslint-disable-next-line lit/no-native-attributes
|
||||
@property({ type: Boolean }) public autofocus = false;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
@property({ type: Boolean }) public required = false;
|
||||
@@ -46,11 +50,8 @@ export class HaGenericPicker extends LitElement {
|
||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||
public hideClearIcon = false;
|
||||
|
||||
@property({ attribute: false })
|
||||
public getItems?: (
|
||||
searchString?: string,
|
||||
section?: string
|
||||
) => (PickerComboBoxItem | string)[];
|
||||
@property({ attribute: false, type: Array })
|
||||
public getItems?: () => PickerComboBoxItem[];
|
||||
|
||||
@property({ attribute: false, type: Array })
|
||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||
@@ -64,11 +65,8 @@ export class HaGenericPicker extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||
|
||||
@property({ attribute: false })
|
||||
public notFoundLabel?: string | ((search: string) => string);
|
||||
|
||||
@property({ attribute: "empty-label" })
|
||||
public emptyLabel?: string;
|
||||
@property({ attribute: "not-found-label", type: String })
|
||||
public notFoundLabel?: string;
|
||||
|
||||
@property({ attribute: "popover-placement" })
|
||||
public popoverPlacement:
|
||||
@@ -88,25 +86,6 @@ export class HaGenericPicker extends LitElement {
|
||||
/** If set picker shows an add button instead of textbox when value isn't set */
|
||||
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||
|
||||
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||
@property({ attribute: false }) public sections?: (
|
||||
| {
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
| "separator"
|
||||
)[];
|
||||
|
||||
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||
firstIndex: number;
|
||||
lastIndex: number;
|
||||
firstItem: PickerComboBoxItem | string;
|
||||
secondItem: PickerComboBoxItem | string;
|
||||
itemsCount: number;
|
||||
}) => string | undefined;
|
||||
|
||||
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||
|
||||
@query(".container") private _containerElement?: HTMLDivElement;
|
||||
|
||||
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
||||
@@ -119,11 +98,6 @@ export class HaGenericPicker extends LitElement {
|
||||
|
||||
@state() private _openedNarrow = false;
|
||||
|
||||
static shadowRootOptions = {
|
||||
...LitElement.shadowRootOptions,
|
||||
delegatesFocus: true,
|
||||
};
|
||||
|
||||
private _narrow = false;
|
||||
|
||||
// helper to set new value after closing picker, to avoid flicker
|
||||
@@ -216,19 +190,16 @@ export class HaGenericPicker extends LitElement {
|
||||
<ha-picker-combo-box
|
||||
.hass=${this.hass}
|
||||
.allowCustomValue=${this.allowCustomValue}
|
||||
.label=${this.searchLabel}
|
||||
.label=${this.searchLabel ??
|
||||
(this.hass?.localize("ui.common.search") || "Search")}
|
||||
.value=${this.value}
|
||||
@value-changed=${this._valueChanged}
|
||||
.rowRenderer=${this.rowRenderer}
|
||||
.notFoundLabel=${this.notFoundLabel}
|
||||
.emptyLabel=${this.emptyLabel}
|
||||
.getItems=${this.getItems}
|
||||
.getAdditionalItems=${this.getAdditionalItems}
|
||||
.searchFn=${this.searchFn}
|
||||
.mode=${dialogMode ? "dialog" : "popover"}
|
||||
.sections=${this.sections}
|
||||
.sectionTitleFunction=${this.sectionTitleFunction}
|
||||
.selectedSection=${this.selectedSection}
|
||||
></ha-picker-combo-box>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -224,9 +224,8 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
||||
.hass=${this.hass}
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.label-picker.no_labels"
|
||||
.notFoundLabel=${this.hass.localize(
|
||||
"ui.components.label-picker.no_match"
|
||||
)}
|
||||
.addButtonLabel=${this.hass.localize("ui.components.label-picker.add")}
|
||||
.placeholder=${placeholder}
|
||||
@@ -289,11 +288,6 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
||||
fireEvent(this, "change");
|
||||
}, 0);
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.label-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { uid } from "../common/util/uid";
|
||||
import "./ha-tooltip";
|
||||
|
||||
@customElement("ha-label")
|
||||
class HaLabel extends LitElement {
|
||||
@property({ type: Boolean, reflect: true }) dense = false;
|
||||
|
||||
@property({ attribute: "description" })
|
||||
public description?: string;
|
||||
|
||||
private _elementId = "label-" + uid();
|
||||
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<ha-tooltip
|
||||
.for=${this._elementId}
|
||||
.disabled=${!this.description?.trim()}
|
||||
>
|
||||
${this.description}
|
||||
</ha-tooltip>
|
||||
<div class="container" .id=${this._elementId}>
|
||||
<span class="content">
|
||||
<slot name="icon"></slot>
|
||||
<slot></slot>
|
||||
</span>
|
||||
</div>
|
||||
<span class="content">
|
||||
<slot name="icon"></slot>
|
||||
<slot></slot>
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -51,7 +36,9 @@ class HaLabel extends LitElement {
|
||||
font-weight: var(--ha-font-weight-medium);
|
||||
line-height: var(--ha-line-height-condensed);
|
||||
letter-spacing: 0.1px;
|
||||
vertical-align: middle;
|
||||
height: 32px;
|
||||
padding: 0 16px;
|
||||
border-radius: var(--ha-border-radius-xl);
|
||||
color: var(--ha-label-text-color);
|
||||
--mdc-icon-size: 12px;
|
||||
@@ -79,23 +66,14 @@ class HaLabel extends LitElement {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
span {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
:host([dense]) {
|
||||
height: 20px;
|
||||
border-radius: var(--ha-border-radius-md);
|
||||
}
|
||||
:host([dense]) .container {
|
||||
padding: 0 12px;
|
||||
border-radius: var(--ha-border-radius-md);
|
||||
}
|
||||
:host([dense]) ::slotted([slot="icon"]) {
|
||||
margin-right: 4px;
|
||||
|
||||
@@ -21,7 +21,6 @@ import "./chips/ha-input-chip";
|
||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||
import "./ha-label-picker";
|
||||
import type { HaLabelPicker } from "./ha-label-picker";
|
||||
import "./ha-tooltip";
|
||||
|
||||
@customElement("ha-labels-picker")
|
||||
export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
||||
@@ -143,17 +142,9 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
||||
const color = label?.color
|
||||
? computeCssColor(label.color)
|
||||
: undefined;
|
||||
const elementId = "label-" + label.label_id;
|
||||
return html`
|
||||
<ha-tooltip
|
||||
.for=${elementId}
|
||||
.disabled=${!label?.description?.trim()}
|
||||
>
|
||||
${label?.description}
|
||||
</ha-tooltip>
|
||||
<ha-input-chip
|
||||
.item=${label}
|
||||
.id=${elementId}
|
||||
@remove=${this._removeItem}
|
||||
@click=${this._openDetail}
|
||||
.disabled=${this.disabled}
|
||||
|
||||
@@ -125,10 +125,9 @@ export class HaLanguagePicker extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.autofocus=${this.autofocus}
|
||||
popover-placement="bottom-end"
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass?.localize(
|
||||
"ui.components.language-picker.no_languages"
|
||||
) || "No languages available"}
|
||||
.notFoundLabel=${this.hass?.localize(
|
||||
"ui.components.language-picker.no_match"
|
||||
)}
|
||||
.placeholder=${this.label ??
|
||||
(this.hass?.localize("ui.components.language-picker.language") ||
|
||||
"Language")}
|
||||
@@ -173,15 +172,6 @@ export class HaLanguagePicker extends LitElement {
|
||||
this.value = ev.detail.value;
|
||||
fireEvent(this, "value-changed", { value: this.value });
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) => {
|
||||
const term = html`<b>‘${search}’</b>`;
|
||||
return this.hass
|
||||
? this.hass.localize("ui.components.language-picker.no_match", {
|
||||
term,
|
||||
})
|
||||
: html`No languages found for ${term}`;
|
||||
};
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { ListItemEl } from "@material/web/list/internal/listitem/list-item";
|
||||
import { styles } from "@material/web/list/internal/listitem/list-item-styles";
|
||||
import { css, html, nothing, type TemplateResult } from "lit";
|
||||
import { css } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import "./ha-ripple";
|
||||
|
||||
export const haMdListStyles = [
|
||||
styles,
|
||||
@@ -26,18 +25,6 @@ export const haMdListStyles = [
|
||||
@customElement("ha-md-list-item")
|
||||
export class HaMdListItem extends ListItemEl {
|
||||
static override styles = haMdListStyles;
|
||||
|
||||
protected renderRipple(): TemplateResult | typeof nothing {
|
||||
if (this.type === "text") {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`<ha-ripple
|
||||
part="ripple"
|
||||
for="item"
|
||||
?disabled=${this.disabled && this.type !== "link"}
|
||||
></ha-ripple>`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { LitVirtualizer } from "@lit-labs/virtualizer";
|
||||
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||
import { mdiMagnify, mdiMinusBoxOutline } from "@mdi/js";
|
||||
import { mdiMagnify } from "@mdi/js";
|
||||
import Fuse from "fuse.js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import {
|
||||
@@ -14,12 +14,11 @@ import memoizeOne from "memoize-one";
|
||||
import { tinykeys } from "tinykeys";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import { HaFuse } from "../resources/fuse";
|
||||
import { haStyleScrollbar } from "../resources/styles";
|
||||
import { loadVirtualizer } from "../resources/virtualizer";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import "./chips/ha-chip-set";
|
||||
import "./chips/ha-filter-chip";
|
||||
import "./ha-combo-box-item";
|
||||
import "./ha-icon";
|
||||
import "./ha-textfield";
|
||||
@@ -28,18 +27,28 @@ import type { HaTextField } from "./ha-textfield";
|
||||
export interface PickerComboBoxItem {
|
||||
id: string;
|
||||
primary: string;
|
||||
a11y_label?: string;
|
||||
secondary?: string;
|
||||
search_labels?: string[];
|
||||
sorting_label?: string;
|
||||
icon_path?: string;
|
||||
icon?: string;
|
||||
}
|
||||
const NO_ITEMS_AVAILABLE_ID = "___no_items_available___";
|
||||
|
||||
// Hack to force empty label to always display empty value by default in the search field
|
||||
export interface PickerComboBoxItemWithLabel extends PickerComboBoxItem {
|
||||
a11y_label: string;
|
||||
}
|
||||
|
||||
const NO_MATCHING_ITEMS_FOUND_ID = "___no_matching_items_found___";
|
||||
|
||||
const DEFAULT_ROW_RENDERER: RenderItemFunction<PickerComboBoxItem> = (
|
||||
item
|
||||
) => html`
|
||||
<ha-combo-box-item type="button" compact>
|
||||
<ha-combo-box-item
|
||||
.type=${item.id === NO_MATCHING_ITEMS_FOUND_ID ? "text" : "button"}
|
||||
compact
|
||||
>
|
||||
${item.icon
|
||||
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
||||
: item.icon_path
|
||||
@@ -78,11 +87,8 @@ export class HaPickerComboBox extends LitElement {
|
||||
|
||||
@state() private _listScrolled = false;
|
||||
|
||||
@property({ attribute: false })
|
||||
public getItems?: (
|
||||
searchString?: string,
|
||||
section?: string
|
||||
) => (PickerComboBoxItem | string)[];
|
||||
@property({ attribute: false, type: Array })
|
||||
public getItems?: () => PickerComboBoxItem[];
|
||||
|
||||
@property({ attribute: false, type: Array })
|
||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||
@@ -90,45 +96,21 @@ export class HaPickerComboBox extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public rowRenderer?: RenderItemFunction<PickerComboBoxItem>;
|
||||
|
||||
@property({ attribute: false })
|
||||
public notFoundLabel?: string | ((search: string) => string);
|
||||
|
||||
@property({ attribute: "empty-label" })
|
||||
public emptyLabel?: string;
|
||||
@property({ attribute: "not-found-label", type: String })
|
||||
public notFoundLabel?: string;
|
||||
|
||||
@property({ attribute: false })
|
||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||
|
||||
@property({ reflect: true }) public mode: "popover" | "dialog" = "popover";
|
||||
|
||||
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||
@property({ attribute: false }) public sections?: (
|
||||
| {
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
| "separator"
|
||||
)[];
|
||||
|
||||
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||
firstIndex: number;
|
||||
lastIndex: number;
|
||||
firstItem: PickerComboBoxItem | string;
|
||||
secondItem: PickerComboBoxItem | string;
|
||||
itemsCount: number;
|
||||
}) => string | undefined;
|
||||
|
||||
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||
|
||||
@query("lit-virtualizer") private _virtualizerElement?: LitVirtualizer;
|
||||
|
||||
@query("ha-textfield") private _searchFieldElement?: HaTextField;
|
||||
|
||||
@state() private _items: (PickerComboBoxItem | string)[] = [];
|
||||
@state() private _items: PickerComboBoxItemWithLabel[] = [];
|
||||
|
||||
@state() private _sectionTitle?: string;
|
||||
|
||||
private _allItems: (PickerComboBoxItem | string)[] = [];
|
||||
private _allItems: PickerComboBoxItemWithLabel[] = [];
|
||||
|
||||
private _selectedItemIndex = -1;
|
||||
|
||||
@@ -139,8 +121,6 @@ export class HaPickerComboBox extends LitElement {
|
||||
|
||||
private _removeKeyboardShortcuts?: () => void;
|
||||
|
||||
private _search = "";
|
||||
|
||||
protected firstUpdated() {
|
||||
this._registerKeyboardShortcuts();
|
||||
}
|
||||
@@ -165,142 +145,74 @@ export class HaPickerComboBox extends LitElement {
|
||||
"Search"}
|
||||
@input=${this._filterChanged}
|
||||
></ha-textfield>
|
||||
${this._renderSectionButtons()}
|
||||
${this.sections?.length
|
||||
? html`
|
||||
<div class="section-title-wrapper">
|
||||
<div
|
||||
class="section-title ${!this.selectedSection &&
|
||||
this._sectionTitle
|
||||
? "show"
|
||||
: ""}"
|
||||
>
|
||||
${this._sectionTitle}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
: nothing}
|
||||
<lit-virtualizer
|
||||
.keyFunction=${this._keyFunction}
|
||||
@scroll=${this._onScrollList}
|
||||
tabindex="0"
|
||||
scroller
|
||||
.items=${this._items}
|
||||
.renderItem=${this._renderItem}
|
||||
style="min-height: 36px;"
|
||||
class=${this._listScrolled ? "scrolled" : ""}
|
||||
@scroll=${this._onScrollList}
|
||||
@focus=${this._focusList}
|
||||
@visibilityChanged=${this._visibilityChanged}
|
||||
>
|
||||
</lit-virtualizer> `;
|
||||
}
|
||||
|
||||
private _renderSectionButtons() {
|
||||
if (!this.sections || this.sections.length === 0) {
|
||||
return nothing;
|
||||
}
|
||||
private _defaultNotFoundItem = memoizeOne(
|
||||
(
|
||||
label: this["notFoundLabel"],
|
||||
localize?: LocalizeFunc
|
||||
): PickerComboBoxItemWithLabel => ({
|
||||
id: NO_MATCHING_ITEMS_FOUND_ID,
|
||||
primary:
|
||||
label ||
|
||||
(localize && localize("ui.components.combo-box.no_match")) ||
|
||||
"No matching items found",
|
||||
icon_path: mdiMagnify,
|
||||
a11y_label:
|
||||
label ||
|
||||
(localize && localize("ui.components.combo-box.no_match")) ||
|
||||
"No matching items found",
|
||||
})
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-chip-set class="sections">
|
||||
${this.sections.map((section) =>
|
||||
section === "separator"
|
||||
? html`<div class="separator"></div>`
|
||||
: html`<ha-filter-chip
|
||||
@click=${this._toggleSection}
|
||||
.section-id=${section.id}
|
||||
.selected=${this.selectedSection === section.id}
|
||||
.label=${section.label}
|
||||
>
|
||||
</ha-filter-chip>`
|
||||
)}
|
||||
</ha-chip-set>
|
||||
`;
|
||||
}
|
||||
private _getAdditionalItems = (searchString?: string) => {
|
||||
const items = this.getAdditionalItems?.(searchString) || [];
|
||||
|
||||
@eventOptions({ passive: true })
|
||||
private _visibilityChanged(ev) {
|
||||
if (
|
||||
this._virtualizerElement &&
|
||||
this.sectionTitleFunction &&
|
||||
this.sections?.length
|
||||
) {
|
||||
const firstItem = this._virtualizerElement.items[ev.first];
|
||||
const secondItem = this._virtualizerElement.items[ev.first + 1];
|
||||
this._sectionTitle = this.sectionTitleFunction({
|
||||
firstIndex: ev.first,
|
||||
lastIndex: ev.last,
|
||||
firstItem: firstItem as PickerComboBoxItem | string,
|
||||
secondItem: secondItem as PickerComboBoxItem | string,
|
||||
itemsCount: this._virtualizerElement.items.length,
|
||||
});
|
||||
}
|
||||
}
|
||||
return items.map<PickerComboBoxItemWithLabel>((item) => ({
|
||||
...item,
|
||||
a11y_label: item.a11y_label || item.primary,
|
||||
}));
|
||||
};
|
||||
|
||||
private _getAdditionalItems = (searchString?: string) =>
|
||||
this.getAdditionalItems?.(searchString) || [];
|
||||
private _getItems = (): PickerComboBoxItemWithLabel[] => {
|
||||
const items = this.getItems ? this.getItems() : [];
|
||||
|
||||
private _getItems = () => {
|
||||
let items = [
|
||||
...(this.getItems
|
||||
? this.getItems(this._search, this.selectedSection)
|
||||
: []),
|
||||
];
|
||||
|
||||
if (!this.sections?.length) {
|
||||
items = items.sort((entityA, entityB) =>
|
||||
const sortedItems = items
|
||||
.map<PickerComboBoxItemWithLabel>((item) => ({
|
||||
...item,
|
||||
a11y_label: item.a11y_label || item.primary,
|
||||
}))
|
||||
.sort((entityA, entityB) =>
|
||||
caseInsensitiveStringCompare(
|
||||
(entityA as PickerComboBoxItem).sorting_label!,
|
||||
(entityB as PickerComboBoxItem).sorting_label!,
|
||||
entityA.sorting_label!,
|
||||
entityB.sorting_label!,
|
||||
this.hass?.locale.language ?? navigator.language
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
items.push(NO_ITEMS_AVAILABLE_ID);
|
||||
if (!sortedItems.length) {
|
||||
sortedItems.push(
|
||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass?.localize)
|
||||
);
|
||||
}
|
||||
|
||||
const additionalItems = this._getAdditionalItems();
|
||||
items.push(...additionalItems);
|
||||
|
||||
if (this.mode === "dialog") {
|
||||
items.push("padding"); // padding for safe area inset
|
||||
}
|
||||
|
||||
return items;
|
||||
sortedItems.push(...additionalItems);
|
||||
return sortedItems;
|
||||
};
|
||||
|
||||
private _renderItem = (item: PickerComboBoxItem | string, index: number) => {
|
||||
if (item === "padding") {
|
||||
return html`<div class="bottom-padding"></div>`;
|
||||
}
|
||||
if (item === NO_ITEMS_AVAILABLE_ID) {
|
||||
return html`
|
||||
<div class="combo-box-row">
|
||||
<ha-combo-box-item type="text" compact>
|
||||
<ha-svg-icon
|
||||
slot="start"
|
||||
.path=${this._search ? mdiMagnify : mdiMinusBoxOutline}
|
||||
></ha-svg-icon>
|
||||
<span slot="headline"
|
||||
>${this._search
|
||||
? typeof this.notFoundLabel === "function"
|
||||
? this.notFoundLabel(this._search)
|
||||
: this.notFoundLabel ||
|
||||
this.hass?.localize("ui.components.combo-box.no_match") ||
|
||||
"No matching items found"
|
||||
: this.emptyLabel ||
|
||||
this.hass?.localize("ui.components.combo-box.no_items") ||
|
||||
"No items available"}</span
|
||||
>
|
||||
</ha-combo-box-item>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
if (typeof item === "string") {
|
||||
return html`<div class="title">${item}</div>`;
|
||||
}
|
||||
|
||||
private _renderItem = (item: PickerComboBoxItem, index: number) => {
|
||||
const renderer = this.rowRenderer || DEFAULT_ROW_RENDERER;
|
||||
return html`<div
|
||||
id=${`list-item-${index}`}
|
||||
@@ -309,7 +221,9 @@ export class HaPickerComboBox extends LitElement {
|
||||
.index=${index}
|
||||
@click=${this._valueSelected}
|
||||
>
|
||||
${renderer(item, index)}
|
||||
${item.id === NO_MATCHING_ITEMS_FOUND_ID
|
||||
? DEFAULT_ROW_RENDERER(item, index)
|
||||
: renderer(item, index)}
|
||||
</div>`;
|
||||
};
|
||||
|
||||
@@ -328,6 +242,10 @@ export class HaPickerComboBox extends LitElement {
|
||||
const value = (ev.currentTarget as any).value as string;
|
||||
const newValue = value?.trim();
|
||||
|
||||
if (newValue === NO_MATCHING_ITEMS_FOUND_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
fireEvent(this, "value-changed", { value: newValue });
|
||||
};
|
||||
|
||||
@@ -338,83 +256,51 @@ export class HaPickerComboBox extends LitElement {
|
||||
private _filterChanged = (ev: Event) => {
|
||||
const textfield = ev.target as HaTextField;
|
||||
const searchString = textfield.value.trim();
|
||||
this._search = searchString;
|
||||
|
||||
if (this.sections?.length) {
|
||||
this._items = this._getItems();
|
||||
} else {
|
||||
if (!searchString) {
|
||||
this._items = this._allItems;
|
||||
return;
|
||||
}
|
||||
|
||||
const index = this._fuseIndex(this._allItems as PickerComboBoxItem[]);
|
||||
const fuse = new HaFuse(
|
||||
this._allItems as PickerComboBoxItem[],
|
||||
{
|
||||
shouldSort: false,
|
||||
minMatchCharLength: Math.min(searchString.length, 2),
|
||||
},
|
||||
index
|
||||
);
|
||||
|
||||
const results = fuse.multiTermsSearch(searchString);
|
||||
let filteredItems = [...this._allItems];
|
||||
|
||||
if (results) {
|
||||
const items: (PickerComboBoxItem | string)[] = results.map(
|
||||
(result) => result.item
|
||||
);
|
||||
|
||||
if (!items.length) {
|
||||
filteredItems.push(NO_ITEMS_AVAILABLE_ID);
|
||||
}
|
||||
|
||||
const additionalItems = this._getAdditionalItems();
|
||||
items.push(...additionalItems);
|
||||
|
||||
filteredItems = items;
|
||||
}
|
||||
|
||||
if (this.searchFn) {
|
||||
filteredItems = this.searchFn(
|
||||
searchString,
|
||||
filteredItems as PickerComboBoxItem[],
|
||||
this._allItems as PickerComboBoxItem[]
|
||||
);
|
||||
}
|
||||
|
||||
this._items = filteredItems as PickerComboBoxItem[];
|
||||
if (!searchString) {
|
||||
this._items = this._allItems;
|
||||
return;
|
||||
}
|
||||
|
||||
const index = this._fuseIndex(this._allItems);
|
||||
const fuse = new HaFuse(
|
||||
this._allItems,
|
||||
{
|
||||
shouldSort: false,
|
||||
minMatchCharLength: Math.min(searchString.length, 2),
|
||||
},
|
||||
index
|
||||
);
|
||||
|
||||
const results = fuse.multiTermsSearch(searchString);
|
||||
let filteredItems = this._allItems as PickerComboBoxItem[];
|
||||
if (results) {
|
||||
const items = results.map((result) => result.item);
|
||||
if (items.length === 0) {
|
||||
items.push(
|
||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass?.localize)
|
||||
);
|
||||
}
|
||||
const additionalItems = this._getAdditionalItems(searchString);
|
||||
items.push(...additionalItems);
|
||||
filteredItems = items;
|
||||
}
|
||||
|
||||
if (this.searchFn) {
|
||||
filteredItems = this.searchFn(
|
||||
searchString,
|
||||
filteredItems,
|
||||
this._allItems
|
||||
);
|
||||
}
|
||||
|
||||
this._items = filteredItems as PickerComboBoxItemWithLabel[];
|
||||
this._selectedItemIndex = -1;
|
||||
if (this._virtualizerElement) {
|
||||
this._virtualizerElement.scrollTo(0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
private _toggleSection(ev: Event) {
|
||||
ev.stopPropagation();
|
||||
this._resetSelectedItem();
|
||||
this._sectionTitle = undefined;
|
||||
const section = (ev.target as HTMLElement)["section-id"] as string;
|
||||
if (!section) {
|
||||
return;
|
||||
}
|
||||
if (this.selectedSection === section) {
|
||||
this.selectedSection = undefined;
|
||||
} else {
|
||||
this.selectedSection = section;
|
||||
}
|
||||
|
||||
this._items = this._getItems();
|
||||
|
||||
// Reset scroll position when filter changes
|
||||
if (this._virtualizerElement) {
|
||||
this._virtualizerElement.scrollToIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
private _registerKeyboardShortcuts() {
|
||||
this._removeKeyboardShortcuts = tinykeys(this, {
|
||||
ArrowUp: this._selectPreviousItem,
|
||||
@@ -458,7 +344,7 @@ export class HaPickerComboBox extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof items[nextIndex] === "string") {
|
||||
if (items[nextIndex].id === NO_MATCHING_ITEMS_FOUND_ID) {
|
||||
// Skip titles, padding and empty search
|
||||
if (nextIndex === maxItems) {
|
||||
return;
|
||||
@@ -487,7 +373,7 @@ export class HaPickerComboBox extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof items[nextIndex] === "string") {
|
||||
if (items[nextIndex]?.id === NO_MATCHING_ITEMS_FOUND_ID) {
|
||||
// Skip titles, padding and empty search
|
||||
if (nextIndex === 0) {
|
||||
return;
|
||||
@@ -509,6 +395,13 @@ export class HaPickerComboBox extends LitElement {
|
||||
|
||||
const nextIndex = 0;
|
||||
|
||||
if (
|
||||
(this._virtualizerElement.items[nextIndex] as PickerComboBoxItem)?.id ===
|
||||
NO_MATCHING_ITEMS_FOUND_ID
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||
this._selectedItemIndex = nextIndex + 1;
|
||||
} else {
|
||||
@@ -526,6 +419,13 @@ export class HaPickerComboBox extends LitElement {
|
||||
|
||||
const nextIndex = this._virtualizerElement.items.length - 1;
|
||||
|
||||
if (
|
||||
(this._virtualizerElement.items[nextIndex] as PickerComboBoxItem)?.id ===
|
||||
NO_MATCHING_ITEMS_FOUND_ID
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||
this._selectedItemIndex = nextIndex - 1;
|
||||
} else {
|
||||
@@ -553,7 +453,10 @@ export class HaPickerComboBox extends LitElement {
|
||||
ev.stopPropagation();
|
||||
const firstItem = this._virtualizerElement?.items[0] as PickerComboBoxItem;
|
||||
|
||||
if (this._virtualizerElement?.items.length === 1) {
|
||||
if (
|
||||
this._virtualizerElement?.items.length === 1 &&
|
||||
firstItem.id !== NO_MATCHING_ITEMS_FOUND_ID
|
||||
) {
|
||||
fireEvent(this, "value-changed", {
|
||||
value: firstItem.id,
|
||||
});
|
||||
@@ -569,7 +472,7 @@ export class HaPickerComboBox extends LitElement {
|
||||
const item = this._virtualizerElement?.items[
|
||||
this._selectedItemIndex
|
||||
] as PickerComboBoxItem;
|
||||
if (item) {
|
||||
if (item && item.id !== NO_MATCHING_ITEMS_FOUND_ID) {
|
||||
fireEvent(this, "value-changed", { value: item.id });
|
||||
}
|
||||
};
|
||||
@@ -581,9 +484,6 @@ export class HaPickerComboBox extends LitElement {
|
||||
this._selectedItemIndex = -1;
|
||||
}
|
||||
|
||||
private _keyFunction = (item: PickerComboBoxItem | string) =>
|
||||
typeof item === "string" ? item : item.id;
|
||||
|
||||
static styles = [
|
||||
haStyleScrollbar,
|
||||
css`
|
||||
@@ -658,80 +558,6 @@ export class HaPickerComboBox extends LitElement {
|
||||
background-color: var(--ha-color-fill-neutral-normal-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.sections {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
gap: var(--ha-space-2);
|
||||
padding: var(--ha-space-3) var(--ha-space-3);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
:host([mode="dialog"]) .sections {
|
||||
padding: var(--ha-space-3) var(--ha-space-4);
|
||||
}
|
||||
|
||||
.sections ha-filter-chip {
|
||||
flex-shrink: 0;
|
||||
--md-filter-chip-selected-container-color: var(
|
||||
--ha-color-fill-primary-normal-hover
|
||||
);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.sections .separator {
|
||||
height: var(--ha-space-8);
|
||||
width: 0;
|
||||
border: 1px solid var(--ha-color-border-neutral-quiet);
|
||||
}
|
||||
|
||||
.section-title,
|
||||
.title {
|
||||
background-color: var(--ha-color-fill-neutral-quiet-resting);
|
||||
padding: var(--ha-space-1) var(--ha-space-2);
|
||||
font-weight: var(--ha-font-weight-bold);
|
||||
color: var(--secondary-text-color);
|
||||
min-height: var(--ha-space-6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:host([mode="dialog"]) .title {
|
||||
padding: var(--ha-space-1) var(--ha-space-4);
|
||||
}
|
||||
|
||||
:host([mode="dialog"]) ha-textfield {
|
||||
padding: 0 var(--ha-space-4);
|
||||
}
|
||||
|
||||
.section-title-wrapper {
|
||||
height: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
width: calc(100% - var(--ha-space-8));
|
||||
}
|
||||
|
||||
.section-title.show {
|
||||
opacity: 1;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.empty-search {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: var(--ha-space-3);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -157,9 +157,7 @@ export const computePanels = memoizeOne(
|
||||
Object.values(panels).forEach((panel) => {
|
||||
if (
|
||||
hiddenPanels.includes(panel.url_path) ||
|
||||
(!panel.title && panel.url_path !== defaultPanel) ||
|
||||
(panel.default_visible === false &&
|
||||
!panelsOrder.includes(panel.url_path))
|
||||
(!panel.title && panel.url_path !== defaultPanel)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,15 @@
|
||||
import "@home-assistant/webawesome/dist/components/popover/popover";
|
||||
import { consume } from "@lit/context";
|
||||
// @ts-ignore
|
||||
import chipStyles from "@material/chips/dist/mdc.chips.min.css";
|
||||
import { mdiPlus, mdiTextureBox } from "@mdi/js";
|
||||
import Fuse from "fuse.js";
|
||||
import { mdiPlaylistPlus } from "@mdi/js";
|
||||
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { LitElement, css, html, nothing, unsafeCSS } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { ensureArray } from "../common/array/ensure-array";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { isValidEntityId } from "../common/entity/valid_entity_id";
|
||||
import { computeRTL } from "../common/util/compute_rtl";
|
||||
import {
|
||||
getAreasAndFloors,
|
||||
type AreaFloorValue,
|
||||
type FloorComboBoxItem,
|
||||
} from "../data/area_floor";
|
||||
import { getConfigEntries, type ConfigEntry } from "../data/config_entries";
|
||||
import { labelsContext } from "../data/context";
|
||||
import { getDevices, type DevicePickerItem } from "../data/device_registry";
|
||||
import type { HaEntityPickerEntityFilterFunc } from "../data/entity";
|
||||
import { getEntities, type EntityComboBoxItem } from "../data/entity_registry";
|
||||
import { domainToName } from "../data/integration";
|
||||
import { getLabels, type LabelRegistryEntry } from "../data/label_registry";
|
||||
import {
|
||||
areaMeetsFilter,
|
||||
deviceMeetsFilter,
|
||||
@@ -34,23 +18,18 @@ import {
|
||||
type TargetTypeFloorless,
|
||||
} from "../data/target";
|
||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||
import { isHelperDomain } from "../panels/config/helpers/const";
|
||||
import { showHelperDetailDialog } from "../panels/config/helpers/show-dialog-helper-detail";
|
||||
import { HaFuse } from "../resources/fuse";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import { brandsUrl } from "../util/brands-url";
|
||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||
import "./ha-generic-picker";
|
||||
import type { PickerComboBoxItem } from "./ha-picker-combo-box";
|
||||
import "./ha-bottom-sheet";
|
||||
import "./ha-button";
|
||||
import "./ha-input-helper-text";
|
||||
import "./ha-svg-icon";
|
||||
import "./ha-tree-indicator";
|
||||
import "./target-picker/ha-target-picker-item-group";
|
||||
import "./target-picker/ha-target-picker-selector";
|
||||
import type { HaTargetPickerSelector } from "./target-picker/ha-target-picker-selector";
|
||||
import "./target-picker/ha-target-picker-value-chip";
|
||||
|
||||
const EMPTY_SEARCH = "___EMPTY_SEARCH___";
|
||||
const SEPARATOR = "________";
|
||||
const CREATE_ID = "___create-new-entity___";
|
||||
|
||||
@customElement("ha-target-picker")
|
||||
export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@@ -89,54 +68,23 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
@property({ attribute: "add-on-top", type: Boolean }) public addOnTop = false;
|
||||
|
||||
@state() private _selectedSection?: TargetTypeFloorless;
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _configEntryLookup: Record<string, ConfigEntry> = {};
|
||||
@state() private _addTargetWidth = 0;
|
||||
|
||||
@state()
|
||||
@consume({ context: labelsContext, subscribe: true })
|
||||
private _labelRegistry!: LabelRegistryEntry[];
|
||||
@state() private _narrow = false;
|
||||
|
||||
@state() private _pickerFilter?: TargetTypeFloorless;
|
||||
|
||||
@state() private _pickerWrapperOpen = false;
|
||||
|
||||
@query(".add-target-wrapper") private _addTargetWrapper?: HTMLDivElement;
|
||||
|
||||
@query("ha-target-picker-selector")
|
||||
private _targetPickerSelectorElement?: HaTargetPickerSelector;
|
||||
|
||||
private _newTarget?: { type: TargetType; id: string };
|
||||
|
||||
private _getDevicesMemoized = memoizeOne(getDevices);
|
||||
|
||||
private _getLabelsMemoized = memoizeOne(getLabels);
|
||||
|
||||
private _getEntitiesMemoized = memoizeOne(getEntities);
|
||||
|
||||
private _getAreasAndFloorsMemoized = memoizeOne(getAreasAndFloors);
|
||||
|
||||
private get _showEntityId() {
|
||||
return this.hass.userData?.showEntityIdPicker;
|
||||
}
|
||||
|
||||
private _fuseIndexes = {
|
||||
area: memoizeOne((states: FloorComboBoxItem[]) =>
|
||||
this._createFuseIndex(states)
|
||||
),
|
||||
entity: memoizeOne((states: EntityComboBoxItem[]) =>
|
||||
this._createFuseIndex(states)
|
||||
),
|
||||
device: memoizeOne((states: DevicePickerItem[]) =>
|
||||
this._createFuseIndex(states)
|
||||
),
|
||||
label: memoizeOne((states: PickerComboBoxItem[]) =>
|
||||
this._createFuseIndex(states)
|
||||
),
|
||||
};
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
|
||||
if (!this.hasUpdated) {
|
||||
this._loadConfigEntries();
|
||||
}
|
||||
}
|
||||
|
||||
private _createFuseIndex = (states) =>
|
||||
Fuse.createIndex(["search_labels"], states);
|
||||
|
||||
protected render() {
|
||||
if (this.addOnTop) {
|
||||
return html` ${this._renderPicker()} ${this._renderItems()} `;
|
||||
@@ -341,63 +289,137 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
|
||||
private _renderPicker() {
|
||||
const sections = [
|
||||
{
|
||||
id: "entity",
|
||||
label: this.hass.localize("ui.components.target-picker.type.entities"),
|
||||
},
|
||||
{
|
||||
id: "device",
|
||||
label: this.hass.localize("ui.components.target-picker.type.devices"),
|
||||
},
|
||||
{
|
||||
id: "area",
|
||||
label: this.hass.localize("ui.components.target-picker.type.areas"),
|
||||
},
|
||||
"separator" as const,
|
||||
{
|
||||
id: "label",
|
||||
label: this.hass.localize("ui.components.target-picker.type.labels"),
|
||||
},
|
||||
];
|
||||
|
||||
return html`
|
||||
<div class="add-target-wrapper">
|
||||
<ha-generic-picker
|
||||
.hass=${this.hass}
|
||||
.disabled=${this.disabled}
|
||||
.autofocus=${this.autofocus}
|
||||
.helper=${this.helper}
|
||||
.sections=${sections}
|
||||
.notFoundLabel=${this._noTargetFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.target-picker.no_targets"
|
||||
)}
|
||||
.sectionTitleFunction=${this._sectionTitleFunction}
|
||||
.selectedSection=${this._selectedSection}
|
||||
.rowRenderer=${this._renderRow}
|
||||
.getItems=${this._getItems}
|
||||
@value-changed=${this._targetPicked}
|
||||
.addButtonLabel=${this.hass.localize(
|
||||
"ui.components.target-picker.add_target"
|
||||
)}
|
||||
.getAdditionalItems=${this._getAdditionalItems}
|
||||
<ha-button
|
||||
id="add-target-button"
|
||||
size="small"
|
||||
appearance="filled"
|
||||
@click=${this._showPicker}
|
||||
>
|
||||
</ha-generic-picker>
|
||||
<ha-svg-icon .path=${mdiPlaylistPlus} slot="start"></ha-svg-icon>
|
||||
${this.hass.localize("ui.components.target-picker.add_target")}
|
||||
</ha-button>
|
||||
${!this._narrow && (this._pickerWrapperOpen || this._open)
|
||||
? html`
|
||||
<wa-popover
|
||||
.open=${this._pickerWrapperOpen}
|
||||
style="--body-width: ${this._addTargetWidth}px;"
|
||||
without-arrow
|
||||
distance="-4"
|
||||
placement="bottom-start"
|
||||
for="add-target-button"
|
||||
auto-size="vertical"
|
||||
auto-size-padding="16"
|
||||
@wa-after-show=${this._showSelector}
|
||||
@wa-after-hide=${this._hidePicker}
|
||||
trap-focus
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label=${this.hass.localize(
|
||||
"ui.components.target-picker.add_target"
|
||||
)}
|
||||
>
|
||||
${this._renderTargetSelector()}
|
||||
</wa-popover>
|
||||
`
|
||||
: this._pickerWrapperOpen || this._open
|
||||
? html`<ha-bottom-sheet
|
||||
flexcontent
|
||||
.open=${this._pickerWrapperOpen}
|
||||
@wa-after-show=${this._showSelector}
|
||||
@closed=${this._hidePicker}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label=${this.hass.localize(
|
||||
"ui.components.target-picker.add_target"
|
||||
)}
|
||||
>
|
||||
${this._renderTargetSelector(true)}
|
||||
</ha-bottom-sheet>`
|
||||
: nothing}
|
||||
</div>
|
||||
${this.helper
|
||||
? html`<ha-input-helper-text .disabled=${this.disabled}
|
||||
>${this.helper}</ha-input-helper-text
|
||||
>`
|
||||
: nothing}
|
||||
`;
|
||||
}
|
||||
|
||||
private _targetPicked(ev: CustomEvent<{ value: string }>) {
|
||||
ev.stopPropagation();
|
||||
const value = ev.detail.value;
|
||||
if (value.startsWith(CREATE_ID)) {
|
||||
this._createNewDomainElement(value.substring(CREATE_ID.length));
|
||||
return;
|
||||
}
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._handleResize();
|
||||
window.addEventListener("resize", this._handleResize);
|
||||
}
|
||||
|
||||
const [type, id] = ev.detail.value.split(SEPARATOR);
|
||||
this._addTarget(id, type as TargetType);
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
window.removeEventListener("resize", this._handleResize);
|
||||
}
|
||||
|
||||
private _handleResize = () => {
|
||||
this._narrow =
|
||||
window.matchMedia("(max-width: 870px)").matches ||
|
||||
window.matchMedia("(max-height: 500px)").matches;
|
||||
};
|
||||
|
||||
private _showPicker() {
|
||||
this._addTargetWidth = this._addTargetWrapper?.offsetWidth || 0;
|
||||
this._pickerWrapperOpen = true;
|
||||
}
|
||||
|
||||
// wait for drawer animation to finish
|
||||
private _showSelector = () => {
|
||||
this._open = true;
|
||||
requestAnimationFrame(() => {
|
||||
this._targetPickerSelectorElement?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
private _handleUpdatePickerFilter(
|
||||
ev: CustomEvent<TargetTypeFloorless | undefined>
|
||||
) {
|
||||
this._updatePickerFilter(
|
||||
typeof ev.detail === "string" ? ev.detail : undefined
|
||||
);
|
||||
}
|
||||
|
||||
private _updatePickerFilter = (filter?: TargetTypeFloorless) => {
|
||||
this._pickerFilter = filter;
|
||||
};
|
||||
|
||||
private _hidePicker(ev) {
|
||||
ev.stopPropagation();
|
||||
this._open = false;
|
||||
this._pickerWrapperOpen = false;
|
||||
|
||||
if (this._newTarget) {
|
||||
this._addTarget(this._newTarget.id, this._newTarget.type);
|
||||
this._newTarget = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private _renderTargetSelector(dialogMode = false) {
|
||||
if (!this._open) {
|
||||
return nothing;
|
||||
}
|
||||
return html`
|
||||
<ha-target-picker-selector
|
||||
.hass=${this.hass}
|
||||
@filter-type-changed=${this._handleUpdatePickerFilter}
|
||||
.filterType=${this._pickerFilter}
|
||||
@target-picked=${this._handleTargetPicked}
|
||||
@create-domain-picked=${this._handleCreateDomain}
|
||||
.targetValue=${this.value}
|
||||
.deviceFilter=${this.deviceFilter}
|
||||
.entityFilter=${this.entityFilter}
|
||||
.includeDomains=${this.includeDomains}
|
||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||
.createDomains=${this.createDomains}
|
||||
.mode=${dialogMode ? "dialog" : "popover"}
|
||||
></ha-target-picker-selector>
|
||||
`;
|
||||
}
|
||||
|
||||
private _addTarget(id: string, type: TargetType) {
|
||||
@@ -432,7 +454,26 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
?.removeAttribute("collapsed");
|
||||
}
|
||||
|
||||
private _createNewDomainElement = (domain: string) => {
|
||||
private _handleTargetPicked = async (
|
||||
ev: CustomEvent<{ type: TargetType; id: string }>
|
||||
) => {
|
||||
ev.stopPropagation();
|
||||
|
||||
this._pickerWrapperOpen = false;
|
||||
|
||||
if (!ev.detail.type || !ev.detail.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// save new target temporarily to add it after dialog closes
|
||||
this._newTarget = ev.detail;
|
||||
};
|
||||
|
||||
private _handleCreateDomain = (ev: CustomEvent<string>) => {
|
||||
this._pickerWrapperOpen = false;
|
||||
|
||||
const domain = ev.detail;
|
||||
|
||||
showHelperDetailDialog(this, {
|
||||
domain,
|
||||
dialogClosedCallback: (item) => {
|
||||
@@ -634,465 +675,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _getRowType = (
|
||||
item:
|
||||
| PickerComboBoxItem
|
||||
| (FloorComboBoxItem & { last?: boolean | undefined })
|
||||
| EntityComboBoxItem
|
||||
| DevicePickerItem
|
||||
) => {
|
||||
if (
|
||||
(item as FloorComboBoxItem).type === "area" ||
|
||||
(item as FloorComboBoxItem).type === "floor"
|
||||
) {
|
||||
return (item as FloorComboBoxItem).type;
|
||||
}
|
||||
|
||||
if ("domain" in item) {
|
||||
return "device";
|
||||
}
|
||||
|
||||
if ("stateObj" in item) {
|
||||
return "entity";
|
||||
}
|
||||
|
||||
if (item.id === EMPTY_SEARCH) {
|
||||
return "empty";
|
||||
}
|
||||
|
||||
return "label";
|
||||
};
|
||||
|
||||
private _sectionTitleFunction = ({
|
||||
firstIndex,
|
||||
lastIndex,
|
||||
firstItem,
|
||||
secondItem,
|
||||
itemsCount,
|
||||
}: {
|
||||
firstIndex: number;
|
||||
lastIndex: number;
|
||||
firstItem: PickerComboBoxItem | string;
|
||||
secondItem: PickerComboBoxItem | string;
|
||||
itemsCount: number;
|
||||
}) => {
|
||||
if (
|
||||
firstItem === undefined ||
|
||||
secondItem === undefined ||
|
||||
typeof firstItem === "string" ||
|
||||
(typeof secondItem === "string" && secondItem !== "padding") ||
|
||||
(firstIndex === 0 && lastIndex === itemsCount - 1)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const type = this._getRowType(firstItem as PickerComboBoxItem);
|
||||
const translationType:
|
||||
| "areas"
|
||||
| "entities"
|
||||
| "devices"
|
||||
| "labels"
|
||||
| undefined =
|
||||
type === "area" || type === "floor"
|
||||
? "areas"
|
||||
: type === "entity"
|
||||
? "entities"
|
||||
: type && type !== "empty"
|
||||
? `${type}s`
|
||||
: undefined;
|
||||
|
||||
return translationType
|
||||
? this.hass.localize(
|
||||
`ui.components.target-picker.type.${translationType}`
|
||||
)
|
||||
: undefined;
|
||||
};
|
||||
|
||||
private _getItems = (searchString: string, section: string) => {
|
||||
this._selectedSection = section as TargetTypeFloorless | undefined;
|
||||
|
||||
return this._getItemsMemoized(
|
||||
this.entityFilter,
|
||||
this.deviceFilter,
|
||||
this.includeDomains,
|
||||
this.includeDeviceClasses,
|
||||
this.value,
|
||||
searchString,
|
||||
this._configEntryLookup,
|
||||
this._selectedSection
|
||||
);
|
||||
};
|
||||
|
||||
private _getItemsMemoized = memoizeOne(
|
||||
(
|
||||
entityFilter: this["entityFilter"],
|
||||
deviceFilter: this["deviceFilter"],
|
||||
includeDomains: this["includeDomains"],
|
||||
includeDeviceClasses: this["includeDeviceClasses"],
|
||||
targetValue: this["value"],
|
||||
searchTerm: string,
|
||||
configEntryLookup: Record<string, ConfigEntry>,
|
||||
filterType?: TargetTypeFloorless
|
||||
) => {
|
||||
const items: (
|
||||
| string
|
||||
| FloorComboBoxItem
|
||||
| EntityComboBoxItem
|
||||
| PickerComboBoxItem
|
||||
)[] = [];
|
||||
|
||||
if (!filterType || filterType === "entity") {
|
||||
let entities = this._getEntitiesMemoized(
|
||||
this.hass,
|
||||
includeDomains,
|
||||
undefined,
|
||||
entityFilter,
|
||||
includeDeviceClasses,
|
||||
undefined,
|
||||
undefined,
|
||||
targetValue?.entity_id
|
||||
? ensureArray(targetValue.entity_id)
|
||||
: undefined,
|
||||
undefined,
|
||||
`entity${SEPARATOR}`
|
||||
);
|
||||
|
||||
if (searchTerm) {
|
||||
entities = this._filterGroup(
|
||||
"entity",
|
||||
entities,
|
||||
searchTerm,
|
||||
(item: EntityComboBoxItem) =>
|
||||
item.stateObj?.entity_id === searchTerm
|
||||
) as EntityComboBoxItem[];
|
||||
}
|
||||
|
||||
if (!filterType && entities.length) {
|
||||
// show group title
|
||||
items.push(
|
||||
this.hass.localize("ui.components.target-picker.type.entities")
|
||||
);
|
||||
}
|
||||
|
||||
items.push(...entities);
|
||||
}
|
||||
|
||||
if (!filterType || filterType === "device") {
|
||||
let devices = this._getDevicesMemoized(
|
||||
this.hass,
|
||||
configEntryLookup,
|
||||
includeDomains,
|
||||
undefined,
|
||||
includeDeviceClasses,
|
||||
deviceFilter,
|
||||
entityFilter,
|
||||
targetValue?.device_id
|
||||
? ensureArray(targetValue.device_id)
|
||||
: undefined,
|
||||
undefined,
|
||||
`device${SEPARATOR}`
|
||||
);
|
||||
|
||||
if (searchTerm) {
|
||||
devices = this._filterGroup("device", devices, searchTerm);
|
||||
}
|
||||
|
||||
if (!filterType && devices.length) {
|
||||
// show group title
|
||||
items.push(
|
||||
this.hass.localize("ui.components.target-picker.type.devices")
|
||||
);
|
||||
}
|
||||
|
||||
items.push(...devices);
|
||||
}
|
||||
|
||||
if (!filterType || filterType === "area") {
|
||||
let areasAndFloors = this._getAreasAndFloorsMemoized(
|
||||
this.hass.states,
|
||||
this.hass.floors,
|
||||
this.hass.areas,
|
||||
this.hass.devices,
|
||||
this.hass.entities,
|
||||
memoizeOne((value: AreaFloorValue): string =>
|
||||
[value.type, value.id].join(SEPARATOR)
|
||||
),
|
||||
includeDomains,
|
||||
undefined,
|
||||
includeDeviceClasses,
|
||||
deviceFilter,
|
||||
entityFilter,
|
||||
targetValue?.area_id ? ensureArray(targetValue.area_id) : undefined,
|
||||
targetValue?.floor_id ? ensureArray(targetValue.floor_id) : undefined
|
||||
);
|
||||
|
||||
if (searchTerm) {
|
||||
areasAndFloors = this._filterGroup(
|
||||
"area",
|
||||
areasAndFloors,
|
||||
searchTerm
|
||||
) as FloorComboBoxItem[];
|
||||
}
|
||||
|
||||
if (!filterType && areasAndFloors.length) {
|
||||
// show group title
|
||||
items.push(
|
||||
this.hass.localize("ui.components.target-picker.type.areas")
|
||||
);
|
||||
}
|
||||
|
||||
items.push(
|
||||
...areasAndFloors.map((item, index) => {
|
||||
const nextItem = areasAndFloors[index + 1];
|
||||
|
||||
if (
|
||||
!nextItem ||
|
||||
(item.type === "area" && nextItem.type === "floor")
|
||||
) {
|
||||
return {
|
||||
...item,
|
||||
last: true,
|
||||
};
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (!filterType || filterType === "label") {
|
||||
let labels = this._getLabelsMemoized(
|
||||
this.hass,
|
||||
this._labelRegistry,
|
||||
includeDomains,
|
||||
undefined,
|
||||
includeDeviceClasses,
|
||||
deviceFilter,
|
||||
entityFilter,
|
||||
targetValue?.label_id ? ensureArray(targetValue.label_id) : undefined,
|
||||
`label${SEPARATOR}`
|
||||
);
|
||||
|
||||
if (searchTerm) {
|
||||
labels = this._filterGroup("label", labels, searchTerm);
|
||||
}
|
||||
|
||||
if (!filterType && labels.length) {
|
||||
// show group title
|
||||
items.push(
|
||||
this.hass.localize("ui.components.target-picker.type.labels")
|
||||
);
|
||||
}
|
||||
|
||||
items.push(...labels);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
);
|
||||
|
||||
private _filterGroup(
|
||||
type: TargetType,
|
||||
items: (FloorComboBoxItem | PickerComboBoxItem | EntityComboBoxItem)[],
|
||||
searchTerm: string,
|
||||
checkExact?: (
|
||||
item: FloorComboBoxItem | PickerComboBoxItem | EntityComboBoxItem
|
||||
) => boolean
|
||||
) {
|
||||
const fuseIndex = this._fuseIndexes[type](items);
|
||||
const fuse = new HaFuse(
|
||||
items,
|
||||
{
|
||||
shouldSort: false,
|
||||
minMatchCharLength: Math.min(searchTerm.length, 2),
|
||||
},
|
||||
fuseIndex
|
||||
);
|
||||
|
||||
const results = fuse.multiTermsSearch(searchTerm);
|
||||
let filteredItems = items;
|
||||
if (results) {
|
||||
filteredItems = results.map((result) => result.item);
|
||||
}
|
||||
|
||||
if (!checkExact) {
|
||||
return filteredItems;
|
||||
}
|
||||
|
||||
// If there is exact match for entity id, put it first
|
||||
const index = filteredItems.findIndex((item) => checkExact(item));
|
||||
if (index === -1) {
|
||||
return filteredItems;
|
||||
}
|
||||
|
||||
const [exactMatch] = filteredItems.splice(index, 1);
|
||||
filteredItems.unshift(exactMatch);
|
||||
|
||||
return filteredItems;
|
||||
}
|
||||
|
||||
private _getAdditionalItems = () => this._getCreateItems(this.createDomains);
|
||||
|
||||
private _getCreateItems = memoizeOne(
|
||||
(createDomains: this["createDomains"]) => {
|
||||
if (!createDomains?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return createDomains.map((domain) => {
|
||||
const primary = this.hass.localize(
|
||||
"ui.components.entity.entity-picker.create_helper",
|
||||
{
|
||||
domain: isHelperDomain(domain)
|
||||
? this.hass.localize(`ui.panel.config.helpers.types.${domain}`)
|
||||
: domainToName(this.hass.localize, domain),
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
id: CREATE_ID + domain,
|
||||
primary: primary,
|
||||
secondary: this.hass.localize(
|
||||
"ui.components.entity.entity-picker.new_entity"
|
||||
),
|
||||
icon_path: mdiPlus,
|
||||
} satisfies EntityComboBoxItem;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
private async _loadConfigEntries() {
|
||||
const configEntries = await getConfigEntries(this.hass);
|
||||
this._configEntryLookup = Object.fromEntries(
|
||||
configEntries.map((entry) => [entry.entry_id, entry])
|
||||
);
|
||||
}
|
||||
|
||||
private _renderRow = (
|
||||
item:
|
||||
| PickerComboBoxItem
|
||||
| (FloorComboBoxItem & { last?: boolean | undefined })
|
||||
| EntityComboBoxItem
|
||||
| DevicePickerItem,
|
||||
index: number
|
||||
) => {
|
||||
if (!item) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const type = this._getRowType(item);
|
||||
let hasFloor = false;
|
||||
let rtl = false;
|
||||
let showEntityId = false;
|
||||
|
||||
if (type === "area" || type === "floor") {
|
||||
item.id = item[type]?.[`${type}_id`];
|
||||
|
||||
rtl = computeRTL(this.hass);
|
||||
hasFloor =
|
||||
type === "area" && !!(item as FloorComboBoxItem).area?.floor_id;
|
||||
}
|
||||
|
||||
if (type === "entity") {
|
||||
showEntityId = !!this._showEntityId;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-combo-box-item
|
||||
id=${`list-item-${index}`}
|
||||
tabindex="-1"
|
||||
.type=${type === "empty" ? "text" : "button"}
|
||||
class=${type === "empty" ? "empty" : ""}
|
||||
style=${(item as FloorComboBoxItem).type === "area" && hasFloor
|
||||
? "--md-list-item-leading-space: var(--ha-space-12);"
|
||||
: ""}
|
||||
>
|
||||
${(item as FloorComboBoxItem).type === "area" && hasFloor
|
||||
? html`
|
||||
<ha-tree-indicator
|
||||
style=${styleMap({
|
||||
width: "var(--ha-space-12)",
|
||||
position: "absolute",
|
||||
top: "var(--ha-space-0)",
|
||||
left: rtl ? undefined : "var(--ha-space-1)",
|
||||
right: rtl ? "var(--ha-space-1)" : undefined,
|
||||
transform: rtl ? "scaleX(-1)" : "",
|
||||
})}
|
||||
.end=${(
|
||||
item as FloorComboBoxItem & { last?: boolean | undefined }
|
||||
).last}
|
||||
slot="start"
|
||||
></ha-tree-indicator>
|
||||
`
|
||||
: nothing}
|
||||
${item.icon
|
||||
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
||||
: item.icon_path
|
||||
? html`<ha-svg-icon
|
||||
slot="start"
|
||||
.path=${item.icon_path}
|
||||
></ha-svg-icon>`
|
||||
: type === "entity" && (item as EntityComboBoxItem).stateObj
|
||||
? html`
|
||||
<state-badge
|
||||
slot="start"
|
||||
.stateObj=${(item as EntityComboBoxItem).stateObj}
|
||||
.hass=${this.hass}
|
||||
></state-badge>
|
||||
`
|
||||
: type === "device" && (item as DevicePickerItem).domain
|
||||
? html`
|
||||
<img
|
||||
slot="start"
|
||||
alt=""
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl({
|
||||
domain: (item as DevicePickerItem).domain!,
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes.darkMode,
|
||||
})}
|
||||
/>
|
||||
`
|
||||
: type === "floor"
|
||||
? html`<ha-floor-icon
|
||||
slot="start"
|
||||
.floor=${(item as FloorComboBoxItem).floor!}
|
||||
></ha-floor-icon>`
|
||||
: type === "area"
|
||||
? html`<ha-svg-icon
|
||||
slot="start"
|
||||
.path=${item.icon_path || mdiTextureBox}
|
||||
></ha-svg-icon>`
|
||||
: nothing}
|
||||
<span slot="headline">${item.primary}</span>
|
||||
${item.secondary
|
||||
? html`<span slot="supporting-text">${item.secondary}</span>`
|
||||
: nothing}
|
||||
${(item as EntityComboBoxItem).stateObj && showEntityId
|
||||
? html`
|
||||
<span slot="supporting-text" class="code">
|
||||
${(item as EntityComboBoxItem).stateObj?.entity_id}
|
||||
</span>
|
||||
`
|
||||
: nothing}
|
||||
${(item as EntityComboBoxItem).domain_name &&
|
||||
(type !== "entity" || !showEntityId)
|
||||
? html`
|
||||
<div slot="trailing-supporting-text" class="domain">
|
||||
${(item as EntityComboBoxItem).domain_name}
|
||||
</div>
|
||||
`
|
||||
: nothing}
|
||||
</ha-combo-box-item>
|
||||
`;
|
||||
};
|
||||
|
||||
private _noTargetFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.target-picker.no_target_found", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return css`
|
||||
.add-target-wrapper {
|
||||
@@ -1101,8 +683,31 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
||||
margin-top: var(--ha-space-3);
|
||||
}
|
||||
|
||||
ha-generic-picker {
|
||||
width: 100%;
|
||||
wa-popover {
|
||||
--wa-space-l: var(--ha-space-0);
|
||||
}
|
||||
|
||||
wa-popover::part(body) {
|
||||
width: min(max(var(--body-width), 336px), 600px);
|
||||
max-width: min(max(var(--body-width), 336px), 600px);
|
||||
max-height: 500px;
|
||||
height: 70vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@media (max-height: 1000px) {
|
||||
wa-popover::part(body) {
|
||||
max-height: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
ha-bottom-sheet {
|
||||
--ha-bottom-sheet-height: 90vh;
|
||||
--ha-bottom-sheet-height: calc(100dvh - var(--ha-space-12));
|
||||
--ha-bottom-sheet-max-height: var(--ha-bottom-sheet-height);
|
||||
--ha-bottom-sheet-max-width: 600px;
|
||||
--ha-bottom-sheet-padding: var(--ha-space-0);
|
||||
--ha-bottom-sheet-surface-background: var(--card-background-color);
|
||||
}
|
||||
|
||||
${unsafeCSS(chipStyles)}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { css, html, LitElement } from "lit";
|
||||
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
||||
import { mdiClose } from "@mdi/js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import {
|
||||
customElement,
|
||||
eventOptions,
|
||||
@@ -6,9 +8,6 @@ import {
|
||||
query,
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { mdiClose } from "@mdi/js";
|
||||
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import { haStyleScrollbar } from "../resources/styles";
|
||||
import type { HomeAssistant } from "../types";
|
||||
@@ -32,8 +31,6 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
||||
*
|
||||
* @slot header - Replace the entire header area.
|
||||
* @slot headerNavigationIcon - Leading header action (e.g. close/back button).
|
||||
* @slot headerTitle - Custom title content (used when header-title is not set).
|
||||
* @slot headerSubtitle - Custom subtitle content (used when header-subtitle is not set).
|
||||
* @slot headerActionItems - Trailing header actions (e.g. buttons, menus).
|
||||
* @slot - Dialog content body.
|
||||
* @slot footer - Dialog footer content.
|
||||
@@ -55,8 +52,8 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
||||
* @attr {boolean} open - Controls the dialog open state.
|
||||
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
|
||||
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
|
||||
* @attr {string} header-title - Header title text. If not set, the headerTitle slot is used.
|
||||
* @attr {string} header-subtitle - Header subtitle text. If not set, the headerSubtitle slot is used.
|
||||
* @attr {string} header-title - Header title text when no custom title slot is provided.
|
||||
* @attr {string} header-subtitle - Header subtitle text when no custom subtitle slot is provided.
|
||||
* @attr {("above"|"below")} header-subtitle-position - Position of the subtitle relative to the title. Defaults to "below".
|
||||
* @attr {boolean} flexcontent - Makes the dialog body a flex container for flexible layouts.
|
||||
*
|
||||
@@ -75,12 +72,6 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
||||
export class HaWaDialog extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: "aria-labelledby" })
|
||||
public ariaLabelledBy?: string;
|
||||
|
||||
@property({ attribute: "aria-describedby" })
|
||||
public ariaDescribedBy?: string;
|
||||
|
||||
@property({ type: Boolean, reflect: true })
|
||||
public open = false;
|
||||
|
||||
@@ -90,11 +81,11 @@ export class HaWaDialog extends LitElement {
|
||||
@property({ type: Boolean, reflect: true, attribute: "prevent-scrim-close" })
|
||||
public preventScrimClose = false;
|
||||
|
||||
@property({ attribute: "header-title" })
|
||||
public headerTitle?: string;
|
||||
@property({ type: String, attribute: "header-title" })
|
||||
public headerTitle = "";
|
||||
|
||||
@property({ attribute: "header-subtitle" })
|
||||
public headerSubtitle?: string;
|
||||
@property({ type: String, attribute: "header-subtitle" })
|
||||
public headerSubtitle = "";
|
||||
|
||||
@property({ type: String, attribute: "header-subtitle-position" })
|
||||
public headerSubtitlePosition: "above" | "below" = "below";
|
||||
@@ -126,11 +117,6 @@ export class HaWaDialog extends LitElement {
|
||||
.open=${this._open}
|
||||
.lightDismiss=${!this.preventScrimClose}
|
||||
without-header
|
||||
aria-labelledby=${ifDefined(
|
||||
this.ariaLabelledBy ||
|
||||
(this.headerTitle !== undefined ? "ha-wa-dialog-title" : undefined)
|
||||
)}
|
||||
aria-describedby=${ifDefined(this.ariaDescribedBy)}
|
||||
@wa-show=${this._handleShow}
|
||||
@wa-after-show=${this._handleAfterShow}
|
||||
@wa-after-hide=${this._handleAfterHide}
|
||||
@@ -147,14 +133,14 @@ export class HaWaDialog extends LitElement {
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
</slot>
|
||||
${this.headerTitle !== undefined
|
||||
? html`<span slot="title" class="title" id="ha-wa-dialog-title">
|
||||
${this.headerTitle
|
||||
? html`<span slot="title" class="title">
|
||||
${this.headerTitle}
|
||||
</span>`
|
||||
: html`<slot name="headerTitle" slot="title"></slot>`}
|
||||
${this.headerSubtitle !== undefined
|
||||
: nothing}
|
||||
${this.headerSubtitle
|
||||
? html`<span slot="subtitle">${this.headerSubtitle}</span>`
|
||||
: html`<slot name="headerSubtitle" slot="subtitle"></slot>`}
|
||||
: nothing}
|
||||
<slot name="headerActionItems" slot="actionItems"></slot>
|
||||
</ha-dialog-header>
|
||||
</slot>
|
||||
|
||||
@@ -545,7 +545,7 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
name: entityName || deviceName || item,
|
||||
context,
|
||||
stateObject,
|
||||
notFound: !stateObject && item !== "all" && item !== "none",
|
||||
notFound: !stateObject,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
1105
src/components/target-picker/ha-target-picker-selector.ts
Normal file
1105
src/components/target-picker/ha-target-picker-selector.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -128,7 +128,9 @@ class HaUserPicker extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.notFoundLabel=${this.hass.localize(
|
||||
"ui.components.user-picker.no_match"
|
||||
)}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
.getItems=${this._getItems}
|
||||
@@ -147,11 +149,6 @@ class HaUserPicker extends LitElement {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
fireEvent(this, "change");
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.user-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -53,9 +53,6 @@ export const enum CalendarEntityFeature {
|
||||
UPDATE_EVENT = 4,
|
||||
}
|
||||
|
||||
/** Type for date values that can come from REST API or subscription */
|
||||
type CalendarDateValue = string | { dateTime: string } | { date: string };
|
||||
|
||||
export const fetchCalendarEvents = async (
|
||||
hass: HomeAssistant,
|
||||
start: Date,
|
||||
@@ -68,11 +65,11 @@ export const fetchCalendarEvents = async (
|
||||
|
||||
const calEvents: CalendarEvent[] = [];
|
||||
const errors: string[] = [];
|
||||
const promises: Promise<CalendarEventApiData[]>[] = [];
|
||||
const promises: Promise<CalendarEvent[]>[] = [];
|
||||
|
||||
calendars.forEach((cal) => {
|
||||
promises.push(
|
||||
hass.callApi<CalendarEventApiData[]>(
|
||||
hass.callApi<CalendarEvent[]>(
|
||||
"GET",
|
||||
`calendars/${cal.entity_id}${params}`
|
||||
)
|
||||
@@ -80,7 +77,7 @@ export const fetchCalendarEvents = async (
|
||||
});
|
||||
|
||||
for (const [idx, promise] of promises.entries()) {
|
||||
let result: CalendarEventApiData[];
|
||||
let result: CalendarEvent[];
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
result = await promise;
|
||||
@@ -90,16 +87,53 @@ export const fetchCalendarEvents = async (
|
||||
}
|
||||
const cal = calendars[idx];
|
||||
result.forEach((ev) => {
|
||||
const normalized = normalizeSubscriptionEventData(ev, cal);
|
||||
if (normalized) {
|
||||
calEvents.push(normalized);
|
||||
const eventStart = getCalendarDate(ev.start);
|
||||
const eventEnd = getCalendarDate(ev.end);
|
||||
if (!eventStart || !eventEnd) {
|
||||
return;
|
||||
}
|
||||
const eventData: CalendarEventData = {
|
||||
uid: ev.uid,
|
||||
summary: ev.summary,
|
||||
description: ev.description,
|
||||
dtstart: eventStart,
|
||||
dtend: eventEnd,
|
||||
recurrence_id: ev.recurrence_id,
|
||||
rrule: ev.rrule,
|
||||
};
|
||||
const event: CalendarEvent = {
|
||||
start: eventStart,
|
||||
end: eventEnd,
|
||||
title: ev.summary,
|
||||
backgroundColor: cal.backgroundColor,
|
||||
borderColor: cal.backgroundColor,
|
||||
calendar: cal.entity_id,
|
||||
eventData: eventData,
|
||||
};
|
||||
|
||||
calEvents.push(event);
|
||||
});
|
||||
}
|
||||
|
||||
return { events: calEvents, errors };
|
||||
};
|
||||
|
||||
const getCalendarDate = (dateObj: any): string | undefined => {
|
||||
if (typeof dateObj === "string") {
|
||||
return dateObj;
|
||||
}
|
||||
|
||||
if (dateObj.dateTime) {
|
||||
return dateObj.dateTime;
|
||||
}
|
||||
|
||||
if (dateObj.date) {
|
||||
return dateObj.date;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const getCalendars = (hass: HomeAssistant): Calendar[] =>
|
||||
Object.keys(hass.states)
|
||||
.filter(
|
||||
@@ -157,89 +191,3 @@ export const deleteCalendarEvent = (
|
||||
recurrence_id,
|
||||
recurrence_range,
|
||||
});
|
||||
|
||||
/**
|
||||
* Calendar event data from both REST API and WebSocket subscription.
|
||||
* Both APIs use the same data format.
|
||||
*/
|
||||
export interface CalendarEventApiData {
|
||||
summary: string;
|
||||
start: CalendarDateValue;
|
||||
end: CalendarDateValue;
|
||||
description?: string | null;
|
||||
location?: string | null;
|
||||
uid?: string | null;
|
||||
recurrence_id?: string | null;
|
||||
rrule?: string | null;
|
||||
}
|
||||
|
||||
export interface CalendarEventSubscription {
|
||||
events: CalendarEventApiData[] | null;
|
||||
}
|
||||
|
||||
export const subscribeCalendarEvents = (
|
||||
hass: HomeAssistant,
|
||||
entity_id: string,
|
||||
start: Date,
|
||||
end: Date,
|
||||
callback: (update: CalendarEventSubscription) => void
|
||||
) =>
|
||||
hass.connection.subscribeMessage<CalendarEventSubscription>(callback, {
|
||||
type: "calendar/event/subscribe",
|
||||
entity_id,
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
});
|
||||
|
||||
const getCalendarDate = (dateObj: CalendarDateValue): string | undefined => {
|
||||
if (typeof dateObj === "string") {
|
||||
return dateObj;
|
||||
}
|
||||
|
||||
if ("dateTime" in dateObj) {
|
||||
return dateObj.dateTime;
|
||||
}
|
||||
|
||||
if ("date" in dateObj) {
|
||||
return dateObj.date;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize calendar event data from API format to internal format.
|
||||
* Handles both REST API format (with dateTime/date objects) and subscription format (strings).
|
||||
* Converts to internal format with { dtstart, dtend, ... }
|
||||
*/
|
||||
export const normalizeSubscriptionEventData = (
|
||||
eventData: CalendarEventApiData,
|
||||
calendar: Calendar
|
||||
): CalendarEvent | null => {
|
||||
const eventStart = getCalendarDate(eventData.start);
|
||||
const eventEnd = getCalendarDate(eventData.end);
|
||||
|
||||
if (!eventStart || !eventEnd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalizedEventData: CalendarEventData = {
|
||||
summary: eventData.summary,
|
||||
dtstart: eventStart,
|
||||
dtend: eventEnd,
|
||||
description: eventData.description ?? undefined,
|
||||
uid: eventData.uid ?? undefined,
|
||||
recurrence_id: eventData.recurrence_id ?? undefined,
|
||||
rrule: eventData.rrule ?? undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
start: eventStart,
|
||||
end: eventEnd,
|
||||
title: eventData.summary,
|
||||
backgroundColor: calendar.backgroundColor,
|
||||
borderColor: calendar.backgroundColor,
|
||||
calendar: calendar.entity_id,
|
||||
eventData: normalizedEventData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -186,8 +186,7 @@ export const getDevices = (
|
||||
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||
excludeDevices?: string[],
|
||||
value?: string,
|
||||
idPrefix = ""
|
||||
value?: string
|
||||
): DevicePickerItem[] => {
|
||||
const devices = Object.values(hass.devices);
|
||||
const entities = Object.values(hass.entities);
|
||||
@@ -299,7 +298,7 @@ export const getDevices = (
|
||||
const domainName = domain ? domainToName(hass.localize, domain) : undefined;
|
||||
|
||||
return {
|
||||
id: `${idPrefix}${device.id}`,
|
||||
id: device.id,
|
||||
label: "",
|
||||
primary:
|
||||
deviceName ||
|
||||
|
||||
@@ -344,8 +344,7 @@ export const getEntities = (
|
||||
includeUnitOfMeasurement?: string[],
|
||||
includeEntities?: string[],
|
||||
excludeEntities?: string[],
|
||||
value?: string,
|
||||
idPrefix = ""
|
||||
value?: string
|
||||
): EntityComboBoxItem[] => {
|
||||
let items: EntityComboBoxItem[] = [];
|
||||
|
||||
@@ -396,9 +395,10 @@ export const getEntities = (
|
||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||
.filter(Boolean)
|
||||
.join(isRTL ? " ◂ " : " ▸ ");
|
||||
const a11yLabel = [deviceName, entityName].filter(Boolean).join(" - ");
|
||||
|
||||
return {
|
||||
id: `${idPrefix}${entityId}`,
|
||||
id: entityId,
|
||||
primary: primary,
|
||||
secondary: secondary,
|
||||
domain_name: domainName,
|
||||
@@ -411,6 +411,7 @@ export const getEntities = (
|
||||
friendlyName,
|
||||
entityId,
|
||||
].filter(Boolean) as string[],
|
||||
a11y_label: a11yLabel,
|
||||
stateObj: stateObj,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -108,8 +108,7 @@ export const getLabels = (
|
||||
includeDeviceClasses?: string[],
|
||||
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||
excludeLabels?: string[],
|
||||
idPrefix = ""
|
||||
excludeLabels?: string[]
|
||||
): PickerComboBoxItem[] => {
|
||||
if (!labels || labels.length === 0) {
|
||||
return [];
|
||||
@@ -263,7 +262,7 @@ export const getLabels = (
|
||||
}
|
||||
|
||||
const items = outputLabels.map<PickerComboBoxItem>((label) => ({
|
||||
id: `${idPrefix}${label.label_id}`,
|
||||
id: label.label_id,
|
||||
primary: label.name,
|
||||
secondary: label.description ?? "",
|
||||
icon: label.icon || undefined,
|
||||
|
||||
@@ -222,7 +222,6 @@ export interface StopAction extends BaseAction {
|
||||
|
||||
export interface SequenceAction extends BaseAction {
|
||||
sequence: (ManualScriptConfig | Action)[];
|
||||
metadata?: {};
|
||||
}
|
||||
|
||||
export interface ParallelAction extends BaseAction {
|
||||
@@ -480,7 +479,6 @@ export const migrateAutomationAction = (
|
||||
}
|
||||
|
||||
if (typeof action === "object" && action !== null && "sequence" in action) {
|
||||
delete (action as SequenceAction).metadata;
|
||||
for (const sequenceAction of (action as SequenceAction).sequence) {
|
||||
migrateAutomationAction(sequenceAction);
|
||||
}
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import "../../components/ha-alert";
|
||||
import "../../components/ha-icon";
|
||||
import "../../components/ha-list-item";
|
||||
import "../../components/ha-spinner";
|
||||
import type {
|
||||
ExternalEntityAddToActions,
|
||||
ExternalEntityAddToAction,
|
||||
} from "../../external_app/external_messaging";
|
||||
import { showToast } from "../../util/toast";
|
||||
|
||||
import type { HomeAssistant } from "../../types";
|
||||
|
||||
@customElement("ha-more-info-add-to")
|
||||
export class HaMoreInfoAddTo extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public entityId!: string;
|
||||
|
||||
@state() private _externalActions?: ExternalEntityAddToActions = {
|
||||
actions: [],
|
||||
};
|
||||
|
||||
@state() private _loading = true;
|
||||
|
||||
private async _loadExternalActions() {
|
||||
if (this.hass.auth.external?.config.hasEntityAddTo) {
|
||||
this._externalActions =
|
||||
await this.hass.auth.external?.sendMessage<"entity/add_to/get_actions">(
|
||||
{
|
||||
type: "entity/add_to/get_actions",
|
||||
payload: { entity_id: this.entityId },
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async _actionSelected(ev: CustomEvent) {
|
||||
const action = (ev.currentTarget as any)
|
||||
.action as ExternalEntityAddToAction;
|
||||
if (!action.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.hass.auth.external!.fireMessage({
|
||||
type: "entity/add_to",
|
||||
payload: {
|
||||
entity_id: this.entityId,
|
||||
app_payload: action.app_payload,
|
||||
},
|
||||
});
|
||||
} catch (err: any) {
|
||||
showToast(this, {
|
||||
message: this.hass.localize(
|
||||
"ui.dialogs.more_info_control.add_to.action_failed",
|
||||
{
|
||||
error: err.message || err,
|
||||
}
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected async firstUpdated() {
|
||||
await this._loadExternalActions();
|
||||
this._loading = false;
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (this._loading) {
|
||||
return html`
|
||||
<div class="loading">
|
||||
<ha-spinner></ha-spinner>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
if (!this._externalActions?.actions.length) {
|
||||
return html`
|
||||
<ha-alert alert-type="info">
|
||||
${this.hass.localize(
|
||||
"ui.dialogs.more_info_control.add_to.no_actions"
|
||||
)}
|
||||
</ha-alert>
|
||||
`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="actions-list">
|
||||
${this._externalActions.actions.map(
|
||||
(action) => html`
|
||||
<ha-list-item
|
||||
graphic="icon"
|
||||
.disabled=${!action.enabled}
|
||||
.action=${action}
|
||||
.twoline=${!!action.details}
|
||||
@click=${this._actionSelected}
|
||||
>
|
||||
<span>${action.name}</span>
|
||||
${action.details
|
||||
? html`<span slot="secondary">${action.details}</span>`
|
||||
: nothing}
|
||||
<ha-icon slot="graphic" .icon=${action.mdi_icon}></ha-icon>
|
||||
</ha-list-item>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: block;
|
||||
padding: var(--ha-space-2) var(--ha-space-6) var(--ha-space-6)
|
||||
var(--ha-space-6);
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: var(--ha-space-8);
|
||||
}
|
||||
|
||||
.actions-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
ha-list-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
ha-list-item[disabled] {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
ha-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-more-info-add-to": HaMoreInfoAddTo;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
mdiPencil,
|
||||
mdiPencilOff,
|
||||
mdiPencilOutline,
|
||||
mdiPlusBoxMultipleOutline,
|
||||
mdiTransitConnectionVariant,
|
||||
} from "@mdi/js";
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
@@ -61,7 +60,6 @@ import {
|
||||
computeShowLogBookComponent,
|
||||
} from "./const";
|
||||
import "./controls/more-info-default";
|
||||
import "./ha-more-info-add-to";
|
||||
import "./ha-more-info-history-and-logbook";
|
||||
import "./ha-more-info-info";
|
||||
import "./ha-more-info-settings";
|
||||
@@ -75,7 +73,7 @@ export interface MoreInfoDialogParams {
|
||||
data?: Record<string, any>;
|
||||
}
|
||||
|
||||
type View = "info" | "history" | "settings" | "related" | "add_to";
|
||||
type View = "info" | "history" | "settings" | "related";
|
||||
|
||||
interface ChildView {
|
||||
viewTag: string;
|
||||
@@ -196,10 +194,6 @@ export class MoreInfoDialog extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
private _shouldShowAddEntityTo(): boolean {
|
||||
return !!this.hass.auth.external?.config.hasEntityAddTo;
|
||||
}
|
||||
|
||||
private _getDeviceId(): string | null {
|
||||
const entity = this.hass.entities[this._entityId!] as
|
||||
| EntityRegistryEntry
|
||||
@@ -301,11 +295,6 @@ export class MoreInfoDialog extends LitElement {
|
||||
this._setView("related");
|
||||
}
|
||||
|
||||
private _goToAddEntityTo(ev) {
|
||||
if (!shouldHandleRequestSelectedEvent(ev)) return;
|
||||
this._setView("add_to");
|
||||
}
|
||||
|
||||
private _breadcrumbClick(ev: Event) {
|
||||
ev.stopPropagation();
|
||||
this._setView("related");
|
||||
@@ -532,22 +521,6 @@ export class MoreInfoDialog extends LitElement {
|
||||
.path=${mdiInformationOutline}
|
||||
></ha-svg-icon>
|
||||
</ha-list-item>
|
||||
${this._shouldShowAddEntityTo()
|
||||
? html`
|
||||
<ha-list-item
|
||||
graphic="icon"
|
||||
@request-selected=${this._goToAddEntityTo}
|
||||
>
|
||||
${this.hass.localize(
|
||||
"ui.dialogs.more_info_control.add_entity_to"
|
||||
)}
|
||||
<ha-svg-icon
|
||||
slot="graphic"
|
||||
.path=${mdiPlusBoxMultipleOutline}
|
||||
></ha-svg-icon>
|
||||
</ha-list-item>
|
||||
`
|
||||
: nothing}
|
||||
</ha-button-menu>
|
||||
`
|
||||
: nothing}
|
||||
@@ -640,14 +613,7 @@ export class MoreInfoDialog extends LitElement {
|
||||
: "entity"}
|
||||
></ha-related-items>
|
||||
`
|
||||
: this._currView === "add_to"
|
||||
? html`
|
||||
<ha-more-info-add-to
|
||||
.hass=${this.hass}
|
||||
.entityId=${entityId}
|
||||
></ha-more-info-add-to>
|
||||
`
|
||||
: nothing
|
||||
: nothing
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
|
||||
@@ -152,18 +152,10 @@ export class MoreInfoHistory extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _setUpdateTimer() {
|
||||
private _setRedrawTimer() {
|
||||
// redraw the graph every minute to update the time axis
|
||||
clearInterval(this._interval);
|
||||
this._interval = window.setInterval(() => {
|
||||
// If using statistics, refresh the data
|
||||
if (this._statistics) {
|
||||
this._fetchStatistics();
|
||||
}
|
||||
// If using history, redraw the graph to update the time axis
|
||||
if (this._stateHistory) {
|
||||
this._redrawGraph();
|
||||
}
|
||||
}, 1000 * 60);
|
||||
this._interval = window.setInterval(() => this._redrawGraph(), 1000 * 60);
|
||||
}
|
||||
|
||||
private async _getStatisticsMetaData(statisticIds: string[] | undefined) {
|
||||
@@ -178,30 +170,6 @@ export class MoreInfoHistory extends LitElement {
|
||||
return statisticsMetaData;
|
||||
}
|
||||
|
||||
private async _fetchStatistics(): Promise<boolean> {
|
||||
// Fire off the metadata and fetch at the same time
|
||||
// to avoid waiting in sequence so the UI responds
|
||||
// faster.
|
||||
const _metadata = this._getStatisticsMetaData([this.entityId]);
|
||||
const _statistics = fetchStatistics(
|
||||
this.hass!,
|
||||
subHours(new Date(), 24),
|
||||
undefined,
|
||||
[this.entityId],
|
||||
"5minute",
|
||||
undefined,
|
||||
statTypes
|
||||
);
|
||||
const [metadata, statistics] = await Promise.all([_metadata, _statistics]);
|
||||
if (metadata && Object.keys(metadata).length) {
|
||||
this._metadata = metadata;
|
||||
this._statistics = statistics;
|
||||
this._statNames = { [this.entityId]: "" };
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async _getStateHistory(): Promise<void> {
|
||||
if (
|
||||
isComponentLoaded(this.hass, "recorder") &&
|
||||
@@ -212,10 +180,27 @@ export class MoreInfoHistory extends LitElement {
|
||||
// has not opted into statistics so there is no need to check as it
|
||||
// requires another round-trip to the server.
|
||||
if (stateObj && stateObj.attributes.state_class) {
|
||||
const hasStatistics = await this._fetchStatistics();
|
||||
if (hasStatistics) {
|
||||
// Using statistics, set up refresh timer
|
||||
this._setUpdateTimer();
|
||||
// Fire off the metadata and fetch at the same time
|
||||
// to avoid waiting in sequence so the UI responds
|
||||
// faster.
|
||||
const _metadata = this._getStatisticsMetaData([this.entityId]);
|
||||
const _statistics = fetchStatistics(
|
||||
this.hass!,
|
||||
subHours(new Date(), 24),
|
||||
undefined,
|
||||
[this.entityId],
|
||||
"5minute",
|
||||
undefined,
|
||||
statTypes
|
||||
);
|
||||
const [metadata, statistics] = await Promise.all([
|
||||
_metadata,
|
||||
_statistics,
|
||||
]);
|
||||
if (metadata && Object.keys(metadata).length) {
|
||||
this._metadata = metadata;
|
||||
this._statistics = statistics;
|
||||
this._statNames = { [this.entityId]: "" };
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -253,7 +238,7 @@ export class MoreInfoHistory extends LitElement {
|
||||
this._error = err;
|
||||
return undefined;
|
||||
});
|
||||
this._setUpdateTimer();
|
||||
this._setRedrawTimer();
|
||||
}
|
||||
|
||||
static styles = [
|
||||
|
||||
@@ -102,17 +102,6 @@ class DialogEditSidebar extends LitElement {
|
||||
this.hass.locale
|
||||
);
|
||||
|
||||
// Add default hidden panels that are missing in hidden
|
||||
for (const panel of panels) {
|
||||
if (
|
||||
panel.default_visible === false &&
|
||||
!this._order.includes(panel.url_path) &&
|
||||
!this._hidden.includes(panel.url_path)
|
||||
) {
|
||||
this._hidden.push(panel.url_path);
|
||||
}
|
||||
}
|
||||
|
||||
const items = [
|
||||
...beforeSpacer,
|
||||
...panels.filter((panel) => this._hidden!.includes(panel.url_path)),
|
||||
|
||||
@@ -36,13 +36,6 @@ interface EMOutgoingMessageConfigGet extends EMMessage {
|
||||
type: "config/get";
|
||||
}
|
||||
|
||||
interface EMOutgoingMessageEntityAddToGetActions extends EMMessage {
|
||||
type: "entity/add_to/get_actions";
|
||||
payload: {
|
||||
entity_id: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface EMOutgoingMessageBarCodeScan extends EMMessage {
|
||||
type: "bar_code/scan";
|
||||
payload: {
|
||||
@@ -82,10 +75,6 @@ interface EMOutgoingMessageWithAnswer {
|
||||
request: EMOutgoingMessageConfigGet;
|
||||
response: ExternalConfig;
|
||||
};
|
||||
"entity/add_to/get_actions": {
|
||||
request: EMOutgoingMessageEntityAddToGetActions;
|
||||
response: ExternalEntityAddToActions;
|
||||
};
|
||||
}
|
||||
|
||||
interface EMOutgoingMessageExoplayerPlayHLS extends EMMessage {
|
||||
@@ -168,14 +157,6 @@ interface EMOutgoingMessageThreadStoreInPlatformKeychain extends EMMessage {
|
||||
};
|
||||
}
|
||||
|
||||
interface EMOutgoingMessageAddEntityTo extends EMMessage {
|
||||
type: "entity/add_to";
|
||||
payload: {
|
||||
entity_id: string;
|
||||
app_payload: string; // Opaque string received from get_actions
|
||||
};
|
||||
}
|
||||
|
||||
type EMOutgoingMessageWithoutAnswer =
|
||||
| EMMessageResultError
|
||||
| EMMessageResultSuccess
|
||||
@@ -196,8 +177,7 @@ type EMOutgoingMessageWithoutAnswer =
|
||||
| EMOutgoingMessageThemeUpdate
|
||||
| EMOutgoingMessageThreadStoreInPlatformKeychain
|
||||
| EMOutgoingMessageImprovScan
|
||||
| EMOutgoingMessageImprovConfigureDevice
|
||||
| EMOutgoingMessageAddEntityTo;
|
||||
| EMOutgoingMessageImprovConfigureDevice;
|
||||
|
||||
export interface EMIncomingMessageRestart {
|
||||
id: number;
|
||||
@@ -313,31 +293,18 @@ type EMIncomingMessage =
|
||||
type EMIncomingMessageHandler = (msg: EMIncomingMessageCommands) => boolean;
|
||||
|
||||
export interface ExternalConfig {
|
||||
hasSettingsScreen?: boolean;
|
||||
hasSidebar?: boolean;
|
||||
canWriteTag?: boolean;
|
||||
hasExoPlayer?: boolean;
|
||||
canCommissionMatter?: boolean;
|
||||
canImportThreadCredentials?: boolean;
|
||||
canTransferThreadCredentialsToKeychain?: boolean;
|
||||
hasAssist?: boolean;
|
||||
hasBarCodeScanner?: number;
|
||||
canSetupImprov?: boolean;
|
||||
downloadFileSupported?: boolean;
|
||||
appVersion?: string;
|
||||
hasEntityAddTo?: boolean; // Supports "Add to" from more-info dialog, with action coming from external app
|
||||
}
|
||||
|
||||
export interface ExternalEntityAddToAction {
|
||||
enabled: boolean;
|
||||
name: string; // Translated name of the action to be displayed in the UI
|
||||
details?: string; // Optional translated details of the action to be displayed in the UI
|
||||
mdi_icon: string; // MDI icon name to be displayed in the UI (e.g., "mdi:car")
|
||||
app_payload: string; // Opaque string to be sent back when the action is selected
|
||||
}
|
||||
|
||||
export interface ExternalEntityAddToActions {
|
||||
actions: ExternalEntityAddToAction[];
|
||||
hasSettingsScreen: boolean;
|
||||
hasSidebar: boolean;
|
||||
canWriteTag: boolean;
|
||||
hasExoPlayer: boolean;
|
||||
canCommissionMatter: boolean;
|
||||
canImportThreadCredentials: boolean;
|
||||
canTransferThreadCredentialsToKeychain: boolean;
|
||||
hasAssist: boolean;
|
||||
hasBarCodeScanner: number;
|
||||
canSetupImprov: boolean;
|
||||
downloadFileSupported: boolean;
|
||||
appVersion: string;
|
||||
}
|
||||
|
||||
export class ExternalMessaging {
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
import type { ReactiveElement } from "lit";
|
||||
import { listenMediaQuery } from "../common/dom/media_query";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { Condition } from "../panels/lovelace/common/validate-condition";
|
||||
import { checkConditionsMet } from "../panels/lovelace/common/validate-condition";
|
||||
|
||||
type Constructor<T> = abstract new (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* Extract media queries from conditions recursively
|
||||
*/
|
||||
export function extractMediaQueries(conditions: Condition[]): string[] {
|
||||
return conditions.reduce<string[]>((array, c) => {
|
||||
if ("conditions" in c && c.conditions) {
|
||||
array.push(...extractMediaQueries(c.conditions));
|
||||
}
|
||||
if (c.condition === "screen" && c.media_query) {
|
||||
array.push(c.media_query);
|
||||
}
|
||||
return array;
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to setup media query listeners for conditional visibility
|
||||
*/
|
||||
export function setupMediaQueryListeners(
|
||||
conditions: Condition[],
|
||||
hass: HomeAssistant,
|
||||
addListener: (unsub: () => void) => void,
|
||||
onUpdate: (conditionsMet: boolean) => void
|
||||
): void {
|
||||
const mediaQueries = extractMediaQueries(conditions);
|
||||
|
||||
if (mediaQueries.length === 0) return;
|
||||
|
||||
// Optimization for single media query
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
conditions[0].condition === "screen" &&
|
||||
!!conditions[0].media_query;
|
||||
|
||||
mediaQueries.forEach((mediaQuery) => {
|
||||
const unsub = listenMediaQuery(mediaQuery, (matches) => {
|
||||
if (hasOnlyMediaQuery) {
|
||||
onUpdate(matches);
|
||||
} else {
|
||||
const conditionsMet = checkConditionsMet(conditions, hass);
|
||||
onUpdate(conditionsMet);
|
||||
}
|
||||
});
|
||||
addListener(unsub);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin to handle conditional listeners for visibility control
|
||||
*
|
||||
* Provides lifecycle management for listeners (media queries, time-based, state changes, etc.)
|
||||
* that control conditional visibility of components.
|
||||
*
|
||||
* Usage:
|
||||
* 1. Extend your component with ConditionalListenerMixin(ReactiveElement)
|
||||
* 2. Override setupConditionalListeners() to setup your listeners
|
||||
* 3. Use addConditionalListener() to register unsubscribe functions
|
||||
* 4. Call clearConditionalListeners() and setupConditionalListeners() when config changes
|
||||
*
|
||||
* The mixin automatically:
|
||||
* - Sets up listeners when component connects to DOM
|
||||
* - Cleans up listeners when component disconnects from DOM
|
||||
*/
|
||||
export const ConditionalListenerMixin = <
|
||||
T extends Constructor<ReactiveElement>,
|
||||
>(
|
||||
superClass: T
|
||||
) => {
|
||||
abstract class ConditionalListenerClass extends superClass {
|
||||
private __listeners: (() => void)[] = [];
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.setupConditionalListeners();
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this.clearConditionalListeners();
|
||||
}
|
||||
|
||||
protected clearConditionalListeners(): void {
|
||||
this.__listeners.forEach((unsub) => unsub());
|
||||
this.__listeners = [];
|
||||
}
|
||||
|
||||
protected addConditionalListener(unsubscribe: () => void): void {
|
||||
this.__listeners.push(unsubscribe);
|
||||
}
|
||||
|
||||
protected setupConditionalListeners(): void {
|
||||
// Override in subclass
|
||||
}
|
||||
}
|
||||
return ConditionalListenerClass;
|
||||
};
|
||||
@@ -332,15 +332,6 @@ class DialogCalendarEventEditor extends LitElement {
|
||||
|
||||
private _allDayToggleChanged(ev) {
|
||||
this._allDay = ev.target.checked;
|
||||
// When switching to all-day mode, normalize dates to midnight so time portions don't interfere with date comparisons
|
||||
if (this._allDay && this._dtstart && this._dtend) {
|
||||
this._dtstart = new Date(
|
||||
formatDate(this._dtstart, this._timeZone!) + "T00:00:00"
|
||||
);
|
||||
this._dtend = new Date(
|
||||
formatDate(this._dtend, this._timeZone!) + "T00:00:00"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private _startDateChanged(ev: CustomEvent) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { mdiChevronDown, mdiPlus, mdiRefresh } from "@mdi/js";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
@@ -21,17 +20,8 @@ import "../../components/ha-menu-button";
|
||||
import "../../components/ha-state-icon";
|
||||
import "../../components/ha-svg-icon";
|
||||
import "../../components/ha-two-pane-top-app-bar-fixed";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarEvent,
|
||||
CalendarEventSubscription,
|
||||
CalendarEventApiData,
|
||||
} from "../../data/calendar";
|
||||
import {
|
||||
getCalendars,
|
||||
normalizeSubscriptionEventData,
|
||||
subscribeCalendarEvents,
|
||||
} from "../../data/calendar";
|
||||
import type { Calendar, CalendarEvent } from "../../data/calendar";
|
||||
import { fetchCalendarEvents, getCalendars } from "../../data/calendar";
|
||||
import { fetchIntegrationManifest } from "../../data/integration";
|
||||
import { showConfigFlowDialog } from "../../dialogs/config-flow/show-dialog-config-flow";
|
||||
import { haStyle } from "../../resources/styles";
|
||||
@@ -52,8 +42,6 @@ class PanelCalendar extends LitElement {
|
||||
|
||||
@state() private _error?: string = undefined;
|
||||
|
||||
@state() private _errorCalendars: string[] = [];
|
||||
|
||||
@state()
|
||||
@storage({
|
||||
key: "deSelectedCalendars",
|
||||
@@ -65,8 +53,6 @@ class PanelCalendar extends LitElement {
|
||||
|
||||
private _end?: Date;
|
||||
|
||||
private _unsubs: Record<string, Promise<UnsubscribeFunc>> = {};
|
||||
|
||||
private _showPaneController = new ResizeController(this, {
|
||||
callback: (entries) => entries[0]?.contentRect.width > 750,
|
||||
});
|
||||
@@ -92,7 +78,6 @@ class PanelCalendar extends LitElement {
|
||||
super.disconnectedCallback();
|
||||
this._mql?.removeListener(this._setIsMobile!);
|
||||
this._mql = undefined;
|
||||
this._unsubscribeAll();
|
||||
}
|
||||
|
||||
private _setIsMobile = (ev: MediaQueryListEvent) => {
|
||||
@@ -209,95 +194,19 @@ class PanelCalendar extends LitElement {
|
||||
.map((cal) => cal);
|
||||
}
|
||||
|
||||
private _subscribeCalendarEvents(calendars: Calendar[]): void {
|
||||
if (!this._start || !this._end || calendars.length === 0) {
|
||||
return;
|
||||
private async _fetchEvents(
|
||||
start: Date | undefined,
|
||||
end: Date | undefined,
|
||||
calendars: Calendar[]
|
||||
): Promise<{ events: CalendarEvent[]; errors: string[] }> {
|
||||
if (!calendars.length || !start || !end) {
|
||||
return { events: [], errors: [] };
|
||||
}
|
||||
|
||||
this._error = undefined;
|
||||
|
||||
calendars.forEach((calendar) => {
|
||||
// Unsubscribe existing subscription if any
|
||||
if (calendar.entity_id in this._unsubs) {
|
||||
this._unsubs[calendar.entity_id]
|
||||
.then((unsubFunc) => unsubFunc())
|
||||
.catch(() => {
|
||||
// Subscription may have already been closed
|
||||
});
|
||||
}
|
||||
|
||||
const unsub = subscribeCalendarEvents(
|
||||
this.hass,
|
||||
calendar.entity_id,
|
||||
this._start!,
|
||||
this._end!,
|
||||
(update: CalendarEventSubscription) => {
|
||||
this._handleCalendarUpdate(calendar, update);
|
||||
}
|
||||
);
|
||||
this._unsubs[calendar.entity_id] = unsub;
|
||||
});
|
||||
return fetchCalendarEvents(this.hass, start, end, calendars);
|
||||
}
|
||||
|
||||
private _handleCalendarUpdate(
|
||||
calendar: Calendar,
|
||||
update: CalendarEventSubscription
|
||||
): void {
|
||||
// Remove events from this calendar
|
||||
this._events = this._events.filter(
|
||||
(event) => event.calendar !== calendar.entity_id
|
||||
);
|
||||
|
||||
if (update.events === null) {
|
||||
// Error fetching events
|
||||
if (!this._errorCalendars.includes(calendar.entity_id)) {
|
||||
this._errorCalendars = [...this._errorCalendars, calendar.entity_id];
|
||||
}
|
||||
this._handleErrors(this._errorCalendars);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove from error list if successfully loaded
|
||||
this._errorCalendars = this._errorCalendars.filter(
|
||||
(id) => id !== calendar.entity_id
|
||||
);
|
||||
this._handleErrors(this._errorCalendars);
|
||||
|
||||
// Add new events from this calendar
|
||||
const newEvents: CalendarEvent[] = update.events
|
||||
.map((eventData: CalendarEventApiData) =>
|
||||
normalizeSubscriptionEventData(eventData, calendar)
|
||||
)
|
||||
.filter((event): event is CalendarEvent => event !== null);
|
||||
|
||||
this._events = [...this._events, ...newEvents];
|
||||
}
|
||||
|
||||
private async _unsubscribeAll(): Promise<void> {
|
||||
await Promise.all(
|
||||
Object.values(this._unsubs).map((unsub) =>
|
||||
unsub
|
||||
.then((unsubFunc) => unsubFunc())
|
||||
.catch(() => {
|
||||
// Subscription may have already been closed
|
||||
})
|
||||
)
|
||||
);
|
||||
this._unsubs = {};
|
||||
}
|
||||
|
||||
private _unsubscribeCalendar(entityId: string): void {
|
||||
if (entityId in this._unsubs) {
|
||||
this._unsubs[entityId]
|
||||
.then((unsubFunc) => unsubFunc())
|
||||
.catch(() => {
|
||||
// Subscription may have already been closed
|
||||
});
|
||||
delete this._unsubs[entityId];
|
||||
}
|
||||
}
|
||||
|
||||
private _requestSelected(ev: CustomEvent<RequestSelectedDetail>) {
|
||||
private async _requestSelected(ev: CustomEvent<RequestSelectedDetail>) {
|
||||
ev.stopPropagation();
|
||||
const entityId = (ev.target as HaListItem).value;
|
||||
if (ev.detail.selected) {
|
||||
@@ -314,10 +223,13 @@ class PanelCalendar extends LitElement {
|
||||
if (!calendar) {
|
||||
return;
|
||||
}
|
||||
this._subscribeCalendarEvents([calendar]);
|
||||
const result = await this._fetchEvents(this._start, this._end, [
|
||||
calendar,
|
||||
]);
|
||||
this._events = [...this._events, ...result.events];
|
||||
this._handleErrors(result.errors);
|
||||
} else {
|
||||
this._deSelectedCalendars = [...this._deSelectedCalendars, entityId];
|
||||
this._unsubscribeCalendar(entityId);
|
||||
this._events = this._events.filter(
|
||||
(event) => event.calendar !== entityId
|
||||
);
|
||||
@@ -342,15 +254,23 @@ class PanelCalendar extends LitElement {
|
||||
): Promise<void> {
|
||||
this._start = ev.detail.start;
|
||||
this._end = ev.detail.end;
|
||||
await this._unsubscribeAll();
|
||||
this._events = [];
|
||||
this._subscribeCalendarEvents(this._selectedCalendars);
|
||||
const result = await this._fetchEvents(
|
||||
this._start,
|
||||
this._end,
|
||||
this._selectedCalendars
|
||||
);
|
||||
this._events = result.events;
|
||||
this._handleErrors(result.errors);
|
||||
}
|
||||
|
||||
private async _handleRefresh(): Promise<void> {
|
||||
await this._unsubscribeAll();
|
||||
this._events = [];
|
||||
this._subscribeCalendarEvents(this._selectedCalendars);
|
||||
const result = await this._fetchEvents(
|
||||
this._start,
|
||||
this._end,
|
||||
this._selectedCalendars
|
||||
);
|
||||
this._events = result.events;
|
||||
this._handleErrors(result.errors);
|
||||
}
|
||||
|
||||
private _handleErrors(error_entity_ids: string[]) {
|
||||
|
||||
@@ -104,6 +104,7 @@ export class HaConfigApplicationCredentials extends LitElement {
|
||||
),
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
direction: "asc",
|
||||
},
|
||||
actions: {
|
||||
title: "",
|
||||
|
||||
@@ -8,24 +8,24 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import "../../../components/chips/ha-chip-set";
|
||||
import "../../../components/chips/ha-input-chip";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-aliases-editor";
|
||||
import "../../../components/ha-area-picker";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/ha-aliases-editor";
|
||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||
import "../../../components/ha-icon-picker";
|
||||
import "../../../components/ha-picture-upload";
|
||||
import "../../../components/ha-settings-row";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import "../../../components/ha-textfield";
|
||||
import { updateAreaRegistryEntry } from "../../../data/area_registry";
|
||||
import "../../../components/ha-area-picker";
|
||||
import type {
|
||||
FloorRegistryEntry,
|
||||
FloorRegistryEntryMutableParams,
|
||||
} from "../../../data/floor_registry";
|
||||
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { showAreaRegistryDetailDialog } from "./show-dialog-area-registry-detail";
|
||||
import type { FloorRegistryDetailDialogParams } from "./show-dialog-floor-registry-detail";
|
||||
import { showAreaRegistryDetailDialog } from "./show-dialog-area-registry-detail";
|
||||
import { updateAreaRegistryEntry } from "../../../data/area_registry";
|
||||
|
||||
class DialogFloorDetail extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@@ -168,6 +168,11 @@ class DialogFloorDetail extends LitElement {
|
||||
)}
|
||||
</h3>
|
||||
|
||||
<p class="description">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.floors.editor.areas_description"
|
||||
)}
|
||||
</p>
|
||||
${areas.length
|
||||
? html`<ha-chip-set>
|
||||
${repeat(
|
||||
@@ -192,17 +197,13 @@ class DialogFloorDetail extends LitElement {
|
||||
</ha-input-chip>`
|
||||
)}
|
||||
</ha-chip-set>`
|
||||
: html`<p class="description">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.floors.editor.areas_description"
|
||||
)}
|
||||
</p>`}
|
||||
: nothing}
|
||||
<ha-area-picker
|
||||
no-add
|
||||
.hass=${this.hass}
|
||||
@value-changed=${this._addArea}
|
||||
.excludeAreas=${areas.map((a) => a.area_id)}
|
||||
.addButtonLabel=${this.hass.localize(
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.floors.editor.add_area"
|
||||
)}
|
||||
></ha-area-picker>
|
||||
|
||||
@@ -588,11 +588,7 @@ export default class HaAutomationActionRow extends LitElement {
|
||||
...this._clipboard,
|
||||
action: deepClone(this.action),
|
||||
};
|
||||
let action = this.action;
|
||||
if ("sequence" in action) {
|
||||
action = { ...this.action, metadata: {} };
|
||||
}
|
||||
copyToClipboard(dump(action));
|
||||
copyToClipboard(dump(this.action));
|
||||
}
|
||||
|
||||
private _onDisable = () => {
|
||||
|
||||
@@ -1054,7 +1054,6 @@ class DialogAddAutomationElement
|
||||
private _onSearchFocus(ev) {
|
||||
this._removeKeyboardShortcuts = tinykeys(ev.target, {
|
||||
ArrowDown: this._focusSearchList,
|
||||
Enter: this._pickSingleItem,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1071,39 +1070,6 @@ class DialogAddAutomationElement
|
||||
this._itemsListFirstElement.focus();
|
||||
};
|
||||
|
||||
private _pickSingleItem = (ev: KeyboardEvent) => {
|
||||
if (!this._filter) {
|
||||
return;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
const automationElementType = this._params!.type;
|
||||
|
||||
const items = [
|
||||
...this._getFilteredItems(
|
||||
automationElementType,
|
||||
this._filter,
|
||||
this.hass.localize,
|
||||
this.hass.services,
|
||||
this._manifests
|
||||
),
|
||||
...(automationElementType !== "trigger"
|
||||
? this._getFilteredBuildingBlocks(
|
||||
automationElementType,
|
||||
this._filter,
|
||||
this.hass.localize
|
||||
)
|
||||
: []),
|
||||
];
|
||||
|
||||
if (items.length !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._params!.add(items[0].key);
|
||||
this.closeDialog();
|
||||
};
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
css`
|
||||
|
||||
@@ -452,10 +452,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
|
||||
.indeterminate=${partial}
|
||||
reducedTouchTarget
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -20,8 +20,7 @@ import "../../../../components/ha-md-divider";
|
||||
import "../../../../components/ha-md-menu-item";
|
||||
import { ACTION_BUILDING_BLOCKS } from "../../../../data/action";
|
||||
import type { ActionSidebarConfig } from "../../../../data/automation";
|
||||
import { domainToName } from "../../../../data/integration";
|
||||
import type { RepeatAction, ServiceAction } from "../../../../data/script";
|
||||
import type { RepeatAction } from "../../../../data/script";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import { isMac } from "../../../../util/is_mac";
|
||||
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
|
||||
@@ -84,23 +83,11 @@ export default class HaAutomationSidebarAction extends LitElement {
|
||||
"ui.panel.config.automation.editor.actions.action"
|
||||
);
|
||||
|
||||
let title =
|
||||
const title =
|
||||
this.hass.localize(
|
||||
`ui.panel.config.automation.editor.actions.type.${type}.label` as LocalizeKeys
|
||||
) || type;
|
||||
|
||||
if (type === "service" && (actionConfig as ServiceAction).action) {
|
||||
const [domain, service] = (actionConfig as ServiceAction).action!.split(
|
||||
".",
|
||||
2
|
||||
);
|
||||
title = `${domainToName(this.hass.localize, domain)}: ${
|
||||
this.hass.localize(`component.${domain}.services.${service}.name`) ||
|
||||
this.hass.services[domain][service]?.name ||
|
||||
title
|
||||
}`;
|
||||
}
|
||||
|
||||
const description = isBuildingBlock
|
||||
? this.hass.localize(
|
||||
`ui.panel.config.automation.editor.actions.type.${type}.description.picker` as LocalizeKeys
|
||||
|
||||
@@ -372,14 +372,16 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
||||
clickable
|
||||
id="backup_id"
|
||||
has-filters
|
||||
.filters=${Object.values(this._filters).filter((filter) =>
|
||||
Array.isArray(filter)
|
||||
? filter.length
|
||||
: filter &&
|
||||
Object.values(filter).some((val) =>
|
||||
Array.isArray(val) ? val.length : val
|
||||
)
|
||||
).length}
|
||||
.filters=${
|
||||
Object.values(this._filters).filter((filter) =>
|
||||
Array.isArray(filter)
|
||||
? filter.length
|
||||
: filter &&
|
||||
Object.values(filter).some((val) =>
|
||||
Array.isArray(val) ? val.length : val
|
||||
)
|
||||
).length
|
||||
}
|
||||
selectable
|
||||
.selected=${this._selected.length}
|
||||
.initialGroupColumn=${this._activeGrouping}
|
||||
@@ -421,28 +423,30 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
||||
</div>
|
||||
|
||||
<div slot="selection-bar">
|
||||
${!this.narrow
|
||||
? html`
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
@click=${this._deleteSelected}
|
||||
variant="danger"
|
||||
>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.delete_selected"
|
||||
)}
|
||||
</ha-button>
|
||||
`
|
||||
: html`
|
||||
<ha-icon-button
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.delete_selected"
|
||||
)}
|
||||
.path=${mdiDelete}
|
||||
class="warning"
|
||||
@click=${this._deleteSelected}
|
||||
></ha-icon-button>
|
||||
`}
|
||||
${
|
||||
!this.narrow
|
||||
? html`
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
@click=${this._deleteSelected}
|
||||
variant="danger"
|
||||
>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.delete_selected"
|
||||
)}
|
||||
</ha-button>
|
||||
`
|
||||
: html`
|
||||
<ha-icon-button
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.delete_selected"
|
||||
)}
|
||||
.path=${mdiDelete}
|
||||
class="warning"
|
||||
@click=${this._deleteSelected}
|
||||
></ha-icon-button>
|
||||
`
|
||||
}
|
||||
</div>
|
||||
|
||||
<ha-filter-states
|
||||
@@ -455,39 +459,43 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
||||
expanded
|
||||
.narrow=${this.narrow}
|
||||
></ha-filter-states>
|
||||
${!this._needsOnboarding
|
||||
? html`
|
||||
<ha-fab
|
||||
slot="fab"
|
||||
?disabled=${backupInProgress}
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.new_backup"
|
||||
)}
|
||||
extended
|
||||
@click=${this._newBackup}
|
||||
>
|
||||
${backupInProgress
|
||||
? html`<div slot="icon" class="loading">
|
||||
<ha-spinner .size=${"small"}></ha-spinner>
|
||||
</div>`
|
||||
: html`<ha-svg-icon
|
||||
slot="icon"
|
||||
.path=${mdiPlus}
|
||||
></ha-svg-icon>`}
|
||||
</ha-fab>
|
||||
`
|
||||
: nothing}
|
||||
${
|
||||
!this._needsOnboarding
|
||||
? html`
|
||||
<ha-fab
|
||||
slot="fab"
|
||||
?disabled=${backupInProgress}
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.backup.backups.new_backup"
|
||||
)}
|
||||
extended
|
||||
@click=${this._newBackup}
|
||||
>
|
||||
${backupInProgress
|
||||
? html`<div slot="icon" class="loading">
|
||||
<ha-spinner .size=${"small"}></ha-spinner>
|
||||
</div>`
|
||||
: html`<ha-svg-icon
|
||||
slot="icon"
|
||||
.path=${mdiPlus}
|
||||
></ha-svg-icon>`}
|
||||
</ha-fab>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
</hass-tabs-subpage-data-table>
|
||||
<ha-md-menu id="overflow-menu" positioning="fixed">
|
||||
<ha-md-menu-item .clickAction=${this._downloadBackup}>
|
||||
<ha-svg-icon slot="start" .path=${mdiDownload}></ha-svg-icon>
|
||||
${this.hass.localize("ui.common.download")}
|
||||
</ha-md-menu-item>
|
||||
<ha-md-menu-item class="warning" .clickAction=${this._deleteBackup}>
|
||||
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
|
||||
${this.hass.localize("ui.common.delete")}
|
||||
</ha-md-menu-item>
|
||||
</ha-md-menu>
|
||||
<ha-md-menu-item .clickAction=${this._downloadBackup}>
|
||||
<ha-svg-icon slot="start" .path=${mdiDownload}></ha-svg-icon>
|
||||
${this.hass.localize("ui.common.download")}
|
||||
</ha-md-menu-item>
|
||||
<ha-md-menu-item class="warning" .clickAction=${this._deleteBackup}>
|
||||
<ha-svg-icon slot="start" .path=${mdiDelete}></ha-svg-icon>
|
||||
${this.hass.localize("ui.common.delete")}
|
||||
</ha-md-menu-item>
|
||||
</ha-md-menu>
|
||||
>
|
||||
</ha-icon-overflow-menu>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -561,15 +569,15 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
||||
navigate(`/config/backup/details/${id}`);
|
||||
}
|
||||
|
||||
private _downloadBackup = async (ev): Promise<void> => {
|
||||
private async _downloadBackup(ev): Promise<void> {
|
||||
const backup = ev.parentElement.anchorElement.backup;
|
||||
if (!backup) {
|
||||
return;
|
||||
}
|
||||
downloadBackup(this.hass, this, backup, this.config);
|
||||
};
|
||||
}
|
||||
|
||||
private _deleteBackup = async (ev): Promise<void> => {
|
||||
private async _deleteBackup(ev): Promise<void> {
|
||||
const backup = ev.parentElement.anchorElement.backup;
|
||||
if (!backup) {
|
||||
return;
|
||||
@@ -601,7 +609,7 @@ class HaConfigBackupBackups extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
fireEvent(this, "ha-refresh-backup-info");
|
||||
};
|
||||
}
|
||||
|
||||
private async _deleteSelected() {
|
||||
const confirm = await showConfirmationDialog(this, {
|
||||
|
||||
@@ -182,11 +182,13 @@ class HaBlueprintOverview extends LitElement {
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
groupable: true,
|
||||
direction: "asc",
|
||||
},
|
||||
path: {
|
||||
title: localize("ui.panel.config.blueprint.overview.headers.file_name"),
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
direction: "asc",
|
||||
flex: 2,
|
||||
},
|
||||
fullpath: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mdiPlus, mdiTag } from "@mdi/js";
|
||||
import { mdiTag, mdiPlus } from "@mdi/js";
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { TemplateResult } from "lit";
|
||||
import { html, LitElement } from "lit";
|
||||
@@ -194,9 +194,8 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
||||
.hass=${this.hass}
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label}
|
||||
.notFoundLabel=${this._notFoundLabel}
|
||||
.emptyLabel=${this.hass.localize(
|
||||
"ui.components.category-picker.no_categories"
|
||||
.notFoundLabel=${this.hass.localize(
|
||||
"ui.components.category-picker.no_match"
|
||||
)}
|
||||
.placeholder=${placeholder}
|
||||
.value=${this.value}
|
||||
@@ -255,11 +254,6 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
||||
fireEvent(this, "change");
|
||||
}, 0);
|
||||
}
|
||||
|
||||
private _notFoundLabel = (search: string) =>
|
||||
this.hass.localize("ui.components.category-picker.no_match", {
|
||||
term: html`<b>‘${search}’</b>`,
|
||||
});
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -20,7 +20,6 @@ import { subscribeEntityRegistry } from "../../../data/entity_registry";
|
||||
import type { UpdateEntity } from "../../../data/update";
|
||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import "../../../components/ha-progress-ring";
|
||||
|
||||
@customElement("ha-config-updates")
|
||||
class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
@@ -57,29 +56,6 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
this._entities?.find((entity) => entity.entity_id === entityId)
|
||||
);
|
||||
|
||||
private _renderUpdateProgress(entity: UpdateEntity) {
|
||||
if (entity.attributes.update_percentage != null) {
|
||||
return html`<ha-progress-ring
|
||||
size="small"
|
||||
.value=${entity.attributes.update_percentage}
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.updates.update_in_progress"
|
||||
)}
|
||||
></ha-progress-ring>`;
|
||||
}
|
||||
|
||||
if (entity.attributes.in_progress) {
|
||||
return html`<ha-spinner
|
||||
size="small"
|
||||
.ariaLabel=${this.hass.localize(
|
||||
"ui.panel.config.updates.update_in_progress"
|
||||
)}
|
||||
></ha-spinner>`;
|
||||
}
|
||||
|
||||
return html`<ha-icon-next></ha-icon-next>`;
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.updateEntities?.length) {
|
||||
return nothing;
|
||||
@@ -130,9 +106,13 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
)}
|
||||
></state-badge>
|
||||
${this.narrow && entity.attributes.in_progress
|
||||
? html`<div class="absolute">
|
||||
${this._renderUpdateProgress(entity)}
|
||||
</div>`
|
||||
? html`<ha-spinner
|
||||
class="absolute"
|
||||
size="small"
|
||||
.ariaLabel=${this.hass.localize(
|
||||
"ui.panel.config.updates.update_in_progress"
|
||||
)}
|
||||
></ha-spinner>`
|
||||
: nothing}
|
||||
</div>
|
||||
<span slot="headline"
|
||||
@@ -148,9 +128,16 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
: nothing}
|
||||
</span>
|
||||
${!this.narrow
|
||||
? html`<div slot="end">
|
||||
${this._renderUpdateProgress(entity)}
|
||||
</div>`
|
||||
? entity.attributes.in_progress
|
||||
? html`<div slot="end">
|
||||
<ha-spinner
|
||||
size="small"
|
||||
.ariaLabel=${this.hass.localize(
|
||||
"ui.panel.config.updates.update_in_progress"
|
||||
)}
|
||||
></ha-spinner>
|
||||
</div>`
|
||||
: html`<ha-icon-next slot="end"></ha-icon-next>`
|
||||
: nothing}
|
||||
</ha-md-list-item>
|
||||
`;
|
||||
@@ -206,13 +193,13 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
div[slot="start"] {
|
||||
position: relative;
|
||||
}
|
||||
div.absolute {
|
||||
ha-spinner.absolute {
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 6px;
|
||||
}
|
||||
state-badge.updating {
|
||||
opacity: 0.2;
|
||||
opacity: 0.5;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -771,10 +771,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
|
||||
.indeterminate=${partial}
|
||||
reducedTouchTarget
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -9,7 +9,6 @@ import "../../../../components/ha-dialog";
|
||||
import "../../../../components/ha-button";
|
||||
import "../../../../components/ha-formfield";
|
||||
import "../../../../components/ha-radio";
|
||||
import "../../../../components/ha-markdown";
|
||||
import type { HaRadio } from "../../../../components/ha-radio";
|
||||
import type {
|
||||
FlowFromGridSourceEnergyPreference,
|
||||
@@ -20,7 +19,11 @@ import {
|
||||
emptyFlowToGridSourceEnergyPreference,
|
||||
energyStatisticHelpUrl,
|
||||
} from "../../../../data/energy";
|
||||
import { isExternalStatistic } from "../../../../data/recorder";
|
||||
import {
|
||||
getDisplayUnit,
|
||||
getStatisticMetadata,
|
||||
isExternalStatistic,
|
||||
} from "../../../../data/recorder";
|
||||
import { getSensorDeviceClassConvertibleUnits } from "../../../../data/sensor";
|
||||
import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||
import { haStyleDialog } from "../../../../resources/styles";
|
||||
@@ -44,6 +47,8 @@ export class DialogEnergyGridFlowSettings
|
||||
|
||||
@state() private _costs?: "no-costs" | "number" | "entity" | "statistic";
|
||||
|
||||
@state() private _pickedDisplayUnit?: string | null;
|
||||
|
||||
@state() private _energy_units?: string[];
|
||||
|
||||
@state() private _error?: string;
|
||||
@@ -76,6 +81,11 @@ export class DialogEnergyGridFlowSettings
|
||||
: "stat_energy_to"
|
||||
];
|
||||
|
||||
this._pickedDisplayUnit = getDisplayUnit(
|
||||
this.hass,
|
||||
initialSourceId,
|
||||
params.metadata
|
||||
);
|
||||
this._energy_units = (
|
||||
await getSensorDeviceClassConvertibleUnits(this.hass, "energy")
|
||||
).units;
|
||||
@@ -93,6 +103,7 @@ export class DialogEnergyGridFlowSettings
|
||||
public closeDialog() {
|
||||
this._params = undefined;
|
||||
this._source = undefined;
|
||||
this._pickedDisplayUnit = undefined;
|
||||
this._error = undefined;
|
||||
this._excludeList = undefined;
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
@@ -106,6 +117,10 @@ export class DialogEnergyGridFlowSettings
|
||||
|
||||
const pickableUnit = this._energy_units?.join(", ") || "";
|
||||
|
||||
const unitPriceSensor = this._pickedDisplayUnit
|
||||
? `${this.hass.config.currency}/${this._pickedDisplayUnit}`
|
||||
: undefined;
|
||||
|
||||
const unitPriceFixed = `${this.hass.config.currency}/kWh`;
|
||||
|
||||
const externalSource =
|
||||
@@ -231,15 +246,9 @@ export class DialogEnergyGridFlowSettings
|
||||
.hass=${this.hass}
|
||||
include-domains='["sensor", "input_number"]'
|
||||
.value=${this._source.entity_energy_price}
|
||||
.label=${this.hass.localize(
|
||||
.label=${`${this.hass.localize(
|
||||
`ui.panel.config.energy.grid.flow_dialog.${this._params.direction}.cost_entity_input`
|
||||
)}
|
||||
.helper=${html`<ha-markdown
|
||||
.content=${this.hass.localize(
|
||||
"ui.panel.config.energy.grid.flow_dialog.cost_entity_helper",
|
||||
{ currency: this.hass.config.currency }
|
||||
)}
|
||||
></ha-markdown>`}
|
||||
)} ${unitPriceSensor ? ` (${unitPriceSensor})` : ""}`}
|
||||
@value-changed=${this._priceEntityChanged}
|
||||
></ha-entity-picker>`
|
||||
: ""}
|
||||
@@ -332,6 +341,16 @@ export class DialogEnergyGridFlowSettings
|
||||
}
|
||||
|
||||
private async _statisticChanged(ev: CustomEvent<{ value: string }>) {
|
||||
if (ev.detail.value) {
|
||||
const metadata = await getStatisticMetadata(this.hass, [ev.detail.value]);
|
||||
this._pickedDisplayUnit = getDisplayUnit(
|
||||
this.hass,
|
||||
ev.detail.value,
|
||||
metadata[0]
|
||||
);
|
||||
} else {
|
||||
this._pickedDisplayUnit = undefined;
|
||||
}
|
||||
this._source = {
|
||||
...this._source!,
|
||||
[this._params!.direction === "from"
|
||||
|
||||
@@ -792,10 +792,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
||||
.indeterminate=${partial}
|
||||
reducedTouchTarget
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -634,10 +634,7 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {
|
||||
.indeterminate=${partial}
|
||||
reducedTouchTarget
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -107,8 +107,6 @@ class HaConfigInfo extends LitElement {
|
||||
const customUiList: { name: string; url: string; version: string }[] =
|
||||
(window as any).CUSTOM_UI_LIST || [];
|
||||
|
||||
const isDark = this.hass.themes?.darkMode || false;
|
||||
|
||||
return html`
|
||||
<hass-subpage
|
||||
.hass=${this.hass}
|
||||
@@ -188,7 +186,7 @@ class HaConfigInfo extends LitElement {
|
||||
: nothing}
|
||||
</ul>
|
||||
</ha-card>
|
||||
<ha-card outlined class="ohf ${isDark ? "dark" : ""}">
|
||||
<ha-card outlined class="ohf">
|
||||
<div>
|
||||
${this.hass.localize("ui.panel.config.info.proud_part_of")}
|
||||
</div>
|
||||
@@ -348,10 +346,6 @@ class HaConfigInfo extends LitElement {
|
||||
max-width: 250px;
|
||||
}
|
||||
|
||||
.ohf.dark img {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
.versions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -8,7 +8,6 @@ import { css, html, LitElement } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { relativeTime } from "../../../../../common/datetime/relative_time";
|
||||
import { getDeviceContext } from "../../../../../common/entity/context/get_device_context";
|
||||
import { navigate } from "../../../../../common/navigate";
|
||||
import { throttle } from "../../../../../common/util/throttle";
|
||||
import "../../../../../components/chart/ha-network-graph";
|
||||
@@ -195,17 +194,11 @@ export class BluetoothNetworkVisualization extends LitElement {
|
||||
];
|
||||
const links: NetworkLink[] = [];
|
||||
Object.values(scanners).forEach((scanner) => {
|
||||
const scannerDevice = this._sourceDevices[scanner.source] as
|
||||
| DeviceRegistryEntry
|
||||
| undefined;
|
||||
const area = scannerDevice
|
||||
? getDeviceContext(scannerDevice, this.hass).area
|
||||
: undefined;
|
||||
const scannerDevice = this._sourceDevices[scanner.source];
|
||||
nodes.push({
|
||||
id: scanner.source,
|
||||
name:
|
||||
scannerDevice?.name_by_user || scannerDevice?.name || scanner.name,
|
||||
context: area?.name,
|
||||
category: 1,
|
||||
value: 5,
|
||||
symbol: "circle",
|
||||
@@ -238,16 +231,10 @@ export class BluetoothNetworkVisualization extends LitElement {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const device = this._sourceDevices[node.address] as
|
||||
| DeviceRegistryEntry
|
||||
| undefined;
|
||||
const area = device
|
||||
? getDeviceContext(device, this.hass).area
|
||||
: undefined;
|
||||
const device = this._sourceDevices[node.address];
|
||||
nodes.push({
|
||||
id: node.address,
|
||||
name: this._getBluetoothDeviceName(node.address),
|
||||
context: area?.name,
|
||||
value: device ? 1 : 0,
|
||||
category: device ? 2 : 3,
|
||||
symbolSize: 20,
|
||||
@@ -307,20 +294,15 @@ export class BluetoothNetworkVisualization extends LitElement {
|
||||
const btDevice = this._data.find((d) => d.address === address);
|
||||
if (btDevice) {
|
||||
tooltipText = `<b>${name}</b><br><b>${this.hass.localize("ui.panel.config.bluetooth.address")}:</b> ${address}<br><b>${this.hass.localize("ui.panel.config.bluetooth.rssi")}:</b> ${btDevice.rssi}<br><b>${this.hass.localize("ui.panel.config.bluetooth.source")}:</b> ${btDevice.source}<br><b>${this.hass.localize("ui.panel.config.bluetooth.updated")}:</b> ${relativeTime(new Date(btDevice.time * 1000), this.hass.locale)}`;
|
||||
const device = this._sourceDevices[address];
|
||||
if (device) {
|
||||
const area = getDeviceContext(device, this.hass).area;
|
||||
if (area) {
|
||||
tooltipText += `<br><b>${this.hass.localize("ui.panel.config.bluetooth.area")}: </b>${area.name}`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const device = this._sourceDevices[address];
|
||||
if (device) {
|
||||
tooltipText = `<b>${name}</b><br><b>${this.hass.localize("ui.panel.config.bluetooth.address")}:</b> ${address}`;
|
||||
const area = getDeviceContext(device, this.hass).area;
|
||||
if (area) {
|
||||
tooltipText += `<br><b>${this.hass.localize("ui.panel.config.bluetooth.area")}: </b>${area.name}`;
|
||||
if (device.area_id) {
|
||||
const area = this.hass.areas[device.area_id];
|
||||
if (area) {
|
||||
tooltipText += `<br><b>${this.hass.localize("ui.panel.config.bluetooth.area")}: </b>${area.name}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import "../../../../../layouts/hass-tabs-subpage";
|
||||
import type { HomeAssistant, Route } from "../../../../../types";
|
||||
import { formatAsPaddedHex } from "./functions";
|
||||
import { zhaTabs } from "./zha-config-dashboard";
|
||||
import type { DeviceRegistryEntry } from "../../../../../data/device_registry";
|
||||
import { getDeviceContext } from "../../../../../common/entity/context/get_device_context";
|
||||
|
||||
@customElement("zha-network-visualization-page")
|
||||
export class ZHANetworkVisualizationPage extends LitElement {
|
||||
@@ -119,11 +117,8 @@ export class ZHANetworkVisualizationPage extends LitElement {
|
||||
} else {
|
||||
label += `<br><b>${this.hass.localize("ui.panel.config.zha.visualization.device_not_in_db")}</b>`;
|
||||
}
|
||||
const haDevice = this.hass.devices[device.device_reg_id] as
|
||||
| DeviceRegistryEntry
|
||||
| undefined;
|
||||
if (haDevice) {
|
||||
const area = getDeviceContext(haDevice, this.hass).area;
|
||||
if (device.area_id) {
|
||||
const area = this.hass.areas[device.area_id];
|
||||
if (area) {
|
||||
label += `<br><b>${this.hass.localize("ui.panel.config.zha.visualization.area")}: </b>${area.name}`;
|
||||
}
|
||||
@@ -209,17 +204,10 @@ export class ZHANetworkVisualizationPage extends LitElement {
|
||||
category = 2; // End Device
|
||||
}
|
||||
|
||||
const haDevice = this.hass.devices[device.device_reg_id] as
|
||||
| DeviceRegistryEntry
|
||||
| undefined;
|
||||
const area = haDevice
|
||||
? getDeviceContext(haDevice, this.hass).area
|
||||
: undefined;
|
||||
// Create node
|
||||
nodes.push({
|
||||
id: device.ieee,
|
||||
name: device.user_given_name || device.name || device.ieee,
|
||||
context: area?.name,
|
||||
category,
|
||||
value: isCoordinator ? 3 : device.device_type === "Router" ? 2 : 1,
|
||||
symbolSize: isCoordinator
|
||||
|
||||
@@ -5,7 +5,6 @@ import type {
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { getDeviceContext } from "../../../../../common/entity/context/get_device_context";
|
||||
import { navigate } from "../../../../../common/navigate";
|
||||
import { debounce } from "../../../../../common/util/debounce";
|
||||
import "../../../../../components/chart/ha-network-graph";
|
||||
@@ -125,7 +124,7 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
|
||||
return tip;
|
||||
}
|
||||
const { id, name } = data as any;
|
||||
const device = this._devices[id] as DeviceRegistryEntry | undefined;
|
||||
const device = this._devices[id];
|
||||
const nodeStatus = this._nodeStatuses[id];
|
||||
let tip = `${(params as any).marker} ${name}`;
|
||||
tip += `<br><b>${this.hass.localize("ui.panel.config.zwave_js.visualization.node_id")}:</b> ${id}`;
|
||||
@@ -139,12 +138,6 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
|
||||
tip += `<br><b>Z-Wave Plus:</b> ${this.hass.localize("ui.panel.config.zwave_js.visualization.version")} ${nodeStatus.zwave_plus_version}`;
|
||||
}
|
||||
}
|
||||
if (device) {
|
||||
const area = getDeviceContext(device, this.hass).area;
|
||||
if (area) {
|
||||
tip += `<br><b>${this.hass.localize("ui.panel.config.zwave_js.visualization.area")}:</b> ${area.name}`;
|
||||
}
|
||||
}
|
||||
return tip;
|
||||
};
|
||||
|
||||
@@ -204,16 +197,10 @@ export class ZWaveJSNetworkVisualization extends SubscribeMixin(LitElement) {
|
||||
if (node.is_controller_node) {
|
||||
controllerNode = node.node_id;
|
||||
}
|
||||
const device = this._devices[node.node_id] as
|
||||
| DeviceRegistryEntry
|
||||
| undefined;
|
||||
const area = device
|
||||
? getDeviceContext(device, this.hass).area
|
||||
: undefined;
|
||||
const device = this._devices[node.node_id];
|
||||
nodes.push({
|
||||
id: String(node.node_id),
|
||||
name: device?.name_by_user ?? device?.name ?? String(node.node_id),
|
||||
context: area?.name,
|
||||
value: node.is_controller_node ? 3 : node.is_routing ? 2 : 1,
|
||||
category:
|
||||
node.status === NodeStatus.Dead
|
||||
|
||||
@@ -320,9 +320,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
||||
|
||||
if (this.hass.panels.light) {
|
||||
result.push({
|
||||
icon: this.hass.panels.light.icon || "mdi:lamps",
|
||||
icon: "mdi:lamps",
|
||||
title: this.hass.localize("panel.light"),
|
||||
show_in_sidebar: true,
|
||||
show_in_sidebar: false,
|
||||
mode: "storage",
|
||||
url_path: "light",
|
||||
filename: "",
|
||||
@@ -334,9 +334,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
||||
|
||||
if (this.hass.panels.security) {
|
||||
result.push({
|
||||
icon: this.hass.panels.security.icon || "mdi:security",
|
||||
icon: "mdi:security",
|
||||
title: this.hass.localize("panel.security"),
|
||||
show_in_sidebar: true,
|
||||
show_in_sidebar: false,
|
||||
mode: "storage",
|
||||
url_path: "security",
|
||||
filename: "",
|
||||
@@ -348,9 +348,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
||||
|
||||
if (this.hass.panels.climate) {
|
||||
result.push({
|
||||
icon: this.hass.panels.climate.icon || "mdi:home-thermometer",
|
||||
icon: "mdi:home-thermometer",
|
||||
title: this.hass.localize("panel.climate"),
|
||||
show_in_sidebar: true,
|
||||
show_in_sidebar: false,
|
||||
mode: "storage",
|
||||
url_path: "climate",
|
||||
filename: "",
|
||||
|
||||
@@ -41,6 +41,7 @@ class DialogRepairsIssueSubtitle extends LitElement {
|
||||
:host {
|
||||
display: block;
|
||||
font-size: var(--ha-font-size-m);
|
||||
margin-bottom: 8px;
|
||||
color: var(--secondary-text-color);
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { mdiOpenInNew } from "@mdi/js";
|
||||
import { mdiClose, mdiOpenInNew } from "@mdi/js";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, state, query } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { isNavigationClick } from "../../../common/dom/is-navigation-click";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-wa-dialog";
|
||||
import "../../../components/ha-md-dialog";
|
||||
import type { HaMdDialog } from "../../../components/ha-md-dialog";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import "../../../components/ha-dialog-footer";
|
||||
import "../../../components/ha-dialog-header";
|
||||
import "./dialog-repairs-issue-subtitle";
|
||||
import "../../../components/ha-markdown";
|
||||
import type { RepairsIssue } from "../../../data/repairs";
|
||||
@@ -25,12 +26,11 @@ class DialogRepairsIssue extends LitElement {
|
||||
|
||||
@state() private _params?: RepairsIssueDialogParams;
|
||||
|
||||
@state() private _open = false;
|
||||
@query("ha-md-dialog") private _dialog?: HaMdDialog;
|
||||
|
||||
public showDialog(params: RepairsIssueDialogParams): void {
|
||||
this._params = params;
|
||||
this._issue = this._params.issue;
|
||||
this._open = true;
|
||||
}
|
||||
|
||||
private _dialogClosed() {
|
||||
@@ -44,7 +44,7 @@ class DialogRepairsIssue extends LitElement {
|
||||
}
|
||||
|
||||
public closeDialog() {
|
||||
this._open = false;
|
||||
this._dialog?.close();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -62,19 +62,32 @@ class DialogRepairsIssue extends LitElement {
|
||||
) || this.hass!.localize("ui.panel.config.repairs.dialog.title");
|
||||
|
||||
return html`
|
||||
<ha-wa-dialog
|
||||
.hass=${this.hass}
|
||||
.open=${this._open}
|
||||
header-title=${dialogTitle}
|
||||
aria-describedby="dialog-repairs-issue-description"
|
||||
<ha-md-dialog
|
||||
open
|
||||
@closed=${this._dialogClosed}
|
||||
aria-labelledby="dialog-repairs-issue-title"
|
||||
aria-describedby="dialog-repairs-issue-description"
|
||||
>
|
||||
<dialog-repairs-issue-subtitle
|
||||
slot="headerSubtitle"
|
||||
.hass=${this.hass}
|
||||
.issue=${this._issue}
|
||||
></dialog-repairs-issue-subtitle>
|
||||
<div class="dialog-content">
|
||||
<ha-dialog-header slot="headline">
|
||||
<ha-icon-button
|
||||
slot="navigationIcon"
|
||||
.label=${this.hass.localize("ui.common.close") ?? "Close"}
|
||||
.path=${mdiClose}
|
||||
@click=${this.closeDialog}
|
||||
></ha-icon-button>
|
||||
<span
|
||||
slot="title"
|
||||
id="dialog-repairs-issue-title"
|
||||
.title=${dialogTitle}
|
||||
>${dialogTitle}</span
|
||||
>
|
||||
<dialog-repairs-issue-subtitle
|
||||
slot="subtitle"
|
||||
.hass=${this.hass}
|
||||
.issue=${this._issue}
|
||||
></dialog-repairs-issue-subtitle>
|
||||
</ha-dialog-header>
|
||||
<div slot="content" class="dialog-content">
|
||||
${this._issue.breaks_in_ha_version
|
||||
? html`
|
||||
<ha-alert alert-type="warning">
|
||||
@@ -109,12 +122,8 @@ class DialogRepairsIssue extends LitElement {
|
||||
`
|
||||
: ""}
|
||||
</div>
|
||||
<ha-dialog-footer slot="footer">
|
||||
<ha-button
|
||||
slot="secondaryAction"
|
||||
appearance="plain"
|
||||
@click=${this._ignoreIssue}
|
||||
>
|
||||
<div slot="actions">
|
||||
<ha-button appearance="plain" @click=${this._ignoreIssue}>
|
||||
${this._issue!.ignored
|
||||
? this.hass!.localize("ui.panel.config.repairs.dialog.unignore")
|
||||
: this.hass!.localize("ui.panel.config.repairs.dialog.ignore")}
|
||||
@@ -122,7 +131,6 @@ class DialogRepairsIssue extends LitElement {
|
||||
${this._issue.learn_more_url
|
||||
? html`
|
||||
<ha-button
|
||||
slot="primaryAction"
|
||||
appearance="filled"
|
||||
rel="noopener noreferrer"
|
||||
href=${learnMoreUrlIsHomeAssistant
|
||||
@@ -141,8 +149,8 @@ class DialogRepairsIssue extends LitElement {
|
||||
</ha-button>
|
||||
`
|
||||
: ""}
|
||||
</ha-dialog-footer>
|
||||
</ha-wa-dialog>
|
||||
</div>
|
||||
</ha-md-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -164,7 +172,7 @@ class DialogRepairsIssue extends LitElement {
|
||||
padding-top: 0;
|
||||
}
|
||||
ha-alert {
|
||||
margin-bottom: var(--ha-space-4);
|
||||
margin-bottom: 16px;
|
||||
display: block;
|
||||
}
|
||||
.dismissed {
|
||||
|
||||
@@ -473,10 +473,7 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) {
|
||||
.indeterminate=${partial}
|
||||
reducedTouchTarget
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -458,10 +458,7 @@ class HaScriptPicker extends SubscribeMixin(LitElement) {
|
||||
.checked=${selected}
|
||||
.indeterminate=${partial}
|
||||
></ha-checkbox>
|
||||
<ha-label
|
||||
style=${color ? `--color: ${color}` : ""}
|
||||
.description=${label.description}
|
||||
>
|
||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
||||
${label.icon
|
||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||
: nothing}
|
||||
|
||||
@@ -371,11 +371,7 @@ export class HaManualScriptEditor extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
const actionType = getActionType(config);
|
||||
if (
|
||||
!["sequence", "unknown"].includes(actionType) ||
|
||||
(actionType === "sequence" && "metadata" in config)
|
||||
) {
|
||||
if (!["sequence", "unknown"].includes(getActionType(config))) {
|
||||
config = { sequence: [config] };
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ export class HaConfigUsers extends LitElement {
|
||||
title: localize("ui.panel.config.users.picker.headers.username"),
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
direction: "asc",
|
||||
template: (user) => html`${user.username || "—"}`,
|
||||
},
|
||||
group: {
|
||||
@@ -97,6 +98,7 @@ export class HaConfigUsers extends LitElement {
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
groupable: true,
|
||||
direction: "asc",
|
||||
},
|
||||
is_active: {
|
||||
title: this.hass.localize(
|
||||
|
||||
@@ -148,9 +148,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
).pipeline_runs.reverse();
|
||||
} catch (e: any) {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.fetch_runs"
|
||||
),
|
||||
title: "Failed to fetch pipeline runs",
|
||||
text: e.message,
|
||||
});
|
||||
return;
|
||||
@@ -178,9 +176,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
).events;
|
||||
} catch (e: any) {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.fetch_events"
|
||||
),
|
||||
title: "Failed to fetch events",
|
||||
text: e.message,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -30,26 +30,16 @@ export class AssistPipelineEvents extends LitElement {
|
||||
const run = this._processEvents(this.events);
|
||||
if (!run) {
|
||||
if (this.events.length) {
|
||||
return html`<ha-alert alert-type="error"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.showing_run"
|
||||
)}</ha-alert
|
||||
>
|
||||
return html`<ha-alert alert-type="error">Error showing run</ha-alert>
|
||||
<ha-card>
|
||||
<ha-expansion-panel>
|
||||
<span slot="header"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.raw"
|
||||
)}</span
|
||||
>
|
||||
<span slot="header">Raw</span>
|
||||
<pre>${JSON.stringify(this.events, null, 2)}</pre>
|
||||
</ha-expansion-panel>
|
||||
</ha-card>`;
|
||||
}
|
||||
return html`<ha-alert alert-type="warning"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.no_events"
|
||||
)}</ha-alert
|
||||
>There were no events in this run.</ha-alert
|
||||
>`;
|
||||
}
|
||||
return html`
|
||||
|
||||
@@ -11,16 +11,31 @@ import type { HomeAssistant } from "../../../../types";
|
||||
import { formatNumber } from "../../../../common/number/format_number";
|
||||
import "../../../../components/ha-yaml-editor";
|
||||
import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box";
|
||||
import type { LocalizeKeys } from "../../../../common/translations/localize";
|
||||
|
||||
const RUN_DATA = ["pipeline", "language"];
|
||||
const WAKE_WORD_DATA = ["engine"];
|
||||
const RUN_DATA = {
|
||||
pipeline: "Pipeline",
|
||||
language: "Language",
|
||||
};
|
||||
const WAKE_WORD_DATA = {
|
||||
engine: "Engine",
|
||||
};
|
||||
|
||||
const STT_DATA = ["engine"];
|
||||
const STT_DATA = {
|
||||
engine: "Engine",
|
||||
};
|
||||
|
||||
const INTENT_DATA = ["engine", "language", "intent_input"];
|
||||
const INTENT_DATA = {
|
||||
engine: "Engine",
|
||||
language: "Language",
|
||||
intent_input: "Input",
|
||||
};
|
||||
|
||||
const TTS_DATA = ["engine", "language", "voice", "tts_input"];
|
||||
const TTS_DATA = {
|
||||
engine: "Engine",
|
||||
language: "Language",
|
||||
voice: "Voice",
|
||||
tts_input: "Input",
|
||||
};
|
||||
|
||||
const STAGES: Record<PipelineRun["stage"], number> = {
|
||||
ready: 0,
|
||||
@@ -87,32 +102,24 @@ const renderProgress = (
|
||||
return html`${durationString}s ✅`;
|
||||
};
|
||||
|
||||
const renderData = (
|
||||
hass: HomeAssistant,
|
||||
data: Record<string, any>,
|
||||
keys: string[]
|
||||
) =>
|
||||
keys.map((key) => {
|
||||
const label = hass.localize(
|
||||
`ui.panel.config.voice_assistants.debug.stages.${key}` as LocalizeKeys
|
||||
);
|
||||
return html`
|
||||
const renderData = (data: Record<string, any>, keys: Record<string, string>) =>
|
||||
Object.entries(keys).map(
|
||||
([key, label]) => html`
|
||||
<div class="row">
|
||||
<div>${label}</div>
|
||||
<div>${data[key]}</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
`
|
||||
);
|
||||
|
||||
const dataMinusKeysRender = (
|
||||
hass: HomeAssistant,
|
||||
data: Record<string, any>,
|
||||
keys: string[]
|
||||
keys: Record<string, string>
|
||||
) => {
|
||||
const result = {};
|
||||
let render = false;
|
||||
for (const key in data) {
|
||||
if (keys.includes(key) || key === "done") {
|
||||
if (key in keys || key === "done") {
|
||||
continue;
|
||||
}
|
||||
render = true;
|
||||
@@ -120,9 +127,7 @@ const dataMinusKeysRender = (
|
||||
}
|
||||
return render
|
||||
? html`<ha-expansion-panel>
|
||||
<span slot="header"
|
||||
>${hass.localize("ui.panel.config.voice_assistants.debug.raw")}</span
|
||||
>
|
||||
<span slot="header">Raw</span>
|
||||
<ha-yaml-editor readOnly autoUpdate .value=${result}></ha-yaml-editor>
|
||||
</ha-expansion-panel>`
|
||||
: "";
|
||||
@@ -134,12 +139,6 @@ export class AssistPipelineDebug extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public pipelineRun!: PipelineRun;
|
||||
|
||||
private _audioElement?: HTMLAudioElement;
|
||||
|
||||
private get _isPlaying(): boolean {
|
||||
return this._audioElement != null && !this._audioElement.paused;
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const lastRunStage: string = this.pipelineRun
|
||||
? ["tts", "intent", "stt", "wake_word"].find(
|
||||
@@ -178,15 +177,11 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.run"
|
||||
)}
|
||||
</div>
|
||||
<div>Run</div>
|
||||
<div>${this.pipelineRun.stage}</div>
|
||||
</div>
|
||||
|
||||
${renderData(this.hass, this.pipelineRun.run, RUN_DATA)}
|
||||
${renderData(this.pipelineRun.run, RUN_DATA)}
|
||||
${messages.length > 0
|
||||
? html`
|
||||
<div class="messages">
|
||||
@@ -208,39 +203,23 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.wake_word"
|
||||
)}</span
|
||||
>
|
||||
<span>Wake word</span>
|
||||
${renderProgress(this.hass, this.pipelineRun, "wake_word")}
|
||||
</div>
|
||||
${this.pipelineRun.wake_word
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(
|
||||
this.hass,
|
||||
this.pipelineRun.wake_word,
|
||||
WAKE_WORD_DATA
|
||||
)}
|
||||
${renderData(this.pipelineRun.wake_word, STT_DATA)}
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
? html`<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.model"
|
||||
)}
|
||||
</div>
|
||||
<div>Model</div>
|
||||
<div>
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
.ww_id}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.timestamp"
|
||||
)}
|
||||
</div>
|
||||
<div>Timestamp</div>
|
||||
<div>
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
.timestamp}
|
||||
@@ -248,7 +227,6 @@ export class AssistPipelineDebug extends LitElement {
|
||||
</div>`
|
||||
: ""}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.wake_word,
|
||||
WAKE_WORD_DATA
|
||||
)}
|
||||
@@ -265,11 +243,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.speech_to_text"
|
||||
)}</span
|
||||
>
|
||||
<span>Speech-to-text</span>
|
||||
${renderProgress(
|
||||
this.hass,
|
||||
this.pipelineRun,
|
||||
@@ -280,30 +254,18 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun.stt
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.hass, this.pipelineRun.stt, STT_DATA)}
|
||||
${renderData(this.pipelineRun.stt, STT_DATA)}
|
||||
<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.language"
|
||||
)}
|
||||
</div>
|
||||
<div>Language</div>
|
||||
<div>${this.pipelineRun.stt.metadata.language}</div>
|
||||
</div>
|
||||
${this.pipelineRun.stt.stt_output
|
||||
? html`<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.output"
|
||||
)}
|
||||
</div>
|
||||
<div>Output</div>
|
||||
<div>${this.pipelineRun.stt.stt_output.text}</div>
|
||||
</div>`
|
||||
: ""}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.stt,
|
||||
STT_DATA
|
||||
)}
|
||||
${dataMinusKeysRender(this.pipelineRun.stt, STT_DATA)}
|
||||
</div>
|
||||
`
|
||||
: ""}
|
||||
@@ -317,28 +279,16 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.natural_language_processing"
|
||||
)}</span
|
||||
>
|
||||
<span>Natural Language Processing</span>
|
||||
${renderProgress(this.hass, this.pipelineRun, "intent")}
|
||||
</div>
|
||||
${this.pipelineRun.intent
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(
|
||||
this.hass,
|
||||
this.pipelineRun.intent,
|
||||
INTENT_DATA
|
||||
)}
|
||||
${renderData(this.pipelineRun.intent, INTENT_DATA)}
|
||||
${this.pipelineRun.intent.intent_output
|
||||
? html`<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.response_type"
|
||||
)}
|
||||
</div>
|
||||
<div>Response type</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.intent_output
|
||||
.response.response_type}
|
||||
@@ -347,11 +297,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun.intent.intent_output.response
|
||||
.response_type === "error"
|
||||
? html`<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.code"
|
||||
)}
|
||||
</div>
|
||||
<div>Error code</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.intent_output
|
||||
.response.data.code}
|
||||
@@ -360,27 +306,18 @@ export class AssistPipelineDebug extends LitElement {
|
||||
: ""}`
|
||||
: ""}
|
||||
<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.prefer_local"
|
||||
)}
|
||||
</div>
|
||||
<div>Prefer handling locally</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.prefer_local_intents}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.processed_locally"
|
||||
)}
|
||||
</div>
|
||||
<div>Processed locally</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.processed_locally}
|
||||
</div>
|
||||
</div>
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.intent,
|
||||
INTENT_DATA
|
||||
)}
|
||||
@@ -397,22 +334,14 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.text_to_speech"
|
||||
)}</span
|
||||
>
|
||||
<span>Text-to-speech</span>
|
||||
${renderProgress(this.hass, this.pipelineRun, "tts")}
|
||||
</div>
|
||||
${this.pipelineRun.tts
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.hass, this.pipelineRun.tts, TTS_DATA)}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.tts,
|
||||
TTS_DATA
|
||||
)}
|
||||
${renderData(this.pipelineRun.tts, TTS_DATA)}
|
||||
${dataMinusKeysRender(this.pipelineRun.tts, TTS_DATA)}
|
||||
</div>
|
||||
`
|
||||
: ""}
|
||||
@@ -420,19 +349,8 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun?.tts?.tts_output
|
||||
? html`
|
||||
<div class="card-actions">
|
||||
<ha-button
|
||||
.variant=${this._isPlaying ? "danger" : "brand"}
|
||||
@click=${this._isPlaying
|
||||
? this._stopTTS
|
||||
: this._playTTS}
|
||||
>
|
||||
${this._isPlaying
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stop_audio"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.play_audio"
|
||||
)}
|
||||
<ha-button @click=${this._playTTS}>
|
||||
Play Audio
|
||||
</ha-button>
|
||||
</div>
|
||||
`
|
||||
@@ -443,11 +361,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${maybeRenderError(this.pipelineRun, "tts", lastRunStage)}
|
||||
<ha-card>
|
||||
<ha-expansion-panel>
|
||||
<span slot="header"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.raw"
|
||||
)}</span
|
||||
>
|
||||
<span slot="header">Raw</span>
|
||||
<ha-yaml-editor
|
||||
read-only
|
||||
auto-update
|
||||
@@ -459,48 +373,14 @@ export class AssistPipelineDebug extends LitElement {
|
||||
}
|
||||
|
||||
private _playTTS(): void {
|
||||
// Stop any existing audio first
|
||||
this._stopTTS();
|
||||
|
||||
const url = this.pipelineRun!.tts!.tts_output!.url;
|
||||
this._audioElement = new Audio(url);
|
||||
|
||||
this._audioElement.addEventListener("error", () => {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.title"
|
||||
),
|
||||
text: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.playing_audio"
|
||||
),
|
||||
});
|
||||
const audio = new Audio(url);
|
||||
audio.addEventListener("error", () => {
|
||||
showAlertDialog(this, { title: "Error", text: "Error playing audio" });
|
||||
});
|
||||
|
||||
this._audioElement.addEventListener("play", () => {
|
||||
this.requestUpdate();
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play();
|
||||
});
|
||||
|
||||
this._audioElement.addEventListener("ended", () => {
|
||||
this.requestUpdate();
|
||||
});
|
||||
|
||||
this._audioElement.addEventListener("canplaythrough", () => {
|
||||
this._audioElement!.play();
|
||||
});
|
||||
}
|
||||
|
||||
private _stopTTS(): void {
|
||||
if (this._audioElement) {
|
||||
this._audioElement.pause();
|
||||
this._audioElement.currentTime = 0;
|
||||
this._audioElement = undefined;
|
||||
this.requestUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public disconnectedCallback(): void {
|
||||
super.disconnectedCallback();
|
||||
this._stopTTS();
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
|
||||
@@ -52,8 +52,6 @@ export class HaLogbook extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public deviceIds?: string[];
|
||||
|
||||
@property({ attribute: false }) public stateFilter?: string[];
|
||||
|
||||
@property({ type: Boolean }) public narrow = false;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public virtualize = false;
|
||||
@@ -167,7 +165,7 @@ export class HaLogbook extends LitElement {
|
||||
protected willUpdate(changedProps: PropertyValues): void {
|
||||
let changed = changedProps.has("time");
|
||||
|
||||
for (const key of ["entityIds", "deviceIds", "stateFilter"]) {
|
||||
for (const key of ["entityIds", "deviceIds"]) {
|
||||
if (!changedProps.has(key)) {
|
||||
continue;
|
||||
}
|
||||
@@ -354,19 +352,9 @@ export class HaLogbook extends LitElement {
|
||||
"recent" in this.time
|
||||
? findStartOfRecentTime(new Date(), this.time.recent)
|
||||
: undefined;
|
||||
|
||||
let eventsFiltered: LogbookEntry[] | undefined;
|
||||
if (this.stateFilter && this.stateFilter.length > 0) {
|
||||
eventsFiltered = streamMessage.events.filter(
|
||||
(e) => e.state && this.stateFilter?.includes(e.state)
|
||||
);
|
||||
} else {
|
||||
eventsFiltered = [...streamMessage.events];
|
||||
}
|
||||
|
||||
// Put newest ones on top. Reverse works in-place so
|
||||
// make a copy first.
|
||||
const newEntries = eventsFiltered.reverse();
|
||||
const newEntries = [...streamMessage.events].reverse();
|
||||
if (!this._logbookEntries || !this._logbookEntries.length) {
|
||||
this._logbookEntries = newEntries;
|
||||
return;
|
||||
|
||||
@@ -2,14 +2,14 @@ import type { PropertyValues } from "lit";
|
||||
import { ReactiveElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import type { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
ConditionalListenerMixin,
|
||||
setupMediaQueryListeners,
|
||||
} from "../../../mixins/conditional-listener-mixin";
|
||||
import { checkConditionsMet } from "../common/validate-condition";
|
||||
attachConditionMediaQueriesListeners,
|
||||
checkConditionsMet,
|
||||
} from "../common/validate-condition";
|
||||
import { createBadgeElement } from "../create-element/create-badge-element";
|
||||
import { createErrorBadgeConfig } from "../create-element/create-element-base";
|
||||
import type { LovelaceBadge } from "../types";
|
||||
@@ -22,7 +22,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("hui-badge")
|
||||
export class HuiBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
export class HuiBadge extends ReactiveElement {
|
||||
@property({ type: Boolean }) public preview = false;
|
||||
|
||||
@property({ attribute: false }) public config?: LovelaceBadgeConfig;
|
||||
@@ -40,16 +40,20 @@ export class HuiBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
|
||||
private _element?: LovelaceBadge;
|
||||
|
||||
private _listeners: MediaQueriesListener[] = [];
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._clearMediaQueries();
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._listenMediaQueries();
|
||||
this._updateVisibility();
|
||||
}
|
||||
|
||||
@@ -133,17 +137,26 @@ export class HuiBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
}
|
||||
}
|
||||
|
||||
protected setupConditionalListeners() {
|
||||
if (!this.config?.visibility || !this.hass) {
|
||||
private _clearMediaQueries() {
|
||||
this._listeners.forEach((unsub) => unsub());
|
||||
this._listeners = [];
|
||||
}
|
||||
|
||||
private _listenMediaQueries() {
|
||||
this._clearMediaQueries();
|
||||
if (!this.config?.visibility) {
|
||||
return;
|
||||
}
|
||||
const conditions = this.config.visibility;
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
conditions[0].condition === "screen" &&
|
||||
!!conditions[0].media_query;
|
||||
|
||||
setupMediaQueryListeners(
|
||||
this._listeners = attachConditionMediaQueriesListeners(
|
||||
this.config.visibility,
|
||||
this.hass,
|
||||
(unsub) => this.addConditionalListener(unsub),
|
||||
(conditionsMet) => {
|
||||
this._updateVisibility(conditionsMet);
|
||||
(matches) => {
|
||||
this._updateVisibility(hasOnlyMediaQuery && matches);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,44 +80,41 @@ export class HuiEnergyCompareCard
|
||||
|
||||
return html`
|
||||
<ha-alert dismissable @alert-dismissed-clicked=${this._stopCompare}>
|
||||
${this.hass.localize(
|
||||
"ui.panel.lovelace.cards.energy.energy_compare.info",
|
||||
{
|
||||
start: html`<b
|
||||
>${formatDate(
|
||||
this._start!,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}${dayDifference > 0
|
||||
? ` -
|
||||
${this.hass.localize("ui.panel.energy.compare.info", {
|
||||
start: html`<b
|
||||
>${formatDate(
|
||||
this._start!,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}${dayDifference > 0
|
||||
? ` -
|
||||
${formatDate(
|
||||
this._end || endOfDay(new Date()),
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}`
|
||||
: ""}</b
|
||||
>`,
|
||||
end: html`<b
|
||||
>${formatDate(
|
||||
this._startCompare,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}${dayDifference > 0
|
||||
? ` -
|
||||
: ""}</b
|
||||
>`,
|
||||
end: html`<b
|
||||
>${formatDate(
|
||||
this._startCompare,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}${dayDifference > 0
|
||||
? ` -
|
||||
${formatDate(this._endCompare, this.hass.locale, this.hass.config)}`
|
||||
: ""}</b
|
||||
>
|
||||
<button class="link" @click=${this._changeCompareMode}>
|
||||
(${this._compareMode === CompareMode.PREVIOUS
|
||||
? this.hass.localize(
|
||||
"ui.panel.lovelace.cards.energy.energy_compare.compare_previous_year"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.lovelace.cards.energy.energy_compare.compare_previous_period"
|
||||
)})
|
||||
</button>`,
|
||||
}
|
||||
)}
|
||||
: ""}</b
|
||||
>
|
||||
<button class="link" @click=${this._changeCompareMode}>
|
||||
(${this._compareMode === CompareMode.PREVIOUS
|
||||
? this.hass.localize(
|
||||
"ui.panel.energy.compare.compare_previous_year"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.energy.compare.compare_previous_period"
|
||||
)})
|
||||
</button>`,
|
||||
})}
|
||||
</ha-alert>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import memoizeOne from "memoize-one";
|
||||
import type { BarSeriesOption, PieSeriesOption } from "echarts/charts";
|
||||
import { PieChart } from "echarts/charts";
|
||||
import type { ECElementEvent } from "echarts/types/dist/shared";
|
||||
import type { PieDataItemOption } from "echarts/types/src/chart/pie/PieSeries";
|
||||
import { filterXSS } from "../../../../common/util/xss";
|
||||
import { getGraphColorByIndex } from "../../../../common/color/colors";
|
||||
import { formatNumber } from "../../../../common/number/format_number";
|
||||
@@ -388,7 +387,6 @@ export class HuiEnergyDevicesGraphCard
|
||||
});
|
||||
|
||||
if (this._chartType === "pie") {
|
||||
const pieChartData = chartData as NonNullable<PieSeriesOption["data"]>;
|
||||
const { summedData, compareSummedData } = getSummedData(energyData);
|
||||
const { consumption, compareConsumption } = computeConsumptionData(
|
||||
summedData,
|
||||
@@ -401,10 +399,7 @@ export class HuiEnergyDevicesGraphCard
|
||||
"from_battery" in summedData;
|
||||
const untracked = showUntracked
|
||||
? totalUsed -
|
||||
pieChartData.reduce(
|
||||
(acc: number, d) => acc + (d as PieDataItemOption).value![0],
|
||||
0
|
||||
)
|
||||
chartData.reduce((acc: number, d: any) => acc + d.value[0], 0)
|
||||
: 0;
|
||||
if (untracked > 0) {
|
||||
const color = getEnergyColor(
|
||||
@@ -414,7 +409,7 @@ export class HuiEnergyDevicesGraphCard
|
||||
false,
|
||||
"--history-unknown-color"
|
||||
);
|
||||
pieChartData.push({
|
||||
chartData.push({
|
||||
id: "untracked",
|
||||
value: [untracked, "untracked"] as any,
|
||||
name: this.hass.localize(
|
||||
@@ -447,20 +442,13 @@ export class HuiEnergyDevicesGraphCard
|
||||
}
|
||||
}
|
||||
}
|
||||
const totalChart = pieChartData.reduce(
|
||||
(acc: number, d) =>
|
||||
this._hiddenStats.includes((d as PieDataItemOption).id as string)
|
||||
? acc
|
||||
: acc + (d as PieDataItemOption).value![0],
|
||||
0
|
||||
);
|
||||
datasets.push({
|
||||
type: "pie",
|
||||
radius: ["0%", compareData ? "30%" : "40%"],
|
||||
name: this.hass.localize(
|
||||
"ui.panel.lovelace.cards.energy.energy_devices_graph.total_energy_usage"
|
||||
),
|
||||
data: [totalChart],
|
||||
data: [totalUsed],
|
||||
label: {
|
||||
show: true,
|
||||
position: "center",
|
||||
@@ -468,7 +456,7 @@ export class HuiEnergyDevicesGraphCard
|
||||
fontSize: computedStyle.getPropertyValue("--ha-font-size-l"),
|
||||
lineHeight: 24,
|
||||
fontWeight: "bold",
|
||||
formatter: `{a}\n${formatNumber(totalChart, this.hass.locale)} kWh`,
|
||||
formatter: `{a}\n${formatNumber(totalUsed, this.hass.locale)} kWh`,
|
||||
},
|
||||
cursor: "default",
|
||||
itemStyle: {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
@@ -8,16 +7,8 @@ import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_elemen
|
||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import { debounce } from "../../../common/util/debounce";
|
||||
import "../../../components/ha-card";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarEvent,
|
||||
CalendarEventSubscription,
|
||||
CalendarEventApiData,
|
||||
} from "../../../data/calendar";
|
||||
import {
|
||||
normalizeSubscriptionEventData,
|
||||
subscribeCalendarEvents,
|
||||
} from "../../../data/calendar";
|
||||
import type { Calendar, CalendarEvent } from "../../../data/calendar";
|
||||
import { fetchCalendarEvents } from "../../../data/calendar";
|
||||
import type {
|
||||
CalendarViewChanged,
|
||||
FullCalendarView,
|
||||
@@ -70,20 +61,18 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
|
||||
@state() private _calendars: Calendar[] = [];
|
||||
|
||||
@state() private _eventDisplay = "list-item";
|
||||
|
||||
@state() private _narrow = false;
|
||||
|
||||
@state() private _error?: string = undefined;
|
||||
|
||||
@state() private _errorCalendars: string[] = [];
|
||||
|
||||
private _startDate?: Date;
|
||||
|
||||
private _endDate?: Date;
|
||||
|
||||
private _resizeObserver?: ResizeObserver;
|
||||
|
||||
private _unsubs: Record<string, Promise<UnsubscribeFunc>> = {};
|
||||
|
||||
public setConfig(config: CalendarCardConfig): void {
|
||||
if (!config.entities?.length) {
|
||||
throw new Error("Entities must be specified");
|
||||
@@ -99,8 +88,7 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
}));
|
||||
|
||||
if (this._config?.entities !== config.entities) {
|
||||
this._unsubscribeAll();
|
||||
// Subscription will happen when view-changed event fires
|
||||
this._fetchCalendarEvents();
|
||||
}
|
||||
|
||||
this._config = { initial_view: "dayGridMonth", ...config };
|
||||
@@ -129,7 +117,6 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
if (this._resizeObserver) {
|
||||
this._resizeObserver.disconnect();
|
||||
}
|
||||
this._unsubscribeAll();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -157,6 +144,7 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
.hass=${this.hass}
|
||||
.views=${views}
|
||||
.initialView=${this._config.initial_view!}
|
||||
.eventDisplay=${this._eventDisplay}
|
||||
.error=${this._error}
|
||||
@view-changed=${this._handleViewChanged}
|
||||
></ha-full-calendar>
|
||||
@@ -185,85 +173,33 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
}
|
||||
|
||||
private async _handleViewChanged(
|
||||
ev: HASSDomEvent<CalendarViewChanged>
|
||||
): Promise<void> {
|
||||
private _handleViewChanged(ev: HASSDomEvent<CalendarViewChanged>): void {
|
||||
this._eventDisplay =
|
||||
ev.detail.view === "dayGridMonth" ? "list-item" : "auto";
|
||||
this._startDate = ev.detail.start;
|
||||
this._endDate = ev.detail.end;
|
||||
await this._unsubscribeAll();
|
||||
this._subscribeCalendarEvents();
|
||||
this._fetchCalendarEvents();
|
||||
}
|
||||
|
||||
private _subscribeCalendarEvents(): void {
|
||||
if (!this.hass || !this._startDate || !this._endDate) {
|
||||
private async _fetchCalendarEvents(): Promise<void> {
|
||||
if (!this._startDate || !this._endDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._error = undefined;
|
||||
|
||||
this._calendars.forEach((calendar) => {
|
||||
const unsub = subscribeCalendarEvents(
|
||||
this.hass!,
|
||||
calendar.entity_id,
|
||||
this._startDate!,
|
||||
this._endDate!,
|
||||
(update: CalendarEventSubscription) => {
|
||||
this._handleCalendarUpdate(calendar, update);
|
||||
}
|
||||
);
|
||||
this._unsubs[calendar.entity_id] = unsub;
|
||||
});
|
||||
}
|
||||
|
||||
private _handleCalendarUpdate(
|
||||
calendar: Calendar,
|
||||
update: CalendarEventSubscription
|
||||
): void {
|
||||
// Remove events from this calendar
|
||||
this._events = this._events.filter(
|
||||
(event) => event.calendar !== calendar.entity_id
|
||||
const result = await fetchCalendarEvents(
|
||||
this.hass!,
|
||||
this._startDate,
|
||||
this._endDate,
|
||||
this._calendars
|
||||
);
|
||||
this._events = result.events;
|
||||
|
||||
if (update.events === null) {
|
||||
// Error fetching events
|
||||
if (!this._errorCalendars.includes(calendar.entity_id)) {
|
||||
this._errorCalendars = [...this._errorCalendars, calendar.entity_id];
|
||||
}
|
||||
if (result.errors.length > 0) {
|
||||
this._error = `${this.hass!.localize(
|
||||
"ui.components.calendar.event_retrieval_error"
|
||||
)}`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove from error list if successfully loaded
|
||||
this._errorCalendars = this._errorCalendars.filter(
|
||||
(id) => id !== calendar.entity_id
|
||||
);
|
||||
if (this._errorCalendars.length === 0) {
|
||||
this._error = undefined;
|
||||
}
|
||||
|
||||
// Add new events from this calendar
|
||||
const newEvents: CalendarEvent[] = update.events
|
||||
.map((eventData: CalendarEventApiData) =>
|
||||
normalizeSubscriptionEventData(eventData, calendar)
|
||||
)
|
||||
.filter((event): event is CalendarEvent => event !== null);
|
||||
|
||||
this._events = [...this._events, ...newEvents];
|
||||
}
|
||||
|
||||
private async _unsubscribeAll(): Promise<void> {
|
||||
await Promise.all(
|
||||
Object.values(this._unsubs).map((unsub) =>
|
||||
unsub
|
||||
.then((unsubFunc) => unsubFunc())
|
||||
.catch(() => {
|
||||
// Subscription may have already been closed
|
||||
})
|
||||
)
|
||||
);
|
||||
this._unsubs = {};
|
||||
}
|
||||
|
||||
private _measureCard() {
|
||||
|
||||
@@ -2,16 +2,16 @@ import type { PropertyValues } from "lit";
|
||||
import { ReactiveElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import type { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
ConditionalListenerMixin,
|
||||
setupMediaQueryListeners,
|
||||
} from "../../../mixins/conditional-listener-mixin";
|
||||
import { migrateLayoutToGridOptions } from "../common/compute-card-grid-size";
|
||||
import { computeCardSize } from "../common/compute-card-size";
|
||||
import { checkConditionsMet } from "../common/validate-condition";
|
||||
import {
|
||||
attachConditionMediaQueriesListeners,
|
||||
checkConditionsMet,
|
||||
} from "../common/validate-condition";
|
||||
import { tryCreateCardElement } from "../create-element/create-card-element";
|
||||
import { createErrorCardElement } from "../create-element/create-element-base";
|
||||
import type { LovelaceCard, LovelaceGridOptions } from "../types";
|
||||
@@ -24,7 +24,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("hui-card")
|
||||
export class HuiCard extends ConditionalListenerMixin(ReactiveElement) {
|
||||
export class HuiCard extends ReactiveElement {
|
||||
@property({ type: Boolean }) public preview = false;
|
||||
|
||||
@property({ attribute: false }) public config?: LovelaceCardConfig;
|
||||
@@ -44,16 +44,20 @@ export class HuiCard extends ConditionalListenerMixin(ReactiveElement) {
|
||||
|
||||
private _element?: LovelaceCard;
|
||||
|
||||
private _listeners: MediaQueriesListener[] = [];
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._clearMediaQueries();
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._listenMediaQueries();
|
||||
this._updateVisibility();
|
||||
}
|
||||
|
||||
@@ -247,17 +251,26 @@ export class HuiCard extends ConditionalListenerMixin(ReactiveElement) {
|
||||
}
|
||||
}
|
||||
|
||||
protected setupConditionalListeners() {
|
||||
if (!this.config?.visibility || !this.hass) {
|
||||
private _clearMediaQueries() {
|
||||
this._listeners.forEach((unsub) => unsub());
|
||||
this._listeners = [];
|
||||
}
|
||||
|
||||
private _listenMediaQueries() {
|
||||
this._clearMediaQueries();
|
||||
if (!this.config?.visibility) {
|
||||
return;
|
||||
}
|
||||
const conditions = this.config.visibility;
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
conditions[0].condition === "screen" &&
|
||||
!!conditions[0].media_query;
|
||||
|
||||
setupMediaQueryListeners(
|
||||
this._listeners = attachConditionMediaQueriesListeners(
|
||||
this.config.visibility,
|
||||
this.hass,
|
||||
(unsub) => this.addConditionalListener(unsub),
|
||||
(conditionsMet) => {
|
||||
this._updateVisibility(conditionsMet);
|
||||
(matches) => {
|
||||
this._updateVisibility(hasOnlyMediaQuery && matches);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import parseAspectRatio from "../../../common/util/parse-aspect-ratio";
|
||||
@@ -98,10 +97,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
||||
: `${sandbox_user_params} ${IFRAME_SANDBOX}`;
|
||||
|
||||
return html`
|
||||
<ha-card
|
||||
class=${classMap({ "hide-background": this._config.hide_background })}
|
||||
.header=${this._config.title}
|
||||
>
|
||||
<ha-card .header=${this._config.title}>
|
||||
<div
|
||||
id="root"
|
||||
style=${styleMap({
|
||||
@@ -137,12 +133,6 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
ha-card.hide-background {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
@@ -64,8 +64,6 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
||||
|
||||
@state() private _targetPickerValue: HassServiceTarget = {};
|
||||
|
||||
@state() private _stateFilter?: string[];
|
||||
|
||||
public getCardSize(): number {
|
||||
return 9 + (this._config?.title ? 1 : 0);
|
||||
}
|
||||
@@ -131,8 +129,6 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
||||
};
|
||||
|
||||
this._targetPickerValue = target;
|
||||
|
||||
this._stateFilter = ensureArray(config.state_filter);
|
||||
}
|
||||
|
||||
private _getEntityIds(): string[] | undefined {
|
||||
@@ -213,7 +209,6 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
||||
.hass=${this.hass}
|
||||
.time=${this._time}
|
||||
.entityIds=${this._getEntityIds()}
|
||||
.stateFilter=${this._stateFilter}
|
||||
narrow
|
||||
relative-time
|
||||
virtualize
|
||||
|
||||
@@ -175,9 +175,9 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
this._names = {};
|
||||
this._entities.forEach((config) => {
|
||||
const stateObj = this.hass!.states[config.entity];
|
||||
this._names[config.entity] =
|
||||
computeLovelaceEntityName(this.hass!, stateObj, config.name) ||
|
||||
config.entity;
|
||||
this._names[config.entity] = stateObj
|
||||
? computeLovelaceEntityName(this.hass!, stateObj, config.name)
|
||||
: config.entity;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +323,6 @@ export interface IframeCardConfig extends LovelaceCardConfig {
|
||||
title?: string;
|
||||
allow?: string;
|
||||
url: string;
|
||||
hide_background?: boolean;
|
||||
}
|
||||
|
||||
export interface LightCardConfig extends LovelaceCardConfig {
|
||||
@@ -346,7 +345,6 @@ export interface LogbookCardConfig extends LovelaceCardConfig {
|
||||
title?: string;
|
||||
hours_to_show?: number;
|
||||
theme?: string;
|
||||
state_filter?: string[];
|
||||
}
|
||||
|
||||
export interface MapEntityConfig extends EntityConfig {
|
||||
|
||||
@@ -20,11 +20,10 @@ const calcPoints = (
|
||||
}
|
||||
});
|
||||
const rangeY = maxY - minY || minY * 0.1;
|
||||
// add top and bottom margins to prevent cropping
|
||||
maxY += rangeY * 0.1;
|
||||
minY -= rangeY * 0.1;
|
||||
if (maxY < 0) {
|
||||
// all values are negative
|
||||
// add margin
|
||||
maxY += rangeY * 0.1;
|
||||
maxY = Math.min(0, maxY);
|
||||
yAxisOrigin = 0;
|
||||
} else if (minY < 0) {
|
||||
@@ -32,6 +31,8 @@ const calcPoints = (
|
||||
yAxisOrigin = (maxY / (maxY - minY || 1)) * height;
|
||||
} else {
|
||||
// all values are positive
|
||||
// add margin
|
||||
minY -= rangeY * 0.1;
|
||||
minY = Math.max(0, minY);
|
||||
}
|
||||
const yDenom = maxY - minY || 1;
|
||||
@@ -50,8 +51,7 @@ export const coordinates = (
|
||||
width: number,
|
||||
height: number,
|
||||
maxDetails: number,
|
||||
limits?: { minX?: number; maxX?: number; minY?: number; maxY?: number },
|
||||
useMean = false
|
||||
limits?: { minX?: number; maxX?: number; minY?: number; maxY?: number }
|
||||
) => {
|
||||
history = history.filter((item) => !Number.isNaN(item[1]));
|
||||
|
||||
@@ -59,8 +59,7 @@ export const coordinates = (
|
||||
history,
|
||||
maxDetails,
|
||||
limits?.minX,
|
||||
limits?.maxX,
|
||||
useMean
|
||||
limits?.maxX
|
||||
);
|
||||
return calcPoints(sampledData, width, height, limits);
|
||||
};
|
||||
@@ -70,8 +69,7 @@ export const coordinatesMinimalResponseCompressedState = (
|
||||
width: number,
|
||||
height: number,
|
||||
maxDetails: number,
|
||||
limits?: { minX?: number; maxX?: number; minY?: number; maxY?: number },
|
||||
useMean = false
|
||||
limits?: { minX?: number; maxX?: number; minY?: number; maxY?: number }
|
||||
) => {
|
||||
if (!history?.length) {
|
||||
return { points: [], yAxisOrigin: 0 };
|
||||
@@ -83,5 +81,5 @@ export const coordinatesMinimalResponseCompressedState = (
|
||||
item.lu * 1000,
|
||||
Number(item.s),
|
||||
]);
|
||||
return coordinates(mappedHistory, width, height, maxDetails, limits, useMean);
|
||||
return coordinates(mappedHistory, width, height, maxDetails, limits);
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@ export const handleAction = async (
|
||||
await hass.loadBackendTranslation("title");
|
||||
const localize = await hass.loadBackendTranslation("services");
|
||||
serviceName = `${domainToName(localize, domain)}: ${
|
||||
localize(`component.${domain}.services.${service}.name`) ||
|
||||
localize(`component.${domain}.services.${serviceName}.name`) ||
|
||||
serviceDomains[domain][service].name ||
|
||||
service
|
||||
}`;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import { listenMediaQuery } from "../../../common/dom/media_query";
|
||||
|
||||
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
|
||||
import { UNKNOWN } from "../../../data/entity";
|
||||
@@ -360,3 +362,31 @@ export function addEntityToCondition(
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
export function extractMediaQueries(conditions: Condition[]): string[] {
|
||||
return conditions.reduce<string[]>((array, c) => {
|
||||
if ("conditions" in c && c.conditions) {
|
||||
array.push(...extractMediaQueries(c.conditions));
|
||||
}
|
||||
if (c.condition === "screen" && c.media_query) {
|
||||
array.push(c.media_query);
|
||||
}
|
||||
return array;
|
||||
}, []);
|
||||
}
|
||||
|
||||
export function attachConditionMediaQueriesListeners(
|
||||
conditions: Condition[],
|
||||
onChange: (visibility: boolean) => void
|
||||
): MediaQueriesListener[] {
|
||||
const mediaQueries = extractMediaQueries(conditions);
|
||||
|
||||
const listeners = mediaQueries.map((query) => {
|
||||
const listener = listenMediaQuery(query, (matches) => {
|
||||
onChange(matches);
|
||||
});
|
||||
return listener;
|
||||
});
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { ReactiveElement } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import { deepEqual } from "../../../common/util/deep-equal";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
ConditionalListenerMixin,
|
||||
setupMediaQueryListeners,
|
||||
} from "../../../mixins/conditional-listener-mixin";
|
||||
import type { HuiCard } from "../cards/hui-card";
|
||||
import type { ConditionalCardConfig } from "../cards/types";
|
||||
import type { Condition } from "../common/validate-condition";
|
||||
import {
|
||||
attachConditionMediaQueriesListeners,
|
||||
checkConditionsMet,
|
||||
extractMediaQueries,
|
||||
validateConditionalConfig,
|
||||
} from "../common/validate-condition";
|
||||
import type { ConditionalRowConfig, LovelaceRow } from "../entity-rows/types";
|
||||
@@ -22,9 +22,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("hui-conditional-base")
|
||||
export class HuiConditionalBase extends ConditionalListenerMixin(
|
||||
ReactiveElement
|
||||
) {
|
||||
export class HuiConditionalBase extends ReactiveElement {
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean }) public preview = false;
|
||||
@@ -33,6 +31,10 @@ export class HuiConditionalBase extends ConditionalListenerMixin(
|
||||
|
||||
protected _element?: HuiCard | LovelaceRow;
|
||||
|
||||
private _listeners: MediaQueriesListener[] = [];
|
||||
|
||||
private _mediaQueries: string[] = [];
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
@@ -61,14 +63,21 @@ export class HuiConditionalBase extends ConditionalListenerMixin(
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._clearMediaQueries();
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._listenMediaQueries();
|
||||
this._updateVisibility();
|
||||
}
|
||||
|
||||
protected setupConditionalListeners() {
|
||||
private _clearMediaQueries() {
|
||||
this._listeners.forEach((unsub) => unsub());
|
||||
this._listeners = [];
|
||||
}
|
||||
|
||||
private _listenMediaQueries() {
|
||||
if (!this._config || !this.hass) {
|
||||
return;
|
||||
}
|
||||
@@ -76,13 +85,27 @@ export class HuiConditionalBase extends ConditionalListenerMixin(
|
||||
const supportedConditions = this._config.conditions.filter(
|
||||
(c) => "condition" in c
|
||||
) as Condition[];
|
||||
const mediaQueries = extractMediaQueries(supportedConditions);
|
||||
|
||||
setupMediaQueryListeners(
|
||||
if (deepEqual(mediaQueries, this._mediaQueries)) return;
|
||||
|
||||
this._clearMediaQueries();
|
||||
|
||||
const conditions = this._config.conditions;
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
"condition" in conditions[0] &&
|
||||
conditions[0].condition === "screen" &&
|
||||
!!conditions[0].media_query;
|
||||
|
||||
this._listeners = attachConditionMediaQueriesListeners(
|
||||
supportedConditions,
|
||||
this.hass,
|
||||
(unsub) => this.addConditionalListener(unsub),
|
||||
(conditionsMet) => {
|
||||
this.setVisibility(conditionsMet);
|
||||
(matches) => {
|
||||
if (hasOnlyMediaQuery) {
|
||||
this.setVisibility(matches);
|
||||
return;
|
||||
}
|
||||
this._updateVisibility();
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -96,8 +119,7 @@ export class HuiConditionalBase extends ConditionalListenerMixin(
|
||||
changed.has("hass") ||
|
||||
changed.has("preview")
|
||||
) {
|
||||
this.clearConditionalListeners();
|
||||
this.setupConditionalListeners();
|
||||
this._listenMediaQueries();
|
||||
this._updateVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,31 +39,29 @@ export class HuiEntityEditor extends LitElement {
|
||||
private _renderItem(item: EntityConfig, index: number) {
|
||||
const stateObj = this.hass.states[item.entity];
|
||||
|
||||
const useDeviceName =
|
||||
stateObj &&
|
||||
entityUseDeviceName(stateObj, this.hass.entities, this.hass.devices);
|
||||
const useDeviceName = entityUseDeviceName(
|
||||
stateObj,
|
||||
this.hass.entities,
|
||||
this.hass.devices
|
||||
);
|
||||
|
||||
const isRTL = computeRTL(this.hass);
|
||||
|
||||
const primary =
|
||||
(stateObj &&
|
||||
this.hass.formatEntityName(
|
||||
stateObj,
|
||||
useDeviceName ? { type: "device" } : { type: "entity" }
|
||||
)) ||
|
||||
item.entity;
|
||||
|
||||
const secondary =
|
||||
stateObj &&
|
||||
this.hass.formatEntityName(
|
||||
stateObj,
|
||||
useDeviceName
|
||||
? [{ type: "area" }]
|
||||
: [{ type: "area" }, { type: "device" }],
|
||||
{
|
||||
separator: isRTL ? " ◂ " : " ▸ ",
|
||||
}
|
||||
);
|
||||
useDeviceName ? { type: "device" } : { type: "entity" }
|
||||
) || item.entity;
|
||||
|
||||
const secondary = this.hass.formatEntityName(
|
||||
stateObj,
|
||||
useDeviceName
|
||||
? [{ type: "area" }]
|
||||
: [{ type: "area" }, { type: "device" }],
|
||||
{
|
||||
separator: isRTL ? " ◂ " : " ▸ ",
|
||||
}
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-md-list-item class="item">
|
||||
|
||||
@@ -4,14 +4,11 @@ import { customElement, property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import { DOMAINS_INPUT_ROW } from "../../../common/const";
|
||||
import { uid } from "../../../common/util/uid";
|
||||
import { stopPropagation } from "../../../common/dom/stop_propagation";
|
||||
import { toggleAttribute } from "../../../common/dom/toggle_attribute";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
||||
import "../../../components/entity/state-badge";
|
||||
import "../../../components/ha-relative-time";
|
||||
import "../../../components/ha-tooltip";
|
||||
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import type { EntitiesCardEntityConfig } from "../cards/types";
|
||||
@@ -39,8 +36,6 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
@property({ attribute: "catch-interaction", type: Boolean })
|
||||
public catchInteraction?;
|
||||
|
||||
private _secondaryInfoElementId = "-" + uid();
|
||||
|
||||
protected render() {
|
||||
if (!this.hass || !this.config) {
|
||||
return nothing;
|
||||
@@ -105,19 +100,7 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
? stateObj.entity_id
|
||||
: this.config.secondary_info === "last-changed"
|
||||
? html`
|
||||
<ha-tooltip
|
||||
for="last-changed${this
|
||||
._secondaryInfoElementId}"
|
||||
placement="right"
|
||||
>
|
||||
${formatDateTimeWithSeconds(
|
||||
new Date(stateObj.last_changed),
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}
|
||||
</ha-tooltip>
|
||||
<ha-relative-time
|
||||
id="last-changed${this._secondaryInfoElementId}"
|
||||
.hass=${this.hass}
|
||||
.datetime=${stateObj.last_changed}
|
||||
capitalize
|
||||
@@ -125,20 +108,7 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
`
|
||||
: this.config.secondary_info === "last-updated"
|
||||
? html`
|
||||
<ha-tooltip
|
||||
for="last-updated${this
|
||||
._secondaryInfoElementId}"
|
||||
placement="right"
|
||||
>
|
||||
${formatDateTimeWithSeconds(
|
||||
new Date(stateObj.last_updated),
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}
|
||||
</ha-tooltip>
|
||||
<ha-relative-time
|
||||
id="last-updated${this
|
||||
._secondaryInfoElementId}"
|
||||
.hass=${this.hass}
|
||||
.datetime=${stateObj.last_updated}
|
||||
capitalize
|
||||
@@ -147,22 +117,7 @@ export class HuiGenericEntityRow extends LitElement {
|
||||
: this.config.secondary_info === "last-triggered"
|
||||
? stateObj.attributes.last_triggered
|
||||
? html`
|
||||
<ha-tooltip
|
||||
for="last-triggered${this
|
||||
._secondaryInfoElementId}"
|
||||
placement="right"
|
||||
>
|
||||
${formatDateTimeWithSeconds(
|
||||
new Date(
|
||||
stateObj.attributes.last_triggered
|
||||
),
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}
|
||||
</ha-tooltip>
|
||||
<ha-relative-time
|
||||
id="last-triggered${this
|
||||
._secondaryInfoElementId}"
|
||||
.hass=${this.hass}
|
||||
.datetime=${stateObj.attributes
|
||||
.last_triggered}
|
||||
|
||||
@@ -16,7 +16,6 @@ const cardConfigStruct = assign(
|
||||
url: optional(string()),
|
||||
aspect_ratio: optional(string()),
|
||||
allow_open_top_navigation: optional(boolean()),
|
||||
hide_background: optional(boolean()),
|
||||
})
|
||||
);
|
||||
|
||||
@@ -30,7 +29,6 @@ const SCHEMA = [
|
||||
{ name: "aspect_ratio", selector: { text: {} } },
|
||||
],
|
||||
},
|
||||
{ name: "hide_background", selector: { boolean: {} } },
|
||||
] as const;
|
||||
|
||||
@customElement("hui-iframe-card-editor")
|
||||
@@ -58,7 +56,6 @@ export class HuiIframeCardEditor
|
||||
.data=${this._config}
|
||||
.schema=${SCHEMA}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`;
|
||||
@@ -68,29 +65,8 @@ export class HuiIframeCardEditor
|
||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
||||
switch (schema.name) {
|
||||
case "hide_background":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.iframe.hide_background"
|
||||
);
|
||||
default:
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private _computeHelperCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
||||
switch (schema.name) {
|
||||
case "hide_background":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.iframe.hide_background_helper"
|
||||
);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) =>
|
||||
this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`);
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import {
|
||||
array,
|
||||
assert,
|
||||
@@ -19,7 +18,6 @@ import "../../../../components/ha-target-picker";
|
||||
import type { HaEntityPickerEntityFilterFunc } from "../../../../data/entity";
|
||||
import { filterLogbookCompatibleEntities } from "../../../../data/logbook";
|
||||
import { targetStruct } from "../../../../data/script";
|
||||
import { resolveEntityIDs } from "../../../../data/selector";
|
||||
import { getSensorNumericDeviceClasses } from "../../../../data/sensor";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import { DEFAULT_HOURS_TO_SHOW } from "../../cards/hui-logbook-card";
|
||||
@@ -35,7 +33,6 @@ const cardConfigStruct = assign(
|
||||
hours_to_show: optional(number()),
|
||||
theme: optional(string()),
|
||||
target: optional(targetStruct),
|
||||
state_filter: optional(array(string())),
|
||||
})
|
||||
);
|
||||
|
||||
@@ -53,13 +50,6 @@ const SCHEMA = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "state_filter",
|
||||
context: {
|
||||
filter_entity: "context_entities",
|
||||
},
|
||||
selector: { state: { multiple: true } },
|
||||
},
|
||||
] as const;
|
||||
|
||||
@customElement("hui-logbook-card-editor")
|
||||
@@ -116,13 +106,7 @@ export class HuiLogbookCardEditor
|
||||
return html`
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${this._data(
|
||||
this._config,
|
||||
this._targetPicker,
|
||||
this.hass.entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas
|
||||
)}
|
||||
.data=${this._config}
|
||||
.schema=${SCHEMA}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
@value-changed=${this._valueChanged}
|
||||
@@ -137,25 +121,6 @@ export class HuiLogbookCardEditor
|
||||
`;
|
||||
}
|
||||
|
||||
private _data = memoizeOne(
|
||||
(
|
||||
config: LogbookCardConfig,
|
||||
target: HassServiceTarget,
|
||||
entities: HomeAssistant["entities"],
|
||||
devices: HomeAssistant["devices"],
|
||||
areas: HomeAssistant["areas"]
|
||||
) => ({
|
||||
...config,
|
||||
context_entities: resolveEntityIDs(
|
||||
this.hass!,
|
||||
target,
|
||||
entities,
|
||||
devices,
|
||||
areas
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
private _filterFunc: HaEntityPickerEntityFilterFunc = (entity) =>
|
||||
filterLogbookCompatibleEntities(entity, this._sensorNumericDeviceClasses);
|
||||
|
||||
@@ -165,9 +130,7 @@ export class HuiLogbookCardEditor
|
||||
}
|
||||
|
||||
private _valueChanged(ev: CustomEvent): void {
|
||||
const newConfig = { ...ev.detail.value };
|
||||
delete newConfig.context_entities;
|
||||
fireEvent(this, "config-changed", { config: newConfig });
|
||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
||||
@@ -178,10 +141,6 @@ export class HuiLogbookCardEditor
|
||||
)} (${this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.config.optional"
|
||||
)})`;
|
||||
case "state_filter":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.logbook.state_filter"
|
||||
);
|
||||
default:
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
|
||||
@@ -155,20 +155,16 @@ export class HuiGraphHeaderFooter
|
||||
}
|
||||
const width = this.clientWidth || this.offsetWidth;
|
||||
// sample to 1 point per hour or 1 point per 5 pixels
|
||||
const maxDetails = Math.max(
|
||||
10,
|
||||
const maxDetails =
|
||||
this._config.detail! > 1
|
||||
? Math.max(width / 5, this._config.hours_to_show!)
|
||||
: this._config.hours_to_show!
|
||||
);
|
||||
const useMean = this._config.detail !== 2;
|
||||
: this._config.hours_to_show!;
|
||||
const { points } = coordinatesMinimalResponseCompressedState(
|
||||
combinedHistory[this._config.entity],
|
||||
width,
|
||||
width / 5,
|
||||
maxDetails,
|
||||
{ minY: this._config.limits?.min, maxY: this._config.limits?.max },
|
||||
useMean
|
||||
{ minY: this._config.limits?.min, maxY: this._config.limits?.max }
|
||||
);
|
||||
this._coordinates = points;
|
||||
},
|
||||
|
||||
@@ -2,13 +2,13 @@ import type { PropertyValues } from "lit";
|
||||
import { ReactiveElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
ConditionalListenerMixin,
|
||||
setupMediaQueryListeners,
|
||||
} from "../../../mixins/conditional-listener-mixin";
|
||||
import { checkConditionsMet } from "../common/validate-condition";
|
||||
attachConditionMediaQueriesListeners,
|
||||
checkConditionsMet,
|
||||
} from "../common/validate-condition";
|
||||
import { createHeadingBadgeElement } from "../create-element/create-heading-badge-element";
|
||||
import type { LovelaceHeadingBadge } from "../types";
|
||||
import type { LovelaceHeadingBadgeConfig } from "./types";
|
||||
@@ -21,7 +21,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("hui-heading-badge")
|
||||
export class HuiHeadingBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
export class HuiHeadingBadge extends ReactiveElement {
|
||||
@property({ type: Boolean }) public preview = false;
|
||||
|
||||
@property({ attribute: false }) public config?: LovelaceHeadingBadgeConfig;
|
||||
@@ -39,16 +39,20 @@ export class HuiHeadingBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
|
||||
private _element?: LovelaceHeadingBadge;
|
||||
|
||||
private _listeners: MediaQueriesListener[] = [];
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._clearMediaQueries();
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._listenMediaQueries();
|
||||
this._updateVisibility();
|
||||
}
|
||||
|
||||
@@ -133,17 +137,26 @@ export class HuiHeadingBadge extends ConditionalListenerMixin(ReactiveElement) {
|
||||
}
|
||||
}
|
||||
|
||||
protected setupConditionalListeners() {
|
||||
if (!this.config?.visibility || !this.hass) {
|
||||
private _clearMediaQueries() {
|
||||
this._listeners.forEach((unsub) => unsub());
|
||||
this._listeners = [];
|
||||
}
|
||||
|
||||
private _listenMediaQueries() {
|
||||
this._clearMediaQueries();
|
||||
if (!this.config?.visibility) {
|
||||
return;
|
||||
}
|
||||
const conditions = this.config.visibility;
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
conditions[0].condition === "screen" &&
|
||||
!!conditions[0].media_query;
|
||||
|
||||
setupMediaQueryListeners(
|
||||
this._listeners = attachConditionMediaQueriesListeners(
|
||||
this.config.visibility,
|
||||
this.hass,
|
||||
(unsub) => this.addConditionalListener(unsub),
|
||||
(conditionsMet) => {
|
||||
this._updateVisibility(conditionsMet);
|
||||
(matches) => {
|
||||
this._updateVisibility(hasOnlyMediaQuery && matches);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ReactiveElement } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { storage } from "../../../common/decorators/storage";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import type { LovelaceSectionElement } from "../../../data/lovelace";
|
||||
import type { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
||||
@@ -13,13 +14,12 @@ import type {
|
||||
} from "../../../data/lovelace/config/section";
|
||||
import { isStrategySection } from "../../../data/lovelace/config/section";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import {
|
||||
ConditionalListenerMixin,
|
||||
setupMediaQueryListeners,
|
||||
} from "../../../mixins/conditional-listener-mixin";
|
||||
import "../cards/hui-card";
|
||||
import type { HuiCard } from "../cards/hui-card";
|
||||
import { checkConditionsMet } from "../common/validate-condition";
|
||||
import {
|
||||
attachConditionMediaQueriesListeners,
|
||||
checkConditionsMet,
|
||||
} from "../common/validate-condition";
|
||||
import { createSectionElement } from "../create-element/create-section-element";
|
||||
import { showCreateCardDialog } from "../editor/card-editor/show-create-card-dialog";
|
||||
import { showEditCardDialog } from "../editor/card-editor/show-edit-card-dialog";
|
||||
@@ -37,7 +37,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("hui-section")
|
||||
export class HuiSection extends ConditionalListenerMixin(ReactiveElement) {
|
||||
export class HuiSection extends ReactiveElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public config!: LovelaceSectionRawConfig;
|
||||
@@ -59,6 +59,8 @@ export class HuiSection extends ConditionalListenerMixin(ReactiveElement) {
|
||||
|
||||
private _layoutElement?: LovelaceSectionElement;
|
||||
|
||||
private _listeners: MediaQueriesListener[] = [];
|
||||
|
||||
private _config: LovelaceSectionConfig | undefined;
|
||||
|
||||
@storage({
|
||||
@@ -112,10 +114,14 @@ export class HuiSection extends ConditionalListenerMixin(ReactiveElement) {
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this._clearMediaQueries();
|
||||
}
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
if (this.hasUpdated) {
|
||||
this._listenMediaQueries();
|
||||
}
|
||||
this._updateElement();
|
||||
}
|
||||
|
||||
@@ -152,17 +158,26 @@ export class HuiSection extends ConditionalListenerMixin(ReactiveElement) {
|
||||
}
|
||||
}
|
||||
|
||||
protected setupConditionalListeners() {
|
||||
if (!this._config?.visibility || !this.hass) {
|
||||
private _clearMediaQueries() {
|
||||
this._listeners.forEach((unsub) => unsub());
|
||||
this._listeners = [];
|
||||
}
|
||||
|
||||
private _listenMediaQueries() {
|
||||
this._clearMediaQueries();
|
||||
if (!this._config?.visibility) {
|
||||
return;
|
||||
}
|
||||
const conditions = this._config.visibility;
|
||||
const hasOnlyMediaQuery =
|
||||
conditions.length === 1 &&
|
||||
conditions[0].condition === "screen" &&
|
||||
conditions[0].media_query != null;
|
||||
|
||||
setupMediaQueryListeners(
|
||||
this._listeners = attachConditionMediaQueriesListeners(
|
||||
this._config.visibility,
|
||||
this.hass,
|
||||
(unsub) => this.addConditionalListener(unsub),
|
||||
(conditionsMet) => {
|
||||
this._updateElement(conditionsMet);
|
||||
(matches) => {
|
||||
this._updateElement(hasOnlyMediaQuery && matches);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -184,6 +199,9 @@ export class HuiSection extends ConditionalListenerMixin(ReactiveElement) {
|
||||
type: sectionConfig.type || DEFAULT_SECTION_LAYOUT,
|
||||
};
|
||||
this._config = sectionConfig;
|
||||
if (this.isConnected) {
|
||||
this._listenMediaQueries();
|
||||
}
|
||||
|
||||
// Create a new layout element if necessary.
|
||||
let addLayoutElement = false;
|
||||
|
||||
@@ -652,7 +652,7 @@
|
||||
"edit": "Edit",
|
||||
"clear": "Clear",
|
||||
"no_entities": "You don't have any entities",
|
||||
"no_match": "No entities found for {term}",
|
||||
"no_match": "No matching entities found",
|
||||
"show_entities": "Show entities",
|
||||
"new_entity": "Create a new entity",
|
||||
"placeholder": "Select an entity",
|
||||
@@ -684,10 +684,10 @@
|
||||
},
|
||||
"target-picker": {
|
||||
"expand": "Expand",
|
||||
"expand_floor_id": "Split this floor into separate areas",
|
||||
"expand_area_id": "Split this area into separate devices and entities",
|
||||
"expand_device_id": "Split this device into separate entities",
|
||||
"expand_label_id": "Split this label into separate areas, devices and entities",
|
||||
"expand_floor_id": "Split this floor into separate areas.",
|
||||
"expand_area_id": "Split this area into separate devices and entities.",
|
||||
"expand_device_id": "Split this device into separate entities.",
|
||||
"expand_label_id": "Split this label into separate areas, devices and entities.",
|
||||
"add_target": "Add target",
|
||||
"remove": "Remove",
|
||||
"remove_floor_id": "Remove floor",
|
||||
@@ -763,7 +763,7 @@
|
||||
},
|
||||
"language-picker": {
|
||||
"language": "Language",
|
||||
"no_match": "No languages found for {term}",
|
||||
"no_match": "No matching languages found",
|
||||
"no_languages": "No languages available"
|
||||
},
|
||||
"tts-picker": {
|
||||
@@ -775,7 +775,7 @@
|
||||
"none": "None"
|
||||
},
|
||||
"user-picker": {
|
||||
"no_match": "No users found for {term}",
|
||||
"no_match": "No matching users found",
|
||||
"user": "User",
|
||||
"add_user": "Add user"
|
||||
},
|
||||
@@ -786,8 +786,8 @@
|
||||
"clear": "Clear",
|
||||
"toggle": "Toggle",
|
||||
"show_devices": "Show devices",
|
||||
"no_devices": "No devices available",
|
||||
"no_match": "No devices found for {term}",
|
||||
"no_devices": "You don't have any devices",
|
||||
"no_match": "No matching devices found",
|
||||
"device": "Device",
|
||||
"unnamed_device": "Unnamed device",
|
||||
"no_area": "No area",
|
||||
@@ -801,8 +801,8 @@
|
||||
"add_category": "Add category",
|
||||
"add_new_sugestion": "Add new category ''{name}''",
|
||||
"add_new": "Add new category…",
|
||||
"no_categories": "No categories available",
|
||||
"no_match": "No categories found for {term}",
|
||||
"no_categories": "You don't have any categories",
|
||||
"no_match": "No matching categories found",
|
||||
"add_dialog": {
|
||||
"title": "Add new category",
|
||||
"text": "Enter the name of the new category.",
|
||||
@@ -817,8 +817,8 @@
|
||||
"add_new_sugestion": "Add new label ''{name}''",
|
||||
"add_new": "Add new label…",
|
||||
"add": "Add label",
|
||||
"no_labels": "No labels available",
|
||||
"no_match": "No labels found for {term}",
|
||||
"no_labels": "You don't have any labels",
|
||||
"no_match": "No matching labels found",
|
||||
"failed_create_label": "Failed to create label."
|
||||
},
|
||||
"area-picker": {
|
||||
@@ -827,8 +827,8 @@
|
||||
"area": "Area",
|
||||
"add_new_sugestion": "Add new area ''{name}''",
|
||||
"add_new": "Add new area…",
|
||||
"no_areas": "No areas available",
|
||||
"no_match": "No areas found for {term}",
|
||||
"no_areas": "You don't have any areas",
|
||||
"no_match": "No matching areas found",
|
||||
"unassigned_areas": "Unassigned areas",
|
||||
"failed_create_area": "Failed to create area."
|
||||
},
|
||||
@@ -838,8 +838,8 @@
|
||||
"floor": "Floor",
|
||||
"add_new_sugestion": "Add new floor ''{name}''",
|
||||
"add_new": "Add new floor…",
|
||||
"no_floors": "No floors available",
|
||||
"no_match": "No floors found for {term}",
|
||||
"no_floors": "You don't have any floors",
|
||||
"no_match": "No matching floors found",
|
||||
"failed_create_floor": "Failed to create floor."
|
||||
},
|
||||
"area-filter": {
|
||||
@@ -853,8 +853,8 @@
|
||||
"statistic-picker": {
|
||||
"statistic": "Statistic",
|
||||
"placeholder": "Select a statistic",
|
||||
"no_statistics": "No statistics available",
|
||||
"no_match": "No statistics found for {term}",
|
||||
"no_statistics": "You don't have any statistics",
|
||||
"no_match": "No matching statistics found",
|
||||
"no_state": "Entity without state",
|
||||
"missing_entity": "Why is my entity not listed?",
|
||||
"learn_more": "Learn more about statistics"
|
||||
@@ -1292,8 +1292,7 @@
|
||||
"add": "Add interaction"
|
||||
},
|
||||
"combo-box": {
|
||||
"no_match": "No matching items found",
|
||||
"no_items": "No items available"
|
||||
"no_match": "No matching items found"
|
||||
},
|
||||
"suggest_with_ai": {
|
||||
"label": "Suggest",
|
||||
@@ -1435,7 +1434,6 @@
|
||||
"back_to_info": "Back to info",
|
||||
"info": "Information",
|
||||
"related": "Related",
|
||||
"add_entity_to": "Add to",
|
||||
"history": "History",
|
||||
"aggregate": "5-minute aggregated",
|
||||
"logbook": "Activity",
|
||||
@@ -1452,10 +1450,6 @@
|
||||
"last_action": "Last action",
|
||||
"last_triggered": "Last triggered"
|
||||
},
|
||||
"add_to": {
|
||||
"no_actions": "No actions available",
|
||||
"action_failed": "Failed to perform the action {error}"
|
||||
},
|
||||
"sun": {
|
||||
"azimuth": "Azimuth",
|
||||
"elevation": "Elevation",
|
||||
@@ -3077,7 +3071,6 @@
|
||||
"remove_co2_signal": "Remove Electricity Maps integration",
|
||||
"add_co2_signal": "Add Electricity Maps integration",
|
||||
"flow_dialog": {
|
||||
"cost_entity_helper": "Any sensor with a unit of `{currency}/(valid energy unit)` (e.g. `{currency}/Wh` or `{currency}/kWh`) may be used and will be automatically converted.",
|
||||
"from": {
|
||||
"header": "Configure grid consumption",
|
||||
"paragraph": "Grid consumption is the energy that flows from the energy grid to your home.",
|
||||
@@ -3638,36 +3631,6 @@
|
||||
"older_run": "Older run",
|
||||
"newer_run": "Newer run",
|
||||
"start_debug_run": "Start debug run",
|
||||
"error": {
|
||||
"code": "Error code",
|
||||
"fetch_events": "Failed to fetch events",
|
||||
"fetch_runs": "Failed to fetch pipeline runs",
|
||||
"playing_audio": "Error playing audio",
|
||||
"showing_run": "Error showing run",
|
||||
"title": "Error"
|
||||
},
|
||||
"no_events": "There were no events in this run.",
|
||||
"play_audio": "Play audio",
|
||||
"raw": "Raw",
|
||||
"run": "Run",
|
||||
"stages": {
|
||||
"engine": "Engine",
|
||||
"input": "Input",
|
||||
"language": "Language",
|
||||
"model": "Model",
|
||||
"natural_language_processing": "Natural language processing",
|
||||
"output": "Output",
|
||||
"pipeline": "Pipeline",
|
||||
"prefer_local": "Prefer handling locally",
|
||||
"processed_locally": "Processed locally",
|
||||
"response_type": "Response type",
|
||||
"speech_to_text": "Speech-to-text",
|
||||
"text_to_speech": "Text-to-speech",
|
||||
"timestamp": "Timestamp",
|
||||
"voice": "Voice",
|
||||
"wake_word": "Wake word"
|
||||
},
|
||||
"stop_audio": "Stop audio",
|
||||
"pipeline": {
|
||||
"header": "Assist pipeline",
|
||||
"run_text_pipeline": "Run text pipeline",
|
||||
@@ -3968,7 +3931,7 @@
|
||||
"type_automation_plural": "[%key:ui::panel::config::blueprint::overview::types_plural::automation%]",
|
||||
"type_script_plural": "[%key:ui::panel::config::blueprint::overview::types_plural::script%]",
|
||||
"new_automation_setup_failed_title": "New {type} setup timed out",
|
||||
"new_automation_setup_failed_text": "Your new {type} was saved, but waiting for it to set up has timed out. This could be due to errors parsing your configuration.yaml, please check the configuration in developer tools. Your {type} will not be visible until this is corrected and {types} are reloaded. Changes to area, category, or labels were not saved and must be reapplied.",
|
||||
"new_automation_setup_failed_text": "Your new {type} has saved, but waiting for it to setup has timed out. This could be due to errors parsing your configuration.yaml, please check the configuration in developer tools. Your {type} will not be visible until this is corrected, and {types} are reloaded. Changes to area, category, or labels were not saved and must be reapplied.",
|
||||
"new_automation_setup_keep_waiting": "You may continue to wait for a response from the server, in case it is just taking an unusually long time to process this {type}.",
|
||||
"new_automation_setup_timedout_success": "The server has responded and this has now setup successfully. You may now close this dialog.",
|
||||
"item_pasted": "{item} pasted",
|
||||
@@ -6563,8 +6526,7 @@
|
||||
"model": "Model",
|
||||
"status": "Status",
|
||||
"version": "Version",
|
||||
"data_rate": "Data rate",
|
||||
"area": "Area"
|
||||
"data_rate": "Data rate"
|
||||
},
|
||||
"node_status": {
|
||||
"0": "Unknown",
|
||||
@@ -7144,11 +7106,6 @@
|
||||
"card_indicates_energy_used": "This card indicates how much of the electricity consumed by your home was generated using non-fossil fuels like solar, wind, and nuclear. The higher, the better!",
|
||||
"low_carbon_energy_consumed": "Low-carbon electricity consumed",
|
||||
"low_carbon_energy_not_calculated": "Consumed low-carbon electricity couldn't be calculated"
|
||||
},
|
||||
"energy_compare": {
|
||||
"info": "You are comparing the period {start} with the period {end}",
|
||||
"compare_previous_year": "Compare previous year",
|
||||
"compare_previous_period": "Compare previous period"
|
||||
}
|
||||
},
|
||||
"heading": {
|
||||
@@ -7712,8 +7669,7 @@
|
||||
},
|
||||
"logbook": {
|
||||
"name": "Activity",
|
||||
"description": "The Activity card shows a list of events for entities.",
|
||||
"state_filter": "State filter"
|
||||
"description": "The Activity card shows a list of events for entities."
|
||||
},
|
||||
"history-graph": {
|
||||
"name": "History graph",
|
||||
@@ -7791,9 +7747,7 @@
|
||||
},
|
||||
"iframe": {
|
||||
"name": "Webpage",
|
||||
"description": "The Webpage card allows you to embed your favorite webpage right into Home Assistant.",
|
||||
"hide_background": "Hide background",
|
||||
"hide_background_helper": "Useful for pages which allow a transparent background."
|
||||
"description": "The Webpage card allows you to embed your favorite webpage right into Home Assistant."
|
||||
},
|
||||
"light": {
|
||||
"name": "Light",
|
||||
@@ -9399,6 +9353,11 @@
|
||||
"energy": {
|
||||
"download_data": "[%key:ui::panel::history::download_data%]",
|
||||
"configure": "[%key:ui::dialogs::quick-bar::commands::navigation::energy%]",
|
||||
"compare": {
|
||||
"info": "You are comparing the period {start} with the period {end}",
|
||||
"compare_previous_year": "Compare previous year",
|
||||
"compare_previous_period": "Compare previous period"
|
||||
},
|
||||
"setup": {
|
||||
"next": "Next",
|
||||
"back": "Back",
|
||||
|
||||
@@ -138,7 +138,6 @@ export interface PanelInfo<T = Record<string, any> | null> {
|
||||
title: string | null;
|
||||
url_path: string;
|
||||
config_panel_domain?: string;
|
||||
default_visible?: boolean;
|
||||
}
|
||||
|
||||
export type Panels = Record<string, PanelInfo>;
|
||||
|
||||
Reference in New Issue
Block a user