Compare commits

...

37 Commits

Author SHA1 Message Date
Aidan Timson 73e05237a4 C 2026-05-21 14:44:20 +01:00
Aidan Timson 6137d7ffff Add target UI 2026-05-21 14:42:18 +01:00
Aidan Timson 625324846f Add target UI 2026-05-21 14:39:37 +01:00
karwosts 7c6609aee7 Make external statistic card unclickable (#52139) 2026-05-21 16:07:43 +03:00
Paul Bottein 7048c5f3d2 Add entity-first card picker for dashboard (#51651)
Co-authored-by: Wendelin <w@pe8.at>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-05-21 15:01:10 +02:00
Aidan Timson 9ed47be6c3 Add to for devices page, merge 3 cards into 1 related card (#52119)
* Add to for devices page

* Rename and reuse original dialogs, drop popover

* Reduce

* Lazy context

* Direct access lazy context

* Default width

* Merge automations and scripts cards

* Format

* Loading state

* Rename key

* Tooltip and move key

* Copy icons used in more info

* Sort

* Merge scenes into one "Related" card

* Adjust

* Fix no labs

* Use same wording for device actions

* Cleanup

* Comments for removal

* Cleanup

* Type check

* Template literals

* Add padding
2026-05-21 15:35:14 +03:00
Aidan Timson 128f4526e3 Fix no entities message in area page, improve message (#52130) 2026-05-21 15:23:26 +03:00
Wendelin 3f1b7ce391 Add automation item comments (#52090)
* Add automation comments

* Line wrap

* Review

* Add truncateWithEllipsis with tests

* Review
2026-05-21 13:50:51 +03:00
renovate[bot] 4073b4e1f5 Update dependency date-fns to v4.2.0 (#52132)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-21 13:46:57 +03:00
Paul Bottein 86a24d1532 Add temperature and precipitation forecast card features (#51866)
* Rework weather forecast card features

* Add show labels option

* Some fixes

* Fixes and cleaning

* Update palette

* Add reference floor to precipitation bar scale

Light drizzle no longer fills the bar when it's also the period max.
Observed values above the floor still drive the scale (storms read full).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Feedbacks

* Use weather unit

* Force celcius for gradient

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 13:42:26 +03:00
Wendelin 46bab5bb01 Automation row target count (#52118)
* Add automation row target count

* fix types
2026-05-20 16:23:40 +03:00
iluvdata e8f486af0a Allow integrations to specify the "domain" of the entity that is rendered in previews (#51829)
* Allow previews to use a domain

* Allow previews to specify preview entity domain

* Allow repair_flow to use previews

* Pull recent changes

* Add domain to previews for TemplatePreview
2026-05-20 12:30:03 +03:00
AlCalzone 211579eade Add Z-Wave credential mangement (#51591)
* first rough draft of Z-Wave credential mangement

* separate user and credentials, error handling, dialog tweaks

* align with upstream API changes, improve error handling

* align more with Matter, use lock entity for services

* remove get_credential_status service

* address review feedback, clarify user types

* user_index -> user_id, fix some pending states

* address review feedback

* clean up unused code, strongly type credential types

* Clear -> Delete, drop icons

* Simplify flow to 1 PIN/Password credential per user

* cleanup, comments, etc.

* address review feedback

* do not show existing credential data

* fix lint errors after branch update

* ignore non-enterable credential types when editing user
2026-05-20 12:05:13 +03:00
markvp f6458925c9 Add hidden device firmware column (#52117) 2026-05-20 08:35:32 +00:00
karwosts ae5e35e7ed Include low battery binary_sensors in low battery count (#52115)
Include low binary battery sensors in low battery count
2026-05-20 08:35:11 +03:00
karwosts 8c1727859a Restore battery chips in Home areas strategy (#52114) 2026-05-20 08:27:12 +03:00
Wendelin 287562221f Remove live condition test tooltip (#52103)
* Remove live condition test hover

* Update src/components/automation/ha-automation-row-live-test.ts

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>

* Review

---------

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
2026-05-20 08:21:45 +03:00
Aidan Timson 2593dfed8d Type assertion and signature improvements for hui changed handlers (#52109)
* Type assertion and signature improvements

* Improve
2026-05-19 20:06:20 +02:00
pcan08 2d92f1fb3b Forget filter from url: remaining pages (#52061)
* refactor: use separate storage and display filters in backup page

Apply the two-lists pattern in backup page: _filters (@state, display only) +
_storageFilters (@storage sessionStorage, state: false). _storageFilters
is only updated when not in URL mode (_fromUrl flag). Init moved from
connectedCallback to willUpdate(!hasUpdated).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: use separate storage and display filters in scenes page

Apply the two-lists pattern in scenes page: _filters (@state, display only) +
_storageFilters (@storage sessionStorage, state: false, with
serializer/deserializer). _storageFilters is only updated when not in
URL mode (_fromUrl flag). Init moved from firstUpdated to
willUpdate(!hasUpdated). The existing updated() hook already calls
_applyFilters() when _entityReg changes, covering the reconnect case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: use separate storage and display filters in automations page

Apply the two-lists pattern in automations page: _filters (@state, display only) +
_storageFilters (@storage sessionStorage, state: false, with
serializer/deserializer). _storageFilters is only updated when not in
URL mode (_fromUrl flag). _fromUrl is set before the await in the async
_filterBlueprint() to prevent any user change during the fetch from
persisting. Init moved from firstUpdated to willUpdate(!hasUpdated).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: use separate storage and display filters in scripts page

Apply the two-lists pattern in scripts page: _filters (@state, display only) +
_storageFilters (@storage sessionStorage, state: false, with
serializer/deserializer). _storageFilters is only updated when not in
URL mode (_fromUrl flag). _fromUrl is set before the await in the async
_filterBlueprint() to prevent any user change during the fetch from
persisting. Init moved from firstUpdated to willUpdate(!hasUpdated).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: don't mix URL filters with storage filters in automation,script and scene pages

When URL params are present, _filters starts empty so URL methods build
from scratch. Previously, _filters was pre-populated from _storageFilters
and the spread in _filterLabel()/_filterBlueprint() would merge storage
filters into the URL-injected ones.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Update src/panels/config/backup/ha-config-backup-backups.ts

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
2026-05-19 17:47:47 +00:00
pcan08 8cff4c6bd2 Helpers page: forget filter from url (#51989)
* fix(helpers): clear URL-injected filters on leaving helpers dashboard

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(helpers): restore previous filters after URL-injected navigation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: use separate storage and display filters

Apply the same pattern as devices and entities pages: split _filters into
a display-only @state and a _storageFilters persisted to sessionStorage.
_storageFilters is only updated when not in URL mode (_fromUrl flag), so
URL-injected filters never persist to storage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: reapply filters when helper entities load on reconnect

_applyFilters() was never called when _filters was restored from
sessionStorage, leaving _filteredHelperEntityIds undefined and the
table appearing empty. Call it whenever _helperEntities updates and
active filters are present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 19:43:31 +02:00
renovate[bot] 5aa8455861 Update tsparticles to v4.0.2 (#52110) 2026-05-19 14:08:32 +00:00
renovate[bot] 4d142734d8 Migrate Renovate config (#52105) 2026-05-19 14:07:06 +00:00
Aidan Timson eaecc76f36 Add to automation/script with triggers/conditions/actions (#51871)
* Setup default add to actions

* Setup default add to actions

* Move event into external only

* Split into sections

* Padding

* Refactor to single type and adapt app interface to frontend style and vice versa

* Refactor to single type and adapt app interface to frontend style and vice versa

* Condition action and navigation actions

* Open dialogs with trigger, condition, action dialogs

* Add divider before add to

* Move add to to the top

* Action

* Triggers and conditions labs feature check

* Suggestion

* Keep query state

* Change to automation_trigger

* Use typed key instead of finding with icon

* Apply suggestions from code review

Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com>

* Finish

* Reset state

* Fix navigation resets

* stated

Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com>

* Split

* Add import, sort imports

---------

Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com>
2026-05-19 14:57:44 +02:00
Aidan Timson 7dc0033c03 Improve typing on value-changed handlers in card features and state controls (#52107) 2026-05-19 14:28:52 +02:00
Paul Bottein 601e6d0542 Distinguish unknown from unavailable entity state (#52089) 2026-05-19 15:24:50 +03:00
Aidan Timson c7ca3dd837 Typing assertion and generic improvements on area controls and conditions (#52106) 2026-05-19 15:11:31 +03:00
renovate[bot] f75a376add Update dependency lint-staged to v17.0.5 (#52104) 2026-05-19 12:54:34 +01:00
Aidan Timson a541204ffb Match python version with core version (#52102) 2026-05-19 13:27:31 +02:00
Aidan Timson cbbce90eae Remove YARN_VERSION from netlify.toml (inherit packageManager) (#52101) 2026-05-19 13:26:33 +02:00
Wendelin 950de204aa Restyle and improve app info (#52100) 2026-05-19 09:37:38 +01:00
Jan-Philipp Benecke 91b6a4c4b6 Migrate energy sources table and drop mwc data table dependency (#52097)
* Migrate energy sources table and drop mwc data table dependency

* Address review comments

* Address review comments
2026-05-19 09:58:18 +03:00
karwosts 643cc4ca7d Make energy electric sources nameable (#52051)
Make electric sources nameable

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
2026-05-19 06:37:49 +00:00
renovate[bot] 9ef71e6cf4 Update tsparticles to v4.0.1 (#52095)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-19 07:18:29 +02:00
renovate[bot] bface72af7 Lock file maintenance (#52096)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-19 07:18:12 +02:00
Paul Bottein 90028b2e22 Clarify cleaning order hint in vacuum more info (#52087) 2026-05-18 22:29:36 +02:00
Ben Hamilton (Ben Gertzfield) 914c48abd5 Allow media player source card feature when list is empty (#52094) 2026-05-18 19:05:12 +00:00
renovate[bot] 79c082acde Update dependency eslint to v10.4.0 (#52093)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-18 20:36:03 +02:00
233 changed files with 12144 additions and 3842 deletions
-1
View File
@@ -1,3 +1,2 @@
[build.environment]
YARN_VERSION = "1.22.11"
NODE_OPTIONS = "--max_old_space_size=6144"
+5 -6
View File
@@ -62,7 +62,6 @@
"@lit-labs/virtualizer": "2.1.1",
"@lit/context": "1.1.6",
"@lit/reactive-element": "2.1.2",
"@material/data-table": "=14.0.0-canary.53b3cad2f.0",
"@material/mwc-base": "0.27.0",
"@material/mwc-formfield": "patch:@material/mwc-formfield@npm%3A0.27.0#~/.yarn/patches/@material-mwc-formfield-npm-0.27.0-9528cb60f6.patch",
"@material/mwc-list": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch",
@@ -75,8 +74,8 @@
"@replit/codemirror-indentation-markers": "6.5.3",
"@swc/helpers": "0.5.21",
"@thomasloven/round-slider": "0.6.0",
"@tsparticles/engine": "4.0.0",
"@tsparticles/preset-links": "4.0.0",
"@tsparticles/engine": "4.0.2",
"@tsparticles/preset-links": "4.0.2",
"@vibrant/color": "4.0.4",
"@webcomponents/scoped-custom-element-registry": "0.0.10",
"@webcomponents/webcomponentsjs": "2.8.0",
@@ -87,7 +86,7 @@
"core-js": "3.49.0",
"cropperjs": "1.6.2",
"culori": "4.0.2",
"date-fns": "4.1.0",
"date-fns": "4.2.0",
"deep-clone-simple": "1.1.1",
"deep-freeze": "0.0.1",
"dialog-polyfill": "0.5.6",
@@ -166,7 +165,7 @@
"babel-plugin-template-html-minifier": "4.1.0",
"browserslist-useragent-regexp": "4.1.4",
"del": "8.0.1",
"eslint": "10.3.0",
"eslint": "10.4.0",
"eslint-config-prettier": "10.1.8",
"eslint-import-resolver-webpack": "0.13.11",
"eslint-plugin-import-x": "4.16.2",
@@ -188,7 +187,7 @@
"jsdom": "29.1.1",
"jszip": "3.10.1",
"license-checker-rseidelsohn": "4.4.2",
"lint-staged": "17.0.4",
"lint-staged": "17.0.5",
"lit-analyzer": "2.0.3",
"lodash.merge": "4.6.2",
"lodash.template": "4.18.1",
+39
View File
@@ -18,7 +18,46 @@
"enabled": true,
"schedule": ["on the 19th day of the month before 4am"]
},
"customDatasources": {
"ha-core-python": {
"defaultRegistryUrlTemplate": "https://raw.githubusercontent.com/home-assistant/core/dev/.python-version",
"format": "plain"
}
},
"customManagers": [
{
"description": "Keep PYTHON_VERSION in sync with home-assistant/core (patch + minor)",
"customType": "regex",
"managerFilePatterns": ["/^\\.github/workflows/[^/]+\\.ya?ml$/"],
"matchStrings": ["PYTHON_VERSION: \"(?<currentValue>[^\"]+)\""],
"depNameTemplate": "python",
"datasourceTemplate": "custom.ha-core-python",
"versioningTemplate": "python"
},
{
"description": "Keep devcontainer image and requires-python in sync with home-assistant/core (minor only)",
"customType": "regex",
"managerFilePatterns": [
"/^\\.devcontainer/Dockerfile$/",
"/^pyproject\\.toml$/"
],
"matchStrings": [
"devcontainers/python:(?<currentValue>[\\d.]+)",
"requires-python = \">=(?<currentValue>[^\"]+)\""
],
"depNameTemplate": "python",
"datasourceTemplate": "custom.ha-core-python",
"versioningTemplate": "python",
"extractVersionTemplate": "^(?<version>\\d+\\.\\d+)"
}
],
"packageRules": [
{
"description": "Group all Python version updates from home-assistant/core",
"matchDepNames": ["python"],
"matchDatasources": ["custom.ha-core-python"],
"groupName": "Python version"
},
{
"description": "MDC packages are pinned to the same version as MWC",
"extends": ["monorepo:material-components-web"],
+1 -1
View File
@@ -3,7 +3,7 @@
* @param arr - The array to get combinations of
* @returns A multidimensional array of all possible combinations
*/
export function getAllCombinations<T>(arr: T[]) {
export function getAllCombinations<T>(arr: readonly T[]): T[][] {
return arr.reduce<T[][]>(
(combinations, element) =>
combinations.concat(
+9
View File
@@ -114,6 +114,15 @@ export const DOMAINS_WITH_DYNAMIC_PICTURE = new Set([
export const UNIT_C = "°C";
export const UNIT_F = "°F";
/** Length units. */
export const UNIT_IN = "in";
export const UNIT_KM = "km";
export const UNIT_MM = "mm";
/** Pressure units. */
export const UNIT_HPA = "hPa";
export const UNIT_INHG = "inHg";
/** Entity ID of the default view. */
export const DEFAULT_VIEW_ENTITY_ID = "group.default_view";
@@ -1,5 +1,5 @@
import type { HassEntity } from "home-assistant-js-websocket";
import { isUnavailableState } from "../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { HomeAssistant } from "../../types";
interface EntityUnitStubConfig {
@@ -21,32 +21,24 @@ export const computeEntityUnitDisplay = (
stateObj: HassEntity | undefined,
config: EntityUnitStubConfig
): string => {
let unit;
if (
stateObj &&
!isUnavailableState(stateObj.state) &&
(config.attribute || stateObj.attributes.device_class !== "duration")
!stateObj ||
stateObj.state === UNAVAILABLE ||
stateObj.state === UNKNOWN ||
(!config.attribute && stateObj.attributes.device_class === "duration")
) {
// check for an explicitly defined unit in config
unit = config.unit;
if (!unit) {
if (!config.attribute) {
// use entity's unit_of_measurement
const stateParts = hass.formatEntityStateToParts(stateObj);
unit = stateParts.find((part) => part.type === "unit")?.value;
} else {
// use attribute's unit if available
const attrParts = hass.formatEntityAttributeValueToParts(
stateObj,
config.attribute
);
unit = attrParts.find((part) => part.type === "unit")?.value;
}
}
return unit ?? "";
return "";
}
return "";
// check for an explicitly defined unit in config
if (config.unit) {
return config.unit;
}
// otherwise derive from the entity's state or attribute
const parts = config.attribute
? hass.formatEntityAttributeValueToParts(stateObj, config.attribute)
: hass.formatEntityStateToParts(stateObj);
return parts.find((part) => part.type === "unit")?.value ?? "";
};
+2 -2
View File
@@ -1,5 +1,5 @@
import type { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE_STATES } from "../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { HomeAssistant } from "../../types";
import { stringCompare } from "../string/compare";
import { computeDomain } from "./compute_domain";
@@ -253,7 +253,7 @@ export const getStatesDomain = (
if (!attribute) {
// All entities can have unavailable states
result.push(...UNAVAILABLE_STATES);
result.push(UNAVAILABLE, UNKNOWN);
}
if (!attribute && domain in FIXED_DOMAIN_STATES) {
+11 -5
View File
@@ -1,5 +1,5 @@
import type { HassEntity } from "home-assistant-js-websocket";
import { isUnavailableState, UNAVAILABLE } from "../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { HomeAssistant } from "../../types";
import { computeStateDomain } from "./compute_state_domain";
@@ -8,14 +8,20 @@ export const computeGroupEntitiesState = (states: HassEntity[]): string => {
return UNAVAILABLE;
}
const validState = states.some(
(stateObj) => !isUnavailableState(stateObj.state)
const allUnavailable = states.every(
(stateObj) => stateObj.state === UNAVAILABLE
);
if (!validState) {
if (allUnavailable) {
return UNAVAILABLE;
}
const hasValidState = states.some(
(stateObj) => stateObj.state !== UNAVAILABLE && stateObj.state !== UNKNOWN
);
if (!hasValidState) {
return UNKNOWN;
}
// Use the first state to determine the domain
// This assumes all states in the group have the same domain
const domain = computeStateDomain(states[0]);
+2 -2
View File
@@ -1,5 +1,5 @@
import type { HassEntity } from "home-assistant-js-websocket";
import { isUnavailableState, OFF, UNAVAILABLE } from "../../data/entity/entity";
import { OFF, UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import { computeDomain } from "./compute_domain";
export function stateActive(stateObj: HassEntity, state?: string): boolean {
@@ -19,7 +19,7 @@ export function stateActive(stateObj: HassEntity, state?: string): boolean {
return compareState !== UNAVAILABLE;
}
if (isUnavailableState(compareState)) {
if (compareState === UNAVAILABLE || compareState === UNKNOWN) {
return false;
}
@@ -0,0 +1,17 @@
/**
* @summary Truncates a string to `maxLength`, appending `ellipsis` only when it actually shortens the result.
* @param text The input string.
* @param maxLength Maximum length of the prefix kept before the ellipsis.
* @param ellipsis Suffix appended when truncation occurs.
* @returns `text` unchanged when its length is `<= maxLength + ellipsis.length`, otherwise `text.substring(0, maxLength) + ellipsis`.
*/
export const truncateWithEllipsis = (
text: string,
maxLength: number,
ellipsis = "..."
): string => {
if (text.length <= maxLength + ellipsis.length) {
return text;
}
return `${text.substring(0, maxLength)}${ellipsis}`;
};
@@ -1,6 +1,5 @@
import { LitElement, css, html, nothing } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators";
import "../ha-tooltip";
export type LiveTestState = "pass" | "fail" | "invalid" | "unknown";
@@ -9,11 +8,10 @@ export type LiveTestState = "pass" | "fail" | "invalid" | "unknown";
*
* @summary
* Small status indicator dot used in automation/condition rows to surface the
* live evaluation result. Renders an optional tooltip with details on hover.
* live evaluation result.
*
* @attr {"pass"|"fail"|"invalid"|"unknown"} state - The current live-test state. Defaults to `unknown`.
* @attr {string} label - Accessible label announced by assistive technology.
* @attr {string} message - Optional tooltip body shown on hover/focus.
*/
@customElement("ha-automation-row-live-test")
export class HaAutomationRowLiveTest extends LitElement {
@@ -21,8 +19,6 @@ export class HaAutomationRowLiveTest extends LitElement {
@property() public label = "";
@property() public message?: string;
protected render() {
return html`
<div
@@ -31,9 +27,6 @@ export class HaAutomationRowLiveTest extends LitElement {
tabindex="0"
aria-label=${this.label}
></div>
${this.message
? html`<ha-tooltip for="indicator">${this.message}</ha-tooltip>`
: nothing}
`;
}
@@ -56,31 +49,15 @@ export class HaAutomationRowLiveTest extends LitElement {
background-color: var(--ha-color-fill-success-loud-resting);
border-color: var(--ha-color-fill-success-loud-resting);
}
:host([state="pass"]) #indicator:hover {
background-color: var(--ha-color-fill-success-loud-hover);
border-color: var(--ha-color-fill-success-loud-hover);
}
:host([state="fail"]) #indicator {
border-color: var(--ha-color-fill-warning-loud-resting);
}
:host([state="fail"]) #indicator:hover {
background-color: var(--ha-color-fill-warning-loud-hover);
border-color: var(--ha-color-fill-warning-loud-hover);
}
:host([state="invalid"]) #indicator {
border-color: var(--ha-color-fill-danger-loud-resting);
}
:host([state="invalid"]) #indicator:hover {
background-color: var(--ha-color-fill-danger-loud-hover);
border-color: var(--ha-color-fill-danger-loud-hover);
}
:host([state="unknown"]) #indicator {
border-color: var(--ha-color-fill-neutral-loud-resting);
}
:host([state="unknown"]) #indicator:hover {
background-color: var(--ha-color-fill-neutral-loud-hover);
border-color: var(--ha-color-fill-neutral-loud-hover);
}
`;
}
@@ -187,7 +187,6 @@ export class HaAutomationRow extends LitElement {
flex: 1;
min-width: 0;
overflow-wrap: anywhere;
margin: 0 var(--ha-space-3);
}
::slotted([slot="header"]) {
overflow-wrap: anywhere;
+1 -1
View File
@@ -116,7 +116,7 @@ export class HaProgressButton extends LitElement {
visibility: hidden;
}
ha-svg-icon {
:host([appearance="brand"]) ha-svg-icon {
color: var(--white-color);
}
`;
@@ -1,10 +1,12 @@
import { consume } from "@lit/context";
import type { HassEntities } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { caseInsensitiveStringCompare } from "../../common/string/compare";
import type { LocalizeFunc } from "../../common/translations/localize";
import { fullEntitiesContext } from "../../data/context";
import type { DeviceAutomation } from "../../data/device/device_automation";
import {
@@ -12,7 +14,7 @@ import {
sortDeviceAutomations,
} from "../../data/device/device_automation";
import type { EntityRegistryEntry } from "../../data/entity/entity_registry";
import type { HomeAssistant, ValueChangedEvent } from "../../types";
import type { CallWS, HomeAssistant, ValueChangedEvent } from "../../types";
import "../ha-generic-picker";
import type { PickerValueRenderer } from "../ha-picker-field";
@@ -46,13 +48,14 @@ export abstract class HaDeviceAutomationPicker<
}
private _localizeDeviceAutomation: (
hass: HomeAssistant,
localize: LocalizeFunc,
states: HassEntities,
entityRegistry: EntityRegistryEntry[],
automation: T
) => string;
private _fetchDeviceAutomations: (
hass: HomeAssistant,
callWS: CallWS,
deviceId: string
) => Promise<T[]>;
@@ -127,7 +130,8 @@ export abstract class HaDeviceAutomationPicker<
const automationListItems = automations.map((automation, idx) => {
const primary = this._localizeDeviceAutomation(
this.hass,
this.hass.localize,
this.hass.states,
this._entityReg,
automation
);
@@ -162,7 +166,12 @@ export abstract class HaDeviceAutomationPicker<
);
const text = automation
? this._localizeDeviceAutomation(this.hass, this._entityReg, automation)
? this._localizeDeviceAutomation(
this.hass.localize,
this.hass.states,
this._entityReg,
automation
)
: value === NO_AUTOMATION_KEY
? this.NO_AUTOMATION_TEXT
: value;
@@ -172,9 +181,9 @@ export abstract class HaDeviceAutomationPicker<
private async _updateDeviceInfo() {
this._automations = this.deviceId
? (await this._fetchDeviceAutomations(this.hass, this.deviceId)).sort(
sortDeviceAutomations
)
? (
await this._fetchDeviceAutomations(this.hass.callWS, this.deviceId)
).sort(sortDeviceAutomations)
: // No device, clear the list of automations
[];
+3 -6
View File
@@ -6,11 +6,7 @@ import { customElement, property, state } from "lit/decorators";
import { STATES_OFF } from "../../common/const";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import {
UNAVAILABLE,
UNKNOWN,
isUnavailableState,
} from "../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import { forwardHaptic } from "../../data/haptics";
import type { HomeAssistant } from "../../types";
import "../ha-formfield";
@@ -20,7 +16,8 @@ import "../ha-switch";
const isOn = (stateObj?: HassEntity) =>
stateObj !== undefined &&
!STATES_OFF.includes(stateObj.state) &&
!isUnavailableState(stateObj.state);
stateObj.state !== UNAVAILABLE &&
stateObj.state !== UNKNOWN;
/**
* @element ha-entity-toggle
@@ -9,7 +9,7 @@ import secondsToDuration from "../../common/datetime/seconds_to_duration";
import { computeStateDomain } from "../../common/entity/compute_state_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
import { isUnavailableState, UNAVAILABLE } from "../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
import { timerTimeRemaining } from "../../data/timer";
import type { HomeAssistant } from "../../types";
@@ -170,7 +170,8 @@ export class HaStateLabelBadge extends LitElement {
}
// eslint-disable-next-line: disable=no-fallthrough
default:
return isUnavailableState(entityState.state)
return entityState.state === UNAVAILABLE ||
entityState.state === UNKNOWN
? "—"
: this.hass!.formatEntityStateToParts(entityState).find(
(part) => part.type === "value"
@@ -209,7 +210,7 @@ export class HaStateLabelBadge extends LitElement {
_timerTimeRemaining = 0
) {
// For unavailable states or certain domains, use a special translation that is truncated to fit within the badge label
if (isUnavailableState(entityState.state)) {
if (entityState.state === UNAVAILABLE || entityState.state === UNKNOWN) {
return this.hass!.localize(`state_badge.default.${entityState.state}`);
}
const domainStateKey = getTruncatedKey(domain, entityState.state);
+3 -3
View File
@@ -29,7 +29,7 @@ export interface AreaControlPickerItem extends PickerComboBoxItem {
deviceClass?: string;
}
const AREA_CONTROL_DOMAINS: readonly AreaControlDomain[] = [
const AREA_CONTROL_DOMAINS = [
"light",
"fan",
"switch",
@@ -43,7 +43,7 @@ const AREA_CONTROL_DOMAINS: readonly AreaControlDomain[] = [
"cover-door",
"cover-window",
"cover-damper",
] as const;
] as const satisfies readonly AreaControlDomain[];
@customElement("ha-area-controls-picker")
export class HaAreaControlsPicker extends LitElement {
@@ -130,7 +130,7 @@ export class HaAreaControlsPicker extends LitElement {
(excludeValues !== undefined && excludeValues.includes(id));
const controlEntities = getAreaControlEntities(
AREA_CONTROL_DOMAINS as unknown as AreaControlDomain[],
AREA_CONTROL_DOMAINS,
areaId,
excludeEntities,
this.hass
+9 -4
View File
@@ -3,7 +3,7 @@ import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import type { ClimateEntity } from "../data/climate";
import { CLIMATE_PRESET_NONE } from "../data/climate";
import { isUnavailableState, OFF } from "../data/entity/entity";
import { OFF, UNAVAILABLE, UNKNOWN } from "../data/entity/entity";
import type { HomeAssistant } from "../types";
@customElement("ha-climate-state")
@@ -14,9 +14,11 @@ class HaClimateState extends LitElement {
protected render(): TemplateResult {
const currentStatus = this._computeCurrentStatus();
const noValue =
this.stateObj.state === UNAVAILABLE || this.stateObj.state === UNKNOWN;
return html`<div class="target">
${!isUnavailableState(this.stateObj.state)
${!noValue
? html`<span class="state-label">
${this._localizeState()}
${this.stateObj.attributes.preset_mode &&
@@ -32,7 +34,7 @@ class HaClimateState extends LitElement {
: this._localizeState()}
</div>
${currentStatus && !isUnavailableState(this.stateObj.state)
${currentStatus && !noValue
? html`
<div class="current">
${this.hass.localize("ui.card.climate.currently")}:
@@ -119,7 +121,10 @@ class HaClimateState extends LitElement {
}
private _localizeState(): string {
if (isUnavailableState(this.stateObj.state)) {
if (
this.stateObj.state === UNAVAILABLE ||
this.stateObj.state === UNKNOWN
) {
return this.hass.localize(`state.default.${this.stateObj.state}`);
}
+11 -4
View File
@@ -6,11 +6,18 @@ import type { HaIconButton } from "./ha-icon-button";
/**
* Event type for the ha-dropdown component when an item is selected.
* @param T - The type of the value of the selected item.
* @param TValue - The type of the selected item's `value`.
* @param TData - The type of the selected item's `data` when set on `ha-dropdown-item`.
*/
export type HaDropdownSelectEvent<T = string> = CustomEvent<{
item: Omit<HaDropdownItem, "value"> & { value: T };
}>;
export type HaDropdownSelectEvent<TValue = string, TData = undefined> = [
TData,
] extends [undefined]
? CustomEvent<{
item: Omit<HaDropdownItem, "value"> & { value: TValue };
}>
: CustomEvent<{
item: Omit<HaDropdownItem, "value"> & { value: TValue; data: TData };
}>;
/**
* Home Assistant dropdown component
+9 -4
View File
@@ -1,7 +1,7 @@
import type { TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { isUnavailableState, OFF } from "../data/entity/entity";
import { OFF, UNAVAILABLE, UNKNOWN } from "../data/entity/entity";
import type { HumidifierEntity } from "../data/humidifier";
import type { HomeAssistant } from "../types";
@@ -13,9 +13,11 @@ class HaHumidifierState extends LitElement {
protected render(): TemplateResult {
const currentStatus = this._computeCurrentStatus();
const noValue =
this.stateObj.state === UNAVAILABLE || this.stateObj.state === UNKNOWN;
return html`<div class="target">
${!isUnavailableState(this.stateObj.state)
${!noValue
? html`<span class="state-label">
${this._localizeState()}
${this.stateObj.attributes.mode
@@ -30,7 +32,7 @@ class HaHumidifierState extends LitElement {
: this._localizeState()}
</div>
${currentStatus && !isUnavailableState(this.stateObj.state)
${currentStatus && !noValue
? html`<div class="current">
${this.hass.localize("ui.card.humidifier.currently")}:
<div class="unit">${currentStatus}</div>
@@ -69,7 +71,10 @@ class HaHumidifierState extends LitElement {
}
private _localizeState(): string {
if (isUnavailableState(this.stateObj.state)) {
if (
this.stateObj.state === UNAVAILABLE ||
this.stateObj.state === UNKNOWN
) {
return this.hass.localize(`state.default.${this.stateObj.state}`);
}
@@ -2,7 +2,7 @@ import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { fireEvent, type HASSDomEvent } from "../../common/dom/fire_event";
import type { ColorTempSelector } from "../../data/selector";
import type { HomeAssistant } from "../../types";
import "../ha-labeled-slider";
@@ -94,10 +94,10 @@ export class HaColorTempSelector extends LitElement {
}
);
private _valueChanged(ev: CustomEvent) {
private _valueChanged(ev: HASSDomEvent<HASSDomEvents["value-changed"]>) {
ev.stopPropagation();
fireEvent(this, "value-changed", {
value: Number((ev.detail as any).value),
value: Number(ev.detail.value),
});
}
}
+1 -1
View File
@@ -837,7 +837,7 @@ export class HaServiceControl extends LitElement {
if (targetDevices.length) {
targetDevices = targetDevices.filter((device) =>
deviceMeetsTargetSelector(
this.hass,
this.hass.states,
Object.values(this.hass.entities),
this.hass.devices[device],
targetSelector
+1
View File
@@ -30,6 +30,7 @@ export class HaSettingsRow extends LitElement {
<slot name="prefix"></slot>
<div
class="body"
part="heading"
?two-line=${!this.threeLine && hasDescription}
?three-line=${this.threeLine}
>
+16 -1
View File
@@ -1,12 +1,13 @@
import "@home-assistant/webawesome/dist/components/textarea/textarea";
import type WaTextarea from "@home-assistant/webawesome/dist/components/textarea/textarea";
import { HasSlotController } from "@home-assistant/webawesome/dist/internal/slot";
import type { PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined";
import { WaInputMixin, waInputStyles } from "./input/wa-input-mixin";
import { stopPropagation } from "../common/dom/stop_propagation";
import { WaInputMixin, waInputStyles } from "./input/wa-input-mixin";
/**
* Home Assistant textarea component
@@ -84,6 +85,20 @@ export class HaTextArea extends WaInputMixin(LitElement) {
this.removeEventListener("keydown", stopPropagation);
}
protected override async firstUpdated(
changedProperties: PropertyValues<this>
): Promise<void> {
super.firstUpdated(changedProperties);
if (this.autofocus) {
await this._textarea?.updateComplete;
this._textarea?.focus();
}
}
public override focus(options?: FocusOptions): void {
this._textarea?.focus(options);
}
protected render() {
const hasLabelSlot = this.label
? false
@@ -17,7 +17,7 @@ import { until } from "lit/directives/until";
import { fireEvent } from "../../common/dom/fire_event";
import { slugify } from "../../common/string/slugify";
import { debounce } from "../../common/util/debounce";
import { isUnavailableState } from "../../data/entity/entity";
import { UNAVAILABLE } from "../../data/entity/entity";
import type {
MediaPickedEvent,
MediaPlayerBrowseAction,
@@ -290,7 +290,7 @@ export class HaMediaPlayerBrowse extends LitElement {
} else if (
err.code === "entity_not_found" &&
this.entityId &&
isUnavailableState(this.hass.states[this.entityId]?.state)
this.hass.states[this.entityId]?.state === UNAVAILABLE
) {
this._setError({
message: this.hass.localize(
@@ -454,7 +454,7 @@ export class HaTargetPickerItemRow extends LitElement {
}
try {
const entries = await extractFromTarget(
this.hass,
this.hass.callWS,
{
[`${this.type}_id`]: [this.itemId],
},
+1 -1
View File
@@ -62,7 +62,7 @@ export const AREA_CONTROLS_BUTTONS: Record<
};
export const getAreaControlEntities = (
controls: AreaControlDomain[],
controls: readonly AreaControlDomain[],
areaId: string,
excludeEntities: string[] | undefined,
hass: HomeAssistant
+4
View File
@@ -95,6 +95,7 @@ export interface TriggerList {
export interface BaseTrigger {
alias?: string;
comment?: string;
/** @deprecated Use `trigger` instead */
platform?: string;
trigger: string;
@@ -240,6 +241,7 @@ export type Trigger = LegacyTrigger | TriggerList | PlatformTrigger;
interface BaseCondition {
condition: string;
alias?: string;
comment?: string;
enabled?: boolean;
options?: Record<string, unknown>;
}
@@ -607,6 +609,7 @@ export interface AutomationClipboard {
export interface BaseSidebarConfig {
delete: () => void;
close: (focus?: boolean) => void;
editComment: () => void;
}
export interface TriggerSidebarConfig extends BaseSidebarConfig {
@@ -668,6 +671,7 @@ export interface OptionSidebarConfig extends BaseSidebarConfig {
rename: () => void;
duplicate: () => void;
defaultOption?: boolean;
comment?: string;
}
export interface ScriptFieldSidebarConfig extends BaseSidebarConfig {
+4 -2
View File
@@ -818,7 +818,8 @@ const describeLegacyTrigger = (
if (trigger.trigger === "device" && trigger.device_id) {
const config = trigger as DeviceTrigger;
const localized = localizeDeviceAutomationTrigger(
hass,
hass.localize,
hass.states,
entityRegistry,
config
);
@@ -1336,7 +1337,8 @@ const describeLegacyCondition = (
if (condition.condition === "device" && condition.device_id) {
const config = condition as DeviceCondition;
const localized = localizeDeviceAutomationCondition(
hass,
hass.localize,
hass.states,
entityRegistry,
config
);
+2 -2
View File
@@ -6,7 +6,7 @@ import { getColorByIndex } from "../common/color/colors";
import { computeDomain } from "../common/entity/compute_domain";
import { computeStateName } from "../common/entity/compute_state_name";
import type { HomeAssistant } from "../types";
import { isUnavailableState } from "./entity/entity";
import { UNAVAILABLE } from "./entity/entity";
import type { EntityRegistryEntry } from "./entity/entity_registry";
export interface Calendar {
@@ -120,7 +120,7 @@ export const getCalendars = (
.filter(
(eid) =>
computeDomain(eid) === "calendar" &&
!isUnavailableState(hass.states[eid].state) &&
hass.states[eid].state !== UNAVAILABLE &&
hass.entities[eid]?.hidden !== true
)
.sort()
+66 -48
View File
@@ -1,17 +1,19 @@
import type { HassEntities } from "home-assistant-js-websocket";
import { computeStateName } from "../../common/entity/compute_state_name";
import type { LocalizeFunc } from "../../common/translations/localize";
import type { HaFormSchema } from "../../components/ha-form/types";
import type { HomeAssistant } from "../../types";
import type { CallWS } from "../../types";
import type { BaseTrigger } from "../automation";
import { migrateAutomationTrigger } from "../automation";
import type { EntityRegistryEntry } from "../entity/entity_registry";
import {
computeEntityRegistryName,
entityRegistryByEntityId,
entityRegistryById,
} from "../entity/entity_registry";
export interface DeviceAutomation {
alias?: string;
comment?: string;
device_id: string;
domain: string;
entity_id?: string;
@@ -39,49 +41,47 @@ export interface DeviceCapabilities {
extra_fields: HaFormSchema[];
}
export const fetchDeviceActions = (hass: HomeAssistant, deviceId: string) =>
hass.callWS<DeviceAction[]>({
export const fetchDeviceActions = (callWS: CallWS, deviceId: string) =>
callWS<DeviceAction[]>({
type: "device_automation/action/list",
device_id: deviceId,
});
export const fetchDeviceConditions = (hass: HomeAssistant, deviceId: string) =>
hass.callWS<DeviceCondition[]>({
export const fetchDeviceConditions = (callWS: CallWS, deviceId: string) =>
callWS<DeviceCondition[]>({
type: "device_automation/condition/list",
device_id: deviceId,
});
export const fetchDeviceTriggers = (hass: HomeAssistant, deviceId: string) =>
hass
.callWS<DeviceTrigger[]>({
type: "device_automation/trigger/list",
device_id: deviceId,
})
.then((triggers) => migrateAutomationTrigger(triggers) as DeviceTrigger[]);
export const fetchDeviceTriggers = (callWS: CallWS, deviceId: string) =>
callWS<DeviceTrigger[]>({
type: "device_automation/trigger/list",
device_id: deviceId,
}).then((triggers) => migrateAutomationTrigger(triggers) as DeviceTrigger[]);
export const fetchDeviceActionCapabilities = (
hass: HomeAssistant,
callWS: CallWS,
action: DeviceAction
) =>
hass.callWS<DeviceCapabilities>({
callWS<DeviceCapabilities>({
type: "device_automation/action/capabilities",
action,
});
export const fetchDeviceConditionCapabilities = (
hass: HomeAssistant,
callWS: CallWS,
condition: DeviceCondition
) =>
hass.callWS<DeviceCapabilities>({
callWS<DeviceCapabilities>({
type: "device_automation/condition/capabilities",
condition,
});
export const fetchDeviceTriggerCapabilities = (
hass: HomeAssistant,
callWS: CallWS,
trigger: DeviceTrigger
) =>
hass.callWS<DeviceCapabilities>({
callWS<DeviceCapabilities>({
type: "device_automation/trigger/capabilities",
trigger,
});
@@ -184,19 +184,16 @@ const compareEntityIdWithEntityRegId = (
};
const getEntityName = (
hass: HomeAssistant,
localize: LocalizeFunc,
states: HassEntities,
entityRegistry: EntityRegistryEntry[],
entityId: string | undefined
): string => {
if (!entityId) {
return (
"<" +
hass.localize("ui.panel.config.automation.editor.unknown_entity") +
">"
);
return `<${localize("ui.panel.config.automation.editor.unknown_entity")}>`;
}
if (entityId.includes(".")) {
const state = hass.states[entityId];
const state = states[entityId];
if (state) {
return computeStateName(state);
}
@@ -204,26 +201,35 @@ const getEntityName = (
}
const entityReg = entityRegistryById(entityRegistry)[entityId];
if (entityReg) {
return computeEntityRegistryName(hass, entityReg) || entityId;
if (entityReg.name) {
return entityReg.name;
}
const state = states[entityReg.entity_id];
if (state) {
return computeStateName(state);
}
return entityReg.original_name ?? entityId;
}
return (
"<" +
hass.localize("ui.panel.config.automation.editor.unknown_entity") +
">"
);
return `<${localize("ui.panel.config.automation.editor.unknown_entity")}>`;
};
export const localizeDeviceAutomationAction = (
hass: HomeAssistant,
localize: LocalizeFunc,
states: HassEntities,
entityRegistry: EntityRegistryEntry[],
action: DeviceAction
): string =>
hass.localize(
localize(
`component.${action.domain}.device_automation.action_type.${action.type}`,
{
entity_name: getEntityName(hass, entityRegistry, action.entity_id),
entity_name: getEntityName(
localize,
states,
entityRegistry,
action.entity_id
),
subtype: action.subtype
? hass.localize(
? localize(
`component.${action.domain}.device_automation.action_subtype.${action.subtype}`
) || action.subtype
: "",
@@ -231,16 +237,22 @@ export const localizeDeviceAutomationAction = (
) || (action.subtype ? `"${action.subtype}" ${action.type}` : action.type!);
export const localizeDeviceAutomationCondition = (
hass: HomeAssistant,
localize: LocalizeFunc,
states: HassEntities,
entityRegistry: EntityRegistryEntry[],
condition: DeviceCondition
): string =>
hass.localize(
localize(
`component.${condition.domain}.device_automation.condition_type.${condition.type}`,
{
entity_name: getEntityName(hass, entityRegistry, condition.entity_id),
entity_name: getEntityName(
localize,
states,
entityRegistry,
condition.entity_id
),
subtype: condition.subtype
? hass.localize(
? localize(
`component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}`
) || condition.subtype
: "",
@@ -251,16 +263,22 @@ export const localizeDeviceAutomationCondition = (
: condition.type!);
export const localizeDeviceAutomationTrigger = (
hass: HomeAssistant,
localize: LocalizeFunc,
states: HassEntities,
entityRegistry: EntityRegistryEntry[],
trigger: DeviceTrigger
): string =>
hass.localize(
localize(
`component.${trigger.domain}.device_automation.trigger_type.${trigger.type}`,
{
entity_name: getEntityName(hass, entityRegistry, trigger.entity_id),
entity_name: getEntityName(
localize,
states,
entityRegistry,
trigger.entity_id
),
subtype: trigger.subtype
? hass.localize(
? localize(
`component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}`
) || trigger.subtype
: "",
@@ -269,18 +287,18 @@ export const localizeDeviceAutomationTrigger = (
(trigger.subtype ? `"${trigger.subtype}" ${trigger.type}` : trigger.type!);
export const localizeExtraFieldsComputeLabelCallback =
(hass: HomeAssistant, deviceAutomation: DeviceAutomation) =>
(localize: LocalizeFunc, deviceAutomation: DeviceAutomation) =>
// Returns a callback for ha-form to calculate labels per schema object
(schema): string =>
hass.localize(
localize(
`component.${deviceAutomation.domain}.device_automation.extra_fields.${schema.name}`
) || schema.name;
export const localizeExtraFieldsComputeHelperCallback =
(hass: HomeAssistant, deviceAutomation: DeviceAutomation) =>
(localize: LocalizeFunc, deviceAutomation: DeviceAutomation) =>
// Returns a callback for ha-form to calculate helper texts per schema object
(schema): string | undefined =>
hass.localize(
localize(
`component.${deviceAutomation.domain}.device_automation.extra_fields_descriptions.${schema.name}`
);
+3
View File
@@ -148,6 +148,7 @@ export interface GridSourceTypeEnergyPreference {
power_config?: PowerConfig;
cost_adjustment_day: number;
name?: string;
}
export interface SolarSourceTypeEnergyPreference {
@@ -156,6 +157,7 @@ export interface SolarSourceTypeEnergyPreference {
stat_energy_from: string;
stat_rate?: string;
config_entry_solar_forecast: string[] | null;
name?: string;
}
export interface BatterySourceTypeEnergyPreference {
@@ -165,6 +167,7 @@ export interface BatterySourceTypeEnergyPreference {
stat_rate?: string; // always available if power_config is set
power_config?: PowerConfig;
stat_soc?: string;
name?: string;
}
export interface GasSourceTypeEnergyPreference {
type: "gas";
-2
View File
@@ -6,10 +6,8 @@ export const UNKNOWN = "unknown";
export const ON = "on";
export const OFF = "off";
export const UNAVAILABLE_STATES = [UNAVAILABLE, UNKNOWN] as const;
export const OFF_STATES = [UNAVAILABLE, UNKNOWN, OFF] as const;
export const isUnavailableState = arrayLiteralIncludes(UNAVAILABLE_STATES);
export const isOffState = arrayLiteralIncludes(OFF_STATES);
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
+97 -199
View File
@@ -1,11 +1,15 @@
import { atLeastVersion } from "../../common/config/version";
import type { HaFormSchema } from "../../components/ha-form/types";
import type { HomeAssistant, TranslationDict } from "../../types";
import type {
CallWS,
HomeAssistant,
HomeAssistantApi,
TranslationDict,
} from "../../types";
import { supervisorApiCall } from "../supervisor/common";
import type { StoreAddonDetails } from "../supervisor/store";
import type { Supervisor, SupervisorArch } from "../supervisor/supervisor";
import type { HassioResponse } from "./common";
import { extractApiErrorMessage, hassioApiResultExtractor } from "./common";
import { extractApiErrorMessage } from "./common";
export type AddonCapability = Exclude<
keyof TranslationDict["ui"]["panel"]["config"]["apps"]["dashboard"]["capability"],
@@ -143,57 +147,38 @@ export interface HassioAddonSetOptionParams {
}
export const reloadHassioAddons = async (hass: HomeAssistant) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: "/addons/reload",
method: "post",
});
return;
}
await hass.callApi<HassioResponse<void>>("POST", `hassio/addons/reload`);
await hass.callWS({
type: "supervisor/api",
endpoint: "/addons/reload",
method: "post",
});
};
export const fetchHassioAddonsInfo = async (
hass: HomeAssistant
): Promise<HassioAddonsInfo> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: "/addons",
method: "get",
});
}
return hassioApiResultExtractor(
await hass.callApi<HassioResponse<HassioAddonsInfo>>("GET", `hassio/addons`)
);
return hass.callWS({
type: "supervisor/api",
endpoint: "/addons",
method: "get",
});
};
export const fetchHassioAddonInfo = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string
): Promise<HassioAddonDetails> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/info`,
method: "get",
});
}
return hassioApiResultExtractor(
await hass.callApi<HassioResponse<HassioAddonDetails>>(
"GET",
`hassio/addons/${slug}/info`
)
);
return callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/info`,
method: "get",
});
};
export const fetchHassioAddonChangelog = async (
hass: HomeAssistant,
api: HomeAssistantApi,
slug: string
) => hass.callApi<string>("GET", `hassio/addons/${slug}/changelog`);
) => api.callApi<string>("GET", `hassio/addons/${slug}/changelog`);
export const fetchHassioAddonLogs = async (hass: HomeAssistant, slug: string) =>
hass.callApi<string>("GET", `hassio/addons/${slug}/logs`);
@@ -204,119 +189,77 @@ export const fetchHassioAddonDocumentation = async (
) => hass.callApi<string>("GET", `hassio/addons/${slug}/documentation`);
export const setHassioAddonOption = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string,
data: HassioAddonSetOptionParams
) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
const response = await hass.callWS<HassioResponse<any>>({
type: "supervisor/api",
endpoint: `/addons/${slug}/options`,
method: "post",
data,
});
const response = await callWS<HassioResponse<any>>({
type: "supervisor/api",
endpoint: `/addons/${slug}/options`,
method: "post",
data,
});
if (response.result === "error") {
throw Error(extractApiErrorMessage(response));
}
return response;
if (response.result === "error") {
throw Error(extractApiErrorMessage(response));
}
return hass.callApi<HassioResponse<any>>(
"POST",
`hassio/addons/${slug}/options`,
data
);
return response;
};
export const validateHassioAddonOption = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string,
data?: any
): Promise<{ message: string; valid: boolean }> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/options/validate`,
method: "post",
data,
});
}
return (
await hass.callApi<HassioResponse<{ message: string; valid: boolean }>>(
"POST",
`hassio/addons/${slug}/options/validate`
)
).data;
return callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/options/validate`,
method: "post",
data,
});
};
export const startHassioAddon = async (hass: HomeAssistant, slug: string) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/start`,
method: "post",
timeout: null,
});
}
return hass.callApi<string>("POST", `hassio/addons/${slug}/start`);
export const startHassioAddon = async (callWS: CallWS, slug: string) => {
return callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/start`,
method: "post",
timeout: null,
});
};
export const stopHassioAddon = async (hass: HomeAssistant, slug: string) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/stop`,
method: "post",
timeout: null,
});
}
return hass.callApi<string>("POST", `hassio/addons/${slug}/stop`);
export const stopHassioAddon = async (callWS: CallWS, slug: string) => {
return callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/stop`,
method: "post",
timeout: null,
});
};
export const setHassioAddonSecurity = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string,
data: HassioAddonSetSecurityParams
) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/security`,
method: "post",
data,
});
return;
}
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/security`,
data
);
await callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/security`,
method: "post",
data,
});
};
export const installHassioAddon = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/install`,
method: "post",
timeout: null,
});
return;
}
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/install`
);
await callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/install`,
method: "post",
timeout: null,
});
};
export const updateHassioAddon = async (
@@ -324,74 +267,37 @@ export const updateHassioAddon = async (
slug: string,
backup: boolean
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2025, 2, 0)) {
await hass.callWS({
type: "hassio/update/addon",
addon: slug,
backup: backup,
});
return;
}
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/store/addons/${slug}/update`,
method: "post",
timeout: null,
data: { backup },
});
return;
}
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/update`,
{ backup }
);
await hass.callWS({
type: "hassio/update/addon",
addon: slug,
backup: backup,
});
};
export const restartHassioAddon = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/restart`,
method: "post",
timeout: null,
});
return;
}
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/restart`
);
await callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/restart`,
method: "post",
timeout: null,
});
};
export const uninstallHassioAddon = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string,
removeData: boolean
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/uninstall`,
method: "post",
timeout: null,
data: { remove_config: removeData },
});
return;
}
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/uninstall`,
{ remove_config: removeData }
);
await callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/uninstall`,
method: "post",
timeout: null,
data: { remove_config: removeData },
});
};
export const fetchAddonInfo = (
@@ -407,21 +313,13 @@ export const fetchAddonInfo = (
);
export const rebuildLocalAddon = async (
hass: HomeAssistant,
callWS: CallWS,
slug: string
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS<undefined>({
type: "supervisor/api",
endpoint: `/addons/${slug}/rebuild`,
method: "post",
timeout: null,
});
}
return (
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}rebuild`
)
).data;
return callWS<undefined>({
type: "supervisor/api",
endpoint: `/addons/${slug}/rebuild`,
method: "post",
timeout: null,
});
};
+7 -17
View File
@@ -1,5 +1,4 @@
import { atLeastVersion } from "../../common/config/version";
import type { HomeAssistant } from "../../types";
import type { CallWS } from "../../types";
export interface HassioResponse<T> {
data: T;
@@ -46,21 +45,12 @@ export const ignoreSupervisorError = (error): boolean => {
};
export const fetchHassioStats = async (
hass: HomeAssistant,
callWS: CallWS,
container: string
): Promise<HassioStats> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS({
type: "supervisor/api",
endpoint: `/${container}/stats`,
method: "get",
});
}
return hassioApiResultExtractor(
await hass.callApi<HassioResponse<HassioStats>>(
"GET",
`hassio/${container}/stats`
)
);
return callWS({
type: "supervisor/api",
endpoint: `/${container}/stats`,
method: "get",
});
};
+6 -1
View File
@@ -7,13 +7,18 @@ export interface GenericPreview {
state: string;
attributes: Record<string, any>;
error?: string;
domain?: string;
}
export const subscribePreviewGeneric = (
hass: HomeAssistant,
domain: string,
flow_id: string,
flow_type: "config_flow" | "options_flow" | "config_subentries_flow",
flow_type:
| "config_flow"
| "options_flow"
| "config_subentries_flow"
| "repair_flow",
user_input: Record<string, any>,
callback: (preview: GenericPreview) => void
): Promise<UnsubscribeFunc> =>
+3
View File
@@ -36,6 +36,7 @@ export const isMaxMode = arrayLiteralIncludes(MODES_MAX);
export const baseActionStruct = object({
alias: optional(string()),
comment: optional(string()),
continue_on_error: optional(boolean()),
enabled: optional(boolean()),
});
@@ -105,6 +106,7 @@ export interface Field {
interface BaseAction {
alias?: string;
comment?: string;
continue_on_error?: boolean;
enabled?: boolean;
}
@@ -195,6 +197,7 @@ export interface ForEachRepeat extends BaseRepeat {
export interface Option {
alias?: string;
comment?: string;
conditions: string | Condition[];
sequence: Action | Action[];
}
+2 -1
View File
@@ -335,7 +335,8 @@ const tryDescribeAction = <T extends ActionType>(
);
}
const localized = localizeDeviceAutomationAction(
hass,
hass.localize,
hass.states,
entityRegistry,
config
);
+5 -5
View File
@@ -641,7 +641,7 @@ export const expandLabelTarget = (
if (
device.labels.includes(labelId) &&
deviceMeetsTargetSelector(
hass,
hass.states,
Object.values(entities),
device,
targetSelector,
@@ -708,7 +708,7 @@ export const expandAreaTarget = (
if (
device.area_id === areaId &&
deviceMeetsTargetSelector(
hass,
hass.states,
Object.values(entities),
device,
targetSelector,
@@ -768,7 +768,7 @@ export const areaMeetsTargetSelector = (
if (
device.area_id === areaId &&
deviceMeetsTargetSelector(
hass,
hass.states,
Object.values(entities),
device,
targetSelector,
@@ -798,7 +798,7 @@ export const areaMeetsTargetSelector = (
};
export const deviceMeetsTargetSelector = (
hass: HomeAssistant,
states: HomeAssistant["states"],
entityRegistry: EntityRegistryDisplayEntry[] | EntityRegistryEntry[],
device: DeviceRegistryEntry,
targetSelector: TargetSelector,
@@ -822,7 +822,7 @@ export const deviceMeetsTargetSelector = (
(reg) => reg.device_id === device.id
);
return entities.some((entity) => {
const entityState = hass.states[entity.entity_id];
const entityState = states[entity.entity_id];
return entityMeetsTargetSelector(
entityState,
targetSelector,
+3 -3
View File
@@ -3,7 +3,7 @@ import { ensureArray } from "../common/array/ensure-array";
import { computeDomain } from "../common/entity/compute_domain";
import type { HaDevicePickerDeviceFilterFunc } from "../components/device/ha-device-picker";
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
import type { HomeAssistant } from "../types";
import type { CallWS, HomeAssistant } from "../types";
import type { AreaRegistryEntry } from "./area/area_registry";
import type { FloorComboBoxItem } from "./area_floor_picker";
import type { DevicePickerItem } from "./device/device_picker";
@@ -47,12 +47,12 @@ export interface ExtractFromTargetResultReferenced {
}
export const extractFromTarget = async (
hass: HomeAssistant,
callWS: CallWS,
target: HassServiceTarget,
expandGroup = false,
primaryEntitiesOnly = true
) =>
hass.callWS<ExtractFromTargetResult>({
callWS<ExtractFromTargetResult>({
type: "extract_from_target",
target,
expand_group: expandGroup,
+2 -2
View File
@@ -2,7 +2,7 @@ import { computeDomain } from "../common/entity/compute_domain";
import { computeStateName } from "../common/entity/compute_state_name";
import { stringCompare } from "../common/string/compare";
import type { HomeAssistant, ServiceCallResponse } from "../types";
import { isUnavailableState } from "./entity/entity";
import { UNAVAILABLE } from "./entity/entity";
export interface TodoList {
entity_id: string;
@@ -49,7 +49,7 @@ export const getTodoLists = (
.filter(
(entityId) =>
computeDomain(entityId) === "todo" &&
!isUnavailableState(hass.states[entityId].state) &&
hass.states[entityId].state !== UNAVAILABLE &&
(includeHidden || hass.entities[entityId]?.hidden !== true)
)
.map((entityId) => ({
+9 -2
View File
@@ -29,6 +29,13 @@ import type {
import type { SVGTemplateResult, TemplateResult } from "lit";
import { css, html, svg } from "lit";
import { styleMap } from "lit/directives/style-map";
import {
UNIT_HPA,
UNIT_IN,
UNIT_INHG,
UNIT_KM,
UNIT_MM,
} from "../common/const";
import { supportsFeature } from "../common/entity/supports-feature";
import { round } from "../common/number/round";
import "../components/ha-svg-icon";
@@ -245,12 +252,12 @@ export const getWeatherUnit = (
case "precipitation":
return (
stateObj.attributes.precipitation_unit ||
(lengthUnit === "km" ? "mm" : "in")
(lengthUnit === UNIT_KM ? UNIT_MM : UNIT_IN)
);
case "pressure":
return (
stateObj.attributes.pressure_unit ||
(lengthUnit === "km" ? "hPa" : "inHg")
(lengthUnit === UNIT_KM ? UNIT_HPA : UNIT_INHG)
);
case "apparent_temperature":
case "dew_point":
+1
View File
@@ -24,6 +24,7 @@ interface TemplatePreviewState {
state: string;
attributes: Record<string, any>;
listeners: TemplateListeners;
domain?: string;
}
interface TemplatePreviewError {
+258
View File
@@ -0,0 +1,258 @@
import type { HomeAssistant } from "../types";
export type ZwaveCredentialType =
| "pin_code"
| "password"
| "rfid_code"
| "ble"
| "nfc"
| "uwb"
| "eye_biometric"
| "face_biometric"
| "finger_biometric"
| "hand_biometric"
| "unspecified_biometric"
| "desfire";
export const ENTERABLE_ZWAVE_CREDENTIAL_TYPES: readonly ZwaveCredentialType[] =
["pin_code", "password"];
// UI surfaces only general + disposable to stay aligned with Matter lock UX.
// Other types (programming, duress, non_access, remote_only, expiring) are
// defined in translations for display in existing-user rows, but are not
// selectable here.
export const SIMPLE_USER_TYPES: readonly string[] = ["general", "disposable"];
// Fallback bounds when a lock advertises an enterable type without
// per-type min/max — values mirror Z-Wave spec defaults.
export const DEFAULT_CREDENTIAL_MIN_LENGTH = 4;
export const DEFAULT_CREDENTIAL_MAX_LENGTH = 10;
export type CredentialErrorCode =
| "required"
| "length"
| "pin_digits_only"
| "";
export const enterableCredentialTypes = (
capabilities: ZwaveCredentialCapabilities
): ZwaveCredentialType[] => {
if (!capabilities.supported_credential_types) {
return [];
}
return ENTERABLE_ZWAVE_CREDENTIAL_TYPES.filter(
(type) => type in capabilities.supported_credential_types
);
};
export const compatibleUserTypes = (
capabilities: ZwaveCredentialCapabilities
): string[] => {
const supported = capabilities.supported_user_types ?? [];
return SIMPLE_USER_TYPES.filter((t) => supported.includes(t));
};
export const canAddZwaveUser = (
capabilities: ZwaveCredentialCapabilities
): boolean =>
enterableCredentialTypes(capabilities).length > 0 &&
compatibleUserTypes(capabilities).length > 0;
export const getCredentialError = (
data: string,
type: ZwaveCredentialType | "",
capability: ZwaveCredentialTypeCapability | undefined
): CredentialErrorCode => {
if (!data) {
return "required";
}
const minLength = capability?.min_length ?? DEFAULT_CREDENTIAL_MIN_LENGTH;
const maxLength = capability?.max_length ?? DEFAULT_CREDENTIAL_MAX_LENGTH;
if (data.length < minLength || data.length > maxLength) {
return "length";
}
if (type === "pin_code" && !/^\d+$/.test(data)) {
return "pin_digits_only";
}
return "";
};
export interface ZwaveCredentialTypeCapability {
num_slots: number;
min_length: number;
max_length: number;
supports_learn: boolean;
}
export interface ZwaveCredentialCapabilities {
supports_user_management: boolean;
max_users: number;
supported_user_types: string[];
max_user_name_length: number;
supported_credential_rules: string[];
supported_credential_types: Partial<
Record<ZwaveCredentialType, ZwaveCredentialTypeCapability>
>;
}
export interface ZwaveCredential {
type: ZwaveCredentialType;
slot: number;
}
export interface ZwaveUser {
user_id: number;
user_name: string | null;
active: boolean;
user_type: string;
credential_rule: string | null;
credentials: ZwaveCredential[];
}
export interface ZwaveUsersResponse {
max_users: number;
users: ZwaveUser[];
}
export interface SetZwaveUserParams {
user_id?: number;
user_name?: string | null;
user_type?: string;
credential_rule?: string;
active?: boolean;
}
export interface SetZwaveUserResult {
user_id: number;
}
export interface SetZwaveCredentialParams {
user_id: number;
credential_type: ZwaveCredentialType;
credential_data: string;
credential_slot?: number;
}
export interface SetZwaveCredentialResult {
credential_slot: number;
user_id: number;
}
export interface DeleteZwaveCredentialParams {
user_id: number;
credential_type: ZwaveCredentialType;
credential_slot: number;
}
// The Z-Wave services key their response by entity_id to support multi-target
// calls. The frontend only ever calls them with a single lock entity, so we
// expect exactly that key. Anything else (no response, mismatched key) is a
// backend contract violation — surface it as a localized error rather than
// letting `cannot read property of undefined` bubble up.
const unwrapEntityResponse = <T>(
hass: HomeAssistant,
response: Record<string, T> | undefined,
entity_id: string
): T => {
const value = response?.[entity_id];
if (value === undefined) {
throw new Error(
hass.localize(
"ui.panel.config.zwave_js.credentials.errors.empty_response"
)
);
}
return value;
};
const callCredentialService = async <T>(
hass: HomeAssistant,
service: string,
entity_id: string,
params: Record<string, unknown> = {}
): Promise<T> => {
// notifyOnError=false — callers surface errors in-dialog instead.
const result = await hass.callService<Record<string, T>>(
"zwave_js",
service,
params,
{ entity_id },
false,
true
);
return unwrapEntityResponse(hass, result.response, entity_id);
};
export const getZwaveCredentialCapabilities = (
hass: HomeAssistant,
entity_id: string
): Promise<ZwaveCredentialCapabilities> =>
callCredentialService<ZwaveCredentialCapabilities>(
hass,
"get_credential_capabilities",
entity_id
);
export const getZwaveUsers = (
hass: HomeAssistant,
entity_id: string
): Promise<ZwaveUsersResponse> =>
callCredentialService<ZwaveUsersResponse>(hass, "get_users", entity_id);
export const setZwaveUser = async (
hass: HomeAssistant,
entity_id: string,
params: SetZwaveUserParams
): Promise<SetZwaveUserResult> => {
// notifyOnError=false — caller surfaces errors in-dialog instead.
const result = await hass.callService<Record<string, SetZwaveUserResult>>(
"zwave_js",
"set_user",
params,
{ entity_id },
false,
true
);
return unwrapEntityResponse(hass, result.response, entity_id);
};
export const deleteZwaveUser = (
hass: HomeAssistant,
entity_id: string,
user_id: number
) =>
hass.callService(
"zwave_js",
"delete_user",
{ user_id },
{ entity_id },
false
);
export const deleteZwaveAllUsers = (hass: HomeAssistant, entity_id: string) =>
hass.callService("zwave_js", "delete_all_users", {}, { entity_id }, false);
export const setZwaveCredential = async (
hass: HomeAssistant,
entity_id: string,
params: SetZwaveCredentialParams
): Promise<SetZwaveCredentialResult> => {
// notifyOnError=false — caller surfaces errors in-dialog instead.
const result = await hass.callService<
Record<string, SetZwaveCredentialResult>
>("zwave_js", "set_credential", params, { entity_id }, false, true);
return unwrapEntityResponse(hass, result.response, entity_id);
};
export const deleteZwaveCredential = (
hass: HomeAssistant,
entity_id: string,
params: DeleteZwaveCredentialParams
) =>
hass.callService(
"zwave_js",
"delete_credential",
params,
{ entity_id },
false
);
@@ -18,7 +18,7 @@ import "../../../components/ha-slider";
import "../../../components/ha-time-input";
import "../../../components/input/ha-input";
import { isTiltOnly } from "../../../data/cover";
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { ImageEntity } from "../../../data/image";
import { computeImageUrl } from "../../../data/image";
import "../../../panels/lovelace/components/hui-timestamp-display";
@@ -108,14 +108,13 @@ class EntityPreviewRow extends LitElement {
private _renderEntityState(stateObj: HassEntity): TemplateResult | string {
const domain = stateObj.entity_id.split(".", 1)[0];
const disabled = stateObj.state === UNAVAILABLE;
const noValue =
stateObj.state === UNAVAILABLE || stateObj.state === UNKNOWN;
if (domain === "button") {
return html`
<ha-button
appearance="plain"
size="small"
.disabled=${isUnavailableState(stateObj.state)}
>
<ha-button appearance="plain" size="small" .disabled=${disabled}>
${this.hass.localize("ui.card.button.press")}
</ha-button>
`;
@@ -151,19 +150,15 @@ class EntityPreviewRow extends LitElement {
return html`
<ha-date-input
.locale=${this.hass.locale}
.disabled=${isUnavailableState(stateObj.state)}
.value=${isUnavailableState(stateObj.state)
? undefined
: stateObj.state}
.disabled=${disabled}
.value=${noValue ? undefined : stateObj.state}
>
</ha-date-input>
`;
}
if (domain === "datetime") {
const dateObj = isUnavailableState(stateObj.state)
? undefined
: new Date(stateObj.state);
const dateObj = noValue ? undefined : new Date(stateObj.state);
const time = dateObj ? format(dateObj, "HH:mm:ss") : undefined;
const date = dateObj ? format(dateObj, "yyyy-MM-dd") : undefined;
return html`
@@ -172,12 +167,12 @@ class EntityPreviewRow extends LitElement {
.label=${computeStateName(stateObj)}
.locale=${this.hass.locale}
.value=${date}
.disabled=${isUnavailableState(stateObj.state)}
.disabled=${disabled}
>
</ha-date-input>
<ha-time-input
.value=${time}
.disabled=${isUnavailableState(stateObj.state)}
.disabled=${disabled}
.locale=${this.hass.locale}
></ha-time-input>
</div>
@@ -187,7 +182,7 @@ class EntityPreviewRow extends LitElement {
if (domain === "event") {
return html`
<div class="when">
${isUnavailableState(stateObj.state)
${noValue
? this.hass.formatEntityState(stateObj)
: html`<hui-timestamp-display
.hass=${this.hass}
@@ -196,7 +191,7 @@ class EntityPreviewRow extends LitElement {
></hui-timestamp-display>`}
</div>
<div class="what">
${isUnavailableState(stateObj.state)
${noValue
? nothing
: this.hass.formatEntityAttributeValue(stateObj, "event_type")}
</div>
@@ -206,9 +201,7 @@ class EntityPreviewRow extends LitElement {
const toggleDomains = ["fan", "light", "remote", "siren", "switch"];
if (toggleDomains.includes(domain)) {
const showToggle =
stateObj.state === "on" ||
stateObj.state === "off" ||
isUnavailableState(stateObj.state);
stateObj.state === "on" || stateObj.state === "off" || noValue;
return html`
${showToggle
? html`
@@ -241,7 +234,7 @@ class EntityPreviewRow extends LitElement {
if (domain === "lock") {
return html`
<ha-button
.disabled=${isUnavailableState(stateObj.state)}
.disabled=${disabled}
class="text-content"
appearance="plain"
size="small"
@@ -266,7 +259,7 @@ class EntityPreviewRow extends LitElement {
<div class="numberflex">
<ha-slider
labeled
.disabled=${stateObj.state === UNAVAILABLE}
.disabled=${disabled}
.step=${Number(stateObj.attributes.step)}
.min=${Number(stateObj.attributes.min)}
.max=${Number(stateObj.attributes.max)}
@@ -280,7 +273,7 @@ class EntityPreviewRow extends LitElement {
: html`<div class="numberflex numberstate">
<ha-input
auto-validate
.disabled=${stateObj.state === UNAVAILABLE}
.disabled=${disabled}
pattern="[0-9]+([\\.][0-9]+)?"
.step=${Number(stateObj.attributes.step)}
.min=${Number(stateObj.attributes.min)}
@@ -303,7 +296,7 @@ class EntityPreviewRow extends LitElement {
<ha-select
.label=${computeStateName(stateObj)}
.value=${stateObj.state}
.disabled=${stateObj.state === UNAVAILABLE}
.disabled=${disabled}
.options=${stateObj.attributes.options?.map((option) => ({
value: option,
label: this.hass!.formatEntityState(stateObj, option),
@@ -317,7 +310,7 @@ class EntityPreviewRow extends LitElement {
const showSensor =
SENSOR_TIMESTAMP_DEVICE_CLASSES.includes(
stateObj.attributes.device_class
) && !isUnavailableState(stateObj.state);
) && !noValue;
return html`
${showSensor
? html`
@@ -339,7 +332,7 @@ class EntityPreviewRow extends LitElement {
return html`
<ha-input
.label=${computeStateName(stateObj)}
.disabled=${isUnavailableState(stateObj.state)}
.disabled=${disabled}
.value=${stateObj.state}
.minlength=${stateObj.attributes.min}
.maxlength=${stateObj.attributes.max}
@@ -354,11 +347,9 @@ class EntityPreviewRow extends LitElement {
if (domain === "time") {
return html`
<ha-time-input
.value=${isUnavailableState(stateObj.state)
? undefined
: stateObj.state}
.value=${noValue ? undefined : stateObj.state}
.locale=${this.hass.locale}
.disabled=${isUnavailableState(stateObj.state)}
.disabled=${disabled}
></ha-time-input>
`;
}
@@ -366,7 +357,7 @@ class EntityPreviewRow extends LitElement {
if (domain === "weather") {
return html`
<div>
${isUnavailableState(stateObj.state) ||
${noValue ||
stateObj.attributes.temperature === undefined ||
stateObj.attributes.temperature === null
? this.hass.formatEntityState(stateObj)
@@ -65,7 +65,7 @@ export class FlowPreviewGeneric extends LitElement {
}
const now = new Date().toISOString();
this._preview = {
entity_id: `${this.stepId}.___flow_preview___`,
entity_id: `${preview.domain ?? this.stepId}.___flow_preview___`,
last_changed: now,
last_updated: now,
context: { id: "", parent_id: null, user_id: null },
@@ -85,7 +85,8 @@ export class FlowPreviewGeneric extends LitElement {
if (
this.flowType !== "config_flow" &&
this.flowType !== "options_flow" &&
this.flowType !== "config_subentries_flow"
this.flowType !== "config_subentries_flow" &&
this.flowType !== "repair_flow"
) {
return;
}
@@ -130,7 +130,7 @@ class FlowPreviewTemplate extends LitElement {
this._listeners = preview.listeners;
const now = new Date().toISOString();
this._preview = {
entity_id: `${this.stepId}.___flow_preview___`,
entity_id: `${preview.domain ?? this.stepId}.___flow_preview___`,
last_changed: now,
last_updated: now,
context: { id: "", parent_id: null, user_id: null },
+17 -3
View File
@@ -9,6 +9,8 @@ import "../../components/ha-dialog";
import "../../components/ha-dialog-footer";
import "../../components/ha-dialog-header";
import "../../components/ha-svg-icon";
import "../../components/ha-textarea";
import type { HaTextArea } from "../../components/ha-textarea";
import "../../components/input/ha-input";
import type { HaInput } from "../../components/input/ha-input";
import type { HomeAssistant } from "../../types";
@@ -28,7 +30,7 @@ class DialogBox extends LitElement {
@state() private _validInput = true;
@query("ha-input") private _textField?: HaInput;
@query("ha-input, ha-textarea") private _textField?: HaInput | HaTextArea;
private _closePromise?: Promise<void>;
@@ -109,7 +111,7 @@ class DialogBox extends LitElement {
</ha-dialog-header>
<div id="dialog-box-description">
${this._params.text ? html` <p>${this._params.text}</p> ` : ""}
${this._params.prompt
${this._params.prompt && !this._params.multiline
? html`
<ha-input
autofocus
@@ -131,7 +133,19 @@ class DialogBox extends LitElement {
: nothing}
</ha-input>
`
: nothing}
: this._params.prompt && this._params.multiline
? html`
<ha-textarea
resize="auto"
autofocus
.value=${this._params.defaultValue}
.placeholder=${this._params.placeholder}
.label=${this._params.inputLabel}
.disabled=${this._loading}
@input=${this._validateInput}
></ha-textarea>
`
: nothing}
</div>
<ha-dialog-footer slot="footer">
${confirmPrompt
+1
View File
@@ -33,6 +33,7 @@ export interface PromptDialogParams extends BaseDialogBoxParams {
inputMin?: number | string;
inputMax?: number | string;
action?: (value?: string) => Promise<void>;
multiline?: boolean;
}
export interface DialogBoxParams
+160
View File
@@ -0,0 +1,160 @@
import { navigate } from "../../common/navigate";
import type { LocalizeFunc } from "../../common/translations/localize";
import { createSearchParam } from "../../common/url/search-params";
import type { SingleHassServiceTarget } from "../../data/target";
import {
ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM,
ADD_AUTOMATION_ELEMENT_QUERY_PARAM,
ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM,
} from "../../panels/config/automation/show-add-automation-element-dialog";
import type { HomeAssistant, TranslationDict } from "../../types";
/** Add to action keys are the keys of the translation dictionary for the add to actions. */
export type AddToActionKey =
TranslationDict["ui"]["dialogs"]["more_info_control"]["add_to"]["actions"] extends infer Actions
? keyof Actions
: never;
interface BaseEntityAddToAction {
/** Whether the action is enabled and can be selected. */
enabled: boolean;
/** Translated name of the action */
name: string;
/** Optional translated description of the action */
description?: string;
/** MDI icon name (e.g., "mdi:car") */
icon: string;
}
export interface DefaultEntityAddToAction extends BaseEntityAddToAction {
/** Type of action handled in the frontend */
type: "default";
/** Stable key used to resolve the action handler */
key: AddToActionKey;
}
export interface ExternalEntityAddToAction extends BaseEntityAddToAction {
/** Type of action. External is handled by external apps instead of in the frontend */
type: "external";
/** Opaque payload for external action handling */
payload?: string;
}
export type EntityAddToAction =
| DefaultEntityAddToAction
| ExternalEntityAddToAction;
export type EntityAddToActions = EntityAddToAction[];
interface ActionDefinition {
translation_key: AddToActionKey;
icon: string;
}
const ADD_TO_TARGET_PLACEHOLDER = "__HA_ADD_TO_TARGET__";
export const ADD_TO_ACTION_ICONS: Record<AddToActionKey, string> = {
automation_trigger: "mdi:robot-outline",
automation_condition: "mdi:playlist-check",
automation_action: "mdi:play-circle-outline",
script_action: "mdi:script-text-outline",
scene: "mdi:palette",
};
export const DEFAULT_ACTION_DEFS: ActionDefinition[] = [
{
translation_key: "automation_trigger",
icon: ADD_TO_ACTION_ICONS.automation_trigger,
},
{
translation_key: "automation_condition",
icon: ADD_TO_ACTION_ICONS.automation_condition,
},
{
translation_key: "automation_action",
icon: ADD_TO_ACTION_ICONS.automation_action,
},
{
translation_key: "script_action",
icon: ADD_TO_ACTION_ICONS.script_action,
},
];
export const getAddToActionLabel = (
localize: LocalizeFunc,
key: AddToActionKey,
target: string
): string =>
localize(`ui.dialogs.more_info_control.add_to.actions.${key}`, { target });
export const getAddToActionLabelParts = (
localize: LocalizeFunc,
key: AddToActionKey
): [string, string] => {
const label = getAddToActionLabel(localize, key, ADD_TO_TARGET_PLACEHOLDER);
const placeholderIndex = label.indexOf(ADD_TO_TARGET_PLACEHOLDER);
if (placeholderIndex === -1) {
return [label, ""];
}
return [
label.slice(0, placeholderIndex),
label.slice(placeholderIndex + ADD_TO_TARGET_PLACEHOLDER.length),
];
};
export const getDefaultAddToActions = (
states: HomeAssistant["states"],
localize: LocalizeFunc,
formatEntityName: HomeAssistant["formatEntityName"],
entityId: string
): EntityAddToActions =>
DEFAULT_ACTION_DEFS.map(
(def: ActionDefinition): EntityAddToAction => ({
type: "default",
key: def.translation_key,
enabled: true,
name: getAddToActionLabel(
localize,
def.translation_key,
states[entityId] !== undefined
? formatEntityName(states[entityId], undefined)
: entityId
),
icon: def.icon,
})
);
/** Handler for adding a target to an automation/script. */
export function addToActionHandler(
key: AddToActionKey,
target: SingleHassServiceTarget
): Promise<boolean> {
const searchParams: Record<string, string> = {};
if (target.entity_id) {
searchParams[ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM] = target.entity_id;
} else if (target.device_id) {
searchParams[ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM] = target.device_id;
}
const params = (addElement: string) =>
`?${createSearchParam({
[ADD_AUTOMATION_ELEMENT_QUERY_PARAM]: addElement,
...searchParams,
})}`;
switch (key) {
case "automation_trigger":
return navigate(`/config/automation/edit/new${params("trigger")}`);
case "automation_condition":
return navigate(`/config/automation/edit/new${params("condition")}`);
case "automation_action":
return navigate(`/config/automation/edit/new${params("action")}`);
case "script_action":
return navigate(`/config/script/edit/new${params("action")}`);
default:
return Promise.reject(new Error(`Unknown action key ${key}`));
}
}
@@ -3,7 +3,7 @@ import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import "../../../components/ha-absolute-time";
import "../../../components/ha-relative-time";
import { isUnavailableState } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { LightEntity } from "../../../data/light";
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../../../data/sensor";
import "../../../panels/lovelace/components/hui-timestamp-display";
@@ -24,7 +24,8 @@ export class HaMoreInfoStateHeader extends LitElement {
private _localizeState(): TemplateResult | string {
if (
this.stateObj.attributes.device_class === SENSOR_DEVICE_CLASS_TIMESTAMP &&
!isUnavailableState(this.stateObj.state)
this.stateObj.state !== UNAVAILABLE &&
this.stateObj.state !== UNKNOWN
) {
return html`
<hui-timestamp-display
@@ -4,7 +4,7 @@ import { customElement, property } from "lit/decorators";
import "../../../components/ha-button";
import "../../../components/ha-relative-time";
import { triggerAutomationActions } from "../../../data/automation";
import { isUnavailableState } from "../../../data/entity/entity";
import { UNAVAILABLE } from "../../../data/entity/entity";
import type { HomeAssistant } from "../../../types";
@customElement("more-info-automation")
@@ -34,7 +34,7 @@ class MoreInfoAutomation extends LitElement {
appearance="plain"
size="small"
@click=${this._runActions}
.disabled=${isUnavailableState(this.stateObj!.state)}
.disabled=${this.stateObj!.state === UNAVAILABLE}
>
${this.hass.localize("ui.card.automation.trigger")}
</ha-button>
@@ -2,7 +2,7 @@ import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../components/ha-button";
import { isUnavailableState } from "../../../data/entity/entity";
import { UNAVAILABLE } from "../../../data/entity/entity";
import type { HomeAssistant } from "../../../types";
@customElement("more-info-counter")
@@ -16,7 +16,7 @@ class MoreInfoCounter extends LitElement {
return nothing;
}
const disabled = isUnavailableState(this.stateObj.state);
const disabled = this.stateObj.state === UNAVAILABLE;
return html`
<div class="actions">
@@ -4,7 +4,7 @@ import { customElement, property } from "lit/decorators";
import "../../../components/ha-date-input";
import "../../../components/ha-time-input";
import { setDateValue } from "../../../data/date";
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
@customElement("more-info-date")
@@ -21,10 +21,9 @@ class MoreInfoDate extends LitElement {
return html`
<ha-date-input
.locale=${this.hass.locale}
.value=${isUnavailableState(this.stateObj.state)
.value=${this.stateObj.state === UNKNOWN
? undefined
: this.stateObj.state}
.disabled=${this.stateObj.state === UNAVAILABLE}
@value-changed=${this._dateChanged}
>
</ha-date-input>
@@ -5,7 +5,7 @@ import { customElement, property } from "lit/decorators";
import "../../../components/ha-date-input";
import "../../../components/ha-time-input";
import { setDateTimeValue } from "../../../data/datetime";
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
@customElement("more-info-datetime")
@@ -19,23 +19,22 @@ class MoreInfoDatetime extends LitElement {
return nothing;
}
const dateObj = isUnavailableState(this.stateObj.state)
? undefined
: new Date(this.stateObj.state);
const dateObj =
this.stateObj.state === UNKNOWN
? undefined
: new Date(this.stateObj.state);
const time = dateObj ? format(dateObj, "HH:mm:ss") : undefined;
const date = dateObj ? format(dateObj, "yyyy-MM-dd") : undefined;
return html`<ha-date-input
.locale=${this.hass.locale}
.value=${date}
.disabled=${this.stateObj.state === UNAVAILABLE}
@value-changed=${this._dateChanged}
>
</ha-date-input>
<ha-time-input
.value=${time}
.locale=${this.hass.locale}
.disabled=${this.stateObj.state === UNAVAILABLE}
@value-changed=${this._timeChanged}
@click=${this._stopEventPropagation}
></ha-time-input>`;
@@ -200,12 +200,13 @@ class MoreInfoMediaPlayer extends LitElement {
protected _renderSourceControl() {
if (
!this.stateObj ||
!supportsFeature(this.stateObj, MediaPlayerEntityFeature.SELECT_SOURCE) ||
!this.stateObj.attributes.source_list?.length
!supportsFeature(this.stateObj, MediaPlayerEntityFeature.SELECT_SOURCE)
) {
return nothing;
}
const sourceList = this.stateObj.attributes.source_list || [];
return html`<ha-tooltip for="source-button">
${this.hass.localize(`ui.card.media_player.source`)}
</ha-tooltip>
@@ -217,7 +218,7 @@ class MoreInfoMediaPlayer extends LitElement {
.path=${mdiLoginVariant}
>
</ha-icon-button>
${this.stateObj.attributes.source_list!.map(
${sourceList.map(
(source) =>
html`<ha-dropdown-item
.value=${source}
@@ -11,7 +11,7 @@ import "../../../components/ha-control-button-group";
import "../../../components/ha-markdown";
import "../../../components/ha-relative-time";
import "../../../components/ha-service-control";
import { isUnavailableState } from "../../../data/entity/entity";
import { UNAVAILABLE } from "../../../data/entity/entity";
import type { ExtEntityRegistryEntry } from "../../../data/entity/entity_registry";
import type { ScriptEntity } from "../../../data/script";
import {
@@ -141,7 +141,7 @@ class MoreInfoScript extends LitElement {
<ha-control-button
class="run-button"
@click=${this._runScript}
.disabled=${isUnavailableState(stateObj.state) || !this._canRun()}
.disabled=${stateObj.state === UNAVAILABLE || !this._canRun()}
>
<ha-svg-icon .path=${mdiPlay}></ha-svg-icon>
${this.hass!.localize("ui.card.script.run")}
@@ -3,7 +3,7 @@ import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../components/ha-date-input";
import "../../../components/ha-time-input";
import { isUnavailableState, UNAVAILABLE } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import { setTimeValue } from "../../../data/time";
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
@@ -20,11 +20,10 @@ class MoreInfoTime extends LitElement {
return html`
<ha-time-input
.value=${isUnavailableState(this.stateObj.state)
.value=${this.stateObj.state === UNKNOWN
? undefined
: this.stateObj.state}
.locale=${this.hass.locale}
.disabled=${this.stateObj.state === UNAVAILABLE}
@value-changed=${this._timeChanged}
@click=${this._stopEventPropagation}
></ha-time-input>
@@ -15,7 +15,7 @@ import "../../../components/item/ha-row-item";
import "../../../components/progress/ha-progress-bar";
import type { BackupConfig } from "../../../data/backup";
import { fetchBackupConfig } from "../../../data/backup";
import { isUnavailableState } from "../../../data/entity/entity";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { EntitySources } from "../../../data/entity/entity_sources";
import { fetchEntitySourcesWithCache } from "../../../data/entity/entity_sources";
import { getSupervisorUpdateConfig } from "../../../data/supervisor/update";
@@ -176,7 +176,8 @@ class MoreInfoUpdate extends LitElement {
if (
!this.hass ||
!this.stateObj ||
isUnavailableState(this.stateObj.state)
this.stateObj.state === UNAVAILABLE ||
this.stateObj.state === UNKNOWN
) {
return nothing;
}
+167 -55
View File
@@ -5,14 +5,18 @@ import "../../components/ha-icon";
import "../../components/ha-spinner";
import "../../components/item/ha-list-item-button";
import "../../components/list/ha-list-base";
import type {
ExternalEntityAddToAction,
ExternalEntityAddToActions,
} from "../../external_app/external_messaging";
import "../../panels/config/automation/target/ha-automation-target-badge";
import { showToast } from "../../util/toast";
import { fireEvent } from "../../common/dom/fire_event";
import type { HomeAssistant } from "../../types";
import {
type AddToActionKey,
type EntityAddToActions,
addToActionHandler,
getDefaultAddToActions,
getAddToActionLabelParts,
} from "./add-to";
@customElement("ha-more-info-add-to")
export class HaMoreInfoAddTo extends LitElement {
@@ -20,54 +24,149 @@ export class HaMoreInfoAddTo extends LitElement {
@property({ attribute: false }) public entityId!: string;
@state() private _externalActions?: ExternalEntityAddToActions = {
actions: [],
};
@state() private _defaultActions: EntityAddToActions = [];
@state() private _externalActions: EntityAddToActions = [];
@state() private _loading = true;
private async _loadExternalActions() {
private async _loadActions() {
this._defaultActions = getDefaultAddToActions(
this.hass.states,
this.hass.localize,
this.hass.formatEntityName,
this.entityId
);
this._externalActions = [];
if (this.hass.auth.external?.config.hasEntityAddTo) {
this._externalActions =
await this.hass.auth.external?.sendMessage<"entity/add_to/get_actions">(
{
type: "entity/add_to/get_actions",
payload: { entity_id: this.entityId },
}
);
try {
const response =
await this.hass.auth.external?.sendMessage<"entity/add_to/get_actions">(
{
type: "entity/add_to/get_actions",
payload: { entity_id: this.entityId },
}
);
if (response?.actions) {
this._externalActions = response.actions.map((action) => ({
type: "external",
enabled: action.enabled,
name: action.name,
description: action.details,
icon: action.mdi_icon,
payload: action.app_payload,
}));
}
} catch (err: unknown) {
// eslint-disable-next-line no-console
console.warn("Failed to fetch add to actions", err);
}
}
}
private async _actionSelected(ev: CustomEvent) {
const action = (ev.currentTarget as any)
.action as ExternalEntityAddToAction;
private async _actionSelected(ev: Event) {
const item = ev.currentTarget as HTMLElement;
const actions =
item.dataset.actionSource === "external"
? this._externalActions
: this._defaultActions;
const action = actions[Number(item.dataset.actionIndex)];
if (!action) {
return;
}
if (!action.enabled) {
return;
}
try {
await this.hass.auth.external!.fireMessage({
type: "entity/add_to",
payload: {
entity_id: this.entityId,
app_payload: action.app_payload,
},
});
fireEvent(this, "add-to-action-selected");
} catch (err: any) {
showToast(this, {
message: this.hass.localize(
"ui.dialogs.more_info_control.add_to.action_failed",
{
error: err.message || err,
}
),
});
if (action.type === "external") {
try {
if (!action.payload) {
throw new Error("Missing external action payload");
}
this.hass.auth.external!.fireMessage({
type: "entity/add_to",
payload: {
entity_id: this.entityId,
app_payload: action.payload,
},
});
fireEvent(this, "add-to-action-selected");
} catch (err: unknown) {
showToast(this, {
message: this.hass.localize(
"ui.dialogs.more_info_control.add_to.action_failed",
{
error: err instanceof Error ? err.message : String(err),
}
),
});
}
return;
}
if (action.type !== "default") {
return;
}
addToActionHandler(action.key, { entity_id: this.entityId });
}
private _renderActionItems(
actions: EntityAddToActions,
source: "default" | "external"
) {
return actions.map(
(action, index) => html`
<ha-list-item-button
aria-label=${action.name}
data-action-index=${index}
data-action-source=${source}
.disabled=${!action.enabled}
@click=${this._actionSelected}
>
<ha-icon slot="start" .icon=${action.icon}></ha-icon>
<span slot="headline" class="action-label">
${action.type === "default"
? this._renderDefaultActionLabel(action.key)
: action.name}
</span>
${action.description
? html`<span slot="supporting-text">${action.description}</span>`
: nothing}
</ha-list-item-button>
`
);
}
private _renderDefaultActionLabel(key: AddToActionKey) {
const [beforeTarget, afterTarget] = getAddToActionLabelParts(
this.hass.localize,
key
);
return html`${beforeTarget}${this._renderTarget()}${afterTarget}`;
}
private _renderTarget() {
return html`<ha-automation-target-badge
target-type="entity"
.targetId=${this.entityId}
.label=${this._targetLabel}
></ha-automation-target-badge>`;
}
private get _targetLabel(): string {
const stateObj = this.hass.states[this.entityId];
return stateObj
? this.hass.formatEntityName(stateObj, undefined)
: this.entityId;
}
protected async firstUpdated() {
await this._loadExternalActions();
await this._loadActions();
this._loading = false;
}
@@ -80,7 +179,7 @@ export class HaMoreInfoAddTo extends LitElement {
`;
}
if (!this._externalActions?.actions.length) {
if (!this._defaultActions.length && !this._externalActions.length) {
return html`
<ha-alert alert-type="info">
${this.hass.localize(
@@ -92,30 +191,27 @@ export class HaMoreInfoAddTo extends LitElement {
return html`
<ha-list-base>
${this._externalActions?.actions.map(
(action) => html`
<ha-list-item-button
.disabled=${!action.enabled}
.action=${action}
@click=${this._actionSelected}
>
<ha-icon slot="start" .icon=${action.mdi_icon}></ha-icon>
<span slot="headline">${action.name}</span>
${action.details
? html`<span slot="supporting-text">${action.details}</span>`
: nothing}
</ha-list-item-button>
`
)}
${this._renderActionItems(this._defaultActions, "default")}
</ha-list-base>
${this._externalActions.length
? html`
<h2 class="section-title">
${this.hass.localize(
"ui.dialogs.more_info_control.add_to.app_actions"
)}
</h2>
<ha-list-base>
${this._renderActionItems(this._externalActions, "external")}
</ha-list-base>
`
: nothing}
`;
}
static styles = css`
:host {
display: block;
padding: var(--ha-space-2) var(--ha-space-6) var(--ha-space-6)
var(--ha-space-6);
padding: var(--ha-space-3) 0 var(--ha-space-4);
}
.loading {
@@ -125,10 +221,26 @@ export class HaMoreInfoAddTo extends LitElement {
padding: var(--ha-space-8);
}
.section-title {
padding: 0 var(--ha-space-6);
margin: var(--ha-space-4) 0 var(--ha-space-1);
font-size: var(--ha-font-size-m);
font-weight: var(--ha-font-weight-medium);
line-height: var(--ha-line-height-normal);
color: var(--secondary-text-color);
}
ha-icon {
display: flex;
align-items: center;
}
.action-label {
display: inline-flex;
align-items: center;
gap: var(--ha-space-1);
flex-wrap: wrap;
}
`;
}
+46 -20
View File
@@ -1,3 +1,4 @@
import "@home-assistant/webawesome/dist/components/divider/divider";
import {
mdiBackupRestore,
mdiChartBoxOutline,
@@ -17,13 +18,13 @@ import {
} from "@mdi/js";
import type { HassEntity } from "home-assistant-js-websocket";
import type { PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { cache } from "lit/directives/cache";
import { classMap } from "lit/directives/class-map";
import { keyed } from "lit/directives/keyed";
import type { HASSDomEvent } from "../../common/dom/fire_event";
import { dynamicElement } from "../../common/dom/dynamic-element-directive";
import type { HASSDomEvent } from "../../common/dom/fire_event";
import { fireEvent } from "../../common/dom/fire_event";
import { stopPropagation } from "../../common/dom/stop_propagation";
import { computeAreaName } from "../../common/entity/compute_area_name";
@@ -57,10 +58,12 @@ import {
getExtendedEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../data/entity/entity_registry";
import { subscribeLabFeature } from "../../data/labs";
import type { ItemType } from "../../data/search";
import { SearchableDomains } from "../../data/search";
import { getSensorNumericDeviceClasses } from "../../data/sensor";
import { ScrollableFadeMixin } from "../../mixins/scrollable-fade-mixin";
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
import {
haStyleDialog,
haStyleDialogFixedTop,
@@ -70,12 +73,12 @@ import "../../state-summary/state-card-content";
import type { HomeAssistant } from "../../types";
import { showConfirmationDialog } from "../generic/show-dialog-box";
import {
computeShowHistoryComponent,
computeShowLogBookComponent,
DOMAINS_WITH_MORE_INFO,
EDITABLE_DOMAINS_WITH_ID,
EDITABLE_DOMAINS_WITH_UNIQUE_ID,
type MoreInfoView,
computeShowHistoryComponent,
computeShowLogBookComponent,
} from "./const";
import "./controls/more-info-default";
import type { FavoritesDialogContext } from "./favorites";
@@ -117,7 +120,9 @@ declare global {
const DEFAULT_VIEW: MoreInfoView = "info";
@customElement("ha-more-info-dialog")
export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
export class MoreInfoDialog extends SubscribeMixin(
ScrollableFadeMixin(LitElement)
) {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean, reflect: true }) public large = false;
@@ -156,6 +161,8 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
@state() private _sensorNumericDeviceClasses?: string[] = [];
@state() private _newTriggersAndConditions = false;
protected scrollFadeThreshold = 24;
protected get scrollableElement(): HTMLElement | null {
@@ -254,7 +261,24 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
}
private _shouldShowAddEntityTo(): boolean {
return !!this.hass.auth.external?.config.hasEntityAddTo;
// When new_triggers_conditions labs feature is promoted, this whole check can be removed.
return (
this._newTriggersAndConditions ||
!!this.hass.auth.external?.config.hasEntityAddTo
);
}
protected hassSubscribe() {
return [
subscribeLabFeature(
this.hass.connection,
"automation",
"new_triggers_conditions",
(feature) => {
this._newTriggersAndConditions = feature.enabled;
}
),
];
}
private _getDeviceId(): string | null {
@@ -680,6 +704,21 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
.path=${mdiDotsVertical}
></ha-icon-button>
${this._shouldShowAddEntityTo()
? html`
<ha-dropdown-item value="add_to">
<ha-svg-icon
slot="icon"
.path=${mdiPlusBoxMultipleOutline}
></ha-svg-icon>
${this.hass.localize(
"ui.dialogs.more_info_control.add_to.title"
)}
</ha-dropdown-item>
<wa-divider></wa-divider>
`
: nothing}
${supportsFavorites
? html`
<ha-dropdown-item value="toggle_edit">
@@ -769,19 +808,6 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
"ui.dialogs.more_info_control.details"
)}
</ha-dropdown-item>
${this._shouldShowAddEntityTo()
? html`
<ha-dropdown-item value="add_to">
<ha-svg-icon
slot="icon"
.path=${mdiPlusBoxMultipleOutline}
></ha-svg-icon>
${this.hass.localize(
"ui.dialogs.more_info_control.add_entity_to"
)}
</ha-dropdown-item>
`
: nothing}
</ha-dropdown>
`
: !__DEMO__ && this._shouldShowAddEntityTo()
@@ -789,7 +815,7 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) {
<ha-icon-button
slot="headerActionItems"
.label=${this.hass.localize(
"ui.dialogs.more_info_control.add_entity_to"
"ui.dialogs.more_info_control.add_to.title"
)}
.path=${mdiPlusBoxMultipleOutline}
@click=${this._goToAddEntityTo}
@@ -199,13 +199,13 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.installing_${this._ttsProviderName}`
);
await installHassioAddon(this.hass, this._ttsAddonName);
await installHassioAddon(this.hass.callWS, this._ttsAddonName);
}
if (!ttsAddon || ttsAddon.state !== "started") {
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.starting_${this._ttsProviderName}`
);
await startHassioAddon(this.hass, this._ttsAddonName);
await startHassioAddon(this.hass.callWS, this._ttsAddonName);
}
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.setup_${this._ttsProviderName}`
@@ -217,13 +217,13 @@ export class HaVoiceAssistantSetupStepLocal extends LitElement {
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.installing_${this._sttProviderName}`
);
await installHassioAddon(this.hass, this._sttAddonName);
await installHassioAddon(this.hass.callWS, this._sttAddonName);
}
if (!sttAddon || sttAddon.state !== "started") {
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.starting_${this._sttProviderName}`
);
await startHassioAddon(this.hass, this._sttAddonName);
await startHassioAddon(this.hass.callWS, this._sttAddonName);
}
this._detailState = this.hass.localize(
`ui.panel.config.voice_assistants.satellite_wizard.local.state.setup_${this._sttProviderName}`
+2 -2
View File
@@ -213,7 +213,7 @@ class HaPanelApp extends LitElement {
let addon: HassioAddonDetails;
try {
addon = await fetchHassioAddonInfo(this.hass, addonSlug);
addon = await fetchHassioAddonInfo(this.hass.callWS, addonSlug);
} catch (err: any) {
await this._showErrorAndNavigateHome(
addonSlug,
@@ -253,7 +253,7 @@ class HaPanelApp extends LitElement {
);
// Set auto-retry window for after starting the app
this._autoRetryUntil = Date.now() + START_WAIT_TIME;
await startHassioAddon(this.hass, addonSlug);
await startHassioAddon(this.hass.callWS, addonSlug);
this._fetchData(addonSlug);
return;
} catch (_err) {
@@ -3,7 +3,7 @@ import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import "../../../../../components/ha-bar";
import "../../../../../components/ha-settings-row";
import "../../../../../components/item/ha-row-item";
import { roundWithOneDecimal } from "../../../../../util/calculate";
@customElement("supervisor-app-metric")
@@ -16,9 +16,9 @@ class SupervisorAppMetric extends LitElement {
protected render(): TemplateResult {
const roundedValue = roundWithOneDecimal(this.value);
return html`<ha-settings-row empty>
<span slot="heading"> ${this.description} </span>
<div slot="description" .title=${this.tooltip ?? ""}>
return html`<ha-row-item empty>
<span slot="headline"> ${this.description} </span>
<div slot="supporting-text" .title=${this.tooltip ?? ""}>
<span class="value"> ${roundedValue} % </span>
<ha-bar
class=${classMap({
@@ -28,16 +28,14 @@ class SupervisorAppMetric extends LitElement {
.value=${this.value}
></ha-bar>
</div>
</ha-settings-row>`;
</ha-row-item>`;
}
static styles = css`
ha-settings-row {
padding: 0;
height: 54px;
ha-row-item {
width: 100%;
}
ha-settings-row > div[slot="description"] {
ha-row-item > div[slot="supporting-text"] {
white-space: normal;
color: var(--secondary-text-color);
display: flex;
@@ -1,283 +0,0 @@
import {
css,
type CSSResultGroup,
html,
LitElement,
nothing,
type PropertyValues,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { atLeastVersion } from "../../../../../common/config/version";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/buttons/ha-progress-button";
import "../../../../../components/ha-alert";
import "../../../../../components/ha-button";
import "../../../../../components/ha-card";
import "../../../../../components/ha-faded";
import "../../../../../components/ha-markdown";
import "../../../../../components/ha-spinner";
import "../../../../../components/ha-switch";
import type { HaSwitch } from "../../../../../components/ha-switch";
import "../../../../../components/item/ha-row-item";
import type { HassioAddonDetails } from "../../../../../data/hassio/addon";
import {
fetchHassioAddonChangelog,
updateHassioAddon,
} from "../../../../../data/hassio/addon";
import {
extractApiErrorMessage,
ignoreSupervisorError,
} from "../../../../../data/hassio/common";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import { extractChangelog } from "../util/supervisor-app";
declare global {
interface HASSDomEvents {
"update-complete": undefined;
}
}
@customElement("supervisor-app-update-available-card")
class SupervisorAppUpdateAvailableCard extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: false }) public addon!: HassioAddonDetails;
@state() private _changelogContent?: string;
@state() private _updating = false;
@state() private _error?: string;
protected render() {
if (!this.addon) {
return nothing;
}
const createBackupTexts = this._computeCreateBackupTexts();
return html`
<ha-card
outlined
.header=${this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.update_name",
{
name: this.addon.name,
}
)}
>
<div class="card-content">
${this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
: ""}
${this.addon.version === this.addon.version_latest
? html`<p>
${this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.no_update",
{
name: this.addon.name,
}
)}
</p>`
: !this._updating
? html`
${this._changelogContent
? html`
<ha-faded>
<ha-markdown .content=${this._changelogContent}>
</ha-markdown>
</ha-faded>
`
: nothing}
<div class="versions">
<p>
${this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.description",
{
name: this.addon.name,
version: this.addon.version,
newest_version: this.addon.version_latest,
}
)}
</p>
</div>
${createBackupTexts
? html`
<hr />
<ha-row-item>
<span slot="headline">
${createBackupTexts.title}
</span>
${createBackupTexts.description
? html`
<span slot="supporting-text">
${createBackupTexts.description}
</span>
`
: nothing}
<ha-switch slot="end" id="create-backup"></ha-switch>
</ha-row-item>
`
: nothing}
`
: html`<ha-spinner
aria-label="Updating"
size="large"
></ha-spinner>
<p class="progress-text">
${this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.updating",
{
name: this.addon.name,
version: this.addon.version_latest,
}
)}
</p>`}
</div>
${this.addon.version !== this.addon.version_latest && !this._updating
? html`
<div class="card-actions">
<span></span>
<ha-progress-button @click=${this._update}>
${this.hass.localize("ui.common.update")}
</ha-progress-button>
</div>
`
: nothing}
</ha-card>
`;
}
protected firstUpdated(changedProps: PropertyValues<this>) {
super.firstUpdated(changedProps);
this._loadAddonData();
}
private _computeCreateBackupTexts():
| { title: string; description?: string }
| undefined {
if (atLeastVersion(this.hass.config.version, 2025, 2, 0)) {
const version = this.addon.version;
return {
title: this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.create_backup.app"
),
description: this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.create_backup.app_description",
{ version: version }
),
};
}
return {
title: this.hass.localize(
"ui.panel.config.apps.dashboard.update_available.create_backup.generic"
),
};
}
get _shouldCreateBackup(): boolean {
const createBackupSwitch = this.shadowRoot?.getElementById(
"create-backup"
) as HaSwitch;
if (createBackupSwitch) {
return createBackupSwitch.checked;
}
return true;
}
private async _loadAddonData() {
if (this.addon.changelog) {
try {
const content = await fetchHassioAddonChangelog(
this.hass,
this.addon.slug
);
this._changelogContent = extractChangelog(
this.addon as HassioAddonDetails,
content
);
} catch (err) {
this._error = extractApiErrorMessage(err);
}
}
}
private async _update() {
this._error = undefined;
this._updating = true;
try {
await updateHassioAddon(
this.hass,
this.addon.slug,
this._shouldCreateBackup
);
} catch (err: any) {
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
this._error = extractApiErrorMessage(err);
this._updating = false;
return;
}
}
fireEvent(this, "update-complete");
this._updating = false;
}
static get styles(): CSSResultGroup {
return [
haStyle,
css`
:host {
display: block;
}
ha-card {
margin: auto;
}
a {
text-decoration: none;
color: var(--primary-text-color);
}
.card-actions {
display: flex;
justify-content: space-between;
}
ha-spinner {
display: block;
margin: 32px;
text-align: center;
}
.progress-text {
text-align: center;
}
ha-markdown {
padding-bottom: var(--ha-space-2);
}
hr {
border-color: var(--divider-color);
border-bottom: none;
margin: var(--ha-space-4) 0 0 0;
}
ha-row-item {
--ha-row-item-padding-inline: 0;
margin-bottom: calc(-1 * var(--ha-space-4));
}
`,
];
}
}
declare global {
interface HTMLElementTagNameMap {
"supervisor-app-update-available-card": SupervisorAppUpdateAvailableCard;
}
}
@@ -183,7 +183,7 @@ class SupervisorAppAudio extends LitElement {
this._selectedOutput === "default" ? null : this._selectedOutput,
};
try {
await setHassioAddonOption(this.hass, this.addon.slug, data);
await setHassioAddonOption(this.hass.callWS, this.addon.slug, data);
if (this.addon?.state === "started") {
await suggestSupervisorAppRestart(this, this.hass, this.addon);
}
@@ -449,7 +449,7 @@ class SupervisorAppConfig extends LitElement {
options: null,
};
try {
await setHassioAddonOption(this.hass, this.addon.slug, data);
await setHassioAddonOption(this.hass.callWS, this.addon.slug, data);
this._configHasChanged = false;
const eventdata = {
success: true,
@@ -488,14 +488,14 @@ class SupervisorAppConfig extends LitElement {
try {
const validation = await validateHassioAddonOption(
this.hass,
this.hass.callWS,
this.addon.slug,
options
);
if (!validation.valid) {
throw Error(validation.message);
}
await setHassioAddonOption(this.hass, this.addon.slug, {
await setHassioAddonOption(this.hass.callWS, this.addon.slug, {
options,
});
@@ -6,9 +6,9 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/buttons/ha-progress-button";
import "../../../../../components/ha-alert";
import "../../../../../components/ha-card";
import "../../../../../components/ha-formfield";
import "../../../../../components/ha-form/ha-form";
import type { HaFormSchema } from "../../../../../components/ha-form/types";
import "../../../../../components/ha-formfield";
import type {
HassioAddonDetails,
HassioAddonSetOptionParams,
@@ -17,8 +17,8 @@ import { setHassioAddonOption } from "../../../../../data/hassio/addon";
import { extractApiErrorMessage } from "../../../../../data/hassio/common";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant } from "../../../../../types";
import { suggestSupervisorAppRestart } from "../dialogs/suggestSupervisorAppRestart";
import { supervisorAppsStyle } from "../../resources/supervisor-apps-style";
import { suggestSupervisorAppRestart } from "../dialogs/suggestSupervisorAppRestart";
@customElement("supervisor-app-network")
class SupervisorAppNetwork extends LitElement {
@@ -160,7 +160,7 @@ class SupervisorAppNetwork extends LitElement {
};
try {
await setHassioAddonOption(this.hass, this.addon.slug, data);
await setHassioAddonOption(this.hass.callWS, this.addon.slug, data);
this._configHasChanged = false;
const eventdata = {
success: true,
@@ -205,7 +205,7 @@ class SupervisorAppNetwork extends LitElement {
};
try {
await setHassioAddonOption(this.hass, this.addon.slug, data);
await setHassioAddonOption(this.hass.callWS, this.addon.slug, data);
this._configHasChanged = false;
const eventdata = {
success: true,
@@ -28,7 +28,7 @@ export const suggestSupervisorAppRestart = async (
});
if (confirmed) {
try {
await restartHassioAddon(hass, addon.slug);
await restartHassioAddon(hass.callWS, addon.slug);
} catch (err: any) {
showAlertDialog(element, {
title: hass.localize(
@@ -46,8 +46,8 @@ class SupervisorAppInfoDashboard extends LitElement {
css`
.content {
margin: auto;
padding: var(--ha-space-2);
max-width: 1024px;
padding: var(--ha-space-4);
max-width: 1200px;
}
`,
];
File diff suppressed because it is too large Load Diff
@@ -1,16 +1,19 @@
import { consume, type ContextType } from "@lit/context";
import type { TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-alert";
import "../../../../../components/ha-button";
import type { HomeAssistant } from "../../../../../types";
import { internationalizationContext } from "../../../../../data/context";
@customElement("supervisor-app-system-managed")
class SupervisorAppSystemManaged extends LitElement {
@property({ type: Boolean }) public narrow = false;
@property({ attribute: false }) public hass!: HomeAssistant;
@state()
@consume({ context: internationalizationContext, subscribe: true })
private i18n!: ContextType<typeof internationalizationContext>;
@property({ type: Boolean, attribute: "hide-button" }) public hideButton =
false;
@@ -19,18 +22,18 @@ class SupervisorAppSystemManaged extends LitElement {
return html`
<ha-alert
alert-type="warning"
.title=${this.hass.localize(
.title=${this.i18n.localize(
"ui.panel.config.apps.dashboard.system_managed.title"
)}
.narrow=${this.narrow}
>
${this.hass.localize(
${this.i18n.localize(
"ui.panel.config.apps.dashboard.system_managed.description"
)}
${!this.hideButton
? html`
<ha-button slot="action" @click=${this._takeControl}>
${this.hass.localize(
${this.i18n.localize(
"ui.panel.config.apps.dashboard.system_managed.take_control"
)}
</ha-button>
@@ -161,7 +161,7 @@ class HaConfigAppDashboard extends LitElement {
}
try {
this._addon = await fetchHassioAddonInfo(this.hass, slug);
this._addon = await fetchHassioAddonInfo(this.hass.callWS, slug);
} catch (err: any) {
if (repositoryUrl) {
try {
@@ -210,7 +210,7 @@ class HaConfigAppDashboard extends LitElement {
}
await addStoreRepository(this.hass, repositoryUrl);
this._addon = await fetchHassioAddonInfo(this.hass, slug);
this._addon = await fetchHassioAddonInfo(this.hass.callWS, slug);
}
private async _apiCalled(ev): Promise<void> {
+19 -16
View File
@@ -220,6 +220,13 @@ class HaConfigAreaPage extends LitElement {
));
}
const nonAutomatedEntities = entities.filter(
(entity) =>
!["scene", "script", "automation"].includes(
computeDomain(entity.entity_id)
)
);
return html`
<hass-subpage
.hass=${this.hass}
@@ -303,23 +310,19 @@ class HaConfigAreaPage extends LitElement {
"ui.panel.config.areas.editor.linked_entities_caption"
)}
>
${entities.length
${nonAutomatedEntities.length
? html`<ha-list>
${entities.map((entity) =>
["scene", "script", "automation"].includes(
computeDomain(entity.entity_id)
)
? ""
: html`
<ha-list-item
@click=${this._openEntity}
.entity=${entity}
hasMeta
>
<span>${entity.name}</span>
<ha-icon-next slot="meta"></ha-icon-next>
</ha-list-item>
`
${nonAutomatedEntities.map(
(entity) => html`
<ha-list-item
@click=${this._openEntity}
.entity=${entity}
hasMeta
>
<span>${entity.name}</span>
<ha-icon-next slot="meta"></ha-icon-next>
</ha-list-item>
`
)}</ha-list
>`
: html`
@@ -107,6 +107,7 @@ export default class HaAutomationActionEditor extends LitElement {
ev.stopPropagation();
const value = {
...(this.action.alias ? { alias: this.action.alias } : {}),
...(this.action.comment ? { comment: this.action.comment } : {}),
...ev.detail.value,
};
fireEvent(this, "value-changed", { value });
@@ -7,6 +7,8 @@ import {
mdiArrowUp,
mdiCheckboxBlankOutline,
mdiCheckboxOutline,
mdiCommentEditOutline,
mdiCommentTextOutline,
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
@@ -34,6 +36,7 @@ import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { computeDomain } from "../../../../common/entity/compute_domain";
import { computeObjectId } from "../../../../common/entity/compute_object_id";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import { truncateWithEllipsis } from "../../../../common/string/truncate-with-ellipsis";
import { handleStructError } from "../../../../common/structs/handle-errors";
import { copyToClipboard } from "../../../../common/util/copy-clipboard";
import "../../../../components/automation/ha-automation-row";
@@ -294,6 +297,11 @@ export default class HaAutomationActionRow extends LitElement {
?.target
: undefined;
const commentTooltipText = truncateWithEllipsis(
this.action.comment?.trim() || "",
250
);
return html`
${type === "service" && "action" in this.action && this.action.action
? html`
@@ -329,6 +337,21 @@ export default class HaAutomationActionRow extends LitElement {
serviceTargetSpec
)
: nothing}
${commentTooltipText
? html`
<ha-svg-icon
id="comment-icon"
.path=${mdiCommentTextOutline}
.label=${this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
)}
class="comment-indicator"
></ha-svg-icon
><ha-tooltip for="comment-icon"
><p>${commentTooltipText}</p></ha-tooltip
>
`
: nothing}
${type !== "condition" &&
(this.action as NonConditionAction).continue_on_error === true
? html`<ha-svg-icon
@@ -384,6 +407,14 @@ export default class HaAutomationActionRow extends LitElement {
)
)}
</ha-dropdown-item>
<ha-dropdown-item value="edit_comment">
<ha-svg-icon slot="icon" .path=${mdiCommentEditOutline}></ha-svg-icon>
${this._renderOverflowLabel(
this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.action.comment ? "edit" : "add"}`
)
)}
</ha-dropdown-item>
<wa-divider></wa-divider>
<ha-dropdown-item value="duplicate" .disabled=${this.disabled}>
<ha-svg-icon
@@ -910,6 +941,38 @@ export default class HaAutomationActionRow extends LitElement {
}
};
private _editCommentAction = async (): Promise<void> => {
const comment = await showPromptDialog(this, {
title: this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.action.comment ? "edit" : "add"}`
),
inputLabel: this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
),
inputType: "string",
defaultValue: this.action.comment,
confirmText: this.hass.localize("ui.common.submit"),
multiline: true,
});
if (comment !== null) {
const value = { ...this.action };
if (comment === "") {
delete value.comment;
} else {
value.comment = comment;
}
fireEvent(this, "value-changed", {
value,
});
if (this._selected && this.optionsInSidebar) {
this.openSidebar(value); // refresh sidebar
} else if (this._yamlMode) {
this._actionEditor?.yamlEditor?.setValue(value);
}
}
};
private _duplicateAction = () => {
fireEvent(this, "duplicate");
};
@@ -1026,6 +1089,7 @@ export default class HaAutomationActionRow extends LitElement {
rename: () => {
this._renameAction();
},
editComment: this._editCommentAction,
toggleYamlMode: () => {
this._toggleYamlMode();
this.openSidebar();
@@ -1121,6 +1185,9 @@ export default class HaAutomationActionRow extends LitElement {
case "rename":
this._renameAction();
break;
case "edit_comment":
this._editCommentAction();
break;
case "duplicate":
this._duplicateAction();
break;
@@ -18,6 +18,7 @@ import { getValueFromDynamic, isDynamic } from "../../../../data/automation";
import type { Action } from "../../../../data/script";
import { EDITOR_SAVE_FAB_TOAST_BOTTOM_OFFSET } from "../editor-toast";
import {
getAddAutomationElementTargetFromQuery,
PASTE_VALUE,
showAddAutomationElementDialog,
} from "../show-add-automation-element-dialog";
@@ -41,6 +42,8 @@ export default class HaAutomationAction extends AutomationSortableListMixin<Acti
@queryAll("ha-automation-action-row")
private _actionRowElements?: HaAutomationActionRow[];
private _openedAddDialogFromQuery = false;
protected get items(): Action[] {
return this.actions;
}
@@ -133,6 +136,33 @@ export default class HaAutomationAction extends AutomationSortableListMixin<Acti
protected updated(changedProps: PropertyValues<this>) {
super.updated(changedProps);
if (!this.hass) {
return;
}
const addActionTargetFromQuery = getAddAutomationElementTargetFromQuery(
this.hass.states,
this.hass.devices,
"action"
);
if (changedProps.has("actions") && addActionTargetFromQuery) {
this._openedAddDialogFromQuery = false;
}
if (
!this._openedAddDialogFromQuery &&
this.root &&
!this.disabled &&
this.actions.length === 0 &&
addActionTargetFromQuery
) {
this._openedAddDialogFromQuery = true;
queueMicrotask(() => this._addActionDialog());
} else if (this._openedAddDialogFromQuery && !addActionTargetFromQuery) {
this._openedAddDialogFromQuery = false;
}
if (
changedProps.has("actions") &&
(this.focusLastItemOnChange || this.focusItemIndexOnChange !== undefined)
@@ -112,11 +112,11 @@ export class HaDeviceAction extends LitElement {
.schema=${this._capabilities.extra_fields}
.disabled=${this.disabled}
.computeLabel=${localizeExtraFieldsComputeLabelCallback(
this.hass,
this.hass.localize,
this.action
)}
.computeHelper=${localizeExtraFieldsComputeHelperCallback(
this.hass,
this.hass.localize,
this.action
)}
@value-changed=${this._extraFieldsChanged}
@@ -149,7 +149,7 @@ export class HaDeviceAction extends LitElement {
private async _getCapabilities() {
this._capabilities = this.action.domain
? await fetchDeviceActionCapabilities(this.hass, this.action)
? await fetchDeviceActionCapabilities(this.hass.callWS, this.action)
: undefined;
}
@@ -186,6 +186,10 @@ export class HaDeviceAction extends LitElement {
}
static styles = css`
:host {
display: block;
margin-bottom: var(--ha-space-3);
}
ha-device-picker {
display: block;
margin-bottom: 24px;
@@ -33,6 +33,7 @@ import type {
import { computeRTL } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce";
import { deepEqual } from "../../../common/util/deep-equal";
import { constructUrlCurrentPath } from "../../../common/url/construct-url";
import "../../../components/entity/state-badge";
import "../../../components/ha-bottom-sheet";
import "../../../components/ha-button";
@@ -128,7 +129,13 @@ import "./add-automation-element/ha-automation-add-from-target";
import "./add-automation-element/ha-automation-add-items";
import "./add-automation-element/ha-automation-add-search";
import type { AddAutomationElementDialogParams } from "./show-add-automation-element-dialog";
import { PASTE_VALUE } from "./show-add-automation-element-dialog";
import {
ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM,
ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM,
ADD_AUTOMATION_ELEMENT_QUERY_PARAM,
getAddAutomationElementTargetFromQuery,
PASTE_VALUE,
} from "./show-add-automation-element-dialog";
import { getTargetText } from "./target/get_target_text";
const TYPES = {
@@ -230,6 +237,8 @@ class DialogAddAutomationElement
@state() private _newTriggersAndConditions = false;
@state() private _openedFromQuery = false;
@state() private _conditionDescriptions: ConditionDescriptions = {};
@state()
@@ -295,10 +304,29 @@ class DialogAddAutomationElement
}
}
public showDialog(params): void {
public showDialog(params: AddAutomationElementDialogParams): void {
this._params = params;
this._resetVariables();
const queryTarget = getAddAutomationElementTargetFromQuery(
this.hass.states,
this.hass.devices,
params.type
);
this._openedFromQuery = !!queryTarget;
if (queryTarget) {
const searchParams = new URLSearchParams(mainWindow.location.search);
searchParams.delete(ADD_AUTOMATION_ELEMENT_QUERY_PARAM);
searchParams.delete(ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM);
searchParams.delete(ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM);
mainWindow.history.replaceState(
mainWindow.history.state,
"",
constructUrlCurrentPath(searchParams.toString())
);
}
this.addKeyboardShortcuts();
this._loadConfigEntries();
@@ -314,16 +342,26 @@ class DialogAddAutomationElement
(feature) => {
this._newTriggersAndConditions = feature.enabled;
this._tab = this._newTriggersAndConditions ? "targets" : "groups";
if (
queryTarget &&
this._newTriggersAndConditions &&
!this._selectedTarget
) {
this._selectedTarget = queryTarget;
this._getItemsByTarget();
}
}
);
// add initial dialog view state to history
mainWindow.history.pushState(
{
dialogData: {},
},
""
);
if (!queryTarget) {
// add initial dialog view state to history
mainWindow.history.pushState(
{
dialogData: {},
},
""
);
}
if (this._params?.type === "action") {
this.hass.loadBackendTranslation("services");
@@ -343,6 +381,16 @@ class DialogAddAutomationElement
// prevent view mode switch when resizing window
this._bottomSheetMode = this._narrow;
if (
queryTarget &&
this._newTriggersAndConditions &&
!this._selectedTarget
) {
this._selectedTarget = queryTarget;
this._tab = "targets";
this._getItemsByTarget();
}
}
public closeDialog(historyState?: any) {
@@ -407,6 +455,7 @@ class DialogAddAutomationElement
this._narrow = false;
this._targetItems = undefined;
this._loadItemsError = false;
this._openedFromQuery = false;
}
private _updateNarrow = () => {
@@ -891,7 +940,9 @@ class DialogAddAutomationElement
></ha-icon-button>
`
: nothing}
${this._narrow && (this._selectedGroup || this._selectedTarget)
${this._narrow &&
(this._selectedGroup || this._selectedTarget) &&
!this._openedFromQuery
? html`<ha-icon-button-prev
slot="navigationIcon"
@click=${this._back}
@@ -2243,7 +2294,14 @@ class DialogAddAutomationElement
if (targetId) {
return getTargetText(
this.hass,
{
entities: this.hass.entities,
devices: this.hass.devices,
areas: this.hass.areas,
floors: this.hass.floors,
},
this.hass.states,
this.hass.localize,
targetType as "floor" | "area" | "device" | "entity" | "label",
targetId,
this._getLabel
@@ -9,7 +9,6 @@ import {
} from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { repeat } from "lit/directives/repeat";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../common/dom/fire_event";
import { stopPropagation } from "../../../../common/dom/stop_propagation";
import "../../../../components/ha-svg-icon";
@@ -21,7 +20,7 @@ import type { LabelRegistryEntry } from "../../../../data/label/label_registry";
import { haStyleScrollbar } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import type { AddAutomationElementListItem } from "../add-automation-element-dialog";
import { getTargetIcon } from "../target/get_target_icon";
import "../target/ha-automation-target-badge";
type Target = [string, string | undefined, string | undefined];
@@ -108,7 +107,10 @@ export class HaAutomationAddItems extends LitElement {
items,
(item) => item.key,
(item) => html`
<ha-list-item-button .value=${item.key} @click=${this._selected}>
<ha-list-item-button
data-value=${item.key}
@click=${this._selected}
>
<div slot="headline" class=${this.target ? "item-headline" : ""}>
${item.name}${this._renderTarget(this.target)}
</div>
@@ -154,27 +156,22 @@ export class HaAutomationAddItems extends LitElement {
`;
}
private _renderTarget = memoizeOne((target?: Target) => {
private _renderTarget(target?: Target) {
if (!target) {
return nothing;
}
return html`<div class="selected-target">
${getTargetIcon(
this.hass,
target[0],
target[1],
this.configEntryLookup,
this.getLabel
)}
<div class="label">${target[2]}</div>
</div>`;
});
return html`<ha-automation-target-badge
.targetType=${target[0]}
.targetId=${target[1]}
.label=${target[2]}
></ha-automation-target-badge>`;
}
private _selected(ev) {
const item = ev.currentTarget;
const item = ev.currentTarget as HTMLElement;
fireEvent(this, "value-changed", {
value: item.value,
value: item.dataset.value,
});
}
@@ -295,42 +292,6 @@ export class HaAutomationAddItems extends LitElement {
ha-svg-icon.plus {
color: var(--primary-color);
}
.selected-target {
display: inline-flex;
gap: var(--ha-space-1);
justify-content: center;
align-items: center;
border-radius: var(--ha-border-radius-md);
background: var(--ha-color-fill-neutral-normal-resting);
padding: 0 var(--ha-space-2) 0 var(--ha-space-1);
border: var(--ha-border-width-sm) solid
var(--ha-color-border-neutral-quiet);
color: var(--ha-color-on-neutral-normal);
overflow: hidden;
}
.selected-target .label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selected-target ha-icon,
.selected-target ha-svg-icon,
.selected-target ha-domain-icon {
display: flex;
padding: var(--ha-space-1) 0;
}
.selected-target ha-floor-icon {
display: flex;
height: 32px;
width: 32px;
align-items: center;
}
.selected-target ha-domain-icon {
filter: grayscale(100%);
}
`,
];
}
@@ -123,6 +123,7 @@ export default class HaAutomationConditionEditor extends LitElement {
ev.stopPropagation();
const value = {
...(this.condition.alias ? { alias: this.condition.alias } : {}),
...(this.condition.comment ? { comment: this.condition.comment } : {}),
...ev.detail.value,
};
fireEvent(this, "value-changed", { value });
@@ -4,6 +4,8 @@ import {
mdiAppleKeyboardCommand,
mdiArrowDown,
mdiArrowUp,
mdiCommentEditOutline,
mdiCommentTextOutline,
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
@@ -33,6 +35,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
import { preventDefaultStopPropagation } from "../../../../common/dom/prevent_default_stop_propagation";
import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import { truncateWithEllipsis } from "../../../../common/string/truncate-with-ellipsis";
import { handleStructError } from "../../../../common/structs/handle-errors";
import { copyToClipboard } from "../../../../common/util/copy-clipboard";
import { debounce } from "../../../../common/util/debounce";
@@ -40,6 +43,7 @@ import "../../../../components/automation/ha-automation-row";
import type { HaAutomationRow } from "../../../../components/automation/ha-automation-row";
import "../../../../components/automation/ha-automation-row-event-chip";
import "../../../../components/automation/ha-automation-row-live-test";
import type { LiveTestState } from "../../../../components/automation/ha-automation-row-live-test";
import "../../../../components/ha-card";
import "../../../../components/ha-condition-icon";
import "../../../../components/ha-dropdown";
@@ -149,10 +153,7 @@ export default class HaAutomationConditionRow extends LitElement {
@state() private _selected = false;
@state() private _liveTestResult: {
state: "pass" | "fail" | "invalid" | "unknown";
message?: string;
} = { state: "unknown" };
@state() private _liveTestResult: LiveTestState = "unknown";
@state()
@consume({ context: fullEntitiesContext, subscribe: true })
@@ -200,6 +201,11 @@ export default class HaAutomationConditionRow extends LitElement {
const conditionTargetSpec =
this.conditionDescriptions[this.condition.condition]?.target;
const commentTooltipText = truncateWithEllipsis(
this.condition.comment?.trim() || "",
250
);
return html`
<ha-condition-icon
slot="leading-icon"
@@ -217,6 +223,21 @@ export default class HaAutomationConditionRow extends LitElement {
conditionTargetSpec
)
: nothing}
${this.condition.comment?.trim()
? html`
<ha-svg-icon
id="comment-icon"
.path=${mdiCommentTextOutline}
.label=${this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
)}
class="comment-indicator"
></ha-svg-icon>
<ha-tooltip for="comment-icon"
><p>${commentTooltipText}</p></ha-tooltip
>
`
: nothing}
</h3>
<ha-automation-row-event-chip
.show=${this._testing}
@@ -264,6 +285,14 @@ export default class HaAutomationConditionRow extends LitElement {
)
)}
</ha-dropdown-item>
<ha-dropdown-item value="edit_comment">
<ha-svg-icon slot="icon" .path=${mdiCommentEditOutline}></ha-svg-icon>
${this._renderOverflowLabel(
this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.condition.comment ? "edit" : "add"}`
)
)}
</ha-dropdown-item>
<wa-divider></wa-divider>
@@ -500,11 +529,10 @@ export default class HaAutomationConditionRow extends LitElement {
>${this._renderRow()}
<ha-automation-row-live-test
slot="icons"
.state=${this._liveTestResult.state}
.state=${this._liveTestResult}
.label=${this.hass.localize(
`ui.panel.config.automation.editor.conditions.live_test_state.${this._liveTestResult.state}`
`ui.panel.config.automation.editor.conditions.live_test_state.${this._liveTestResult}`
)}
.message=${this._liveTestResult.message}
></ha-automation-row-live-test
></ha-automation-row>`
: html`
@@ -591,12 +619,7 @@ export default class HaAutomationConditionRow extends LitElement {
}
private _resetSubscription() {
this._liveTestResult = {
state: "unknown",
message: this.hass.localize(
"ui.panel.config.automation.editor.conditions.live_test_state.unknown"
),
};
this._liveTestResult = "unknown";
if (this._conditionUnsub) {
this._conditionUnsub.then((unsub) => unsub());
this._conditionUnsub = undefined;
@@ -621,12 +644,7 @@ export default class HaAutomationConditionRow extends LitElement {
if (result.error) {
this._handleLiveTestError(result.error);
} else {
this._liveTestResult = {
state: result.result ? "pass" : "fail",
message: this.hass.localize(
`ui.panel.config.automation.editor.conditions.testing_${result.result ? "pass" : "error"}`
),
};
this._liveTestResult = result.result ? "pass" : "fail";
}
},
this.condition
@@ -643,10 +661,7 @@ export default class HaAutomationConditionRow extends LitElement {
private _handleLiveTestError(error: any) {
const invalid =
typeof error !== "string" && error.code === "invalid_format";
this._liveTestResult = {
state: invalid ? "invalid" : "unknown",
message: typeof error === "string" ? error : error.message,
};
this._liveTestResult = invalid ? "invalid" : "unknown";
}
private _onValueChange(event: CustomEvent) {
@@ -813,6 +828,38 @@ export default class HaAutomationConditionRow extends LitElement {
}
};
private _editCommentCondition = async (): Promise<void> => {
const comment = await showPromptDialog(this, {
title: this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.condition.comment ? "edit" : "add"}`
),
inputLabel: this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
),
inputType: "string",
defaultValue: this.condition.comment,
confirmText: this.hass.localize("ui.common.submit"),
multiline: true,
});
if (comment !== null) {
const value = { ...this.condition };
if (comment === "") {
delete value.comment;
} else {
value.comment = comment;
}
fireEvent(this, "value-changed", {
value,
});
if (this._selected && this.optionsInSidebar) {
this.openSidebar(value); // refresh sidebar
} else if (this._yamlMode) {
this.conditionEditor?.yamlEditor?.setValue(value);
}
}
};
private _duplicateCondition = () => {
fireEvent(this, "duplicate");
};
@@ -954,6 +1001,7 @@ export default class HaAutomationConditionRow extends LitElement {
rename: () => {
this._renameCondition();
},
editComment: this._editCommentCondition,
toggleYamlMode: () => {
this._toggleYamlMode();
this.openSidebar();
@@ -1025,6 +1073,9 @@ export default class HaAutomationConditionRow extends LitElement {
case "rename":
this._renameCondition();
break;
case "edit_comment":
this._editCommentCondition();
break;
case "duplicate":
this._duplicateCondition();
break;
@@ -27,6 +27,7 @@ import { subscribeLabFeature } from "../../../../data/labs";
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
import { EDITOR_SAVE_FAB_TOAST_BOTTOM_OFFSET } from "../editor-toast";
import {
getAddAutomationElementTargetFromQuery,
PASTE_VALUE,
showAddAutomationElementDialog,
} from "../show-add-automation-element-dialog";
@@ -57,6 +58,8 @@ export default class HaAutomationCondition extends AutomationSortableListMixin<C
private _unsub?: Promise<UnsubscribeFunc>;
private _openedAddDialogFromQuery = false;
protected get items(): Condition[] {
return this.conditions;
}
@@ -118,6 +121,33 @@ export default class HaAutomationCondition extends AutomationSortableListMixin<C
}
protected updated(changedProperties: PropertyValues<this>) {
if (!this.hass) {
return;
}
const addConditionTargetFromQuery = getAddAutomationElementTargetFromQuery(
this.hass.states,
this.hass.devices,
"condition"
);
if (changedProperties.has("conditions") && addConditionTargetFromQuery) {
this._openedAddDialogFromQuery = false;
}
if (
!this._openedAddDialogFromQuery &&
this.root &&
!this.disabled &&
this.conditions.length === 0 &&
addConditionTargetFromQuery
) {
this._openedAddDialogFromQuery = true;
queueMicrotask(() => this._addConditionDialog());
} else if (this._openedAddDialogFromQuery && !addConditionTargetFromQuery) {
this._openedAddDialogFromQuery = false;
}
if (!changedProperties.has("conditions")) {
return;
}
@@ -113,11 +113,11 @@ export class HaDeviceCondition extends LitElement {
.schema=${this._capabilities.extra_fields}
.disabled=${this.disabled}
.computeLabel=${localizeExtraFieldsComputeLabelCallback(
this.hass,
this.hass.localize,
this.condition
)}
.computeHelper=${localizeExtraFieldsComputeHelperCallback(
this.hass,
this.hass.localize,
this.condition
)}
@value-changed=${this._extraFieldsChanged}
@@ -151,7 +151,7 @@ export class HaDeviceCondition extends LitElement {
const condition = this.condition;
this._capabilities = condition.domain
? await fetchDeviceConditionCapabilities(this.hass, condition)
? await fetchDeviceConditionCapabilities(this.hass.callWS, condition)
: undefined;
}
@@ -188,6 +188,10 @@ export class HaDeviceCondition extends LitElement {
}
static styles = css`
:host {
display: block;
margin-bottom: var(--ha-space-3);
}
ha-device-picker {
display: block;
margin-bottom: 24px;
@@ -1,5 +1,5 @@
import type { PropertyValues } from "lit";
import { html, LitElement } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import {
@@ -22,6 +22,7 @@ import type { HomeAssistant } from "../../../../../types";
const numericStateConditionStruct = object({
alias: optional(string()),
comment: optional(string()),
condition: literal("numeric_state"),
entity_id: optional(string()),
attribute: optional(string()),
@@ -255,6 +256,13 @@ export default class HaNumericStateCondition extends LitElement {
);
}
};
static styles = css`
:host {
display: block;
margin-bottom: var(--ha-space-3);
}
`;
}
declare global {
@@ -1,7 +1,8 @@
import type { PropertyValues } from "lit";
import { html, LitElement } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import {
array,
assert,
boolean,
literal,
@@ -10,10 +11,9 @@ import {
optional,
string,
union,
array,
} from "superstruct";
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
import { ensureArray } from "../../../../../common/array/ensure-array";
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
import { fireEvent } from "../../../../../common/dom/fire_event";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
@@ -25,6 +25,7 @@ import type { ConditionElement } from "../ha-automation-condition-row";
const stateConditionStruct = object({
alias: optional(string()),
comment: optional(string()),
condition: literal("state"),
entity_id: optional(string()),
attribute: optional(string()),
@@ -142,6 +143,13 @@ export class HaStateCondition extends LitElement implements ConditionElement {
);
}
};
static styles = css`
:host {
display: block;
margin-bottom: var(--ha-space-3);
}
`;
}
declare global {
@@ -0,0 +1,79 @@
import { consume, type ContextType } from "@lit/context";
import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../common/dom/fire_event";
import "../../../components/ha-button";
import "../../../components/ha-settings-row";
import { internationalizationContext } from "../../../data/context";
@customElement("ha-automation-comment")
export class HaAutomationComment extends LitElement {
@property() public comment!: string;
@state()
@consume({ context: internationalizationContext, subscribe: true })
private _i18n!: ContextType<typeof internationalizationContext>;
protected render() {
return html`
<ha-settings-row narrow>
<div class="heading" slot="heading">
<span class="title" id="comment-label">
${this._i18n.localize(
"ui.panel.config.automation.editor.comment.label"
)}
</span>
<ha-button
@click=${this._handleClick}
size="small"
appearance="plain"
>
${this._i18n.localize("ui.common.edit")}
</ha-button>
</div>
<p aria-labelledby="comment-label">${this.comment}</p>
</ha-settings-row>
`;
}
private _handleClick() {
fireEvent(this, "edit-comment");
}
static styles = css`
ha-settings-row {
margin-inline: calc(-1 * var(--ha-space-4));
}
ha-settings-row::part(heading) {
padding-inline-end: 0;
overflow: visible;
}
.heading {
display: flex;
justify-content: space-between;
align-items: center;
}
p {
margin: var(--ha-space-2) 0 0;
border: var(--ha-border-width-sm) solid
var(--ha-color-border-neutral-quiet);
padding: var(--ha-space-1) var(--ha-space-3);
border-radius: var(--ha-border-radius-lg);
background-color: var(--ha-color-fill-neutral-quiet-resting);
white-space: pre-wrap;
}
ha-button {
margin-inline-end: calc(-1 * var(--ha-space-3));
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-automation-comment": HaAutomationComment;
}
interface HASSDomEvents {
"edit-comment": undefined;
}
}
@@ -77,6 +77,7 @@ import { showAssignCategoryDialog } from "../category/show-dialog-assign-categor
import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-automation-mode";
import { showAutomationSaveDialog } from "./automation-save-dialog/show-dialog-automation-save";
import { showAutomationSaveTimeoutDialog } from "./automation-save-timeout-dialog/show-dialog-automation-save-timeout";
import { ADD_AUTOMATION_ELEMENT_QUERY_PARAM } from "./show-add-automation-element-dialog";
import "./blueprint-automation-editor";
import type { EditorDomainHooks } from "./ha-automation-script-editor-mixin";
import {
@@ -572,11 +573,21 @@ export class HaAutomationEditor extends AutomationScriptEditorMixin<AutomationCo
protected updated(changedProps: PropertyValues): void {
super.updated(changedProps);
if (!this.hass) {
return;
}
const shouldResetNewAutomationConfigFromQuery =
changedProps.has("route") &&
this.route?.path === "/new" &&
new URLSearchParams(window.location.search).has(
ADD_AUTOMATION_ELEMENT_QUERY_PARAM
);
const oldAutomationId = changedProps.get("automationId");
if (
changedProps.has("automationId") &&
this.automationId &&
this.hass &&
// Only refresh config if we picked a new automation. If same ID, don't fetch it.
oldAutomationId !== this.automationId
) {
@@ -585,10 +596,10 @@ export class HaAutomationEditor extends AutomationScriptEditorMixin<AutomationCo
}
if (
changedProps.has("automationId") &&
(changedProps.has("automationId") ||
shouldResetNewAutomationConfigFromQuery) &&
!this.automationId &&
!this.entityId &&
this.hass
!this.entityId
) {
const initData = getAutomationEditorInitData();
this.dirty = !!initData;
@@ -169,15 +169,19 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
private _filter = "";
@state()
private _filters: DataTableFilters = {};
@storage({
storage: "sessionStorage",
key: "automation-table-filters-full",
state: true,
state: false,
subscribe: false,
serializer: serializeFilters,
deserializer: deserializeFilters,
})
private _filters: DataTableFilters = {};
private _storageFilters: DataTableFilters = {};
private _fromUrl = false;
@state() private _expandedFilter?: string;
@@ -760,6 +764,23 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
`;
}
protected willUpdate(changedProps: PropertyValues) {
super.willUpdate(changedProps);
if (!this.hasUpdated) {
const hasUrlFilter =
this._searchParms.has("blueprint") || this._searchParms.has("label");
if (!hasUrlFilter) {
this._filters = this._storageFilters;
}
if (this._searchParms.has("blueprint")) {
this._filterBlueprint();
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
}
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (changedProps.has("_entityReg")) {
@@ -767,15 +788,6 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
}
}
firstUpdated() {
if (this._searchParms.has("blueprint")) {
this._filterBlueprint();
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterExpanded(ev) {
if (ev.detail.expanded) {
this._expandedFilter = ev.target.localName;
@@ -793,6 +805,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
items: undefined,
},
};
if (!this._fromUrl) {
this._storageFilters = this._filters;
}
this._applyFilters();
};
@@ -803,6 +818,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
private _filterChanged(ev) {
const type = ev.target.localName;
this._filters = { ...this._filters, [type]: ev.detail };
if (!this._fromUrl) {
this._storageFilters = this._filters;
}
this._applyFilters();
}
@@ -858,6 +876,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
if (!label) {
return;
}
this._fromUrl = true;
this._filters = {
...this._filters,
"ha-filter-labels": {
@@ -873,6 +892,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
if (!blueprint) {
return;
}
this._fromUrl = true;
const related = await findRelated(
this.hass,
"automation_blueprint",
@@ -890,6 +910,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
private _clearFilter() {
this._filters = {};
if (!this._fromUrl) {
this._storageFilters = {};
}
this._applyFilters();
}
@@ -3,6 +3,8 @@ import {
mdiAppleKeyboardCommand,
mdiArrowDown,
mdiArrowUp,
mdiCommentEditOutline,
mdiCommentTextOutline,
mdiDelete,
mdiDotsVertical,
mdiPlusCircleMultipleOutline,
@@ -17,6 +19,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
import { preventDefaultStopPropagation } from "../../../../common/dom/prevent_default_stop_propagation";
import { stopPropagation } from "../../../../common/dom/stop_propagation";
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
import { truncateWithEllipsis } from "../../../../common/string/truncate-with-ellipsis";
import "../../../../components/automation/ha-automation-row";
import type { HaAutomationRow } from "../../../../components/automation/ha-automation-row";
import "../../../../components/ha-card";
@@ -37,11 +40,11 @@ import type { Action, Option } from "../../../../data/script";
import { showPromptDialog } from "../../../../dialogs/generic/show-dialog-box";
import type { HomeAssistant } from "../../../../types";
import { isMac } from "../../../../util/is_mac";
import { showEditorToast } from "../editor-toast";
import "../action/ha-automation-action";
import type HaAutomationAction from "../action/ha-automation-action";
import "../condition/ha-automation-condition";
import type HaAutomationCondition from "../condition/ha-automation-condition";
import { showEditorToast } from "../editor-toast";
import {
editorStyles,
indentStyle,
@@ -138,8 +141,12 @@ export default class HaAutomationOptionRow extends LitElement {
</div>
`;
}
private _renderRow() {
const commentTooltipText = truncateWithEllipsis(
this.option?.comment?.trim() || "",
250
);
return html`
<h3 slot="header">
${this.option
@@ -150,6 +157,21 @@ export default class HaAutomationOptionRow extends LitElement {
: this.hass.localize(
"ui.panel.config.automation.editor.actions.type.choose.default"
)}
${this.option?.comment?.trim()
? html`
<ha-svg-icon
id="comment-icon"
.path=${mdiCommentTextOutline}
.label=${this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
)}
class="comment-indicator"
></ha-svg-icon>
<ha-tooltip for="comment-icon"
><p>${commentTooltipText}</p></ha-tooltip
>
`
: nothing}
</h3>
<slot name="icons" slot="icons"></slot>
@@ -177,6 +199,17 @@ export default class HaAutomationOptionRow extends LitElement {
)
)}
</ha-dropdown-item>
<ha-dropdown-item value="edit_comment">
<ha-svg-icon
slot="icon"
.path=${mdiCommentEditOutline}
></ha-svg-icon>
${this._renderOverflowLabel(
this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.option?.comment ? "edit" : "add"}`
)
)}
</ha-dropdown-item>
<ha-dropdown-item value="duplicate" .disabled=${this.disabled}>
<ha-svg-icon
@@ -361,6 +394,9 @@ export default class HaAutomationOptionRow extends LitElement {
case "rename":
this._renameOption();
break;
case "edit_comment":
this._editCommentOption();
break;
case "delete":
this._removeOption();
break;
@@ -424,6 +460,39 @@ export default class HaAutomationOptionRow extends LitElement {
}
};
private _editCommentOption = async (): Promise<void> => {
if (!this.option) {
return;
}
const comment = await showPromptDialog(this, {
title: this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.option.comment ? "edit" : "add"}`
),
inputLabel: this.hass.localize(
"ui.panel.config.automation.editor.comment.label"
),
inputType: "string",
defaultValue: this.option.comment,
confirmText: this.hass.localize("ui.common.submit"),
multiline: true,
});
if (comment !== null) {
const value: Option = { ...this.option };
if (comment === "") {
delete value.comment;
} else {
value.comment = comment;
}
fireEvent(this, "value-changed", {
value,
});
if (this._selected) {
this.openSidebar(value); // refresh sidebar
}
}
};
private _conditionChanged(ev: CustomEvent) {
ev.stopPropagation();
const conditions = ev.detail.value as Condition[];
@@ -455,7 +524,8 @@ export default class HaAutomationOptionRow extends LitElement {
this.openSidebar();
}
public openSidebar(): void {
public openSidebar(option?: Option): void {
const sidebarOption = option ?? this.option;
fireEvent(this, "open-sidebar", {
close: (focus?: boolean) => {
this._selected = false;
@@ -467,9 +537,11 @@ export default class HaAutomationOptionRow extends LitElement {
rename: () => {
this._renameOption();
},
editComment: this._editCommentOption,
delete: this._removeOption,
duplicate: this._duplicateOption,
defaultOption: !!this.defaultActions,
comment: sidebarOption?.comment,
} satisfies OptionSidebarConfig);
this._selected = true;
this._collapsed = false;
@@ -1,23 +1,60 @@
import type { HassServiceTarget } from "home-assistant-js-websocket";
import { fireEvent } from "../../../common/dom/fire_event";
import type { SingleHassServiceTarget } from "../../../data/target";
import type { HomeAssistant } from "../../../types";
export const PASTE_VALUE = "__paste__";
export const ADD_AUTOMATION_ELEMENT_QUERY_PARAM = "add_automation_element";
export const ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM = "target_entity_id";
export const ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM = "target_device_id";
/** Parameters for the add automation element dialog. */
export interface AddAutomationElementDialogParams {
type: "trigger" | "condition" | "action";
add: (key: string, target?: HassServiceTarget) => void;
clipboardItem: string | undefined;
clipboardPasteToastBottomOffset?: number;
}
/** Get the target from the query parameters. */
export const getAddAutomationElementTargetFromQuery = (
states: HomeAssistant["states"],
devices: HomeAssistant["devices"],
type: AddAutomationElementDialogParams["type"]
): SingleHassServiceTarget | undefined => {
const params = new URLSearchParams(window.location.search);
if (params.get(ADD_AUTOMATION_ELEMENT_QUERY_PARAM) !== type) {
return undefined;
}
const entityId = params.get(ADD_AUTOMATION_ELEMENT_ENTITY_TARGET_PARAM);
if (entityId && states[entityId]) {
return { entity_id: entityId };
}
const deviceId = params.get(ADD_AUTOMATION_ELEMENT_DEVICE_TARGET_PARAM);
if (deviceId && devices[deviceId]) {
return { device_id: deviceId };
}
return undefined;
};
const loadDialog = () => import("./add-automation-element-dialog");
/** Show the add automation element dialog. */
export const showAddAutomationElementDialog = (
element: HTMLElement,
dialogParams: AddAutomationElementDialogParams
): void => {
const params = new URLSearchParams(window.location.search);
fireEvent(element, "show-dialog", {
dialogTag: "add-automation-element-dialog",
dialogImport: loadDialog,
dialogParams,
addHistory:
params.get(ADD_AUTOMATION_ELEMENT_QUERY_PARAM) !== dialogParams.type,
});
};
@@ -3,6 +3,7 @@ import {
mdiAppleKeyboardCommand,
mdiCheckboxBlankOutline,
mdiCheckboxOutline,
mdiCommentEditOutline,
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
@@ -26,8 +27,8 @@ import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
import "../../../../components/ha-dropdown-item";
import { ACTION_BUILDING_BLOCKS } from "../../../../data/action";
import type { ActionSidebarConfig } from "../../../../data/automation";
import { domainToName } from "../../../../data/integration";
import type { DomainManifestLookup } from "../../../../data/integration";
import { domainToName } from "../../../../data/integration";
import type {
NonConditionAction,
RepeatAction,
@@ -38,6 +39,7 @@ import { isMac } from "../../../../util/is_mac";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import { getAutomationActionType } from "../action/ha-automation-action-row";
import { getRepeatType } from "../action/types/ha-automation-action-repeat";
import "../ha-automation-comment";
import { overflowStyles, sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@@ -175,6 +177,15 @@ export default class HaAutomationSidebarAction extends LitElement {
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<ha-dropdown-item slot="menu-items" value="edit_comment">
<ha-svg-icon slot="icon" .path=${mdiCommentEditOutline}></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.config.config.action.comment ? "edit" : "add"}`
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<wa-divider slot="menu-items"></wa-divider>
<ha-dropdown-item
@@ -377,6 +388,12 @@ export default class HaAutomationSidebarAction extends LitElement {
@ui-mode-not-available=${this._handleUiModeNotAvailable}
></ha-automation-action-editor>`
)}
${this.config.config.action.comment?.trim() && !this.yamlMode
? html`<ha-automation-comment
@edit-comment=${this.config.editComment}
.comment=${this.config.config.action.comment}
></ha-automation-comment>`
: nothing}
</ha-automation-sidebar-card>`;
}
@@ -425,6 +442,9 @@ export default class HaAutomationSidebarAction extends LitElement {
case "rename":
this.config.rename();
break;
case "edit_comment":
this.config.editComment();
break;
case "run":
this.config.run();
break;
@@ -1,6 +1,7 @@
import "@home-assistant/webawesome/dist/components/divider/divider";
import {
mdiAppleKeyboardCommand,
mdiCommentEditOutline,
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
@@ -34,6 +35,7 @@ import type { HomeAssistant } from "../../../../types";
import { isMac } from "../../../../util/is_mac";
import "../condition/ha-automation-condition-editor";
import type HaAutomationConditionEditor from "../condition/ha-automation-condition-editor";
import "../ha-automation-comment";
import { overflowStyles, sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
@@ -149,6 +151,19 @@ export default class HaAutomationSidebarCondition extends LitElement {
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<ha-dropdown-item
slot="menu-items"
value="edit_comment"
.disabled=${this.disabled}
>
<ha-svg-icon slot="icon" .path=${mdiCommentEditOutline}></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.config.config.comment ? "edit" : "add"}`
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<wa-divider slot="menu-items"></wa-divider>
@@ -332,6 +347,12 @@ export default class HaAutomationSidebarCondition extends LitElement {
sidebar
></ha-automation-condition-editor>`
)}
${this.config.config.comment?.trim() && !this.yamlMode
? html`<ha-automation-comment
@edit-comment=${this.config.editComment}
.comment=${this.config.config.comment}
></ha-automation-comment>`
: nothing}
<div class="testing-wrapper">
<div
class="testing ${classMap({
@@ -396,6 +417,9 @@ export default class HaAutomationSidebarCondition extends LitElement {
case "rename":
this.config.rename();
break;
case "edit_comment":
this.config.editComment();
break;
case "test":
this.config.test();
break;
@@ -1,6 +1,7 @@
import "@home-assistant/webawesome/dist/components/divider/divider";
import {
mdiAppleKeyboardCommand,
mdiCommentEditOutline,
mdiDelete,
mdiPlusCircleMultipleOutline,
mdiRenameBox,
@@ -14,6 +15,7 @@ import type { OptionSidebarConfig } from "../../../../data/automation";
import type { HomeAssistant } from "../../../../types";
import { isMac } from "../../../../util/is_mac";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import "../ha-automation-comment";
import { overflowStyles, sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
@@ -72,6 +74,22 @@ export default class HaAutomationSidebarOption extends LitElement {
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<ha-dropdown-item
slot="menu-items"
value="edit_comment"
.disabled=${!!disabled}
>
<ha-svg-icon
slot="icon"
.path=${mdiCommentEditOutline}
></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.config.comment ? "edit" : "add"}`
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<ha-dropdown-item
slot="menu-items"
@@ -126,6 +144,12 @@ export default class HaAutomationSidebarOption extends LitElement {
`}
<div class="description">${description}</div>
${!this.config.defaultOption && this.config.comment?.trim()
? html`<ha-automation-comment
@edit-comment=${this.config.editComment}
.comment=${this.config.comment}
></ha-automation-comment>`
: nothing}
</ha-automation-sidebar-card>`;
}
@@ -140,6 +164,9 @@ export default class HaAutomationSidebarOption extends LitElement {
case "rename":
this.config.rename();
break;
case "edit_comment":
this.config.editComment();
break;
case "duplicate":
this.config.duplicate();
break;
@@ -1,18 +1,24 @@
import { mdiAppleKeyboardCommand, mdiDelete, mdiPlaylistEdit } from "@mdi/js";
import {
mdiAppleKeyboardCommand,
mdiCommentEditOutline,
mdiDelete,
mdiPlaylistEdit,
} from "@mdi/js";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
import "../../../../components/ha-dropdown-item";
import type { ScriptFieldSidebarConfig } from "../../../../data/automation";
import type { HomeAssistant } from "../../../../types";
import { isMac } from "../../../../util/is_mac";
import "../../script/ha-script-field-editor";
import type HaAutomationConditionEditor from "../action/ha-automation-action-editor";
import "../ha-automation-comment";
import { overflowStyles, sidebarEditorStyles } from "../styles";
import "./ha-automation-sidebar-card";
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
@customElement("ha-automation-sidebar-script-field")
export default class HaAutomationSidebarScriptField extends LitElement {
@@ -62,6 +68,15 @@ export default class HaAutomationSidebarScriptField extends LitElement {
@wa-select=${this._handleDropdownSelect}
>
<span slot="title">${title}</span>
<ha-dropdown-item slot="menu-items" value="edit_comment">
<ha-svg-icon slot="icon" .path=${mdiCommentEditOutline}></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
`ui.panel.config.automation.editor.comment.${this.config.config.field.description ? "edit" : "add"}`
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
<ha-dropdown-item
slot="menu-items"
value="toggle_yaml_mode"
@@ -121,6 +136,12 @@ export default class HaAutomationSidebarScriptField extends LitElement {
@yaml-changed=${this._yamlChangedSidebar}
></ha-script-field-editor>`
)}
${this.config.config.field.description?.trim() && !this.yamlMode
? html`<ha-automation-comment
@edit-comment=${this.config.editComment}
.comment=${this.config.config.field.description}
></ha-automation-comment>`
: nothing}
</ha-automation-sidebar-card>`;
}
@@ -168,6 +189,9 @@ export default class HaAutomationSidebarScriptField extends LitElement {
case "toggle_yaml_mode":
this._toggleYamlMode();
break;
case "edit_comment":
this.config.editComment();
break;
case "delete":
this.config.delete();
break;
@@ -1,6 +1,7 @@
import "@home-assistant/webawesome/dist/components/divider/divider";
import {
mdiAppleKeyboardCommand,
mdiCommentEditOutline,
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
@@ -18,9 +19,12 @@ import { customElement, property, query, state } from "lit/decorators";
import { keyed } from "lit/directives/keyed";
import { fireEvent } from "../../../../common/dom/fire_event";
import { handleStructError } from "../../../../common/structs/handle-errors";
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
import "../../../../components/ha-dropdown-item";
import type {
LegacyTrigger,
Trigger,
TriggerList,
TriggerSidebarConfig,
} from "../../../../data/automation";
import {
@@ -30,11 +34,11 @@ import {
} from "../../../../data/trigger";
import type { HomeAssistant } from "../../../../types";
import { isMac } from "../../../../util/is_mac";
import "../ha-automation-comment";
import { overflowStyles, sidebarEditorStyles } from "../styles";
import "../trigger/ha-automation-trigger-editor";
import type HaAutomationTriggerEditor from "../trigger/ha-automation-trigger-editor";
import "./ha-automation-sidebar-card";
import type { HaDropdownSelectEvent } from "../../../../components/ha-dropdown";
@customElement("ha-automation-sidebar-trigger")
export default class HaAutomationSidebarTrigger extends LitElement {
@@ -125,7 +129,24 @@ export default class HaAutomationSidebarTrigger extends LitElement {
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>
${type !== "list"
? html`<ha-dropdown-item
slot="menu-items"
value="edit_comment"
.disabled=${this.disabled}
>
<ha-svg-icon
slot="icon"
.path=${mdiCommentEditOutline}
></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
`ui.panel.config.automation.editor.comment.${(this.config.config as Exclude<Trigger, TriggerList>).comment ? "edit" : "add"}`
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-dropdown-item>`
: nothing}
${!this.yamlMode &&
!("id" in this.config.config) &&
!this._requestShowId
@@ -321,6 +342,14 @@ export default class HaAutomationSidebarTrigger extends LitElement {
sidebar
></ha-automation-trigger-editor>`
)}
${!isTriggerList(this.config.config) &&
this.config.config.comment?.trim() &&
!this.yamlMode
? html`<ha-automation-comment
@edit-comment=${this.config.editComment}
.comment=${this.config.config.comment}
></ha-automation-comment>`
: nothing}
</ha-automation-sidebar-card>
`;
}
@@ -372,6 +401,9 @@ export default class HaAutomationSidebarTrigger extends LitElement {
case "rename":
this.config.rename();
break;
case "edit_comment":
this.config.editComment();
break;
case "show_id":
this._showTriggerId();
break;
+1
View File
@@ -4,6 +4,7 @@ export const baseTriggerStruct = object({
trigger: string(),
id: optional(string()),
enabled: optional(boolean()),
comment: optional(string()),
});
export const forDictStruct = object({
+12
View File
@@ -52,6 +52,18 @@ export const rowStyles = css`
ha-automation-row-event-chip.event-chip {
position: absolute;
}
.comment-indicator {
color: var(--ha-color-on-neutral-normal);
}
.comment-indicator + ha-tooltip::part(body) {
cursor: default;
max-width: 300px;
}
.comment-indicator + ha-tooltip p {
white-space: pre-wrap;
margin: 0;
}
`;
export const editorStyles = css`
@@ -7,10 +7,11 @@ import "../../../../components/ha-state-icon";
import "../../../../components/ha-svg-icon";
import type { ConfigEntry } from "../../../../data/config_entries";
import type { LabelRegistryEntry } from "../../../../data/label/label_registry";
import type { HomeAssistant } from "../../../../types";
import type { HomeAssistant, HomeAssistantRegistries } from "../../../../types";
export const getTargetIcon = (
hass: HomeAssistant,
registries: HomeAssistantRegistries,
states: HomeAssistant["states"],
targetType: string,
targetId: string | undefined,
configEntryLookup: Record<string, ConfigEntry>,
@@ -21,15 +22,15 @@ export const getTargetIcon = (
return nothing;
}
if (targetType === "floor" && hass.floors[targetId]) {
if (targetType === "floor" && registries.floors[targetId]) {
return html`<ha-floor-icon
.slot=${slot}
.floor=${hass.floors[targetId]}
.floor=${registries.floors[targetId]}
></ha-floor-icon>`;
}
if (targetType === "area") {
const area = hass.areas[targetId];
const area = registries.areas[targetId];
if (area?.icon) {
return html`<ha-icon .slot=${slot} .icon=${area.icon}></ha-icon>`;
}
@@ -39,8 +40,8 @@ export const getTargetIcon = (
></ha-svg-icon>`;
}
if (targetType === "device" && hass.devices[targetId]) {
const device = hass.devices[targetId];
if (targetType === "device" && registries.devices[targetId]) {
const device = registries.devices[targetId];
const configEntry = device.primary_config_entry
? configEntryLookup[device.primary_config_entry]
: undefined;
@@ -55,9 +56,9 @@ export const getTargetIcon = (
}
}
if (targetType === "entity" && hass.states[targetId]) {
if (targetType === "entity" && states[targetId]) {
return html`<ha-state-icon
.stateObj=${hass.states[targetId]}
.stateObj=${states[targetId]}
.slot=${slot}
></ha-state-icon>`;
}
@@ -2,54 +2,60 @@ import { computeAreaName } from "../../../../common/entity/compute_area_name";
import { computeDeviceName } from "../../../../common/entity/compute_device_name";
import { computeEntityNameList } from "../../../../common/entity/compute_entity_name_display";
import { computeFloorName } from "../../../../common/entity/compute_floor_name";
import type { LocalizeFunc } from "../../../../common/translations/localize";
import type { LabelRegistryEntry } from "../../../../data/label/label_registry";
import type { HomeAssistant } from "../../../../types";
import type { HomeAssistant, HomeAssistantRegistries } from "../../../../types";
export const getTargetText = (
hass: HomeAssistant,
registries: HomeAssistantRegistries,
states: HomeAssistant["states"],
localize: LocalizeFunc,
targetType: "floor" | "area" | "device" | "entity" | "label",
targetId: string,
getLabel?: (id: string) => LabelRegistryEntry | undefined
): string => {
if (targetType === "floor") {
return (
(hass.floors[targetId] && computeFloorName(hass.floors[targetId])) ||
hass.localize(
(registries.floors[targetId] &&
computeFloorName(registries.floors[targetId])) ||
localize(
"ui.panel.config.automation.editor.actions.type.service.description.target_unknown_floor"
)
);
}
if (targetType === "area") {
return (
(hass.areas[targetId] && computeAreaName(hass.areas[targetId])) ||
hass.localize(
(registries.areas[targetId] &&
computeAreaName(registries.areas[targetId])) ||
localize(
"ui.panel.config.automation.editor.actions.type.service.description.target_unknown_area"
)
);
}
if (targetType === "device") {
return (
(hass.devices[targetId] && computeDeviceName(hass.devices[targetId])) ||
hass.localize(
(registries.devices[targetId] &&
computeDeviceName(registries.devices[targetId])) ||
localize(
"ui.panel.config.automation.editor.actions.type.service.description.target_unknown_device"
)
);
}
if (targetType === "entity" && hass.states[targetId]) {
const stateObj = hass.states[targetId];
if (targetType === "entity" && states[targetId]) {
const stateObj = states[targetId];
const [entityName, deviceName] = computeEntityNameList(
stateObj,
[{ type: "entity" }, { type: "device" }, { type: "area" }],
hass.entities,
hass.devices,
hass.areas,
hass.floors
registries.entities,
registries.devices,
registries.areas,
registries.floors
);
return entityName || deviceName || targetId;
}
if (targetType === "entity") {
return hass.localize(
return localize(
"ui.panel.config.automation.editor.actions.type.service.description.target_unknown_entity"
);
}
@@ -58,7 +64,7 @@ export const getTargetText = (
const label = getLabel(targetId);
return (
label?.name ||
hass.localize(
localize(
"ui.panel.config.automation.editor.actions.type.service.description.target_unknown_label"
)
);

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