Cloud: allow remote enable (#19691)

* Cloud: allow remote enable

* core does this
This commit is contained in:
Bram Kragten 2024-02-14 15:05:18 +01:00 committed by GitHub
parent 2dc9d268ec
commit 8136cc8008
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -18,6 +18,7 @@ export interface CloudPreferences {
google_enabled: boolean;
alexa_enabled: boolean;
remote_enabled: boolean;
remote_allow_remote_enable: boolean;
google_secure_devices_pin: string | undefined;
cloudhooks: { [webhookId: string]: CloudWebhook };
alexa_report_state: boolean;
@ -139,6 +140,7 @@ export const updateCloudPref = (
google_report_state?: CloudPreferences["google_report_state"];
google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"];
tts_default_voice?: CloudPreferences["tts_default_voice"];
remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"];
}
) =>
hass.callWS({

View File

@ -13,6 +13,7 @@ import {
CloudStatusLoggedIn,
connectCloudRemote,
disconnectCloudRemote,
updateCloudPref,
} from "../../../../data/cloud";
import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast";
@ -29,7 +30,8 @@ export class CloudRemotePref extends LitElement {
return nothing;
}
const { remote_enabled } = this.cloudStatus.prefs;
const { remote_enabled, remote_allow_remote_enable } =
this.cloudStatus.prefs;
const {
remote_connected,
@ -126,6 +128,12 @@ export class CloudRemotePref extends LitElement {
.path=${mdiContentCopy}
@click=${this._copyURL}
></ha-svg-icon>
<ha-formfield .label=${"Allow external activation"}>
<ha-switch
.checked=${remote_allow_remote_enable}
@change=${this._toggleAllowRemoteEnabledChanged}
></ha-switch>
</ha-formfield>
</div>
<div class="card-actions">
<mwc-button @click=${this._openCertInfo}>
@ -160,6 +168,20 @@ export class CloudRemotePref extends LitElement {
}
}
private async _toggleAllowRemoteEnabledChanged(ev) {
const toggle = ev.target as HaSwitch;
try {
await updateCloudPref(this.hass, {
remote_allow_remote_enable: toggle.checked,
});
fireEvent(this, "ha-refresh-cloud-status");
} catch (err: any) {
alert(err.message);
toggle.checked = !toggle.checked;
}
}
private async _copyURL(ev): Promise<void> {
const url = ev.currentTarget.url;
await copyToClipboard(url);
@ -216,6 +238,9 @@ export class CloudRemotePref extends LitElement {
color: var(--secondary-text-color);
cursor: pointer;
}
ha-formfield {
margin-top: 8px;
}
`;
}
}