From 12e57dfcae9e72c6f2b94f391b7b9cf60a532dbc Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 17 Aug 2022 14:20:35 -0400 Subject: [PATCH] Allow testing describe functionality in the gallery (#13398) --- .../src/pages/automation/describe-action.ts | 34 ++++++++++++++++++- .../pages/automation/describe-condition.ts | 33 +++++++++++++++++- .../src/pages/automation/describe-trigger.ts | 29 +++++++++++++++- 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/gallery/src/pages/automation/describe-action.ts b/gallery/src/pages/automation/describe-action.ts index 49fa3dc7f9..cf8249901f 100644 --- a/gallery/src/pages/automation/describe-action.ts +++ b/gallery/src/pages/automation/describe-action.ts @@ -1,7 +1,9 @@ import { dump } from "js-yaml"; import { html, css, LitElement, TemplateResult } from "lit"; -import { customElement, property } from "lit/decorators"; +import { customElement, property, state } from "lit/decorators"; import "../../../../src/components/ha-card"; +import "../../../../src/components/ha-yaml-editor"; +import { Action } from "../../../../src/data/script"; import { describeAction } from "../../../../src/data/script_i18n"; import { getEntity } from "../../../../src/fake_data/entity"; import { provideHass } from "../../../../src/fake_data/provide_hass"; @@ -103,16 +105,38 @@ const ACTIONS = [ }, ]; +const initialAction: Action = { + service: "light.turn_on", + target: { + entity_id: "light.kitchen", + }, +}; + @customElement("demo-automation-describe-action") export class DemoAutomationDescribeAction extends LitElement { @property({ attribute: false }) hass!: HomeAssistant; + @state() _action = initialAction; + protected render(): TemplateResult { if (!this.hass) { return html``; } return html` +
+ + ${this._action + ? describeAction(this.hass, this._action) + : ""} + + +
+ ${ACTIONS.map( (conf) => html`
@@ -132,6 +156,11 @@ export class DemoAutomationDescribeAction extends LitElement { hass.addEntities(ENTITIES); } + private _dataChanged(ev: CustomEvent): void { + ev.stopPropagation(); + this._action = ev.detail.isValid ? ev.detail.value : undefined; + } + static get styles() { return css` ha-card { @@ -147,6 +176,9 @@ export class DemoAutomationDescribeAction extends LitElement { span { margin-right: 16px; } + ha-yaml-editor { + width: 50%; + } `; } } diff --git a/gallery/src/pages/automation/describe-condition.ts b/gallery/src/pages/automation/describe-condition.ts index 11de8b9781..e77a7a2af6 100644 --- a/gallery/src/pages/automation/describe-condition.ts +++ b/gallery/src/pages/automation/describe-condition.ts @@ -1,7 +1,9 @@ import { dump } from "js-yaml"; import { html, css, LitElement, TemplateResult } from "lit"; -import { customElement } from "lit/decorators"; +import { customElement, state } from "lit/decorators"; import "../../../../src/components/ha-card"; +import "../../../../src/components/ha-yaml-editor"; +import { Condition } from "../../../../src/data/automation"; import { describeCondition } from "../../../../src/data/automation_i18n"; const conditions = [ @@ -17,11 +19,32 @@ const conditions = [ { condition: "template" }, ]; +const initialCondition: Condition = { + condition: "state", + entity_id: "light.kitchen", + state: "on", +}; + @customElement("demo-automation-describe-condition") export class DemoAutomationDescribeCondition extends LitElement { + @state() _condition = initialCondition; + protected render(): TemplateResult { return html` +
+ + ${this._condition + ? describeCondition(this._condition) + : ""} + + +
+ ${conditions.map( (conf) => html`
@@ -34,6 +57,11 @@ export class DemoAutomationDescribeCondition extends LitElement { `; } + private _dataChanged(ev: CustomEvent): void { + ev.stopPropagation(); + this._condition = ev.detail.isValid ? ev.detail.value : undefined; + } + static get styles() { return css` ha-card { @@ -49,6 +77,9 @@ export class DemoAutomationDescribeCondition extends LitElement { span { margin-right: 16px; } + ha-yaml-editor { + width: 50%; + } `; } } diff --git a/gallery/src/pages/automation/describe-trigger.ts b/gallery/src/pages/automation/describe-trigger.ts index 6bfe3213c3..41b589489b 100644 --- a/gallery/src/pages/automation/describe-trigger.ts +++ b/gallery/src/pages/automation/describe-trigger.ts @@ -1,7 +1,9 @@ import { dump } from "js-yaml"; import { html, css, LitElement, TemplateResult } from "lit"; -import { customElement } from "lit/decorators"; +import { customElement, state } from "lit/decorators"; import "../../../../src/components/ha-card"; +import "../../../../src/components/ha-yaml-editor"; +import { Trigger } from "../../../../src/data/automation"; import { describeTrigger } from "../../../../src/data/automation_i18n"; const triggers = [ @@ -20,11 +22,28 @@ const triggers = [ { platform: "event" }, ]; +const initialTrigger: Trigger = { + platform: "state", + entity_id: "light.kitchen", +}; + @customElement("demo-automation-describe-trigger") export class DemoAutomationDescribeTrigger extends LitElement { + @state() _trigger = initialTrigger; + protected render(): TemplateResult { return html` +
+ + ${this._trigger ? describeTrigger(this._trigger) : ""} + + +
${triggers.map( (conf) => html`
@@ -37,6 +56,11 @@ export class DemoAutomationDescribeTrigger extends LitElement { `; } + private _dataChanged(ev: CustomEvent): void { + ev.stopPropagation(); + this._trigger = ev.detail.isValid ? ev.detail.value : undefined; + } + static get styles() { return css` ha-card { @@ -52,6 +76,9 @@ export class DemoAutomationDescribeTrigger extends LitElement { span { margin-right: 16px; } + ha-yaml-editor { + width: 50%; + } `; } }