Skip to content

Commit

Permalink
Allow toggling cloud integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Sep 20, 2018
1 parent 8dc202a commit 8857274
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/panels/config/cloud/ha-config-cloud-account.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@polymer/paper-button/paper-button.js';
import '@polymer/paper-card/paper-card.js';
import '@polymer/paper-item/paper-item-body.js';
import '@polymer/paper-toggle-button/paper-toggle-button.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';

Expand Down Expand Up @@ -61,6 +62,11 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {
a {
color: var(--primary-color);
}
paper-card > paper-toggle-button {
position: absolute;
right: 8px;
top: 16px;
}
</style>
<hass-subpage header="Home Assistant Cloud">
<div class="content">
Expand Down Expand Up @@ -108,6 +114,10 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {
</div>
<paper-card heading="Alexa">
<paper-toggle-button
checked='[[cloudStatus.alexa_enabled]]'
on-change='_alexaChanged'
></paper-toggle-button>
<div class="card-content">
With the Alexa integration for Home Assistant Cloud you'll be able to control all your Home Assistant devices via any Alexa-enabled device.
<ul>
Expand All @@ -125,6 +135,10 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {
</paper-card>
<paper-card heading="Google Assistant">
<paper-toggle-button
checked='[[cloudStatus.google_enabled]]'
on-change='_googleChanged'
></paper-toggle-button>
<div class="card-content">
With the Google Assistant integration for Home Assistant Cloud you'll be able to control all your Home Assistant devices via any Google Assistant-enabled device.
<ul>
Expand Down Expand Up @@ -214,6 +228,26 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {

return 'Unable to determine subscription status.';
}

_alexaChanged(ev) {
this._handleToggleChange('alexa_enabled', ev.target);
}

_googleChanged(ev) {
this._handleToggleChange('google_enabled', ev.target);
}

async _handleToggleChange(property, element) {
try {
await this.hass.callWS({
type: 'cloud/update_prefs',
[property]: element.checked,
});
this.fire('ha-refresh-cloud-status');
} catch (err) {
element.checked = !element.checked;
}
}
}

customElements.define('ha-config-cloud-account', HaConfigCloudAccount);

0 comments on commit 8857274

Please sign in to comment.