mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +00:00
Add Alexa report state (#3272)
This commit is contained in:
parent
a9cac343b0
commit
1add5077af
@ -35,6 +35,7 @@ export interface CloudPreferences {
|
||||
alexa_entity_configs: {
|
||||
[entityId: string]: AlexaEntityConfig;
|
||||
};
|
||||
alexa_report_state: boolean;
|
||||
}
|
||||
|
||||
export type CloudStatusLoggedIn = CloudStatusBase & {
|
||||
@ -42,7 +43,6 @@ export type CloudStatusLoggedIn = CloudStatusBase & {
|
||||
google_entities: EntityFilter;
|
||||
google_domains: string[];
|
||||
alexa_entities: EntityFilter;
|
||||
alexa_domains: string[];
|
||||
prefs: CloudPreferences;
|
||||
remote_domain: string | undefined;
|
||||
remote_connected: boolean;
|
||||
@ -95,6 +95,7 @@ export const updateCloudPref = (
|
||||
prefs: {
|
||||
google_enabled?: CloudPreferences["google_enabled"];
|
||||
alexa_enabled?: CloudPreferences["alexa_enabled"];
|
||||
alexa_report_state?: CloudPreferences["alexa_report_state"];
|
||||
google_secure_devices_pin?: CloudPreferences["google_secure_devices_pin"];
|
||||
}
|
||||
) =>
|
||||
|
@ -33,13 +33,13 @@ export class CloudAlexaPref extends LitElement {
|
||||
return html``;
|
||||
}
|
||||
|
||||
const enabled = this.cloudStatus!.prefs.alexa_enabled;
|
||||
const { alexa_enabled, alexa_report_state } = this.cloudStatus!.prefs;
|
||||
|
||||
return html`
|
||||
<ha-card header="Alexa">
|
||||
<paper-toggle-button
|
||||
.checked="${enabled}"
|
||||
@change="${this._toggleChanged}"
|
||||
.checked=${alexa_enabled}
|
||||
@change=${this._enabledToggleChanged}
|
||||
></paper-toggle-button>
|
||||
<div class="card-content">
|
||||
With the Alexa integration for Home Assistant Cloud you'll be able to
|
||||
@ -62,6 +62,21 @@ export class CloudAlexaPref extends LitElement {
|
||||
>This integration requires an Alexa-enabled device like the Amazon
|
||||
Echo.</em
|
||||
>
|
||||
${alexa_enabled
|
||||
? html`
|
||||
<h3>Enable State Reporting</h3>
|
||||
<p>
|
||||
If you enable state reporting, Home Assistant will sent
|
||||
<b>all</b> state changes of exposed entities to Amazon. This
|
||||
allows you to always see the latest states in the Alexa app
|
||||
and use the state changes to create routines.
|
||||
</p>
|
||||
<paper-toggle-button
|
||||
.checked=${alexa_report_state}
|
||||
@change=${this._reportToggleChanged}
|
||||
></paper-toggle-button>
|
||||
`
|
||||
: ""}
|
||||
</div>
|
||||
<div class="card-actions">
|
||||
<div class="spacer"></div>
|
||||
@ -73,7 +88,7 @@ export class CloudAlexaPref extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private async _toggleChanged(ev) {
|
||||
private async _enabledToggleChanged(ev) {
|
||||
const toggle = ev.target as PaperToggleButtonElement;
|
||||
try {
|
||||
await updateCloudPref(this.hass!, { alexa_enabled: toggle.checked! });
|
||||
@ -83,6 +98,18 @@ export class CloudAlexaPref extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private async _reportToggleChanged(ev) {
|
||||
const toggle = ev.target as PaperToggleButtonElement;
|
||||
try {
|
||||
await updateCloudPref(this.hass!, {
|
||||
alexa_report_state: toggle.checked!,
|
||||
});
|
||||
fireEvent(this, "ha-refresh-cloud-status");
|
||||
} catch (err) {
|
||||
toggle.checked = !toggle.checked;
|
||||
}
|
||||
}
|
||||
|
||||
static get styles(): CSSResult {
|
||||
return css`
|
||||
a {
|
||||
@ -103,6 +130,12 @@ export class CloudAlexaPref extends LitElement {
|
||||
.spacer {
|
||||
flex-grow: 1;
|
||||
}
|
||||
h3 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
h3 + p {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user