Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export interface ZWaveJSSetConfigParamData {
value: string | number;
}

export interface ZWaveJSDataCollectionStatus {
enabled: boolean;
opted_in: boolean;
}

export enum NodeStatus {
Unknown,
Asleep,
Expand All @@ -75,6 +80,26 @@ export const fetchNetworkStatus = (
entry_id,
});

export const fetchDataCollectionStatus = (
hass: HomeAssistant,
entry_id: string
): Promise<ZWaveJSDataCollectionStatus> =>
hass.callWS({
type: "zwave_js/data_collection_status",
entry_id,
});

export const setDataCollectionPreference = (
hass: HomeAssistant,
entry_id: string,
opted_in: boolean
): Promise<any> =>
hass.callWS({
type: "zwave_js/update_data_collection_preference",
entry_id,
opted_in,
});

export const fetchNodeStatus = (
hass: HomeAssistant,
entry_id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import "../../../../../components/ha-svg-icon";
import "../../../../../components/ha-icon-next";
import { getSignedPath } from "../../../../../data/auth";
import {
fetchDataCollectionStatus,
fetchNetworkStatus,
fetchNodeStatus,
NodeStatus,
setDataCollectionPreference,
ZWaveJSNetwork,
ZWaveJSNode,
} from "../../../../../data/zwave_js";
Expand Down Expand Up @@ -55,6 +57,8 @@ class ZWaveJSConfigDashboard extends LitElement {

@internalProperty() private _icon = mdiCircle;

@internalProperty() private _dataCollectionOptIn?: boolean;

protected firstUpdated() {
if (this.hass) {
this._fetchData();
Expand Down Expand Up @@ -167,6 +171,38 @@ class ZWaveJSConfigDashboard extends LitElement {
</mwc-button>
</div>
</ha-card>
<ha-card>
<div class="card-header">
<h1>Third-Party Data Reporting</h1>
${this._dataCollectionOptIn !== undefined
? html`
<ha-switch
.checked=${this._dataCollectionOptIn === true}
@change=${this._dataCollectionToggled}
></ha-switch>
`
: html`
<ha-circular-progress
size="small"
active
></ha-circular-progress>
`}
</div>
<div class="card-content">
<p>
Enable the reporting of anonymized telemetry and
statistics to the <em>Z-Wave JS organization</em>.
Information about the data that is collected and how it is
used, including an example of the data collected, can be
found in the
<a
target="_blank"
href="https://zwave-js.github.io/node-zwave-js/#/data-collection/data-collection?id=usage-statistics"
>Z-Wave JS data collection documentation</a
>.
</p>
</div>
</ha-card>
`
: ``}
<button class="link dump" @click=${this._dumpDebugClicked}>
Expand All @@ -183,11 +219,22 @@ class ZWaveJSConfigDashboard extends LitElement {
if (!this.configEntryId) {
return;
}
this._network = await fetchNetworkStatus(this.hass!, this.configEntryId);
const [network, dataCollectionStatus] = await Promise.all([
fetchNetworkStatus(this.hass!, this.configEntryId),
fetchDataCollectionStatus(this.hass!, this.configEntryId),
]);

this._network = network;

this._status = this._network.client.state;
if (this._status === "connected") {
this._icon = mdiCheckCircle;
}

this._dataCollectionOptIn =
dataCollectionStatus.opted_in === true ||
dataCollectionStatus.enabled === true;

this._fetchNodeStatus();
}

Expand All @@ -213,6 +260,14 @@ class ZWaveJSConfigDashboard extends LitElement {
});
}

private _dataCollectionToggled(ev) {
setDataCollectionPreference(
this.hass!,
this.configEntryId!,
ev.target.checked
);
}

private async _dumpDebugClicked() {
await this._fetchNodeStatus();

Expand Down Expand Up @@ -321,8 +376,19 @@ class ZWaveJSConfigDashboard extends LitElement {
font-size: 1rem;
}

.card-header {
display: flex;
}
.card-header h1 {
flex: 1;
}
.card-header ha-switch {
width: 48px;
margin-top: 16px;
}

ha-card {
margin: 0 auto;
margin: 0px auto 24px;
max-width: 600px;
}

Expand Down