1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

Add support for service action description placeholders (#27636)

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
Jan Bouwhuis
2025-11-26 09:54:30 +01:00
committed by GitHub
parent ebbcad812a
commit ae3a405a7b
8 changed files with 75 additions and 19 deletions

View File

@@ -465,10 +465,16 @@ export class HaServiceControl extends LitElement {
? computeObjectId(this._value.action) ? computeObjectId(this._value.action)
: undefined; : undefined;
const descriptionPlaceholders =
domain && serviceName
? this.hass.services[domain][serviceName].description_placeholders
: undefined;
const description = const description =
(serviceName && (serviceName &&
this.hass.localize( this.hass.localize(
`component.${domain}.services.${serviceName}.description` `component.${domain}.services.${serviceName}.description`,
descriptionPlaceholders
)) || )) ||
serviceData?.description; serviceData?.description;
@@ -537,7 +543,8 @@ export class HaServiceControl extends LitElement {
.disabled=${this.disabled} .disabled=${this.disabled}
.value=${this._value?.data?.entity_id} .value=${this._value?.data?.entity_id}
.label=${this.hass.localize( .label=${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.entity_id.description` `component.${domain}.services.${serviceName}.fields.entity_id.description`,
descriptionPlaceholders
) || entityId.description} ) || entityId.description}
@value-changed=${this._entityPicked} @value-changed=${this._entityPicked}
allow-custom-entity allow-custom-entity
@@ -575,7 +582,8 @@ export class HaServiceControl extends LitElement {
left-chevron left-chevron
.expanded=${!dataField.collapsed} .expanded=${!dataField.collapsed}
.header=${this.hass.localize( .header=${this.hass.localize(
`component.${domain}.services.${serviceName}.sections.${dataField.key}.name` `component.${domain}.services.${serviceName}.sections.${dataField.key}.name`,
descriptionPlaceholders
) || ) ||
dataField.name || dataField.name ||
dataField.key} dataField.key}
@@ -611,7 +619,10 @@ export class HaServiceControl extends LitElement {
serviceName: string | undefined serviceName: string | undefined
) { ) {
return this.hass!.localize( return this.hass!.localize(
`component.${domain}.services.${serviceName}.sections.${dataField.key}.description` `component.${domain}.services.${serviceName}.sections.${dataField.key}.description`,
domain && serviceName
? this.hass.services[domain][serviceName].description_placeholders
: undefined
); );
} }
@@ -658,6 +669,10 @@ export class HaServiceControl extends LitElement {
} }
const showOptional = showOptionalToggle(dataField); const showOptional = showOptionalToggle(dataField);
const descriptionPlaceholders =
domain && serviceName
? this.hass.services[domain][serviceName].description_placeholders
: undefined;
return dataField.selector && return dataField.selector &&
(!dataField.advanced || (!dataField.advanced ||
@@ -679,7 +694,8 @@ export class HaServiceControl extends LitElement {
></ha-checkbox>`} ></ha-checkbox>`}
<span slot="heading" <span slot="heading"
>${this.hass.localize( >${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${dataField.key}.name` `component.${domain}.services.${serviceName}.fields.${dataField.key}.name`,
descriptionPlaceholders
) || ) ||
dataField.name || dataField.name ||
dataField.key}</span dataField.key}</span
@@ -689,7 +705,8 @@ export class HaServiceControl extends LitElement {
breaks breaks
allow-svg allow-svg
.content=${this.hass.localize( .content=${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description` `component.${domain}.services.${serviceName}.fields.${dataField.key}.description`,
descriptionPlaceholders
) || dataField?.description} ) || dataField?.description}
></ha-markdown> ></ha-markdown>
</span> </span>

View File

@@ -92,8 +92,14 @@ class HaServicePicker extends LitElement {
`; `;
} }
const descriptionPlaceholders =
this.hass.services[domain][service].description_placeholders;
const serviceName = const serviceName =
localize(`component.${domain}.services.${service}.name`) || localize(
`component.${domain}.services.${service}.name`,
descriptionPlaceholders
) ||
services[domain][service].name || services[domain][service].name ||
service; service;
@@ -163,16 +169,21 @@ class HaServicePicker extends LitElement {
const serviceId = `${domain}.${service}`; const serviceId = `${domain}.${service}`;
const domainName = domainToName(localize, domain); const domainName = domainToName(localize, domain);
const descriptionPlaceholders =
this.hass.services[domain][service].description_placeholders;
const name = const name =
this.hass.localize( this.hass.localize(
`component.${domain}.services.${service}.name` `component.${domain}.services.${service}.name`,
descriptionPlaceholders
) || ) ||
services[domain][service].name || services[domain][service].name ||
service; service;
const description = const description =
this.hass.localize( this.hass.localize(
`component.${domain}.services.${service}.description` `component.${domain}.services.${service}.description`,
descriptionPlaceholders
) || ) ||
services[domain][service].description || services[domain][service].description ||
""; "";

View File

@@ -219,9 +219,13 @@ const tryDescribeAction = <T extends ActionType>(
if (config.action) { if (config.action) {
const [domain, serviceName] = config.action.split(".", 2); const [domain, serviceName] = config.action.split(".", 2);
const descriptionPlaceholders =
hass.services[domain][serviceName].description_placeholders;
const service = const service =
hass.localize(`component.${domain}.services.${serviceName}.name`) || hass.localize(
hass.services[domain][serviceName]?.name; `component.${domain}.services.${serviceName}.name`,
descriptionPlaceholders
) || hass.services[domain][serviceName]?.name;
if (config.metadata) { if (config.metadata) {
return hass.localize( return hass.localize(

View File

@@ -871,13 +871,17 @@ class DialogAddAutomationElement
`, `,
key: `${DYNAMIC_PREFIX}${dmn}.${service}`, key: `${DYNAMIC_PREFIX}${dmn}.${service}`,
name: `${domain ? "" : `${domainToName(localize, dmn)}: `}${ name: `${domain ? "" : `${domainToName(localize, dmn)}: `}${
this.hass.localize(`component.${dmn}.services.${service}.name`) || this.hass.localize(
`component.${dmn}.services.${service}.name`,
this.hass.services[dmn][service].description_placeholders
) ||
services[dmn][service]?.name || services[dmn][service]?.name ||
service service
}`, }`,
description: description:
this.hass.localize( this.hass.localize(
`component.${dmn}.services.${service}.description` `component.${dmn}.services.${service}.description`,
this.hass.services[dmn][service].description_placeholders
) || ) ||
services[dmn][service]?.description || services[dmn][service]?.description ||
"", "",

View File

@@ -93,8 +93,12 @@ export default class HaAutomationSidebarAction extends LitElement {
".", ".",
2 2
); );
title = `${domainToName(this.hass.localize, domain)}: ${ title = `${domainToName(this.hass.localize, domain)}: ${
this.hass.localize(`component.${domain}.services.${service}.name`) || this.hass.localize(
`component.${domain}.services.${service}.name`,
this.hass.services[domain][service].description_placeholders
) ||
this.hass.services[domain][service]?.name || this.hass.services[domain][service]?.name ||
title title
}`; }`;

View File

@@ -135,6 +135,11 @@ class HaPanelDevAction extends LitElement {
? computeObjectId(this._serviceData?.action) ? computeObjectId(this._serviceData?.action)
: undefined; : undefined;
const descriptionPlaceholders =
domain && serviceName
? this.hass.services[domain][serviceName].description_placeholders
: undefined;
return html` return html`
<div class="content"> <div class="content">
<p> <p>
@@ -307,12 +312,14 @@ class HaPanelDevAction extends LitElement {
<td><pre>${field.key}</pre></td> <td><pre>${field.key}</pre></td>
<td> <td>
${this.hass.localize( ${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.description` `component.${domain}.services.${serviceName}.fields.${field.key}.description`,
descriptionPlaceholders
) || field.description} ) || field.description}
</td> </td>
<td> <td>
${this.hass.localize( ${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.example` `component.${domain}.services.${serviceName}.fields.${field.key}.example`,
descriptionPlaceholders
) || field.example} ) || field.example}
</td> </td>
</tr>` </tr>`
@@ -643,7 +650,11 @@ class HaPanelDevAction extends LitElement {
} catch (_err: any) { } catch (_err: any) {
value = value =
this.hass.localize( this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.example` `component.${domain}.services.${serviceName}.fields.${field.key}.example`,
domain && serviceName
? this.hass.services[domain][serviceName]
.description_placeholders
: undefined
) || field.example; ) || field.example;
} }
example[field.key] = value; example[field.key] = value;

