From 8136cc8008d4e261cc39ca57e0a841b7f5d1983a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 14 Feb 2024 15:05:18 +0100 Subject: [PATCH] Cloud: allow remote enable (#19691) * Cloud: allow remote enable * core does this --- src/data/cloud.ts | 2 ++ .../config/cloud/account/cloud-remote-pref.ts | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/data/cloud.ts b/src/data/cloud.ts index b498428f9a21..c732b2a65f54 100644 --- a/src/data/cloud.ts +++ b/src/data/cloud.ts @@ -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({ diff --git a/src/panels/config/cloud/account/cloud-remote-pref.ts b/src/panels/config/cloud/account/cloud-remote-pref.ts index bcfb4bdde797..b74e94dce372 100644 --- a/src/panels/config/cloud/account/cloud-remote-pref.ts +++ b/src/panels/config/cloud/account/cloud-remote-pref.ts @@ -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} > + + +
@@ -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 { 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; + } `; } }