Add support for "all" as entity ID in action "service" (#7954)

This commit is contained in:
Philip Allgaier 2021-01-05 11:02:47 +01:00 committed by GitHub
parent 1667973a66
commit 2fdc746392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -195,7 +195,7 @@ export default class HaAutomationActionRow extends LitElement {
<ul> <ul>
${this._warnings.map((warning) => html`<li>${warning}</li>`)} ${this._warnings.map((warning) => html`<li>${warning}</li>`)}
</ul> </ul>
You can still edit your config in yaml. You can still edit your config in YAML.
</div>` </div>`
: ""} : ""}
${yamlMode ${yamlMode

View File

@ -19,12 +19,12 @@ import type { HaYamlEditor } from "../../../../../components/ha-yaml-editor";
import { ServiceAction } from "../../../../../data/script"; import { ServiceAction } from "../../../../../data/script";
import type { PolymerChangedEvent } from "../../../../../polymer-types"; import type { PolymerChangedEvent } from "../../../../../polymer-types";
import type { HomeAssistant } from "../../../../../types"; import type { HomeAssistant } from "../../../../../types";
import { EntityId } from "../../../../lovelace/common/structs/is-entity-id"; import { EntityIdOrAll } from "../../../../lovelace/common/structs/is-entity-id";
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row"; import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
const actionStruct = object({ const actionStruct = object({
service: optional(string()), service: optional(string()),
entity_id: optional(EntityId), entity_id: optional(EntityIdOrAll),
data: optional(any()), data: optional(any()),
}); });

View File

@ -7,7 +7,7 @@ const isEntityId = (value: unknown, context: StructContext): StructResult => {
if (!value.includes(".")) { if (!value.includes(".")) {
return [ return [
context.fail({ context.fail({
type: "entity id should be in the format 'domain.entity'", type: "Entity ID should be in the format 'domain.entity'",
}), }),
]; ];
} }
@ -15,3 +15,16 @@ const isEntityId = (value: unknown, context: StructContext): StructResult => {
}; };
export const EntityId = struct("entity-id", isEntityId); export const EntityId = struct("entity-id", isEntityId);
const isEntityIdOrAll = (
value: unknown,
context: StructContext
): StructResult => {
if (typeof value === "string" && value === "all") {
return true;
}
return isEntityId(value, context);
};
export const EntityIdOrAll = struct("entity-id-all", isEntityIdOrAll);