Add button for Alexa to sync entities (#3284)

* Add button for Alexa to sync entities

* Lint
This commit is contained in:
Paulus Schoutsen 2019-06-19 11:43:17 -07:00 committed by GitHub
parent 83889a8fd7
commit 90f0d9fa00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -8,3 +8,6 @@ export interface AlexaEntity {
export const fetchCloudAlexaEntities = (hass: HomeAssistant) =>
hass.callWS<AlexaEntity[]>({ type: "cloud/alexa/entities" });
export const syncCloudAlexaEntities = (hass: HomeAssistant) =>
hass.callWS({ type: "cloud/alexa/sync" });

View File

@ -1,10 +1,10 @@
import {
html,
LitElement,
PropertyDeclarations,
TemplateResult,
CSSResult,
css,
property,
} from "lit-element";
import "@material/mwc-button";
import "@polymer/paper-toggle-button/paper-toggle-button";
@ -16,17 +16,12 @@ import "../../../../components/ha-card";
import { fireEvent } from "../../../../common/dom/fire_event";
import { HomeAssistant } from "../../../../types";
import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud";
import { syncCloudAlexaEntities } from "../../../../data/alexa";
export class CloudAlexaPref extends LitElement {
public hass?: HomeAssistant;
public cloudStatus?: CloudStatusLoggedIn;
static get properties(): PropertyDeclarations {
return {
hass: {},
cloudStatus: {},
};
}
@property() public hass?: HomeAssistant;
@property() public cloudStatus?: CloudStatusLoggedIn;
@property() private _syncing = false;
protected render(): TemplateResult | void {
if (!this.cloudStatus) {
@ -79,6 +74,9 @@ export class CloudAlexaPref extends LitElement {
: ""}
</div>
<div class="card-actions">
<mwc-button @click=${this._handleSync} .disabled=${this._syncing}>
Sync Entities
</mwc-button>
<div class="spacer"></div>
<a href="/config/cloud/alexa">
<mwc-button>Manage Entities</mwc-button>
@ -88,6 +86,17 @@ export class CloudAlexaPref extends LitElement {
`;
}
private async _handleSync() {
this._syncing = true;
try {
await syncCloudAlexaEntities(this.hass!);
} catch (err) {
alert(`Failed to sync entities: ${err.body.message}`);
} finally {
this._syncing = false;
}
}
private async _enabledToggleChanged(ev) {
const toggle = ev.target as PaperToggleButtonElement;
try {