mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 22:37:21 +00:00
Allow selecting multiple entities for state trigger (#12334)
Co-authored-by: Zack Barett <zackbarett@hey.com>
This commit is contained in:
parent
76e1721c58
commit
511368da13
@ -69,7 +69,7 @@ export interface BaseTrigger {
|
||||
|
||||
export interface StateTrigger extends BaseTrigger {
|
||||
platform: "state";
|
||||
entity_id: string;
|
||||
entity_id: string | string[];
|
||||
attribute?: string;
|
||||
from?: string | number;
|
||||
to?: string | string[] | number;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { html, LitElement, PropertyValues } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import {
|
||||
array,
|
||||
assert,
|
||||
assign,
|
||||
literal,
|
||||
@ -10,6 +11,7 @@ import {
|
||||
union,
|
||||
} from "superstruct";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { ensureArray } from "../../../../../common/ensure-array";
|
||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||
import { hasTemplate } from "../../../../../common/string/has-template";
|
||||
import { StateTrigger } from "../../../../../data/automation";
|
||||
@ -24,7 +26,7 @@ const stateTriggerStruct = assign(
|
||||
baseTriggerStruct,
|
||||
object({
|
||||
platform: literal("state"),
|
||||
entity_id: optional(string()),
|
||||
entity_id: optional(union([string(), array(string())])),
|
||||
attribute: optional(string()),
|
||||
from: optional(string()),
|
||||
to: optional(string()),
|
||||
@ -39,11 +41,15 @@ export class HaStateTrigger extends LitElement implements TriggerElement {
|
||||
@property() public trigger!: StateTrigger;
|
||||
|
||||
public static get defaultConfig() {
|
||||
return { entity_id: "" };
|
||||
return { entity_id: [] };
|
||||
}
|
||||
|
||||
private _schema = memoizeOne((entityId) => [
|
||||
{ name: "entity_id", required: true, selector: { entity: {} } },
|
||||
{
|
||||
name: "entity_id",
|
||||
required: true,
|
||||
selector: { entity: { multiple: true } },
|
||||
},
|
||||
{
|
||||
name: "attribute",
|
||||
selector: { attribute: { entity_id: entityId } },
|
||||
@ -85,7 +91,11 @@ export class HaStateTrigger extends LitElement implements TriggerElement {
|
||||
protected render() {
|
||||
const trgFor = createDurationData(this.trigger.for);
|
||||
|
||||
const data = { ...this.trigger, ...{ for: trgFor } };
|
||||
const data = {
|
||||
...this.trigger,
|
||||
entity_id: ensureArray(this.trigger.entity_id),
|
||||
for: trgFor,
|
||||
};
|
||||
const schema = this._schema(this.trigger.entity_id);
|
||||
|
||||
return html`
|
||||
|
Loading…
x
Reference in New Issue
Block a user