View File

@@ -400,7 +400,9 @@ class HaLogbookRenderer extends LitElement {
? `${domainToName(this.hass.localize, item.context_domain)}: ? `${domainToName(this.hass.localize, item.context_domain)}:
${ ${
this.hass.localize( this.hass.localize(
`component.${item.context_domain}.services.${item.context_service}.name` `component.${item.context_domain}.services.${item.context_service}.name`,
this.hass.services[item.context_domain][item.context_service]
.description_placeholders
) || ) ||
this.hass.services[item.context_domain]?.[item.context_service]?.name || this.hass.services[item.context_domain]?.[item.context_service]?.name ||
item.context_service item.context_service

View File

@@ -67,7 +67,10 @@ export const handleAction = async (
await hass.loadBackendTranslation("title"); await hass.loadBackendTranslation("title");
const localize = await hass.loadBackendTranslation("services"); const localize = await hass.loadBackendTranslation("services");
serviceName = `${domainToName(localize, domain)}: ${ serviceName = `${domainToName(localize, domain)}: ${
localize(`component.${domain}.services.${service}.name`) || localize(
`component.${domain}.services.${service}.name`,
hass.services[domain][service].description_placeholders
) ||
serviceDomains[domain][service].name || serviceDomains[domain][service].name ||
service service
}`; }`;