From b7a4f97ecacd6e6e4e9d48f31ac387ab2fbfdb49 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Mon, 26 Apr 2021 18:19:48 -0400 Subject: [PATCH] Add opt-in toggle for zwave-js telemetry to config panel (#8958) --- src/data/zwave_js.ts | 25 +++++++ .../zwave_js/zwave_js-config-dashboard.ts | 71 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index d6db70bd21..b34338a150 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -56,6 +56,11 @@ export interface ZWaveJSSetConfigParamData { value: string | number; } +export interface ZWaveJSDataCollectionStatus { + enabled: boolean; + opted_in: boolean; +} + export enum NodeStatus { Unknown, Asleep, @@ -75,6 +80,26 @@ export const fetchNetworkStatus = ( entry_id, }); +export const fetchDataCollectionStatus = ( + hass: HomeAssistant, + entry_id: string +): Promise => + hass.callWS({ + type: "zwave_js/data_collection_status", + entry_id, + }); + +export const setDataCollectionPreference = ( + hass: HomeAssistant, + entry_id: string, + opted_in: boolean +): Promise => + hass.callWS({ + type: "zwave_js/update_data_collection_preference", + entry_id, + opted_in, + }); + export const fetchNodeStatus = ( hass: HomeAssistant, entry_id: string, diff --git a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts index bc219081a4..eb53eeafba 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts @@ -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"; @@ -55,6 +57,8 @@ class ZWaveJSConfigDashboard extends LitElement { @internalProperty() private _icon = mdiCircle; + @internalProperty() private _dataCollectionOptIn?: boolean; + protected firstUpdated() { if (this.hass) { this._fetchData(); @@ -167,6 +171,39 @@ class ZWaveJSConfigDashboard extends LitElement { + +
+

Third-Party Data Reporting

+ ${this._dataCollectionOptIn !== undefined + ? html` + + ` + : html` + + `} +
+
+

+ Enable the reporting of anonymized telemetry and + statistics to the Z-Wave JS organization. This + data will be used to focus development efforts and improve + the user experience. Information about the data that is + collected and how it is used, including an example of the + data collected, can be found in the + Z-Wave JS data collection documentation. +

+
+
` : ``}