Skip to content

Commit

Permalink
Cloud: allow remote enable (#19691)
Browse files Browse the repository at this point in the history
* Cloud: allow remote enable

* core does this
  • Loading branch information
bramkragten authored Feb 14, 2024
1 parent 2dc9d26 commit 8136cc8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/data/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down
27 changes: 26 additions & 1 deletion src/panels/config/cloud/account/cloud-remote-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CloudStatusLoggedIn,
connectCloudRemote,
disconnectCloudRemote,
updateCloudPref,
} from "../../../../data/cloud";
import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast";
Expand All @@ -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,
Expand Down Expand Up @@ -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}>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -216,6 +238,9 @@ export class CloudRemotePref extends LitElement {
color: var(--secondary-text-color);
cursor: pointer;
}
ha-formfield {
margin-top: 8px;
}
`;
}
}
Expand Down

0 comments on commit 8136cc8

Please sign in to comment.