mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-05 09:00:11 +00:00
Compare commits
71 Commits
rc
...
card-visib
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef0368f9c3 | ||
|
|
8fc305ec6b | ||
|
|
fd657fbf68 | ||
|
|
885f4564a9 | ||
|
|
d27c2e3a04 | ||
|
|
f2655ec226 | ||
|
|
1c3043ed37 | ||
|
|
86bfb6a482 | ||
|
|
bd3a1ea281 | ||
|
|
90757b6f97 | ||
|
|
6a2bbb02a2 | ||
|
|
698197dccd | ||
|
|
665ff88d58 | ||
|
|
bb8dd69e7b | ||
|
|
819182977c | ||
|
|
2d838e22d2 | ||
|
|
036cbe0a1a | ||
|
|
6fc039340e | ||
|
|
e1b0a3e737 | ||
|
|
d59d436080 | ||
|
|
0fe0bf12f2 | ||
|
|
f5a3877f47 | ||
|
|
31d04f5338 | ||
|
|
4f7d223aa7 | ||
|
|
484c60073d | ||
|
|
0e1ab1a60c | ||
|
|
cef11e0c18 | ||
|
|
55e75e80d2 | ||
|
|
126a78ec8a | ||
|
|
063af39f0f | ||
|
|
132c4c8201 | ||
|
|
4c08e960f1 | ||
|
|
a8020256de | ||
|
|
2ea57c33ae | ||
|
|
db1408666c | ||
|
|
260288a061 | ||
|
|
45fd685913 | ||
|
|
896d76b218 | ||
|
|
cec24117dc | ||
|
|
34006d268b | ||
|
|
54c03d91df | ||
|
|
52a56a1c4e | ||
|
|
e49feeb4aa | ||
|
|
a0c30e433a | ||
|
|
354ce027eb | ||
|
|
5c224a942d | ||
|
|
0efa4f81d4 | ||
|
|
3ad2f35f29 | ||
|
|
7a21d5f7bc | ||
|
|
33226587e6 | ||
|
|
bd2673f311 | ||
|
|
cecadde497 | ||
|
|
494b8811d0 | ||
|
|
4e0a49b3da | ||
|
|
3145fed5dc | ||
|
|
3dd040fdc7 | ||
|
|
e3abe9736c | ||
|
|
fe41e72774 | ||
|
|
7078ef52d4 | ||
|
|
f1c9802ee3 | ||
|
|
35697e3f94 | ||
|
|
8ea7ad3026 | ||
|
|
73747fbedc | ||
|
|
aaa92bd354 | ||
|
|
5f75fc5bcb | ||
|
|
5fa44548c3 | ||
|
|
1945c11621 | ||
|
|
930575d292 | ||
|
|
0147dbab00 | ||
|
|
13ace24b83 | ||
|
|
616333591a |
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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
|
||||
# ℹ️ 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@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
|
||||
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
|
||||
|
||||
28
package.json
28
package.json
@@ -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.0",
|
||||
"@material/web": "2.4.1",
|
||||
"@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.2",
|
||||
"@vaadin/vaadin-themable-mixin": "24.9.2",
|
||||
"@vaadin/combo-box": "24.9.4",
|
||||
"@vaadin/vaadin-themable-mixin": "24.9.4",
|
||||
"@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.13",
|
||||
"hls.js": "1.6.14",
|
||||
"home-assistant-js-websocket": "9.5.0",
|
||||
"idb-keyval": "6.2.2",
|
||||
"intl-messageformat": "10.7.18",
|
||||
@@ -154,11 +154,11 @@
|
||||
"@babel/preset-env": "7.28.5",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.21.5",
|
||||
"@lokalise/node-api": "15.3.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",
|
||||
"@octokit/auth-oauth-device": "8.0.3",
|
||||
"@octokit/plugin-retry": "8.0.3",
|
||||
"@octokit/rest": "22.0.1",
|
||||
"@rsdoctor/rspack-plugin": "1.3.7",
|
||||
"@rspack/core": "1.6.0",
|
||||
"@rspack/dev-server": "1.1.4",
|
||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||
"@types/chromecast-caf-receiver": "6.0.22",
|
||||
@@ -178,7 +178,7 @@
|
||||
"@types/tar": "6.1.13",
|
||||
"@types/ua-parser-js": "0.7.39",
|
||||
"@types/webspeechapi": "0.0.29",
|
||||
"@vitest/coverage-v8": "4.0.3",
|
||||
"@vitest/coverage-v8": "4.0.6",
|
||||
"babel-loader": "10.0.0",
|
||||
"babel-plugin-template-html-minifier": "4.1.0",
|
||||
"browserslist-useragent-regexp": "4.1.3",
|
||||
@@ -201,7 +201,7 @@
|
||||
"gulp-rename": "2.1.0",
|
||||
"html-minifier-terser": "7.2.0",
|
||||
"husky": "9.1.7",
|
||||
"jsdom": "27.0.1",
|
||||
"jsdom": "27.1.0",
|
||||
"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.1",
|
||||
"tar": "7.5.2",
|
||||
"terser-webpack-plugin": "5.3.14",
|
||||
"ts-lit-plugin": "2.0.2",
|
||||
"typescript": "5.9.3",
|
||||
"typescript-eslint": "8.46.2",
|
||||
"vite-tsconfig-paths": "5.1.4",
|
||||
"vitest": "4.0.3",
|
||||
"vitest": "4.0.6",
|
||||
"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.4.0",
|
||||
"globals": "16.5.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 = "20251104.0"
|
||||
version = "20251029.0"
|
||||
license = "Apache-2.0"
|
||||
license-files = ["LICENSE*"]
|
||||
description = "The Home Assistant frontend"
|
||||
|
||||
110
src/common/datetime/check_time.ts
Normal file
110
src/common/datetime/check_time.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { TZDate } from "@date-fns/tz";
|
||||
import { isBefore, isAfter, isWithinInterval } from "date-fns";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { TimeZone } from "../../data/translation";
|
||||
import { WEEKDAY_MAP, type WeekdayShort } from "./weekday";
|
||||
|
||||
/**
|
||||
* Parse a time string (HH:MM or HH:MM:SS) and set it on today's date in the given timezone
|
||||
* @param timeString The time string to parse
|
||||
* @param timezone The timezone to use
|
||||
* @returns The Date object
|
||||
*/
|
||||
const parseTimeString = (timeString: string, timezone: string): Date => {
|
||||
const parts = timeString.split(":");
|
||||
|
||||
if (parts.length < 2 || parts.length > 3) {
|
||||
throw new Error(
|
||||
`Invalid time format: ${timeString}. Expected HH:MM or HH:MM:SS`
|
||||
);
|
||||
}
|
||||
|
||||
const hours = parseInt(parts[0], 10);
|
||||
const minutes = parseInt(parts[1], 10);
|
||||
const seconds = parts.length === 3 ? parseInt(parts[2], 10) : 0;
|
||||
|
||||
if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
|
||||
throw new Error(`Invalid time values in: ${timeString}`);
|
||||
}
|
||||
|
||||
// Add range validation
|
||||
if (hours < 0 || hours > 23) {
|
||||
throw new Error(`Invalid hours in: ${timeString}. Must be 0-23`);
|
||||
}
|
||||
if (minutes < 0 || minutes > 59) {
|
||||
throw new Error(`Invalid minutes in: ${timeString}. Must be 0-59`);
|
||||
}
|
||||
if (seconds < 0 || seconds > 59) {
|
||||
throw new Error(`Invalid seconds in: ${timeString}. Must be 0-59`);
|
||||
}
|
||||
|
||||
const now = new TZDate(new Date(), timezone);
|
||||
const dateWithTime = new TZDate(
|
||||
now.getFullYear(),
|
||||
now.getMonth(),
|
||||
now.getDate(),
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
0,
|
||||
timezone
|
||||
);
|
||||
|
||||
return new Date(dateWithTime.getTime());
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the current time matches the time condition (after/before/weekday)
|
||||
* @param hass Home Assistant object
|
||||
* @param after Optional time string (HH:MM) for after condition
|
||||
* @param before Optional time string (HH:MM) for before condition
|
||||
* @param weekdays Optional array of weekdays to match
|
||||
* @returns true if current time matches the condition
|
||||
*/
|
||||
export const checkTimeInRange = (
|
||||
hass: HomeAssistant,
|
||||
after?: string,
|
||||
before?: string,
|
||||
weekdays?: WeekdayShort[]
|
||||
): boolean => {
|
||||
const timezone =
|
||||
hass.locale.time_zone === TimeZone.server
|
||||
? hass.config.time_zone
|
||||
: Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
const now = new TZDate(new Date(), timezone);
|
||||
|
||||
// Check weekday condition
|
||||
if (weekdays && weekdays.length > 0) {
|
||||
const currentWeekday = WEEKDAY_MAP[now.getDay()];
|
||||
if (!weekdays.includes(currentWeekday)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check time conditions
|
||||
if (!after && !before) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const afterDate = after ? parseTimeString(after, timezone) : undefined;
|
||||
const beforeDate = before ? parseTimeString(before, timezone) : undefined;
|
||||
|
||||
if (afterDate && beforeDate) {
|
||||
if (isBefore(beforeDate, afterDate)) {
|
||||
// Crosses midnight (e.g., 22:00 to 06:00)
|
||||
return isAfter(now, afterDate) || isBefore(now, beforeDate);
|
||||
}
|
||||
return isWithinInterval(now, { start: afterDate, end: beforeDate });
|
||||
}
|
||||
|
||||
if (afterDate) {
|
||||
return !isBefore(now, afterDate);
|
||||
}
|
||||
|
||||
if (beforeDate) {
|
||||
return !isAfter(now, beforeDate);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -1,18 +1,7 @@
|
||||
import { getWeekStartByLocale } from "weekstart";
|
||||
import type { FrontendLocaleData } from "../../data/translation";
|
||||
import { FirstWeekday } from "../../data/translation";
|
||||
|
||||
export const weekdays = [
|
||||
"sunday",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
] as const;
|
||||
|
||||
type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||
import { WEEKDAYS_LONG, type WeekdayIndex } from "./weekday";
|
||||
|
||||
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
||||
if (locale.first_weekday === FirstWeekday.language) {
|
||||
@@ -23,12 +12,12 @@ export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
||||
}
|
||||
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
||||
}
|
||||
return weekdays.includes(locale.first_weekday)
|
||||
? (weekdays.indexOf(locale.first_weekday) as WeekdayIndex)
|
||||
return WEEKDAYS_LONG.includes(locale.first_weekday)
|
||||
? (WEEKDAYS_LONG.indexOf(locale.first_weekday) as WeekdayIndex)
|
||||
: 1;
|
||||
};
|
||||
|
||||
export const firstWeekday = (locale: FrontendLocaleData) => {
|
||||
const index = firstWeekdayIndex(locale);
|
||||
return weekdays[index];
|
||||
return WEEKDAYS_LONG[index];
|
||||
};
|
||||
|
||||
59
src/common/datetime/weekday.ts
Normal file
59
src/common/datetime/weekday.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
export type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||
|
||||
export type WeekdayShort =
|
||||
| "sun"
|
||||
| "mon"
|
||||
| "tue"
|
||||
| "wed"
|
||||
| "thu"
|
||||
| "fri"
|
||||
| "sat";
|
||||
|
||||
export type WeekdayLong =
|
||||
| "sunday"
|
||||
| "monday"
|
||||
| "tuesday"
|
||||
| "wednesday"
|
||||
| "thursday"
|
||||
| "friday"
|
||||
| "saturday";
|
||||
|
||||
export const WEEKDAYS_SHORT = [
|
||||
"sun",
|
||||
"mon",
|
||||
"tue",
|
||||
"wed",
|
||||
"thu",
|
||||
"fri",
|
||||
"sat",
|
||||
] as const satisfies readonly WeekdayShort[];
|
||||
|
||||
export const WEEKDAYS_LONG = [
|
||||
"sunday",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
] as const satisfies readonly WeekdayLong[];
|
||||
|
||||
export const WEEKDAY_MAP = {
|
||||
0: "sun",
|
||||
1: "mon",
|
||||
2: "tue",
|
||||
3: "wed",
|
||||
4: "thu",
|
||||
5: "fri",
|
||||
6: "sat",
|
||||
} as const satisfies Record<WeekdayIndex, WeekdayShort>;
|
||||
|
||||
export const WEEKDAY_SHORT_TO_LONG = {
|
||||
sun: "sunday",
|
||||
mon: "monday",
|
||||
tue: "tuesday",
|
||||
wed: "wednesday",
|
||||
thu: "thursday",
|
||||
fri: "friday",
|
||||
sat: "saturday",
|
||||
} as const satisfies Record<WeekdayShort, WeekdayLong>;
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
mdiLabel,
|
||||
mdiTextureBox,
|
||||
} from "@mdi/js";
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
@@ -20,12 +19,9 @@ import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { computeEntityName } from "../../common/entity/compute_entity_name";
|
||||
import { getEntityContext } from "../../common/entity/context/get_entity_context";
|
||||
import { computeRTL } from "../../common/util/compute_rtl";
|
||||
import type { AreaRegistryEntry } from "../../data/area_registry";
|
||||
import { getConfigEntry } from "../../data/config_entries";
|
||||
import { labelsContext } from "../../data/context";
|
||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
||||
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||
import { domainToName } from "../../data/integration";
|
||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
||||
import {
|
||||
@@ -115,10 +111,10 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const { name, context, iconPath, fallbackIconPath, stateObject, notFound } =
|
||||
const { name, context, iconPath, fallbackIconPath, stateObject } =
|
||||
this._itemData(this.type, this.itemId);
|
||||
|
||||
const showEntities = this.type !== "entity" && !notFound;
|
||||
const showEntities = this.type !== "entity";
|
||||
|
||||
const entries = this.parentEntries || this._entries;
|
||||
|
||||
@@ -132,7 +128,7 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-md-list-item type="text" class=${notFound ? "error" : ""}>
|
||||
<ha-md-list-item type="text">
|
||||
<div class="icon" slot="start">
|
||||
${this.subEntry
|
||||
? html`
|
||||
@@ -152,15 +148,11 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
/>`
|
||||
: fallbackIconPath
|
||||
? html`<ha-svg-icon .path=${fallbackIconPath}></ha-svg-icon>`
|
||||
: this.type === "entity"
|
||||
: stateObject
|
||||
? html`
|
||||
<ha-state-icon
|
||||
.hass=${this.hass}
|
||||
.stateObj=${stateObject ||
|
||||
({
|
||||
entity_id: this.itemId,
|
||||
attributes: {},
|
||||
} as HassEntity)}
|
||||
.stateObj=${stateObject}
|
||||
>
|
||||
</ha-state-icon>
|
||||
`
|
||||
@@ -168,14 +160,8 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
</div>
|
||||
|
||||
<div slot="headline">${name}</div>
|
||||
${notFound || (context && !this.hideContext)
|
||||
? html`<span slot="supporting-text"
|
||||
>${notFound
|
||||
? this.hass.localize(
|
||||
`ui.components.target-picker.${this.type}_not_found`
|
||||
)
|
||||
: context}</span
|
||||
>`
|
||||
${context && !this.hideContext
|
||||
? html`<span slot="supporting-text">${context}</span>`
|
||||
: nothing}
|
||||
${this._domainName && this.subEntry
|
||||
? html`<span slot="supporting-text" class="domain"
|
||||
@@ -488,28 +474,26 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
|
||||
private _itemData = memoizeOne((type: TargetType, item: string) => {
|
||||
if (type === "floor") {
|
||||
const floor: FloorRegistryEntry | undefined = this.hass.floors?.[item];
|
||||
const floor = this.hass.floors?.[item];
|
||||
return {
|
||||
name: floor?.name || item,
|
||||
iconPath: floor?.icon,
|
||||
fallbackIconPath: floor ? floorDefaultIconPath(floor) : mdiHome,
|
||||
notFound: !floor,
|
||||
};
|
||||
}
|
||||
if (type === "area") {
|
||||
const area: AreaRegistryEntry | undefined = this.hass.areas?.[item];
|
||||
const area = this.hass.areas?.[item];
|
||||
return {
|
||||
name: area?.name || item,
|
||||
context: area?.floor_id && this.hass.floors?.[area.floor_id]?.name,
|
||||
context: area.floor_id && this.hass.floors?.[area.floor_id]?.name,
|
||||
iconPath: area?.icon,
|
||||
fallbackIconPath: mdiTextureBox,
|
||||
notFound: !area,
|
||||
};
|
||||
}
|
||||
if (type === "device") {
|
||||
const device: DeviceRegistryEntry | undefined = this.hass.devices?.[item];
|
||||
const device = this.hass.devices?.[item];
|
||||
|
||||
if (device?.primary_config_entry) {
|
||||
if (device.primary_config_entry) {
|
||||
this._getDeviceDomain(device.primary_config_entry);
|
||||
}
|
||||
|
||||
@@ -517,25 +501,24 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
name: device ? computeDeviceNameDisplay(device, this.hass) : item,
|
||||
context: device?.area_id && this.hass.areas?.[device.area_id]?.name,
|
||||
fallbackIconPath: mdiDevices,
|
||||
notFound: !device,
|
||||
};
|
||||
}
|
||||
if (type === "entity") {
|
||||
this._setDomainName(computeDomain(item));
|
||||
|
||||
const stateObject: HassEntity | undefined = this.hass.states[item];
|
||||
const entityName = stateObject
|
||||
? computeEntityName(stateObject, this.hass.entities, this.hass.devices)
|
||||
: item;
|
||||
const { area, device } = stateObject
|
||||
? getEntityContext(
|
||||
stateObject,
|
||||
this.hass.entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas,
|
||||
this.hass.floors
|
||||
)
|
||||
: { area: undefined, device: undefined };
|
||||
const stateObject = this.hass.states[item];
|
||||
const entityName = computeEntityName(
|
||||
stateObject,
|
||||
this.hass.entities,
|
||||
this.hass.devices
|
||||
);
|
||||
const { area, device } = getEntityContext(
|
||||
stateObject,
|
||||
this.hass.entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas,
|
||||
this.hass.floors
|
||||
);
|
||||
const deviceName = device ? computeDeviceName(device) : undefined;
|
||||
const areaName = area ? computeAreaName(area) : undefined;
|
||||
const context = [areaName, entityName ? deviceName : undefined]
|
||||
@@ -545,19 +528,15 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
name: entityName || deviceName || item,
|
||||
context,
|
||||
stateObject,
|
||||
notFound: !stateObject,
|
||||
};
|
||||
}
|
||||
|
||||
// type label
|
||||
const label: LabelRegistryEntry | undefined = this._labelRegistry.find(
|
||||
(lab) => lab.label_id === item
|
||||
);
|
||||
const label = this._labelRegistry.find((lab) => lab.label_id === item);
|
||||
return {
|
||||
name: label?.name || item,
|
||||
iconPath: label?.icon,
|
||||
fallbackIconPath: mdiLabel,
|
||||
notFound: !label,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -618,20 +597,11 @@ export class HaTargetPickerItemRow extends LitElement {
|
||||
border-radius: var(--ha-card-border-radius, var(--ha-border-radius-lg));
|
||||
}
|
||||
|
||||
.error {
|
||||
background: var(--ha-color-fill-warning-quiet-resting);
|
||||
}
|
||||
|
||||
.error [slot="supporting-text"] {
|
||||
color: var(--ha-color-on-warning-normal);
|
||||
}
|
||||
|
||||
state-badge {
|
||||
color: var(--ha-color-on-neutral-quiet);
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 24px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import { CONDITION_BUILDING_BLOCKS } from "./condition";
|
||||
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
|
||||
import type { Action, Field, MODES } from "./script";
|
||||
import { migrateAutomationAction } from "./script";
|
||||
import type { WeekdayShort } from "../common/datetime/weekday";
|
||||
|
||||
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
||||
export const AUTOMATION_DEFAULT_MAX = 10;
|
||||
@@ -257,13 +258,11 @@ export interface ZoneCondition extends BaseCondition {
|
||||
zone: string;
|
||||
}
|
||||
|
||||
type Weekday = "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat";
|
||||
|
||||
export interface TimeCondition extends BaseCondition {
|
||||
condition: "time";
|
||||
after?: string;
|
||||
before?: string;
|
||||
weekday?: Weekday | Weekday[];
|
||||
weekday?: WeekdayShort | WeekdayShort[];
|
||||
}
|
||||
|
||||
export interface TemplateCondition extends BaseCondition {
|
||||
|
||||
@@ -152,10 +152,18 @@ export class MoreInfoHistory extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _setRedrawTimer() {
|
||||
// redraw the graph every minute to update the time axis
|
||||
private _setUpdateTimer() {
|
||||
clearInterval(this._interval);
|
||||
this._interval = window.setInterval(() => this._redrawGraph(), 1000 * 60);
|
||||
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);
|
||||
}
|
||||
|
||||
private async _getStatisticsMetaData(statisticIds: string[] | undefined) {
|
||||
@@ -170,6 +178,30 @@ 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") &&
|
||||
@@ -180,27 +212,10 @@ 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) {
|
||||
// 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]: "" };
|
||||
const hasStatistics = await this._fetchStatistics();
|
||||
if (hasStatistics) {
|
||||
// Using statistics, set up refresh timer
|
||||
this._setUpdateTimer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -238,7 +253,7 @@ export class MoreInfoHistory extends LitElement {
|
||||
this._error = err;
|
||||
return undefined;
|
||||
});
|
||||
this._setRedrawTimer();
|
||||
this._setUpdateTimer();
|
||||
}
|
||||
|
||||
static styles = [
|
||||
|
||||
@@ -33,7 +33,7 @@ const COMPONENTS = {
|
||||
"media-browser": () =>
|
||||
import("../panels/media-browser/ha-panel-media-browser"),
|
||||
light: () => import("../panels/light/ha-panel-light"),
|
||||
security: () => import("../panels/security/ha-panel-security"),
|
||||
safety: () => import("../panels/safety/ha-panel-safety"),
|
||||
climate: () => import("../panels/climate/ha-panel-climate"),
|
||||
};
|
||||
|
||||
|
||||
@@ -332,6 +332,15 @@ 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,23 +1,24 @@
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { goBack } from "../../common/navigate";
|
||||
import { debounce } from "../../common/util/debounce";
|
||||
import { deepEqual } from "../../common/util/deep-equal";
|
||||
import "../../components/ha-icon-button-arrow-prev";
|
||||
import "../../components/ha-menu-button";
|
||||
import type { LovelaceStrategyViewConfig } from "../../data/lovelace/config/view";
|
||||
import type { LovelaceConfig } from "../../data/lovelace/config/types";
|
||||
import { haStyle } from "../../resources/styles";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { generateLovelaceViewStrategy } from "../lovelace/strategies/get-strategy";
|
||||
import type { Lovelace } from "../lovelace/types";
|
||||
import "../lovelace/views/hui-view";
|
||||
import "../lovelace/views/hui-view-container";
|
||||
|
||||
const CLIMATE_LOVELACE_VIEW_CONFIG: LovelaceStrategyViewConfig = {
|
||||
strategy: {
|
||||
type: "climate",
|
||||
},
|
||||
const CLIMATE_LOVELACE_CONFIG: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
strategy: {
|
||||
type: "climate",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@customElement("ha-panel-climate")
|
||||
@@ -32,119 +33,65 @@ class PanelClimate extends LitElement {
|
||||
|
||||
@state() private _searchParms = new URLSearchParams(window.location.search);
|
||||
|
||||
public firstUpdated(_changedProperties: PropertyValues): void {
|
||||
super.firstUpdated(_changedProperties);
|
||||
}
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
// Initial setup
|
||||
if (!this.hasUpdated) {
|
||||
this.hass.loadFragmentTranslation("lovelace");
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changedProps.has("hass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldHass = changedProps.get("hass") as this["hass"];
|
||||
if (oldHass && oldHass.localize !== this.hass.localize) {
|
||||
if (oldHass?.locale !== this.hass.locale) {
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldHass && this.hass) {
|
||||
// If the entity registry changed, ask the user if they want to refresh the config
|
||||
if (
|
||||
oldHass.entities !== this.hass.entities ||
|
||||
oldHass.devices !== this.hass.devices ||
|
||||
oldHass.areas !== this.hass.areas ||
|
||||
oldHass.floors !== this.hass.floors
|
||||
) {
|
||||
if (this.hass.config.state === "RUNNING") {
|
||||
this._debounceRegistriesChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If ha started, refresh the config
|
||||
if (
|
||||
this.hass.config.state === "RUNNING" &&
|
||||
oldHass.config.state !== "RUNNING"
|
||||
) {
|
||||
this._setLovelace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _debounceRegistriesChanged = debounce(
|
||||
() => this._registriesChanged(),
|
||||
200
|
||||
);
|
||||
|
||||
private _registriesChanged = async () => {
|
||||
this._setLovelace();
|
||||
};
|
||||
|
||||
private _back(ev) {
|
||||
ev.stopPropagation();
|
||||
goBack();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div class="header">
|
||||
<div class="toolbar">
|
||||
${
|
||||
this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ha-menu-button>
|
||||
`
|
||||
}
|
||||
${this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ha-menu-button>
|
||||
`}
|
||||
<div class="main-title">${this.hass.localize("panel.climate")}</div>
|
||||
</div>
|
||||
</div>
|
||||
${
|
||||
this._lovelace
|
||||
? html`
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view
|
||||
></hui-view-container>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view>
|
||||
</hui-view-container>
|
||||
`;
|
||||
}
|
||||
|
||||
private async _setLovelace() {
|
||||
const viewConfig = await generateLovelaceViewStrategy(
|
||||
CLIMATE_LOVELACE_VIEW_CONFIG,
|
||||
this.hass
|
||||
);
|
||||
|
||||
const config = { views: [viewConfig] };
|
||||
const rawConfig = { views: [CLIMATE_LOVELACE_VIEW_CONFIG] };
|
||||
|
||||
if (deepEqual(config, this._lovelace?.config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
private _setLovelace() {
|
||||
this._lovelace = {
|
||||
config: config,
|
||||
rawConfig: rawConfig,
|
||||
config: CLIMATE_LOVELACE_CONFIG,
|
||||
rawConfig: CLIMATE_LOVELACE_CONFIG,
|
||||
editMode: false,
|
||||
urlPath: "climate",
|
||||
mode: "generated",
|
||||
|
||||
@@ -20,6 +20,7 @@ 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) {
|
||||
@@ -56,6 +57,29 @@ 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;
|
||||
@@ -106,13 +130,9 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
)}
|
||||
></state-badge>
|
||||
${this.narrow && entity.attributes.in_progress
|
||||
? html`<ha-spinner
|
||||
class="absolute"
|
||||
size="small"
|
||||
.ariaLabel=${this.hass.localize(
|
||||
"ui.panel.config.updates.update_in_progress"
|
||||
)}
|
||||
></ha-spinner>`
|
||||
? html`<div class="absolute">
|
||||
${this._renderUpdateProgress(entity)}
|
||||
</div>`
|
||||
: nothing}
|
||||
</div>
|
||||
<span slot="headline"
|
||||
@@ -128,16 +148,9 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
: nothing}
|
||||
</span>
|
||||
${!this.narrow
|
||||
? 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>`
|
||||
? html`<div slot="end">
|
||||
${this._renderUpdateProgress(entity)}
|
||||
</div>`
|
||||
: nothing}
|
||||
</ha-md-list-item>
|
||||
`;
|
||||
@@ -193,13 +206,13 @@ class HaConfigUpdates extends SubscribeMixin(LitElement) {
|
||||
div[slot="start"] {
|
||||
position: relative;
|
||||
}
|
||||
ha-spinner.absolute {
|
||||
div.absolute {
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 6px;
|
||||
}
|
||||
state-badge.updating {
|
||||
opacity: 0.5;
|
||||
opacity: 0.2;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -332,13 +332,13 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
if (this.hass.panels.security) {
|
||||
if (this.hass.panels.safety) {
|
||||
result.push({
|
||||
icon: "mdi:security",
|
||||
title: this.hass.localize("panel.security"),
|
||||
title: this.hass.localize("panel.safety"),
|
||||
show_in_sidebar: false,
|
||||
mode: "storage",
|
||||
url_path: "security",
|
||||
url_path: "safety",
|
||||
filename: "",
|
||||
default: false,
|
||||
require_admin: false,
|
||||
@@ -470,13 +470,13 @@ export class HaConfigLovelaceDashboards extends LitElement {
|
||||
}
|
||||
|
||||
private _canDelete(urlPath: string) {
|
||||
return !["lovelace", "energy", "light", "security", "climate"].includes(
|
||||
return !["lovelace", "energy", "light", "safety", "climate"].includes(
|
||||
urlPath
|
||||
);
|
||||
}
|
||||
|
||||
private _canEdit(urlPath: string) {
|
||||
return !["light", "security", "climate"].includes(urlPath);
|
||||
return !["light", "safety", "climate"].includes(urlPath);
|
||||
}
|
||||
|
||||
private _handleDelete = async (item: DataTableItem) => {
|
||||
|
||||
@@ -148,7 +148,9 @@ export class AssistPipelineDebug extends LitElement {
|
||||
).pipeline_runs.reverse();
|
||||
} catch (e: any) {
|
||||
showAlertDialog(this, {
|
||||
title: "Failed to fetch pipeline runs",
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.fetch_runs"
|
||||
),
|
||||
text: e.message,
|
||||
});
|
||||
return;
|
||||
@@ -176,7 +178,9 @@ export class AssistPipelineDebug extends LitElement {
|
||||
).events;
|
||||
} catch (e: any) {
|
||||
showAlertDialog(this, {
|
||||
title: "Failed to fetch events",
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.fetch_events"
|
||||
),
|
||||
text: e.message,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -30,16 +30,26 @@ export class AssistPipelineEvents extends LitElement {
|
||||
const run = this._processEvents(this.events);
|
||||
if (!run) {
|
||||
if (this.events.length) {
|
||||
return html`<ha-alert alert-type="error">Error showing run</ha-alert>
|
||||
return html`<ha-alert alert-type="error"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.showing_run"
|
||||
)}</ha-alert
|
||||
>
|
||||
<ha-card>
|
||||
<ha-expansion-panel>
|
||||
<span slot="header">Raw</span>
|
||||
<span slot="header"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.raw"
|
||||
)}</span
|
||||
>
|
||||
<pre>${JSON.stringify(this.events, null, 2)}</pre>
|
||||
</ha-expansion-panel>
|
||||
</ha-card>`;
|
||||
}
|
||||
return html`<ha-alert alert-type="warning"
|
||||
>There were no events in this run.</ha-alert
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.no_events"
|
||||
)}</ha-alert
|
||||
>`;
|
||||
}
|
||||
return html`
|
||||
|
||||
@@ -11,31 +11,16 @@ 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: "Pipeline",
|
||||
language: "Language",
|
||||
};
|
||||
const WAKE_WORD_DATA = {
|
||||
engine: "Engine",
|
||||
};
|
||||
const RUN_DATA = ["pipeline", "language"];
|
||||
const WAKE_WORD_DATA = ["engine"];
|
||||
|
||||
const STT_DATA = {
|
||||
engine: "Engine",
|
||||
};
|
||||
const STT_DATA = ["engine"];
|
||||
|
||||
const INTENT_DATA = {
|
||||
engine: "Engine",
|
||||
language: "Language",
|
||||
intent_input: "Input",
|
||||
};
|
||||
const INTENT_DATA = ["engine", "language", "intent_input"];
|
||||
|
||||
const TTS_DATA = {
|
||||
engine: "Engine",
|
||||
language: "Language",
|
||||
voice: "Voice",
|
||||
tts_input: "Input",
|
||||
};
|
||||
const TTS_DATA = ["engine", "language", "voice", "tts_input"];
|
||||
|
||||
const STAGES: Record<PipelineRun["stage"], number> = {
|
||||
ready: 0,
|
||||
@@ -102,24 +87,32 @@ const renderProgress = (
|
||||
return html`${durationString}s ✅`;
|
||||
};
|
||||
|
||||
const renderData = (data: Record<string, any>, keys: Record<string, string>) =>
|
||||
Object.entries(keys).map(
|
||||
([key, label]) => html`
|
||||
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`
|
||||
<div class="row">
|
||||
<div>${label}</div>
|
||||
<div>${data[key]}</div>
|
||||
</div>
|
||||
`
|
||||
);
|
||||
`;
|
||||
});
|
||||
|
||||
const dataMinusKeysRender = (
|
||||
hass: HomeAssistant,
|
||||
data: Record<string, any>,
|
||||
keys: Record<string, string>
|
||||
keys: string[]
|
||||
) => {
|
||||
const result = {};
|
||||
let render = false;
|
||||
for (const key in data) {
|
||||
if (key in keys || key === "done") {
|
||||
if (keys.includes(key) || key === "done") {
|
||||
continue;
|
||||
}
|
||||
render = true;
|
||||
@@ -127,7 +120,9 @@ const dataMinusKeysRender = (
|
||||
}
|
||||
return render
|
||||
? html`<ha-expansion-panel>
|
||||
<span slot="header">Raw</span>
|
||||
<span slot="header"
|
||||
>${hass.localize("ui.panel.config.voice_assistants.debug.raw")}</span
|
||||
>
|
||||
<ha-yaml-editor readOnly autoUpdate .value=${result}></ha-yaml-editor>
|
||||
</ha-expansion-panel>`
|
||||
: "";
|
||||
@@ -139,6 +134,12 @@ 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(
|
||||
@@ -177,11 +178,15 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<div>Run</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.run"
|
||||
)}
|
||||
</div>
|
||||
<div>${this.pipelineRun.stage}</div>
|
||||
</div>
|
||||
|
||||
${renderData(this.pipelineRun.run, RUN_DATA)}
|
||||
${renderData(this.hass, this.pipelineRun.run, RUN_DATA)}
|
||||
${messages.length > 0
|
||||
? html`
|
||||
<div class="messages">
|
||||
@@ -203,23 +208,39 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span>Wake word</span>
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.wake_word"
|
||||
)}</span
|
||||
>
|
||||
${renderProgress(this.hass, this.pipelineRun, "wake_word")}
|
||||
</div>
|
||||
${this.pipelineRun.wake_word
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.pipelineRun.wake_word, STT_DATA)}
|
||||
${renderData(
|
||||
this.hass,
|
||||
this.pipelineRun.wake_word,
|
||||
WAKE_WORD_DATA
|
||||
)}
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
? html`<div class="row">
|
||||
<div>Model</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.model"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
.ww_id}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>Timestamp</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.timestamp"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.wake_word.wake_word_output
|
||||
.timestamp}
|
||||
@@ -227,6 +248,7 @@ export class AssistPipelineDebug extends LitElement {
|
||||
</div>`
|
||||
: ""}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.wake_word,
|
||||
WAKE_WORD_DATA
|
||||
)}
|
||||
@@ -243,7 +265,11 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span>Speech-to-text</span>
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.speech_to_text"
|
||||
)}</span
|
||||
>
|
||||
${renderProgress(
|
||||
this.hass,
|
||||
this.pipelineRun,
|
||||
@@ -254,18 +280,30 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun.stt
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.pipelineRun.stt, STT_DATA)}
|
||||
${renderData(this.hass, this.pipelineRun.stt, STT_DATA)}
|
||||
<div class="row">
|
||||
<div>Language</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.language"
|
||||
)}
|
||||
</div>
|
||||
<div>${this.pipelineRun.stt.metadata.language}</div>
|
||||
</div>
|
||||
${this.pipelineRun.stt.stt_output
|
||||
? html`<div class="row">
|
||||
<div>Output</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.output"
|
||||
)}
|
||||
</div>
|
||||
<div>${this.pipelineRun.stt.stt_output.text}</div>
|
||||
</div>`
|
||||
: ""}
|
||||
${dataMinusKeysRender(this.pipelineRun.stt, STT_DATA)}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.stt,
|
||||
STT_DATA
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: ""}
|
||||
@@ -279,16 +317,28 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span>Natural Language Processing</span>
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.natural_language_processing"
|
||||
)}</span
|
||||
>
|
||||
${renderProgress(this.hass, this.pipelineRun, "intent")}
|
||||
</div>
|
||||
${this.pipelineRun.intent
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.pipelineRun.intent, INTENT_DATA)}
|
||||
${renderData(
|
||||
this.hass,
|
||||
this.pipelineRun.intent,
|
||||
INTENT_DATA
|
||||
)}
|
||||
${this.pipelineRun.intent.intent_output
|
||||
? html`<div class="row">
|
||||
<div>Response type</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.response_type"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.intent_output
|
||||
.response.response_type}
|
||||
@@ -297,7 +347,11 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun.intent.intent_output.response
|
||||
.response_type === "error"
|
||||
? html`<div class="row">
|
||||
<div>Error code</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.error.code"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.intent_output
|
||||
.response.data.code}
|
||||
@@ -306,18 +360,27 @@ export class AssistPipelineDebug extends LitElement {
|
||||
: ""}`
|
||||
: ""}
|
||||
<div class="row">
|
||||
<div>Prefer handling locally</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.prefer_local"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.prefer_local_intents}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div>Processed locally</div>
|
||||
<div>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.processed_locally"
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
${this.pipelineRun.intent.processed_locally}
|
||||
</div>
|
||||
</div>
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.intent,
|
||||
INTENT_DATA
|
||||
)}
|
||||
@@ -334,14 +397,22 @@ export class AssistPipelineDebug extends LitElement {
|
||||
<ha-card>
|
||||
<div class="card-content">
|
||||
<div class="row heading">
|
||||
<span>Text-to-speech</span>
|
||||
<span
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.stages.text_to_speech"
|
||||
)}</span
|
||||
>
|
||||
${renderProgress(this.hass, this.pipelineRun, "tts")}
|
||||
</div>
|
||||
${this.pipelineRun.tts
|
||||
? html`
|
||||
<div class="card-content">
|
||||
${renderData(this.pipelineRun.tts, TTS_DATA)}
|
||||
${dataMinusKeysRender(this.pipelineRun.tts, TTS_DATA)}
|
||||
${renderData(this.hass, this.pipelineRun.tts, TTS_DATA)}
|
||||
${dataMinusKeysRender(
|
||||
this.hass,
|
||||
this.pipelineRun.tts,
|
||||
TTS_DATA
|
||||
)}
|
||||
</div>
|
||||
`
|
||||
: ""}
|
||||
@@ -349,8 +420,19 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${this.pipelineRun?.tts?.tts_output
|
||||
? html`
|
||||
<div class="card-actions">
|
||||
<ha-button @click=${this._playTTS}>
|
||||
Play Audio
|
||||
<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>
|
||||
</div>
|
||||
`
|
||||
@@ -361,7 +443,11 @@ export class AssistPipelineDebug extends LitElement {
|
||||
${maybeRenderError(this.pipelineRun, "tts", lastRunStage)}
|
||||
<ha-card>
|
||||
<ha-expansion-panel>
|
||||
<span slot="header">Raw</span>
|
||||
<span slot="header"
|
||||
>${this.hass.localize(
|
||||
"ui.panel.config.voice_assistants.debug.raw"
|
||||
)}</span
|
||||
>
|
||||
<ha-yaml-editor
|
||||
read-only
|
||||
auto-update
|
||||
@@ -373,14 +459,48 @@ export class AssistPipelineDebug extends LitElement {
|
||||
}
|
||||
|
||||
private _playTTS(): void {
|
||||
// Stop any existing audio first
|
||||
this._stopTTS();
|
||||
|
||||
const url = this.pipelineRun!.tts!.tts_output!.url;
|
||||
const audio = new Audio(url);
|
||||
audio.addEventListener("error", () => {
|
||||
showAlertDialog(this, { title: "Error", text: "Error playing audio" });
|
||||
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"
|
||||
),
|
||||
});
|
||||
});
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play();
|
||||
|
||||
this._audioElement.addEventListener("play", () => {
|
||||
this.requestUpdate();
|
||||
});
|
||||
|
||||
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`
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { goBack } from "../../common/navigate";
|
||||
import { debounce } from "../../common/util/debounce";
|
||||
import { deepEqual } from "../../common/util/deep-equal";
|
||||
import "../../components/ha-icon-button-arrow-prev";
|
||||
import "../../components/ha-menu-button";
|
||||
import type { LovelaceStrategyViewConfig } from "../../data/lovelace/config/view";
|
||||
import type { LovelaceConfig } from "../../data/lovelace/config/types";
|
||||
import { haStyle } from "../../resources/styles";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { generateLovelaceViewStrategy } from "../lovelace/strategies/get-strategy";
|
||||
import type { Lovelace } from "../lovelace/types";
|
||||
import "../lovelace/views/hui-view";
|
||||
import "../lovelace/views/hui-view-container";
|
||||
|
||||
const LIGHT_LOVELACE_VIEW_CONFIG: LovelaceStrategyViewConfig = {
|
||||
strategy: {
|
||||
type: "light",
|
||||
},
|
||||
const LIGHT_LOVELACE_CONFIG: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
strategy: {
|
||||
type: "light",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@customElement("ha-panel-light")
|
||||
@@ -33,118 +34,60 @@ class PanelLight extends LitElement {
|
||||
@state() private _searchParms = new URLSearchParams(window.location.search);
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
// Initial setup
|
||||
if (!this.hasUpdated) {
|
||||
this.hass.loadFragmentTranslation("lovelace");
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changedProps.has("hass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldHass = changedProps.get("hass") as this["hass"];
|
||||
if (oldHass && oldHass.localize !== this.hass.localize) {
|
||||
if (oldHass?.locale !== this.hass.locale) {
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldHass && this.hass) {
|
||||
// If the entity registry changed, ask the user if they want to refresh the config
|
||||
if (
|
||||
oldHass.entities !== this.hass.entities ||
|
||||
oldHass.devices !== this.hass.devices ||
|
||||
oldHass.areas !== this.hass.areas ||
|
||||
oldHass.floors !== this.hass.floors
|
||||
) {
|
||||
if (this.hass.config.state === "RUNNING") {
|
||||
this._debounceRegistriesChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If ha started, refresh the config
|
||||
if (
|
||||
this.hass.config.state === "RUNNING" &&
|
||||
oldHass.config.state !== "RUNNING"
|
||||
) {
|
||||
this._setLovelace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _debounceRegistriesChanged = debounce(
|
||||
() => this._registriesChanged(),
|
||||
200
|
||||
);
|
||||
|
||||
private _registriesChanged = async () => {
|
||||
this._setLovelace();
|
||||
};
|
||||
|
||||
private _back(ev) {
|
||||
ev.stopPropagation();
|
||||
goBack();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div class="header">
|
||||
<div class="toolbar">
|
||||
${
|
||||
this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ha-menu-button>
|
||||
`
|
||||
}
|
||||
${this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ha-menu-button>
|
||||
`}
|
||||
<div class="main-title">${this.hass.localize("panel.light")}</div>
|
||||
</div>
|
||||
</div>
|
||||
${
|
||||
this._lovelace
|
||||
? html`
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view
|
||||
></hui-view-container>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view>
|
||||
</hui-view-container>
|
||||
`;
|
||||
}
|
||||
|
||||
private async _setLovelace() {
|
||||
const viewConfig = await generateLovelaceViewStrategy(
|
||||
LIGHT_LOVELACE_VIEW_CONFIG,
|
||||
this.hass
|
||||
);
|
||||
|
||||
const config = { views: [viewConfig] };
|
||||
const rawConfig = { views: [LIGHT_LOVELACE_VIEW_CONFIG] };
|
||||
|
||||
if (deepEqual(config, this._lovelace?.config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
private _setLovelace() {
|
||||
this._lovelace = {
|
||||
config: config,
|
||||
rawConfig: rawConfig,
|
||||
config: LIGHT_LOVELACE_CONFIG,
|
||||
rawConfig: LIGHT_LOVELACE_CONFIG,
|
||||
editMode: false,
|
||||
urlPath: "light",
|
||||
mode: "generated",
|
||||
|
||||
@@ -52,6 +52,8 @@ 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;
|
||||
@@ -165,7 +167,7 @@ export class HaLogbook extends LitElement {
|
||||
protected willUpdate(changedProps: PropertyValues): void {
|
||||
let changed = changedProps.has("time");
|
||||
|
||||
for (const key of ["entityIds", "deviceIds"]) {
|
||||
for (const key of ["entityIds", "deviceIds", "stateFilter"]) {
|
||||
if (!changedProps.has(key)) {
|
||||
continue;
|
||||
}
|
||||
@@ -352,9 +354,19 @@ 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 = [...streamMessage.events].reverse();
|
||||
const newEntries = eventsFiltered.reverse();
|
||||
if (!this._logbookEntries || !this._logbookEntries.length) {
|
||||
this._logbookEntries = newEntries;
|
||||
return;
|
||||
|
||||
@@ -80,41 +80,44 @@ export class HuiEnergyCompareCard
|
||||
|
||||
return html`
|
||||
<ha-alert dismissable @alert-dismissed-clicked=${this._stopCompare}>
|
||||
${this.hass.localize("ui.panel.energy.compare.info", {
|
||||
start: html`<b
|
||||
>${formatDate(
|
||||
this._start!,
|
||||
this.hass.locale,
|
||||
this.hass.config
|
||||
)}${dayDifference > 0
|
||||
? ` -
|
||||
${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
|
||||
? ` -
|
||||
${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
|
||||
? ` -
|
||||
${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.energy.compare.compare_previous_year"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.energy.compare.compare_previous_period"
|
||||
)})
|
||||
</button>`,
|
||||
})}
|
||||
>`,
|
||||
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>`,
|
||||
}
|
||||
)}
|
||||
</ha-alert>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -61,8 +61,6 @@ 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;
|
||||
@@ -144,7 +142,6 @@ 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>
|
||||
@@ -174,8 +171,6 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
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;
|
||||
this._fetchCalendarEvents();
|
||||
|
||||
@@ -33,7 +33,7 @@ import type { HomeSummaryCard } from "./types";
|
||||
const COLORS: Record<HomeSummary, string> = {
|
||||
light: "amber",
|
||||
climate: "deep-orange",
|
||||
security: "blue-grey",
|
||||
safety: "blue-grey",
|
||||
media_players: "blue",
|
||||
};
|
||||
|
||||
@@ -142,20 +142,20 @@ export class HuiHomeSummaryCard extends LitElement implements LovelaceCard {
|
||||
? `${formattedMinTemp}°`
|
||||
: `${formattedMinTemp} - ${formattedMaxTemp}°`;
|
||||
}
|
||||
case "security": {
|
||||
case "safety": {
|
||||
// Alarm and lock status
|
||||
const securityFilters = HOME_SUMMARIES_FILTERS.security.map((filter) =>
|
||||
const safetyFilters = HOME_SUMMARIES_FILTERS.safety.map((filter) =>
|
||||
generateEntityFilter(this.hass!, filter)
|
||||
);
|
||||
|
||||
const securityEntities = findEntities(allEntities, securityFilters);
|
||||
const safetyEntities = findEntities(allEntities, safetyFilters);
|
||||
|
||||
const locks = securityEntities.filter((entityId) => {
|
||||
const locks = safetyEntities.filter((entityId) => {
|
||||
const domain = computeDomain(entityId);
|
||||
return domain === "lock";
|
||||
});
|
||||
|
||||
const alarms = securityEntities.filter((entityId) => {
|
||||
const alarms = safetyEntities.filter((entityId) => {
|
||||
const domain = computeDomain(entityId);
|
||||
return domain === "alarm_control_panel";
|
||||
});
|
||||
|
||||
@@ -64,6 +64,8 @@ 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);
|
||||
}
|
||||
@@ -129,6 +131,8 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
||||
};
|
||||
|
||||
this._targetPickerValue = target;
|
||||
|
||||
this._stateFilter = ensureArray(config.state_filter);
|
||||
}
|
||||
|
||||
private _getEntityIds(): string[] | undefined {
|
||||
@@ -209,6 +213,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
||||
.hass=${this.hass}
|
||||
.time=${this._time}
|
||||
.entityIds=${this._getEntityIds()}
|
||||
.stateFilter=${this._stateFilter}
|
||||
narrow
|
||||
relative-time
|
||||
virtualize
|
||||
|
||||
@@ -345,6 +345,7 @@ export interface LogbookCardConfig extends LovelaceCardConfig {
|
||||
title?: string;
|
||||
hours_to_show?: number;
|
||||
theme?: string;
|
||||
state_filter?: string[];
|
||||
}
|
||||
|
||||
export interface MapEntityConfig extends EntityConfig {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
mdiAccount,
|
||||
mdiAmpersand,
|
||||
mdiCalendarClock,
|
||||
mdiGateOr,
|
||||
mdiMapMarker,
|
||||
mdiNotEqualVariant,
|
||||
@@ -15,6 +16,7 @@ export const ICON_CONDITION: Record<Condition["condition"], string> = {
|
||||
numeric_state: mdiNumeric,
|
||||
state: mdiStateMachine,
|
||||
screen: mdiResponsive,
|
||||
time: mdiCalendarClock,
|
||||
user: mdiAccount,
|
||||
and: mdiAmpersand,
|
||||
not: mdiNotEqualVariant,
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import { checkTimeInRange } from "../../../common/datetime/check_time";
|
||||
import {
|
||||
WEEKDAYS_SHORT,
|
||||
type WeekdayShort,
|
||||
} from "../../../common/datetime/weekday";
|
||||
import type { MediaQueriesListener } from "../../../common/dom/media_query";
|
||||
import { listenMediaQuery } from "../../../common/dom/media_query";
|
||||
|
||||
@@ -12,6 +17,7 @@ export type Condition =
|
||||
| NumericStateCondition
|
||||
| StateCondition
|
||||
| ScreenCondition
|
||||
| TimeCondition
|
||||
| UserCondition
|
||||
| OrCondition
|
||||
| AndCondition
|
||||
@@ -52,6 +58,13 @@ export interface ScreenCondition extends BaseCondition {
|
||||
media_query?: string;
|
||||
}
|
||||
|
||||
export interface TimeCondition extends BaseCondition {
|
||||
condition: "time";
|
||||
after?: string;
|
||||
before?: string;
|
||||
weekdays?: WeekdayShort[];
|
||||
}
|
||||
|
||||
export interface UserCondition extends BaseCondition {
|
||||
condition: "user";
|
||||
users?: string[];
|
||||
@@ -152,6 +165,15 @@ function checkScreenCondition(condition: ScreenCondition, _: HomeAssistant) {
|
||||
: false;
|
||||
}
|
||||
|
||||
function checkTimeCondition(condition: TimeCondition, hass: HomeAssistant) {
|
||||
return checkTimeInRange(
|
||||
hass,
|
||||
condition.after,
|
||||
condition.before,
|
||||
condition.weekdays
|
||||
);
|
||||
}
|
||||
|
||||
function checkLocationCondition(
|
||||
condition: LocationCondition,
|
||||
hass: HomeAssistant
|
||||
@@ -197,6 +219,8 @@ export function checkConditionsMet(
|
||||
return conditions.every((c) => {
|
||||
if ("condition" in c) {
|
||||
switch (c.condition) {
|
||||
case "time":
|
||||
return checkTimeCondition(c, hass);
|
||||
case "screen":
|
||||
return checkScreenCondition(c, hass);
|
||||
case "user":
|
||||
@@ -273,6 +297,17 @@ function validateScreenCondition(condition: ScreenCondition) {
|
||||
return condition.media_query != null;
|
||||
}
|
||||
|
||||
function validateTimeCondition(condition: TimeCondition) {
|
||||
const hasTime = condition.after != null || condition.before != null;
|
||||
const hasWeekdays =
|
||||
condition.weekdays != null && condition.weekdays.length > 0;
|
||||
const weekdaysValid =
|
||||
!hasWeekdays ||
|
||||
condition.weekdays!.every((w: WeekdayShort) => WEEKDAYS_SHORT.includes(w));
|
||||
|
||||
return (hasTime || hasWeekdays) && weekdaysValid;
|
||||
}
|
||||
|
||||
function validateUserCondition(condition: UserCondition) {
|
||||
return condition.users != null;
|
||||
}
|
||||
@@ -312,6 +347,8 @@ export function validateConditionalConfig(
|
||||
switch (c.condition) {
|
||||
case "screen":
|
||||
return validateScreenCondition(c);
|
||||
case "time":
|
||||
return validateTimeCondition(c);
|
||||
case "user":
|
||||
return validateUserCondition(c);
|
||||
case "location":
|
||||
|
||||
@@ -25,6 +25,7 @@ import "./types/ha-card-condition-numeric_state";
|
||||
import "./types/ha-card-condition-or";
|
||||
import "./types/ha-card-condition-screen";
|
||||
import "./types/ha-card-condition-state";
|
||||
import "./types/ha-card-condition-time";
|
||||
import "./types/ha-card-condition-user";
|
||||
import { storage } from "../../../../common/decorators/storage";
|
||||
|
||||
@@ -33,6 +34,7 @@ const UI_CONDITION = [
|
||||
"numeric_state",
|
||||
"state",
|
||||
"screen",
|
||||
"time",
|
||||
"user",
|
||||
"and",
|
||||
"not",
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import {
|
||||
literal,
|
||||
array,
|
||||
object,
|
||||
optional,
|
||||
string,
|
||||
assert,
|
||||
enums,
|
||||
} from "superstruct";
|
||||
import memoizeOne from "memoize-one";
|
||||
import type { HomeAssistant } from "../../../../../types";
|
||||
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||
import {
|
||||
WEEKDAY_SHORT_TO_LONG,
|
||||
WEEKDAYS_SHORT,
|
||||
} from "../../../../../common/datetime/weekday";
|
||||
import type { TimeCondition } from "../../../common/validate-condition";
|
||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||
import type {
|
||||
HaFormSchema,
|
||||
SchemaUnion,
|
||||
} from "../../../../../components/ha-form/types";
|
||||
import "../../../../../components/ha-form/ha-form";
|
||||
|
||||
const timeConditionStruct = object({
|
||||
condition: literal("time"),
|
||||
after: optional(string()),
|
||||
before: optional(string()),
|
||||
weekdays: optional(array(enums(WEEKDAYS_SHORT))),
|
||||
});
|
||||
|
||||
@customElement("ha-card-condition-time")
|
||||
export class HaCardConditionTime extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public condition!: TimeCondition;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
public static get defaultConfig(): TimeCondition {
|
||||
return { condition: "time", after: "08:00", before: "17:00" };
|
||||
}
|
||||
|
||||
protected static validateUIConfig(condition: TimeCondition) {
|
||||
return assert(condition, timeConditionStruct);
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(localize: LocalizeFunc) =>
|
||||
[
|
||||
{ name: "after", selector: { time: {} } },
|
||||
{ name: "before", selector: { time: {} } },
|
||||
{
|
||||
name: "weekdays",
|
||||
selector: {
|
||||
select: {
|
||||
mode: "list",
|
||||
multiple: true,
|
||||
options: WEEKDAYS_SHORT.map((day) => ({
|
||||
value: day,
|
||||
label: localize(`ui.weekdays.${WEEKDAY_SHORT_TO_LONG[day]}`),
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
] as const satisfies HaFormSchema[]
|
||||
);
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${this.condition}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.schema=${this._schema(this.hass.localize)}
|
||||
.disabled=${this.disabled}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`;
|
||||
}
|
||||
|
||||
private _valueChanged(ev: CustomEvent) {
|
||||
ev.stopPropagation();
|
||||
const data = ev.detail.value as TimeCondition;
|
||||
fireEvent(this, "value-changed", { value: data });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (
|
||||
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
): string =>
|
||||
this.hass.localize(
|
||||
`ui.panel.lovelace.editor.condition-editor.condition.time.${schema.name}`
|
||||
);
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-card-condition-time": HaCardConditionTime;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
string,
|
||||
} from "superstruct";
|
||||
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import "../../../../components/entity/ha-entities-picker";
|
||||
import "../../../../components/ha-target-picker";
|
||||
@@ -24,6 +25,7 @@ import { DEFAULT_HOURS_TO_SHOW } from "../../cards/hui-logbook-card";
|
||||
import { targetStruct } from "../../../../data/script";
|
||||
import { getSensorNumericDeviceClasses } from "../../../../data/sensor";
|
||||
import type { HaEntityPickerEntityFilterFunc } from "../../../../data/entity";
|
||||
import { resolveEntityIDs } from "../../../../data/selector";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
@@ -33,6 +35,7 @@ const cardConfigStruct = assign(
|
||||
hours_to_show: optional(number()),
|
||||
theme: optional(string()),
|
||||
target: optional(targetStruct),
|
||||
state_filter: optional(array(string())),
|
||||
})
|
||||
);
|
||||
|
||||
@@ -50,6 +53,13 @@ const SCHEMA = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "state_filter",
|
||||
context: {
|
||||
filter_entity: "context_entities",
|
||||
},
|
||||
selector: { state: { multiple: true } },
|
||||
},
|
||||
] as const;
|
||||
|
||||
@customElement("hui-logbook-card-editor")
|
||||
@@ -106,7 +116,13 @@ export class HuiLogbookCardEditor
|
||||
return html`
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${this._config}
|
||||
.data=${this._data(
|
||||
this._config,
|
||||
this._targetPicker,
|
||||
this.hass.entities,
|
||||
this.hass.devices,
|
||||
this.hass.areas
|
||||
)}
|
||||
.schema=${SCHEMA}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
@value-changed=${this._valueChanged}
|
||||
@@ -122,6 +138,25 @@ 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);
|
||||
|
||||
@@ -131,7 +166,9 @@ export class HuiLogbookCardEditor
|
||||
}
|
||||
|
||||
private _valueChanged(ev: CustomEvent): void {
|
||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
||||
const newConfig = { ...ev.detail.value };
|
||||
delete newConfig.context_entities;
|
||||
fireEvent(this, "config-changed", { config: newConfig });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
||||
@@ -142,6 +179,10 @@ 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}`
|
||||
|
||||
@@ -48,7 +48,7 @@ const STRATEGIES: Record<LovelaceStrategyConfigType, Record<string, any>> = {
|
||||
import("./home/home-media-players-view-strategy"),
|
||||
"home-area": () => import("./home/home-area-view-strategy"),
|
||||
light: () => import("../../light/strategies/light-view-strategy"),
|
||||
security: () => import("../../security/strategies/security-view-strategy"),
|
||||
safety: () => import("../../safety/strategies/safety-view-strategy"),
|
||||
climate: () => import("../../climate/strategies/climate-view-strategy"),
|
||||
},
|
||||
section: {
|
||||
|
||||
@@ -2,12 +2,12 @@ import type { EntityFilter } from "../../../../../common/entity/entity_filter";
|
||||
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||
import { climateEntityFilters } from "../../../../climate/strategies/climate-view-strategy";
|
||||
import { lightEntityFilters } from "../../../../light/strategies/light-view-strategy";
|
||||
import { securityEntityFilters } from "../../../../security/strategies/security-view-strategy";
|
||||
import { safetyEntityFilters } from "../../../../safety/strategies/safety-view-strategy";
|
||||
|
||||
export const HOME_SUMMARIES = [
|
||||
"light",
|
||||
"climate",
|
||||
"security",
|
||||
"safety",
|
||||
"media_players",
|
||||
] as const;
|
||||
|
||||
@@ -16,14 +16,14 @@ export type HomeSummary = (typeof HOME_SUMMARIES)[number];
|
||||
export const HOME_SUMMARIES_ICONS: Record<HomeSummary, string> = {
|
||||
light: "mdi:lamps",
|
||||
climate: "mdi:home-thermometer",
|
||||
security: "mdi:security",
|
||||
safety: "mdi:security",
|
||||
media_players: "mdi:multimedia",
|
||||
};
|
||||
|
||||
export const HOME_SUMMARIES_FILTERS: Record<HomeSummary, EntityFilter[]> = {
|
||||
light: lightEntityFilters,
|
||||
climate: climateEntityFilters,
|
||||
security: securityEntityFilters,
|
||||
safety: safetyEntityFilters,
|
||||
media_players: [{ domain: "media_player", entity_category: "none" }],
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ export const getSummaryLabel = (
|
||||
localize: LocalizeFunc,
|
||||
summary: HomeSummary
|
||||
) => {
|
||||
if (summary === "light" || summary === "climate" || summary === "security") {
|
||||
if (summary === "light" || summary === "climate" || summary === "safety") {
|
||||
return localize(`panel.${summary}`);
|
||||
}
|
||||
return localize(`ui.panel.lovelace.strategy.home.summary_list.${summary}`);
|
||||
|
||||
@@ -104,7 +104,7 @@ export class HomeAreaViewStrategy extends ReactiveElement {
|
||||
const {
|
||||
light,
|
||||
climate,
|
||||
security,
|
||||
safety,
|
||||
media_players: mediaPlayers,
|
||||
} = entitiesBySummary;
|
||||
|
||||
@@ -136,16 +136,16 @@ export class HomeAreaViewStrategy extends ReactiveElement {
|
||||
});
|
||||
}
|
||||
|
||||
if (security.length > 0) {
|
||||
if (safety.length > 0) {
|
||||
sections.push({
|
||||
type: "grid",
|
||||
cards: [
|
||||
computeHeadingCard(
|
||||
getSummaryLabel(hass.localize, "security"),
|
||||
HOME_SUMMARIES_ICONS.security,
|
||||
"/security?historyBack=1"
|
||||
getSummaryLabel(hass.localize, "safety"),
|
||||
HOME_SUMMARIES_ICONS.safety,
|
||||
"/safety?historyBack=1"
|
||||
),
|
||||
...security.map(computeTileCard),
|
||||
...safety.map(computeTileCard),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { ReactiveElement } from "lit";
|
||||
import { customElement } from "lit/decorators";
|
||||
import { isComponentLoaded } from "../../../../common/config/is_component_loaded";
|
||||
import {
|
||||
findEntities,
|
||||
generateEntityFilter,
|
||||
} from "../../../../common/entity/entity_filter";
|
||||
import { floorDefaultIcon } from "../../../../components/ha-floor-icon";
|
||||
import { generateEntityFilter } from "../../../../common/entity/entity_filter";
|
||||
import type { AreaRegistryEntry } from "../../../../data/area_registry";
|
||||
import { getEnergyPreferences } from "../../../../data/energy";
|
||||
import type { LovelaceCardConfig } from "../../../../data/lovelace/config/card";
|
||||
@@ -25,7 +21,7 @@ import type {
|
||||
import { getAreas, getFloors } from "../areas/helpers/areas-strategy-helper";
|
||||
import type { CommonControlSectionStrategyConfig } from "../usage_prediction/common-controls-section-strategy";
|
||||
import { getHomeStructure } from "./helpers/home-structure";
|
||||
import { HOME_SUMMARIES_FILTERS } from "./helpers/home-summaries";
|
||||
import { floorDefaultIcon } from "../../../../components/ha-floor-icon";
|
||||
|
||||
export interface HomeMainViewStrategyConfig {
|
||||
type: "home-main";
|
||||
@@ -148,105 +144,82 @@ export class HomeMainViewStrategy extends ReactiveElement {
|
||||
column_span: maxColumns,
|
||||
} as LovelaceStrategySectionConfig;
|
||||
|
||||
const allEntities = Object.keys(hass.states);
|
||||
|
||||
const mediaPlayerFilter = HOME_SUMMARIES_FILTERS.media_players.map(
|
||||
(filter) => generateEntityFilter(hass, filter)
|
||||
);
|
||||
|
||||
const lightsFilters = HOME_SUMMARIES_FILTERS.light.map((filter) =>
|
||||
generateEntityFilter(hass, filter)
|
||||
);
|
||||
|
||||
const climateFilters = HOME_SUMMARIES_FILTERS.climate.map((filter) =>
|
||||
generateEntityFilter(hass, filter)
|
||||
);
|
||||
|
||||
const securityFilters = HOME_SUMMARIES_FILTERS.security.map((filter) =>
|
||||
generateEntityFilter(hass, filter)
|
||||
);
|
||||
|
||||
const hasLights = findEntities(allEntities, lightsFilters).length > 0;
|
||||
const hasMediaPlayers =
|
||||
findEntities(allEntities, mediaPlayerFilter).length > 0;
|
||||
const hasClimate = findEntities(allEntities, climateFilters).length > 0;
|
||||
const hasSecurity = findEntities(allEntities, securityFilters).length > 0;
|
||||
// Check if there are any media player entities
|
||||
const mediaPlayerFilter = generateEntityFilter(hass, {
|
||||
domain: "media_player",
|
||||
entity_category: "none",
|
||||
});
|
||||
const hasMediaPlayers = Object.keys(hass.states).some(mediaPlayerFilter);
|
||||
|
||||
const summaryCards: LovelaceCardConfig[] = [
|
||||
hasLights &&
|
||||
({
|
||||
type: "home-summary",
|
||||
summary: "light",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/light?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard),
|
||||
hasClimate &&
|
||||
({
|
||||
type: "home-summary",
|
||||
summary: "climate",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/climate?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard),
|
||||
hasSecurity &&
|
||||
({
|
||||
type: "home-summary",
|
||||
summary: "security",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/security?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard),
|
||||
hasMediaPlayers &&
|
||||
({
|
||||
type: "home-summary",
|
||||
summary: "media_players",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "media-players",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard),
|
||||
].filter(Boolean) as LovelaceCardConfig[];
|
||||
{
|
||||
type: "heading",
|
||||
heading: hass.localize("ui.panel.lovelace.strategy.home.summaries"),
|
||||
},
|
||||
{
|
||||
type: "home-summary",
|
||||
summary: "light",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/light?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard,
|
||||
{
|
||||
type: "home-summary",
|
||||
summary: "climate",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/climate?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard,
|
||||
{
|
||||
type: "home-summary",
|
||||
summary: "safety",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/safety?historyBack=1",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard,
|
||||
];
|
||||
|
||||
// Only add media players summary if there are media player entities
|
||||
if (hasMediaPlayers) {
|
||||
summaryCards.push({
|
||||
type: "home-summary",
|
||||
summary: "media_players",
|
||||
vertical: true,
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "media-players",
|
||||
},
|
||||
grid_options: {
|
||||
rows: 2,
|
||||
columns: 4,
|
||||
},
|
||||
} satisfies HomeSummaryCard);
|
||||
}
|
||||
|
||||
const summarySection: LovelaceSectionConfig = {
|
||||
type: "grid",
|
||||
column_span: maxColumns,
|
||||
cards: [],
|
||||
cards: summaryCards,
|
||||
};
|
||||
|
||||
if (summaryCards.length) {
|
||||
summarySection.cards!.push(
|
||||
{
|
||||
type: "heading",
|
||||
heading: hass.localize("ui.panel.lovelace.strategy.home.summaries"),
|
||||
},
|
||||
...summaryCards
|
||||
);
|
||||
}
|
||||
|
||||
const weatherFilter = generateEntityFilter(hass, {
|
||||
domain: "weather",
|
||||
entity_category: "none",
|
||||
@@ -302,7 +275,7 @@ export class HomeMainViewStrategy extends ReactiveElement {
|
||||
[
|
||||
favoriteSection.cards && favoriteSection,
|
||||
commonControlsSection,
|
||||
summarySection.cards && summarySection,
|
||||
summarySection,
|
||||
...floorsSections,
|
||||
widgetSection.cards && widgetSection,
|
||||
] satisfies (LovelaceSectionRawConfig | undefined)[]
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { goBack } from "../../common/navigate";
|
||||
import { debounce } from "../../common/util/debounce";
|
||||
import { deepEqual } from "../../common/util/deep-equal";
|
||||
import "../../components/ha-icon-button-arrow-prev";
|
||||
import "../../components/ha-menu-button";
|
||||
import type { LovelaceStrategyViewConfig } from "../../data/lovelace/config/view";
|
||||
import type { LovelaceConfig } from "../../data/lovelace/config/types";
|
||||
import { haStyle } from "../../resources/styles";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { generateLovelaceViewStrategy } from "../lovelace/strategies/get-strategy";
|
||||
import type { Lovelace } from "../lovelace/types";
|
||||
import "../lovelace/views/hui-view";
|
||||
import "../lovelace/views/hui-view-container";
|
||||
|
||||
const SECURITY_LOVELACE_VIEW_CONFIG: LovelaceStrategyViewConfig = {
|
||||
strategy: {
|
||||
type: "security",
|
||||
},
|
||||
const SAFETY_LOVELACE_CONFIG: LovelaceConfig = {
|
||||
views: [
|
||||
{
|
||||
strategy: {
|
||||
type: "safety",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@customElement("ha-panel-security")
|
||||
class PanelSecurity extends LitElement {
|
||||
@customElement("ha-panel-safety")
|
||||
class PanelSafety extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public narrow = false;
|
||||
@@ -33,120 +34,62 @@ class PanelSecurity extends LitElement {
|
||||
@state() private _searchParms = new URLSearchParams(window.location.search);
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
// Initial setup
|
||||
if (!this.hasUpdated) {
|
||||
this.hass.loadFragmentTranslation("lovelace");
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changedProps.has("hass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldHass = changedProps.get("hass") as this["hass"];
|
||||
if (oldHass && oldHass.localize !== this.hass.localize) {
|
||||
if (oldHass?.locale !== this.hass.locale) {
|
||||
this._setLovelace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldHass && this.hass) {
|
||||
// If the entity registry changed, ask the user if they want to refresh the config
|
||||
if (
|
||||
oldHass.entities !== this.hass.entities ||
|
||||
oldHass.devices !== this.hass.devices ||
|
||||
oldHass.areas !== this.hass.areas ||
|
||||
oldHass.floors !== this.hass.floors
|
||||
) {
|
||||
if (this.hass.config.state === "RUNNING") {
|
||||
this._debounceRegistriesChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If ha started, refresh the config
|
||||
if (
|
||||
this.hass.config.state === "RUNNING" &&
|
||||
oldHass.config.state !== "RUNNING"
|
||||
) {
|
||||
this._setLovelace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _debounceRegistriesChanged = debounce(
|
||||
() => this._registriesChanged(),
|
||||
200
|
||||
);
|
||||
|
||||
private _registriesChanged = async () => {
|
||||
this._setLovelace();
|
||||
};
|
||||
|
||||
private _back(ev) {
|
||||
ev.stopPropagation();
|
||||
goBack();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
protected render(): TemplateResult {
|
||||
return html`
|
||||
<div class="header">
|
||||
<div class="toolbar">
|
||||
${
|
||||
this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
></ha-menu-button>
|
||||
`
|
||||
}
|
||||
<div class="main-title">${this.hass.localize("panel.security")}</div>
|
||||
</div>
|
||||
</div>
|
||||
${
|
||||
this._lovelace
|
||||
? html`
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
${this._searchParms.has("historyBack")
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
@click=${this._back}
|
||||
slot="navigationIcon"
|
||||
></ha-icon-button-arrow-prev>
|
||||
`
|
||||
: html`
|
||||
<ha-menu-button
|
||||
slot="navigationIcon"
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view
|
||||
></hui-view-container>
|
||||
`
|
||||
: nothing
|
||||
}
|
||||
></ha-menu-button>
|
||||
`}
|
||||
<div class="main-title">${this.hass.localize("panel.safety")}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hui-view-container .hass=${this.hass}>
|
||||
<hui-view
|
||||
.hass=${this.hass}
|
||||
.narrow=${this.narrow}
|
||||
.lovelace=${this._lovelace}
|
||||
.index=${this._viewIndex}
|
||||
></hui-view>
|
||||
</hui-view-container>
|
||||
`;
|
||||
}
|
||||
|
||||
private async _setLovelace() {
|
||||
const viewConfig = await generateLovelaceViewStrategy(
|
||||
SECURITY_LOVELACE_VIEW_CONFIG,
|
||||
this.hass
|
||||
);
|
||||
|
||||
const config = { views: [viewConfig] };
|
||||
const rawConfig = { views: [SECURITY_LOVELACE_VIEW_CONFIG] };
|
||||
|
||||
if (deepEqual(config, this._lovelace?.config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
private _setLovelace() {
|
||||
this._lovelace = {
|
||||
config: config,
|
||||
rawConfig: rawConfig,
|
||||
config: SAFETY_LOVELACE_CONFIG,
|
||||
rawConfig: SAFETY_LOVELACE_CONFIG,
|
||||
editMode: false,
|
||||
urlPath: "security",
|
||||
urlPath: "safety",
|
||||
mode: "generated",
|
||||
locale: this.hass.locale,
|
||||
enableFullEditMode: () => undefined,
|
||||
@@ -248,6 +191,6 @@ class PanelSecurity extends LitElement {
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-panel-security": PanelSecurity;
|
||||
"ha-panel-safety": PanelSafety;
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,11 @@ import {
|
||||
} from "../../lovelace/strategies/areas/helpers/areas-strategy-helper";
|
||||
import { getHomeStructure } from "../../lovelace/strategies/home/helpers/home-structure";
|
||||
|
||||
export interface SecurityViewStrategyConfig {
|
||||
type: "security";
|
||||
export interface SafetyViewStrategyConfig {
|
||||
type: "safety";
|
||||
}
|
||||
|
||||
export const securityEntityFilters: EntityFilter[] = [
|
||||
export const safetyEntityFilters: EntityFilter[] = [
|
||||
{
|
||||
domain: "camera",
|
||||
entity_category: "none",
|
||||
@@ -67,7 +67,7 @@ export const securityEntityFilters: EntityFilter[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const processAreasForSecurity = (
|
||||
const processAreasForSafety = (
|
||||
areaIds: string[],
|
||||
hass: HomeAssistant,
|
||||
entities: string[]
|
||||
@@ -81,12 +81,12 @@ const processAreasForSecurity = (
|
||||
const areaFilter = generateEntityFilter(hass, {
|
||||
area: area.area_id,
|
||||
});
|
||||
const areaSecurityEntities = entities.filter(areaFilter);
|
||||
const areaSafetyEntities = entities.filter(areaFilter);
|
||||
const areaCards: LovelaceCardConfig[] = [];
|
||||
|
||||
const computeTileCard = computeAreaTileCardConfig(hass, "", false);
|
||||
|
||||
for (const entityId of areaSecurityEntities) {
|
||||
for (const entityId of areaSafetyEntities) {
|
||||
areaCards.push(computeTileCard(entityId));
|
||||
}
|
||||
|
||||
@@ -121,10 +121,10 @@ const processUnassignedEntities = (
|
||||
return areaCards;
|
||||
};
|
||||
|
||||
@customElement("security-view-strategy")
|
||||
export class SecurityViewStrategy extends ReactiveElement {
|
||||
@customElement("safety-view-strategy")
|
||||
export class SafetyViewStrategy extends ReactiveElement {
|
||||
static async generate(
|
||||
_config: SecurityViewStrategyConfig,
|
||||
_config: SafetyViewStrategyConfig,
|
||||
hass: HomeAssistant
|
||||
): Promise<LovelaceViewConfig> {
|
||||
const areas = getAreas(hass.areas);
|
||||
@@ -135,11 +135,11 @@ export class SecurityViewStrategy extends ReactiveElement {
|
||||
|
||||
const allEntities = Object.keys(hass.states);
|
||||
|
||||
const securityFilters = securityEntityFilters.map((filter) =>
|
||||
const safetyFilters = safetyEntityFilters.map((filter) =>
|
||||
generateEntityFilter(hass, filter)
|
||||
);
|
||||
|
||||
const entities = findEntities(allEntities, securityFilters);
|
||||
const entities = findEntities(allEntities, safetyFilters);
|
||||
|
||||
const floorCount = home.floors.length + (home.areas.length ? 1 : 0);
|
||||
|
||||
@@ -164,7 +164,7 @@ export class SecurityViewStrategy extends ReactiveElement {
|
||||
],
|
||||
};
|
||||
|
||||
const areaCards = processAreasForSecurity(areaIds, hass, entities);
|
||||
const areaCards = processAreasForSafety(areaIds, hass, entities);
|
||||
|
||||
if (areaCards.length > 0) {
|
||||
section.cards!.push(...areaCards);
|
||||
@@ -188,7 +188,7 @@ export class SecurityViewStrategy extends ReactiveElement {
|
||||
],
|
||||
};
|
||||
|
||||
const areaCards = processAreasForSecurity(home.areas, hass, entities);
|
||||
const areaCards = processAreasForSafety(home.areas, hass, entities);
|
||||
|
||||
if (areaCards.length > 0) {
|
||||
section.cards!.push(...areaCards);
|
||||
@@ -209,9 +209,9 @@ export class SecurityViewStrategy extends ReactiveElement {
|
||||
heading:
|
||||
sections.length > 0
|
||||
? hass.localize(
|
||||
"ui.panel.lovelace.strategy.security.other_devices"
|
||||
"ui.panel.lovelace.strategy.safety.other_devices"
|
||||
)
|
||||
: hass.localize("ui.panel.lovelace.strategy.security.devices"),
|
||||
: hass.localize("ui.panel.lovelace.strategy.safety.devices"),
|
||||
},
|
||||
...unassignedCards,
|
||||
],
|
||||
@@ -229,6 +229,6 @@ export class SecurityViewStrategy extends ReactiveElement {
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"security-view-strategy": SecurityViewStrategy;
|
||||
"safety-view-strategy": SafetyViewStrategy;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
"media_browser": "Media",
|
||||
"profile": "Profile",
|
||||
"light": "Lights",
|
||||
"security": "Security",
|
||||
"safety": "Safety",
|
||||
"climate": "Climate"
|
||||
},
|
||||
"state": {
|
||||
@@ -695,11 +695,6 @@
|
||||
"remove_device_id": "Remove device",
|
||||
"remove_entity_id": "Remove entity",
|
||||
"remove_label_id": "Remove label",
|
||||
"floor_not_found": "Floor not found",
|
||||
"area_not_found": "Area not found",
|
||||
"device_not_found": "Device not found",
|
||||
"entity_not_found": "Entity not found",
|
||||
"label_not_found": "Label not found",
|
||||
"devices_count": "{count} {count, plural,\n one {device}\n other {devices}\n}",
|
||||
"entities_count": "{count} {count, plural,\n one {entity}\n other {entities}\n}",
|
||||
"target_details": "Target details",
|
||||
@@ -3631,6 +3626,36 @@
|
||||
"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",
|
||||
@@ -6955,7 +6980,7 @@
|
||||
"lights": "Lights",
|
||||
"other_lights": "Other lights"
|
||||
},
|
||||
"security": {
|
||||
"safety": {
|
||||
"devices": "Devices",
|
||||
"other_devices": "Other devices"
|
||||
},
|
||||
@@ -7106,6 +7131,11 @@
|
||||
"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": {
|
||||
@@ -7519,6 +7549,12 @@
|
||||
"state_equal": "State is equal to",
|
||||
"state_not_equal": "State is not equal to"
|
||||
},
|
||||
"time": {
|
||||
"label": "Time",
|
||||
"after": "After",
|
||||
"before": "Before",
|
||||
"weekdays": "Weekdays"
|
||||
},
|
||||
"location": {
|
||||
"label": "Location",
|
||||
"locations": "Locations",
|
||||
@@ -7669,7 +7705,8 @@
|
||||
},
|
||||
"logbook": {
|
||||
"name": "Activity",
|
||||
"description": "The Activity card shows a list of events for entities."
|
||||
"description": "The Activity card shows a list of events for entities.",
|
||||
"state_filter": "State filter"
|
||||
},
|
||||
"history-graph": {
|
||||
"name": "History graph",
|
||||
@@ -9353,11 +9390,6 @@
|
||||
"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",
|
||||
|
||||
209
test/common/datetime/check_time.test.ts
Normal file
209
test/common/datetime/check_time.test.ts
Normal file
@@ -0,0 +1,209 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { checkTimeInRange } from "../../../src/common/datetime/check_time";
|
||||
import type { HomeAssistant } from "../../../src/types";
|
||||
import {
|
||||
NumberFormat,
|
||||
TimeFormat,
|
||||
FirstWeekday,
|
||||
DateFormat,
|
||||
TimeZone,
|
||||
} from "../../../src/data/translation";
|
||||
|
||||
describe("checkTimeInRange", () => {
|
||||
let mockHass: HomeAssistant;
|
||||
|
||||
beforeEach(() => {
|
||||
mockHass = {
|
||||
locale: {
|
||||
language: "en-US",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.language,
|
||||
date_format: DateFormat.language,
|
||||
time_zone: TimeZone.local,
|
||||
first_weekday: FirstWeekday.language,
|
||||
},
|
||||
config: {
|
||||
time_zone: "America/Los_Angeles",
|
||||
},
|
||||
} as HomeAssistant;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("time ranges within same day", () => {
|
||||
it("should return true when current time is within range", () => {
|
||||
// Set time to 10:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when current time is before range", () => {
|
||||
// Set time to 7:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 7, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when current time is after range", () => {
|
||||
// Set time to 6:00 PM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 18, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("time ranges crossing midnight", () => {
|
||||
it("should return true when current time is before midnight", () => {
|
||||
// Set time to 11:00 PM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 23, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "22:00", "06:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true when current time is after midnight", () => {
|
||||
// Set time to 3:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 3, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "22:00", "06:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when outside the range", () => {
|
||||
// Set time to 10:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "22:00", "06:00")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("only 'after' condition", () => {
|
||||
it("should return true when after specified time", () => {
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
expect(checkTimeInRange(mockHass, "08:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when before specified time", () => {
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 6, 0, 0));
|
||||
expect(checkTimeInRange(mockHass, "08:00")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("only 'before' condition", () => {
|
||||
it("should return true when before specified time", () => {
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
expect(checkTimeInRange(mockHass, undefined, "17:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when after specified time", () => {
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 18, 0, 0));
|
||||
expect(checkTimeInRange(mockHass, undefined, "17:00")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("weekday filtering", () => {
|
||||
it("should return true on matching weekday", () => {
|
||||
// January 15, 2024 is a Monday
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, undefined, undefined, ["mon"])).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false on non-matching weekday", () => {
|
||||
// January 15, 2024 is a Monday
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, undefined, undefined, ["tue"])).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should work with multiple weekdays", () => {
|
||||
// January 15, 2024 is a Monday
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(
|
||||
checkTimeInRange(mockHass, undefined, undefined, ["mon", "wed", "fri"])
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("combined time and weekday conditions", () => {
|
||||
it("should return true when both match", () => {
|
||||
// January 15, 2024 is a Monday at 10:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00", ["mon"])).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when time matches but weekday doesn't", () => {
|
||||
// January 15, 2024 is a Monday at 10:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00", ["tue"])).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when weekday matches but time doesn't", () => {
|
||||
// January 15, 2024 is a Monday at 6:00 AM
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 6, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00", ["mon"])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("no conditions", () => {
|
||||
it("should return true when no conditions specified", () => {
|
||||
vi.setSystemTime(new Date(2024, 0, 15, 10, 0, 0));
|
||||
|
||||
expect(checkTimeInRange(mockHass)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("DST transitions", () => {
|
||||
it("should handle spring forward transition (losing an hour)", () => {
|
||||
// March 10, 2024 at 1:30 AM PST - before spring forward
|
||||
// At 2:00 AM, clocks jump to 3:00 AM PDT
|
||||
vi.setSystemTime(new Date(2024, 2, 10, 1, 30, 0));
|
||||
|
||||
// Should be within range that crosses the transition
|
||||
expect(checkTimeInRange(mockHass, "01:00", "04:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle spring forward transition after the jump", () => {
|
||||
// March 10, 2024 at 3:30 AM PDT - after spring forward
|
||||
vi.setSystemTime(new Date(2024, 2, 10, 3, 30, 0));
|
||||
|
||||
// Should still be within range
|
||||
expect(checkTimeInRange(mockHass, "01:00", "04:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle fall back transition (gaining an hour)", () => {
|
||||
// November 3, 2024 at 1:30 AM PDT - before fall back
|
||||
// At 2:00 AM PDT, clocks fall back to 1:00 AM PST
|
||||
vi.setSystemTime(new Date(2024, 10, 3, 1, 30, 0));
|
||||
|
||||
// Should be within range that crosses the transition
|
||||
expect(checkTimeInRange(mockHass, "01:00", "03:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle midnight crossing during DST transition", () => {
|
||||
// March 10, 2024 at 1:00 AM - during spring forward night
|
||||
vi.setSystemTime(new Date(2024, 2, 10, 1, 0, 0));
|
||||
|
||||
// Range that crosses midnight and DST transition
|
||||
expect(checkTimeInRange(mockHass, "22:00", "04:00")).toBe(true);
|
||||
});
|
||||
|
||||
it("should correctly compare times on DST transition day", () => {
|
||||
// November 3, 2024 at 10:00 AM - after fall back completed
|
||||
vi.setSystemTime(new Date(2024, 10, 3, 10, 0, 0));
|
||||
|
||||
// Normal business hours should work correctly
|
||||
expect(checkTimeInRange(mockHass, "08:00", "17:00")).toBe(true);
|
||||
expect(checkTimeInRange(mockHass, "12:00", "17:00")).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user