mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Make using template rendering optional when using MQTT publish from the config entry page (#14828)
This commit is contained in:
parent
d4d3a1cb65
commit
1d1ff410b2
@ -33,6 +33,9 @@ class HaPanelDevMqtt extends LitElement {
|
|||||||
@LocalStorage("panel-dev-mqtt-retain-ls", true, false)
|
@LocalStorage("panel-dev-mqtt-retain-ls", true, false)
|
||||||
private _retain = false;
|
private _retain = false;
|
||||||
|
|
||||||
|
@LocalStorage("panel-dev-mqtt-allow-template-ls", true, false)
|
||||||
|
private _allowTemplate = false;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<hass-subpage .narrow=${this.narrow} .hass=${this.hass}>
|
<hass-subpage .narrow=${this.narrow} .hass=${this.hass}>
|
||||||
@ -74,7 +77,25 @@ class HaPanelDevMqtt extends LitElement {
|
|||||||
></ha-switch>
|
></ha-switch>
|
||||||
</ha-formfield>
|
</ha-formfield>
|
||||||
</div>
|
</div>
|
||||||
<p>${this.hass.localize("ui.panel.config.mqtt.payload")}</p>
|
<p>
|
||||||
|
<ha-formfield
|
||||||
|
.label=${this.hass!.localize(
|
||||||
|
"ui.panel.config.mqtt.allow_template"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ha-switch
|
||||||
|
@change=${this._handleAllowTemplate}
|
||||||
|
.checked=${this._allowTemplate}
|
||||||
|
></ha-switch>
|
||||||
|
</ha-formfield>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
${this._allowTemplate
|
||||||
|
? this.hass.localize("ui.panel.config.mqtt.payload")
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.mqtt.payload_no_template"
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
<ha-code-editor
|
<ha-code-editor
|
||||||
mode="jinja2"
|
mode="jinja2"
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
@ -119,13 +140,18 @@ class HaPanelDevMqtt extends LitElement {
|
|||||||
this._retain = (ev.target! as any).checked;
|
this._retain = (ev.target! as any).checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleAllowTemplate(ev: CustomEvent) {
|
||||||
|
this._allowTemplate = (ev.target! as any).checked;
|
||||||
|
}
|
||||||
|
|
||||||
private _publish(): void {
|
private _publish(): void {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.hass.callService("mqtt", "publish", {
|
this.hass.callService("mqtt", "publish", {
|
||||||
topic: this._topic,
|
topic: this._topic,
|
||||||
payload_template: this._payload,
|
payload: !this._allowTemplate ? this._payload : undefined,
|
||||||
|
payload_template: this._allowTemplate ? this._payload : undefined,
|
||||||
qos: parseInt(this._qos),
|
qos: parseInt(this._qos),
|
||||||
retain: this._retain,
|
retain: this._retain,
|
||||||
});
|
});
|
||||||
|
@ -3215,6 +3215,8 @@
|
|||||||
"description_publish": "Publish a packet",
|
"description_publish": "Publish a packet",
|
||||||
"topic": "Topic",
|
"topic": "Topic",
|
||||||
"payload": "Payload (template allowed)",
|
"payload": "Payload (template allowed)",
|
||||||
|
"payload_no_template": "Payload",
|
||||||
|
"allow_template": "Allow template",
|
||||||
"publish": "Publish",
|
"publish": "Publish",
|
||||||
"description_listen": "Listen to a topic",
|
"description_listen": "Listen to a topic",
|
||||||
"json_formatting": "Format JSON content",
|
"json_formatting": "Format JSON content",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user