From 7e12f161990df70b6fd1589f123643829af5db78 Mon Sep 17 00:00:00 2001 From: karwosts Date: Sat, 29 Jun 2024 08:56:13 -0700 Subject: [PATCH 1/3] Button to copy service response as json for templates --- src/components/ha-yaml-editor.ts | 1 + .../service/developer-tools-service.ts | 20 ++++++++++++++++++- src/translations/en.json | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/ha-yaml-editor.ts b/src/components/ha-yaml-editor.ts index 882a12cd73a3..84f4ae5550e1 100644 --- a/src/components/ha-yaml-editor.ts +++ b/src/components/ha-yaml-editor.ts @@ -107,6 +107,7 @@ export class HaYamlEditor extends LitElement { "ui.components.yaml-editor.copy_to_clipboard" )} + ` : nothing} `; diff --git a/src/panels/developer-tools/service/developer-tools-service.ts b/src/panels/developer-tools/service/developer-tools-service.ts index fb5f374f21d2..93bf962c6b36 100644 --- a/src/panels/developer-tools/service/developer-tools-service.ts +++ b/src/panels/developer-tools/service/developer-tools-service.ts @@ -11,10 +11,13 @@ import { hasTemplate } from "../../../common/string/has-template"; import { extractSearchParam } from "../../../common/url/search-params"; import { HaProgressButton } from "../../../components/buttons/ha-progress-button"; import { LocalizeFunc } from "../../../common/translations/localize"; +import { showToast } from "../../../util/toast"; +import { copyToClipboard } from "../../../common/util/copy-clipboard"; import "../../../components/entity/ha-entity-picker"; import "../../../components/ha-card"; import "../../../components/ha-alert"; +import "../../../components/ha-button"; import "../../../components/ha-expansion-panel"; import "../../../components/ha-icon-button"; import "../../../components/ha-service-control"; @@ -189,7 +192,13 @@ class HaPanelDevService extends LitElement { readOnly autoUpdate .value=${this._response} - > + > + ${this.hass.localize( + "ui.panel.developer-tools.tabs.services.copy_clipboard_template" + )} + ` @@ -291,6 +300,15 @@ class HaPanelDevService extends LitElement { `; } + private async _copyTemplate(): Promise { + await copyToClipboard( + `{% set service_response = ${JSON.stringify(this._response)} %}` + ); + showToast(this, { + message: this.hass.localize("ui.common.copied_clipboard"), + }); + } + private _filterSelectorFields = memoizeOne((fields) => fields.filter((field) => !field.selector) ); diff --git a/src/translations/en.json b/src/translations/en.json index 822152b2214e..1b71dec0c8b8 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -6689,6 +6689,7 @@ "all_parameters": "All available parameters", "accepts_target": "This service accepts a target, for example: `entity_id: light.bed_light`", "no_template_ui_support": "The UI does not support templates, you can still use the YAML editor.", + "copy_clipboard_template": "Copy to clipboard (template)", "errors": { "ui": { "no_service": "No service selected, please select a service", From e059272fc8caee6246030c200a780a049e6cec8b Mon Sep 17 00:00:00 2001 From: karwosts Date: Sat, 13 Jul 2024 08:47:33 -0700 Subject: [PATCH 2/3] service -> action --- src/panels/developer-tools/action/developer-tools-action.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/panels/developer-tools/action/developer-tools-action.ts b/src/panels/developer-tools/action/developer-tools-action.ts index 5e2991017565..a18bfa2e5720 100644 --- a/src/panels/developer-tools/action/developer-tools-action.ts +++ b/src/panels/developer-tools/action/developer-tools-action.ts @@ -196,7 +196,7 @@ class HaPanelDevAction extends LitElement { > ${this.hass.localize( - "ui.panel.developer-tools.tabs.services.copy_clipboard_template" + "ui.panel.developer-tools.tabs.actions.copy_clipboard_template" )} @@ -303,7 +303,7 @@ class HaPanelDevAction extends LitElement { private async _copyTemplate(): Promise { await copyToClipboard( - `{% set service_response = ${JSON.stringify(this._response)} %}` + `{% set action_response = ${JSON.stringify(this._response)} %}` ); showToast(this, { message: this.hass.localize("ui.common.copied_clipboard"), From b8096bee2eb5b6985aff09b37985d2760d5633a3 Mon Sep 17 00:00:00 2001 From: karwosts Date: Fri, 19 Jul 2024 09:43:18 -0700 Subject: [PATCH 3/3] update --- src/components/ha-yaml-editor.ts | 16 ++++++++++------ .../action/developer-tools-action.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/ha-yaml-editor.ts b/src/components/ha-yaml-editor.ts index 84f4ae5550e1..0d9d2c4b85c3 100644 --- a/src/components/ha-yaml-editor.ts +++ b/src/components/ha-yaml-editor.ts @@ -49,6 +49,8 @@ export class HaYamlEditor extends LitElement { @property({ type: Boolean }) public copyClipboard = false; + @property({ type: Boolean }) public hasExtraActions = false; + @state() private _yaml = ""; public setValue(value): void { @@ -100,13 +102,15 @@ export class HaYamlEditor extends LitElement { @value-changed=${this._onChange} dir="ltr" > - ${this.copyClipboard + ${this.copyClipboard || this.hasExtraActions ? html`
- - ${this.hass.localize( - "ui.components.yaml-editor.copy_to_clipboard" - )} - + ${this.copyClipboard + ? html` + ${this.hass.localize( + "ui.components.yaml-editor.copy_to_clipboard" + )} + ` + : nothing}
` : nothing} diff --git a/src/panels/developer-tools/action/developer-tools-action.ts b/src/panels/developer-tools/action/developer-tools-action.ts index a18bfa2e5720..2bbb69d5bf07 100644 --- a/src/panels/developer-tools/action/developer-tools-action.ts +++ b/src/panels/developer-tools/action/developer-tools-action.ts @@ -192,6 +192,7 @@ class HaPanelDevAction extends LitElement { copyClipboard readOnly autoUpdate + hasExtraActions .value=${this._response} >