mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 13:57:21 +00:00
Add button for Alexa to sync entities (#3284)
* Add button for Alexa to sync entities * Lint
This commit is contained in:
parent
83889a8fd7
commit
90f0d9fa00
@ -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" });
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user