Skip to content

Commit e65a8a6

Browse files
Add device database toggle to analytics (#27948)
Co-authored-by: Petar Petrov <[email protected]>
1 parent 318452d commit e65a8a6

File tree

3 files changed

+101
-42
lines changed

3 files changed

+101
-42
lines changed

src/data/analytics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface AnalyticsPreferences {
55
diagnostics?: boolean;
66
usage?: boolean;
77
statistics?: boolean;
8+
snapshots?: boolean;
89
}
910

1011
export interface Analytics {

src/panels/config/core/ha-config-analytics.ts

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { mdiOpenInNew } from "@mdi/js";
21
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
3-
import { css, html, LitElement } from "lit";
2+
import { css, html, LitElement, nothing } from "lit";
43
import { customElement, property, state } from "lit/decorators";
54
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
65
import "../../../components/ha-analytics";
7-
import "../../../components/ha-button";
86
import "../../../components/ha-card";
9-
import "../../../components/ha-checkbox";
107
import "../../../components/ha-settings-row";
11-
import "../../../components/ha-svg-icon";
128
import type { Analytics } from "../../../data/analytics";
139
import {
1410
getAnalyticsDetails,
@@ -17,6 +13,8 @@ import {
1713
import { haStyle } from "../../../resources/styles";
1814
import type { HomeAssistant } from "../../../types";
1915
import { documentationUrl } from "../../../util/documentation-url";
16+
import type { HaSwitch } from "../../../components/ha-switch";
17+
import "../../../components/ha-alert";
2018

2119
@customElement("ha-config-analytics")
2220
class ConfigAnalytics extends LitElement {
@@ -34,37 +32,82 @@ class ConfigAnalytics extends LitElement {
3432
: undefined;
3533

3634
return html`
37-
<ha-card outlined>
35+
<ha-card
36+
outlined
37+
.header=${this.hass.localize("ui.panel.config.analytics.header") ||
38+
"Home Assistant analytics"}
39+
>
3840
<div class="card-content">
39-
${error ? html`<div class="error">${error}</div>` : ""}
40-
<p>${this.hass.localize("ui.panel.config.analytics.intro")}</p>
41+
${error ? html`<div class="error">${error}</div>` : nothing}
42+
<p>
43+
${this.hass.localize("ui.panel.config.analytics.intro")}
44+
<a
45+
href=${documentationUrl(this.hass, "/integrations/analytics/")}
46+
target="_blank"
47+
rel="noreferrer"
48+
>${this.hass.localize("ui.panel.config.analytics.learn_more")}</a
49+
>.
50+
</p>
4151
<ha-analytics
4252
translation_key_panel="config"
4353
@analytics-preferences-changed=${this._preferencesChanged}
4454
.localize=${this.hass.localize}
4555
.analytics=${this._analyticsDetails}
4656
></ha-analytics>
4757
</div>
48-
<div class="card-actions">
49-
<ha-button @click=${this._save}>
50-
${this.hass.localize(
51-
"ui.panel.config.core.section.core.core_config.save_button"
52-
)}
53-
</ha-button>
54-
</div>
5558
</ha-card>
56-
<div class="footer">
57-
<ha-button
58-
size="small"
59-
appearance="plain"
60-
href=${documentationUrl(this.hass, "/integrations/analytics/")}
61-
target="_blank"
62-
rel="noreferrer"
63-
>
64-
<ha-svg-icon slot="end" .path=${mdiOpenInNew}></ha-svg-icon>
65-
${this.hass.localize("ui.panel.config.analytics.learn_more")}
66-
</ha-button>
67-
</div>
59+
${this._analyticsDetails &&
60+
"snapshots" in this._analyticsDetails.preferences
61+
? html`<ha-card
62+
outlined
63+
.header=${this.hass.localize(
64+
"ui.panel.config.analytics.preferences.snapshots.header"
65+
)}
66+
>
67+
<div class="card-content">
68+
<p>
69+
${this.hass.localize(
70+
"ui.panel.config.analytics.preferences.snapshots.info"
71+
)}
72+
<a
73+
href=${documentationUrl(this.hass, "/device-database/")}
74+
target="_blank"
75+
rel="noreferrer"
76+
>${this.hass.localize(
77+
"ui.panel.config.analytics.preferences.snapshots.learn_more"
78+
)}</a
79+
>.
80+
</p>
81+
<ha-alert
82+
.title=${this.hass.localize(
83+
"ui.panel.config.analytics.preferences.snapshots.alert.title"
84+
)}
85+
>${this.hass.localize(
86+
"ui.panel.config.analytics.preferences.snapshots.alert.content"
87+
)}</ha-alert
88+
>
89+
<ha-settings-row>
90+
<span slot="heading" data-for="snapshots">
91+
${this.hass.localize(
92+
`ui.panel.config.analytics.preferences.snapshots.title`
93+
)}
94+
</span>
95+
<span slot="description" data-for="snapshots">
96+
${this.hass.localize(
97+
`ui.panel.config.analytics.preferences.snapshots.description`
98+
)}
99+
</span>
100+
<ha-switch
101+
@change=${this._handleDeviceRowClick}
102+
.checked=${!!this._analyticsDetails?.preferences.snapshots}
103+
.disabled=${this._analyticsDetails === undefined}
104+
name="snapshots"
105+
>
106+
</ha-switch>
107+
</ha-settings-row>
108+
</div>
109+
</ha-card>`
110+
: nothing}
68111
`;
69112
}
70113

@@ -96,11 +139,25 @@ class ConfigAnalytics extends LitElement {
96139
}
97140
}
98141

142+
private _handleDeviceRowClick(ev: Event) {
143+
const target = ev.target as HaSwitch;
144+
145+
this._analyticsDetails = {
146+
...this._analyticsDetails!,
147+
preferences: {
148+
...this._analyticsDetails!.preferences,
149+
snapshots: target.checked,
150+
},
151+
};
152+
this._save();
153+
}
154+
99155
private _preferencesChanged(event: CustomEvent): void {
100156
this._analyticsDetails = {
101157
...this._analyticsDetails!,
102158
preferences: event.detail.preferences,
103159
};
160+
this._save();
104161
}
105162

106163
static get styles(): CSSResultGroup {
@@ -117,21 +174,10 @@ class ConfigAnalytics extends LitElement {
117174
p {
118175
margin-top: 0;
119176
}
120-
.card-actions {
121-
display: flex;
122-
flex-direction: row-reverse;
123-
justify-content: space-between;
124-
align-items: center;
125-
}
126-
.footer {
127-
padding: 32px 0 16px;
128-
text-align: center;
129-
}
130-
131-
ha-button[size="small"] ha-svg-icon {
132-
--mdc-icon-size: 16px;
177+
ha-card:not(:first-of-type) {
178+
margin-top: 24px;
133179
}
134-
`, // row-reverse so we tab first to "save"
180+
`,
135181
];
136182
}
137183
}

src/translations/en.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6780,6 +6780,7 @@
67806780
},
67816781
"analytics": {
67826782
"caption": "Analytics",
6783+
"header": "Home Assistant analytics",
67836784
"description": "Learn how to share data to improve Home Assistant",
67846785
"preferences": {
67856786
"base": {
@@ -6797,10 +6798,21 @@
67976798
"diagnostics": {
67986799
"title": "Diagnostics",
67996800
"description": "Share crash reports when unexpected errors occur."
6801+
},
6802+
"snapshots": {
6803+
"title": "Devices",
6804+
"description": "Generic information about your devices.",
6805+
"header": "Device analytics",
6806+
"info": "Anonymously share data about your devices to help build the Open Home Foundation’s device database. This free, open source resource helps users find useful information about smart home devices. Only device-specific details (like model or manufacturer) are shared — never personally identifying information (like the names you assign).",
6807+
"learn_more": "Learn more about the device database and how we process your data",
6808+
"alert": {
6809+
"title": "Important",
6810+
"content": "Only enable this option if you understand that your device information will be shared."
6811+
}
68006812
}
68016813
},
68026814
"need_base_enabled": "You need to enable basic analytics for this option to be available",
6803-
"learn_more": "How we process your data",
6815+
"learn_more": "Learn how we process your data",
68046816
"intro": "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.",
68056817
"download_device_info": "Preview device analytics"
68066818
},

0 commit comments

Comments
 (0)