Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for enableing/disabling cloud ICE servers #22527

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/data/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions src/panels/config/cloud/account/cloud-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -196,6 +197,11 @@ export class CloudAccount extends SubscribeMixin(LitElement) {
.cloudStatus=${this.cloudStatus}
></cloud-tts-pref>

<cloud-ice-servers-pref
.hass=${this.hass}
.cloudStatus=${this.cloudStatus}
></cloud-ice-servers-pref>

<ha-tip .hass=${this.hass}>
<a href="/config/voice-assistants">
${this.hass.localize(
Expand Down
106 changes: 106 additions & 0 deletions src/panels/config/cloud/account/cloud-ice-servers-pref.ts
Original file line number Diff line number Diff line change
@@ -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;
klejejs marked this conversation as resolved.
Show resolved Hide resolved

return html`
<ha-card
outlined
header=${this.hass.localize(
"ui.panel.config.cloud.account.ice_servers.title"
)}
>
<div class="header-actions">
<a
href="https://www.nabucasa.com/config/"
klejejs marked this conversation as resolved.
Show resolved Hide resolved
target="_blank"
rel="noreferrer"
class="icon-link"
>
<ha-icon-button
.label=${this.hass.localize(
"ui.panel.config.cloud.account.ice_servers.link_learn_how_it_works"
)}
.path=${mdiHelpCircle}
></ha-icon-button>
</a>
<ha-switch
.checked=${cloud_ice_servers_enabled}
@change=${this._toggleCloudICEServersEnabledChanged}
></ha-switch>
</div>

<div class="card-content">
<p>
${this.hass.localize(
"ui.panel.config.cloud.account.ice_servers.info"
)}
</p>
</div>
</ha-card>
`;
}

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically use these kind of alerts but handle it properly in the UI.

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;
}
}
5 changes: 5 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
bramkragten marked this conversation as resolved.
Show resolved Hide resolved
"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.",
Expand Down
Loading