2021-03-29 09:47:04 +02:00
|
|
|
import "@material/mwc-button/mwc-button";
|
2021-05-18 16:37:53 +02:00
|
|
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|
|
|
import { customElement, property, state } from "lit/decorators";
|
2021-03-29 09:47:04 +02:00
|
|
|
import { fireEvent } from "../common/dom/fire_event";
|
|
|
|
import { LocalizeFunc } from "../common/translations/localize";
|
|
|
|
import "../components/ha-analytics";
|
2021-04-07 03:48:10 +02:00
|
|
|
import { analyticsLearnMore } from "../components/ha-analytics-learn-more";
|
|
|
|
import { Analytics, setAnalyticsPreferences } from "../data/analytics";
|
2021-03-29 09:47:04 +02:00
|
|
|
import { onboardAnalyticsStep } from "../data/onboarding";
|
|
|
|
import type { HomeAssistant } from "../types";
|
|
|
|
|
|
|
|
@customElement("onboarding-analytics")
|
|
|
|
class OnboardingAnalytics extends LitElement {
|
|
|
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
|
|
|
|
|
|
|
@property() public localize!: LocalizeFunc;
|
|
|
|
|
2021-05-07 22:16:14 +02:00
|
|
|
@state() private _error?: string;
|
2021-03-29 09:47:04 +02:00
|
|
|
|
2021-05-07 22:16:14 +02:00
|
|
|
@state() private _analyticsDetails: Analytics = {
|
2021-04-07 03:48:10 +02:00
|
|
|
preferences: {},
|
|
|
|
};
|
2021-03-29 09:47:04 +02:00
|
|
|
|
|
|
|
protected render(): TemplateResult {
|
|
|
|
return html`
|
|
|
|
<p>
|
2021-04-27 22:44:28 +02:00
|
|
|
Share anonymized information from your installation to help make Home
|
|
|
|
Assistant better and help us convince manufacturers to add local control
|
|
|
|
and privacy-focused features.
|
2021-03-29 09:47:04 +02:00
|
|
|
</p>
|
|
|
|
<ha-analytics
|
|
|
|
@analytics-preferences-changed=${this._preferencesChanged}
|
|
|
|
.hass=${this.hass}
|
|
|
|
.analytics=${this._analyticsDetails}
|
|
|
|
>
|
|
|
|
</ha-analytics>
|
|
|
|
${this._error ? html`<div class="error">${this._error}</div>` : ""}
|
|
|
|
<div class="footer">
|
2021-04-07 03:48:10 +02:00
|
|
|
<mwc-button @click=${this._save} .disabled=${!this._analyticsDetails}>
|
2021-03-29 09:47:04 +02:00
|
|
|
${this.localize("ui.panel.page-onboarding.analytics.finish")}
|
|
|
|
</mwc-button>
|
2021-04-07 03:48:10 +02:00
|
|
|
${analyticsLearnMore(this.hass)}
|
2021-03-29 09:47:04 +02:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected firstUpdated(changedProps) {
|
|
|
|
super.firstUpdated(changedProps);
|
|
|
|
this.addEventListener("keypress", (ev) => {
|
|
|
|
if (ev.keyCode === 13) {
|
|
|
|
this._save(ev);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private _preferencesChanged(event: CustomEvent): void {
|
|
|
|
this._analyticsDetails = {
|
|
|
|
...this._analyticsDetails!,
|
|
|
|
preferences: event.detail.preferences,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private async _save(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
try {
|
|
|
|
await setAnalyticsPreferences(
|
|
|
|
this.hass,
|
|
|
|
this._analyticsDetails!.preferences
|
|
|
|
);
|
|
|
|
|
|
|
|
await onboardAnalyticsStep(this.hass);
|
|
|
|
fireEvent(this, "onboarding-step", {
|
|
|
|
type: "analytics",
|
|
|
|
});
|
2021-09-30 12:39:03 +02:00
|
|
|
} catch (err: any) {
|
2021-03-29 09:47:04 +02:00
|
|
|
alert(`Failed to save: ${err.message}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 22:16:14 +02:00
|
|
|
static get styles(): CSSResultGroup {
|
2021-03-29 09:47:04 +02:00
|
|
|
return css`
|
|
|
|
.error {
|
|
|
|
color: var(--error-color);
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
margin-top: 16px;
|
2021-04-07 03:48:10 +02:00
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
flex-direction: row-reverse;
|
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
color: var(--primary-color);
|
2021-03-29 09:47:04 +02:00
|
|
|
}
|
|
|
|
`;
|
2021-04-07 03:48:10 +02:00
|
|
|
|
|
|
|
// footer is direction reverse to tab to "NEXT" first
|
2021-03-29 09:47:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
"onboarding-analytics": OnboardingAnalytics;
|
|
|
|
}
|
|
|
|
}
|