Use _ prefix for local vars on MQTT config entry page (#14898)

This commit is contained in:
Jan Bouwhuis 2022-12-28 11:22:40 +01:00 committed by GitHub
parent 81e3652446
commit d4d3a1cb65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,16 +22,16 @@ class HaPanelDevMqtt extends LitElement {
@property({ type: Boolean }) public narrow!: boolean; @property({ type: Boolean }) public narrow!: boolean;
@LocalStorage("panel-dev-mqtt-topic-ls", true, false) @LocalStorage("panel-dev-mqtt-topic-ls", true, false)
private topic = ""; private _topic = "";
@LocalStorage("panel-dev-mqtt-payload-ls", true, false) @LocalStorage("panel-dev-mqtt-payload-ls", true, false)
private payload = ""; private _payload = "";
@LocalStorage("panel-dev-mqtt-qos-ls", true, false) @LocalStorage("panel-dev-mqtt-qos-ls", true, false)
private qos = "0"; private _qos = "0";
@LocalStorage("panel-dev-mqtt-retain-ls", true, false) @LocalStorage("panel-dev-mqtt-retain-ls", true, false)
private retain = false; private _retain = false;
protected render(): TemplateResult { protected render(): TemplateResult {
return html` return html`
@ -53,12 +53,12 @@ class HaPanelDevMqtt extends LitElement {
<div class="panel-dev-mqtt-fields"> <div class="panel-dev-mqtt-fields">
<ha-textfield <ha-textfield
.label=${this.hass.localize("ui.panel.config.mqtt.topic")} .label=${this.hass.localize("ui.panel.config.mqtt.topic")}
.value=${this.topic} .value=${this._topic}
@change=${this._handleTopic} @change=${this._handleTopic}
></ha-textfield> ></ha-textfield>
<ha-select <ha-select
.label=${this.hass.localize("ui.panel.config.mqtt.qos")} .label=${this.hass.localize("ui.panel.config.mqtt.qos")}
.value=${this.qos} .value=${this._qos}
@selected=${this._handleQos} @selected=${this._handleQos}
>${qosLevel.map( >${qosLevel.map(
(qos) => (qos) =>
@ -70,7 +70,7 @@ class HaPanelDevMqtt extends LitElement {
> >
<ha-switch <ha-switch
@change=${this._handleRetain} @change=${this._handleRetain}
.checked=${this.retain} .checked=${this._retain}
></ha-switch> ></ha-switch>
</ha-formfield> </ha-formfield>
</div> </div>
@ -80,7 +80,7 @@ class HaPanelDevMqtt extends LitElement {
autocomplete-entities autocomplete-entities
autocomplete-icons autocomplete-icons
.hass=${this.hass} .hass=${this.hass}
.value=${this.payload} .value=${this._payload}
@value-changed=${this._handlePayload} @value-changed=${this._handlePayload}
dir="ltr" dir="ltr"
></ha-code-editor> ></ha-code-editor>
@ -101,22 +101,22 @@ class HaPanelDevMqtt extends LitElement {
} }
private _handleTopic(ev: CustomEvent) { private _handleTopic(ev: CustomEvent) {
this.topic = (ev.target! as any).value; this._topic = (ev.target! as any).value;
} }
private _handlePayload(ev: CustomEvent) { private _handlePayload(ev: CustomEvent) {
this.payload = ev.detail.value; this._payload = ev.detail.value;
} }
private _handleQos(ev: CustomEvent) { private _handleQos(ev: CustomEvent) {
const newValue = (ev.target! as any).value; const newValue = (ev.target! as any).value;
if (newValue >= 0 && newValue !== this.qos) { if (newValue >= 0 && newValue !== this._qos) {
this.qos = newValue; this._qos = newValue;
} }
} }
private _handleRetain(ev: CustomEvent) { private _handleRetain(ev: CustomEvent) {
this.retain = (ev.target! as any).checked; this._retain = (ev.target! as any).checked;
} }
private _publish(): void { private _publish(): void {
@ -124,10 +124,10 @@ class HaPanelDevMqtt extends LitElement {
return; return;
} }
this.hass.callService("mqtt", "publish", { this.hass.callService("mqtt", "publish", {
topic: this.topic, topic: this._topic,
payload_template: this.payload, payload_template: this._payload,
qos: parseInt(this.qos), qos: parseInt(this._qos),
retain: this.retain, retain: this._retain,
}); });
} }