mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 05:16:34 +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) =>
|
export const fetchCloudAlexaEntities = (hass: HomeAssistant) =>
|
||||||
hass.callWS<AlexaEntity[]>({ type: "cloud/alexa/entities" });
|
hass.callWS<AlexaEntity[]>({ type: "cloud/alexa/entities" });
|
||||||
|
|
||||||
|
export const syncCloudAlexaEntities = (hass: HomeAssistant) =>
|
||||||
|
hass.callWS({ type: "cloud/alexa/sync" });
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
html,
|
html,
|
||||||
LitElement,
|
LitElement,
|
||||||
PropertyDeclarations,
|
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
css,
|
css,
|
||||||
|
property,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import "@polymer/paper-toggle-button/paper-toggle-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 { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud";
|
import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud";
|
||||||
|
import { syncCloudAlexaEntities } from "../../../../data/alexa";
|
||||||
|
|
||||||
export class CloudAlexaPref extends LitElement {
|
export class CloudAlexaPref extends LitElement {
|
||||||
public hass?: HomeAssistant;
|
@property() public hass?: HomeAssistant;
|
||||||
public cloudStatus?: CloudStatusLoggedIn;
|
@property() public cloudStatus?: CloudStatusLoggedIn;
|
||||||
|
@property() private _syncing = false;
|
||||||
static get properties(): PropertyDeclarations {
|
|
||||||
return {
|
|
||||||
hass: {},
|
|
||||||
cloudStatus: {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult | void {
|
protected render(): TemplateResult | void {
|
||||||
if (!this.cloudStatus) {
|
if (!this.cloudStatus) {
|
||||||
@ -79,6 +74,9 @@ export class CloudAlexaPref extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
|
<mwc-button @click=${this._handleSync} .disabled=${this._syncing}>
|
||||||
|
Sync Entities
|
||||||
|
</mwc-button>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<a href="/config/cloud/alexa">
|
<a href="/config/cloud/alexa">
|
||||||
<mwc-button>Manage Entities</mwc-button>
|
<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) {
|
private async _enabledToggleChanged(ev) {
|
||||||
const toggle = ev.target as PaperToggleButtonElement;
|
const toggle = ev.target as PaperToggleButtonElement;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user