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

Allow toggling cloud integrations #1690

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Changes from all commits
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
40 changes: 39 additions & 1 deletion 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 All @@ -142,7 +156,11 @@ class HaConfigCloudAccount extends EventsMixin(PolymerElement) {
<p><em>This integration requires a Google Assistant-enabled device like the Google Home or Android phone.</em></p>
</div>
<div class="card-actions">
<ha-call-api-button hass="[[hass]]" path="cloud/google_actions/sync">Sync devices</ha-call-api-button>
<ha-call-api-button
hass="[[hass]]"
disabled='[[!cloudStatus.google_enabled]]'
path="cloud/google_actions/sync"
>Sync devices</ha-call-api-button>
</div>
</paper-card>
</ha-config-section>
Expand Down Expand Up @@ -214,6 +232,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);