From 834355c22a57d5d0d895d32891f1cc6bb00b8d6e Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Fri, 25 Oct 2024 12:23:55 +0300 Subject: [PATCH 1/4] Add setting for enable/disable cloud ICE servers --- src/data/cloud.ts | 2 + .../config/cloud/account/cloud-account.ts | 6 + .../cloud/account/cloud-ice-servers-pref.ts | 106 ++++++++++++++++++ src/translations/en.json | 5 + 4 files changed, 119 insertions(+) create mode 100644 src/panels/config/cloud/account/cloud-ice-servers-pref.ts diff --git a/src/data/cloud.ts b/src/data/cloud.ts index e3d62b513bb6..0c7b16e1daf7 100644 --- a/src/data/cloud.ts +++ b/src/data/cloud.ts @@ -27,6 +27,7 @@ export interface CloudPreferences { alexa_report_state: boolean; google_report_state: boolean; tts_default_voice: [string, string]; + cloud_ice_servers_enabled: boolean; } export interface CloudStatusLoggedIn { @@ -145,6 +146,7 @@ export const updateCloudPref = ( tts_default_voice?: CloudPreferences["tts_default_voice"]; remote_allow_remote_enable?: CloudPreferences["remote_allow_remote_enable"]; strict_connection?: CloudPreferences["strict_connection"]; + cloud_ice_servers_enabled?: CloudPreferences["cloud_ice_servers_enabled"]; } ) => hass.callWS({ diff --git a/src/panels/config/cloud/account/cloud-account.ts b/src/panels/config/cloud/account/cloud-account.ts index 2d458c9c7f7d..931f4c10d098 100644 --- a/src/panels/config/cloud/account/cloud-account.ts +++ b/src/panels/config/cloud/account/cloud-account.ts @@ -25,6 +25,7 @@ import { SubscribeMixin } from "../../../../mixins/subscribe-mixin"; import { haStyle } from "../../../../resources/styles"; import { HomeAssistant } from "../../../../types"; import "../../ha-config-section"; +import "./cloud-ice-servers-pref"; import "./cloud-remote-pref"; import "./cloud-tts-pref"; import "./cloud-webhooks"; @@ -196,6 +197,11 @@ export class CloudAccount extends SubscribeMixin(LitElement) { .cloudStatus=${this.cloudStatus} > + + ${this.hass.localize( diff --git a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts new file mode 100644 index 000000000000..8b457700501c --- /dev/null +++ b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts @@ -0,0 +1,106 @@ +import { mdiHelpCircle } from "@mdi/js"; +import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; +import { customElement, property } from "lit/decorators"; +import { fireEvent } from "../../../../common/dom/fire_event"; +import "../../../../components/ha-card"; +import "../../../../components/ha-switch"; +import type { HaSwitch } from "../../../../components/ha-switch"; +import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud"; +import type { HomeAssistant } from "../../../../types"; + +@customElement("cloud-ice-servers-pref") +export class CloudICEServersPref extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @property({ attribute: false }) public cloudStatus?: CloudStatusLoggedIn; + + protected render() { + if (!this.cloudStatus) { + return nothing; + } + + const { cloud_ice_servers_enabled } = this.cloudStatus.prefs; + + return html` + + + +
+

+ ${this.hass.localize( + "ui.panel.config.cloud.account.ice_servers.info" + )} +

+
+ + `; + } + + private async _toggleCloudICEServersEnabledChanged(ev) { + const toggle = ev.target as HaSwitch; + + try { + await updateCloudPref(this.hass, { + cloud_ice_servers_enabled: toggle.checked, + }); + fireEvent(this, "ha-refresh-cloud-status"); + } catch (err: any) { + alert(err.message); + toggle.checked = !toggle.checked; + } + } + + static get styles(): CSSResultGroup { + return css` + a { + color: var(--primary-color); + } + .header-actions { + position: absolute; + right: 16px; + inset-inline-end: 16px; + inset-inline-start: initial; + top: 24px; + display: flex; + flex-direction: row; + } + .header-actions .icon-link { + margin-top: -16px; + margin-right: 8px; + margin-inline-end: 8px; + margin-inline-start: initial; + direction: var(--direction); + color: var(--secondary-text-color); + } + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "cloud-ice-servers-pref": CloudICEServersPref; + } +} diff --git a/src/translations/en.json b/src/translations/en.json index ce5d7ee5e829..d811d3cda14e 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3922,6 +3922,11 @@ "certificate_expire": "Certificate renewal at {date}", "more_info": "More details" }, + "ice_servers": { + "title": "Cloud WebRTC ICE servers", + "info": "Do you want to use Home Assistant Cloud for WebRTC connections? Enable this option to use the Home Assistant Cloud WebRTC ICE servers.", + "link_learn_how_it_works": "Learn how it works" + }, "alexa": { "title": "Alexa", "info": "With the Alexa integration for Home Assistant Cloud you'll be able to control all your Home Assistant devices via any Alexa-enabled device.", From dbe9d88782f617951f0a5677b7d57f0c7b6b3a39 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Wed, 30 Oct 2024 13:42:18 +0200 Subject: [PATCH 2/4] Fix copytexts, feature URL, refactor variable --- src/panels/config/cloud/account/cloud-ice-servers-pref.ts | 7 ++++--- src/translations/en.json | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts index 8b457700501c..d6be05414130 100644 --- a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts +++ b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts @@ -19,7 +19,8 @@ export class CloudICEServersPref extends LitElement { return nothing; } - const { cloud_ice_servers_enabled } = this.cloudStatus.prefs; + const { cloud_ice_servers_enabled: cloudICEServersEnabled } = + this.cloudStatus.prefs; return html` diff --git a/src/translations/en.json b/src/translations/en.json index 4f4ac7d9253e..db5e1e046443 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3930,8 +3930,8 @@ "more_info": "More details" }, "ice_servers": { - "title": "Cloud WebRTC ICE servers", - "info": "Do you want to use Home Assistant Cloud for WebRTC connections? Enable this option to use the Home Assistant Cloud WebRTC ICE servers.", + "title": "WebRTC connections", + "info": "Home Assistant Cloud provides WebRTC servers. This improves your ability to view your camera streams when you are away from home.", "link_learn_how_it_works": "Learn how it works" }, "alexa": { From eafdba8bfd99c1144c0f48ac2bf67e392fbb3542 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 30 Oct 2024 14:07:12 +0100 Subject: [PATCH 3/4] imports --- src/panels/config/cloud/account/cloud-ice-servers-pref.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts index d6be05414130..8b9349b16a24 100644 --- a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts +++ b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts @@ -1,11 +1,14 @@ import { mdiHelpCircle } from "@mdi/js"; -import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; +import type { CSSResultGroup } from "lit"; +import { LitElement, css, html, nothing } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-card"; +import "../../../../components/ha-icon-button"; import "../../../../components/ha-switch"; import type { HaSwitch } from "../../../../components/ha-switch"; -import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud"; +import type { CloudStatusLoggedIn } from "../../../../data/cloud"; +import { updateCloudPref } from "../../../../data/cloud"; import type { HomeAssistant } from "../../../../types"; @customElement("cloud-ice-servers-pref") From 83e9dff438075b5595102d1266e78a5346f2254b Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 30 Oct 2024 14:52:39 +0100 Subject: [PATCH 4/4] Use toast instead of alert --- src/panels/config/cloud/account/cloud-ice-servers-pref.ts | 3 ++- src/panels/config/cloud/account/cloud-remote-pref.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts index 8b9349b16a24..76fc62ac225c 100644 --- a/src/panels/config/cloud/account/cloud-ice-servers-pref.ts +++ b/src/panels/config/cloud/account/cloud-ice-servers-pref.ts @@ -10,6 +10,7 @@ import type { HaSwitch } from "../../../../components/ha-switch"; import type { CloudStatusLoggedIn } from "../../../../data/cloud"; import { updateCloudPref } from "../../../../data/cloud"; import type { HomeAssistant } from "../../../../types"; +import { showToast } from "../../../../util/toast"; @customElement("cloud-ice-servers-pref") export class CloudICEServersPref extends LitElement { @@ -72,7 +73,7 @@ export class CloudICEServersPref extends LitElement { }); fireEvent(this, "ha-refresh-cloud-status"); } catch (err: any) { - alert(err.message); + showToast(this, { message: err.message }); toggle.checked = !toggle.checked; } } diff --git a/src/panels/config/cloud/account/cloud-remote-pref.ts b/src/panels/config/cloud/account/cloud-remote-pref.ts index baace154bd14..3bf946b05734 100644 --- a/src/panels/config/cloud/account/cloud-remote-pref.ts +++ b/src/panels/config/cloud/account/cloud-remote-pref.ts @@ -250,7 +250,7 @@ export class CloudRemotePref extends LitElement { } fireEvent(this, "ha-refresh-cloud-status"); } catch (err: any) { - alert(err.message); + showToast(this, { message: err.message }); toggle.checked = !toggle.checked; } } @@ -264,7 +264,7 @@ export class CloudRemotePref extends LitElement { }); fireEvent(this, "ha-refresh-cloud-status"); } catch (err: any) { - alert(err.message); + showToast(this, { message: err.message }); toggle.checked = !toggle.checked; } }