From fa0ba6be31a56568b46345d0eadb389ef737855d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Hagelb=C3=A4ck?= Date: Thu, 18 Feb 2021 21:17:29 +0100 Subject: [PATCH] Config setting to opt-in to setting Plejd clock time --- plejd/PlejdBLEHandler.js | 18 ++++++++++++------ plejd/README.md | 27 ++++++++++++++------------- plejd/config.json | 2 ++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/plejd/PlejdBLEHandler.js b/plejd/PlejdBLEHandler.js index a49bbcb..418a072 100644 --- a/plejd/PlejdBLEHandler.js +++ b/plejd/PlejdBLEHandler.js @@ -220,7 +220,11 @@ class PlejBLEHandler extends EventEmitter { this.emit('connected'); // Connected and authenticated, request current time and start ping - this._requestCurrentPlejdTime(); + if (this.config.updatePlejdClock) { + this._requestCurrentPlejdTime(); + } else { + logger.info('Plejd clock updates disabled in configuration.'); + } this.startPing(); this.startWriteQueue(); @@ -668,7 +672,7 @@ class PlejBLEHandler extends EventEmitter { } async _requestCurrentPlejdTime() { - logger.info('Requesting current Plejd time...'); + logger.info('Requesting current Plejd clock time...'); // Eg: 0b0102001b: 0b: id, 0102: read, 001b: time const payload = Buffer.from( @@ -943,10 +947,12 @@ class PlejBLEHandler extends EventEmitter { || Math.abs(diffSeconds) > 60 ) { const plejdTime = new Date(plejdTimestampUTC); - logger.debug(`Plejd time update ${plejdTime.toString()}, diff ${diffSeconds} seconds`); - if (Math.abs(diffSeconds) > 60) { + logger.debug( + `Plejd clock time update ${plejdTime.toString()}, diff ${diffSeconds} seconds`, + ); + if (this.config.updatePlejdClock && Math.abs(diffSeconds) > 60) { logger.warn( - `Plejd time off by more than 1 minute. Reported time: ${plejdTime.toString()}, diff ${diffSeconds} seconds. Time will be set hourly.`, + `Plejd clock time off by more than 1 minute. Reported time: ${plejdTime.toString()}, diff ${diffSeconds} seconds. Time will be set hourly.`, ); if (this.connectedDevice && deviceId === this.connectedDevice.id) { const newLocalTimestamp = (now.getTime() - offsetSecondsGuess) / 1000; @@ -965,7 +971,7 @@ class PlejBLEHandler extends EventEmitter { }); } } else if (deviceId !== BLE_BROADCAST_DEVICE_ID) { - logger.info('Got time response. Plejd time in sync with Home Assistant time'); + logger.info('Got time response. Plejd clock time in sync with Home Assistant time'); } } } else { diff --git a/plejd/README.md b/plejd/README.md index 3791b1f..3a16cf0 100644 --- a/plejd/README.md +++ b/plejd/README.md @@ -121,20 +121,21 @@ The above is used to notify the add-on when Home Assistant has started successfu The plugin needs you to configure some settings before working. You find these on the Add-on page after you've installed it. -| Parameter | Value | -| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| site | Name of your Plejd site, the name is displayed in the Plejd app (top bar). | -| username | Username of your Plejd account, this is used to fetch the crypto key and devices from the Plejd API. | -| password | Password of your Plejd account, this is used to fetch the crypto key and devices from the Plejd API. | -| mqttBroker | URL of the MQTT Broker, eg. mqtt://localhost | -| mqttUsername | Username of the MQTT broker | -| mqttPassword | Password of the MQTT broker | -| includeRoomsAsLights | Adds all rooms as lights, making it possible to turn on/off lights by room instead. Setting this to false will ignore all rooms. | -| logLevel | Minimim log level. Supported values are `error`, `warn`, `info`, `debug`, `verbose`, `silly` with increasing amount of logging. Do not log more than `info` for production purposes. | -| connectionTimeout | Number of seconds to wait when scanning and connecting. Might need to be tweaked on platforms other than RPi 4. Defaults to: 2 seconds. | -| writeQueueWaitTime | Wait time between message sent to Plejd over BLE, defaults to 400. If that doesn't work, try changing the value higher in steps of 50. | +| Parameter | Value | +| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| site | Name of your Plejd site, the name is displayed in the Plejd app (top bar). | +| username | Username of your Plejd account, this is used to fetch the crypto key and devices from the Plejd API. | +| password | Password of your Plejd account, this is used to fetch the crypto key and devices from the Plejd API. | +| mqttBroker | URL of the MQTT Broker, eg. mqtt://localhost | +| mqttUsername | Username of the MQTT broker | +| mqttPassword | Password of the MQTT broker | +| includeRoomsAsLights | Adds all rooms as lights, making it possible to turn on/off lights by room instead. Setting this to false will ignore all rooms. | +| updatePlejdClock | Hourly update Plejd devices' clock if out of sync. Clock is used for time-based scenes. Not recommended if you have a Plejd gateway. Clock updates may flicker scene-controlled devices. | +| logLevel | Minimim log level. Supported values are `error`, `warn`, `info`, `debug`, `verbose`, `silly` with increasing amount of logging. Do not log more than `info` for production purposes. | +| connectionTimeout | Number of seconds to wait when scanning and connecting. Might need to be tweaked on platforms other than RPi 4. Defaults to: 2 seconds. | +| writeQueueWaitTime | Wait time between message sent to Plejd over BLE, defaults to 400. If that doesn't work, try changing the value higher in steps of 50. | -## Having issues to get the addon working? +## Troubleshooting If you're having issues to get the addon working, there are a few things you can look into: diff --git a/plejd/config.json b/plejd/config.json index a160a8f..5c545ea 100644 --- a/plejd/config.json +++ b/plejd/config.json @@ -19,6 +19,7 @@ "mqttPassword": "", "includeRoomsAsLights": false, "preferCachedApiResponse": false, + "updatePlejdClock": false, "logLevel": "info", "connectionTimeout": 2, "writeQueueWaitTime": 400 @@ -32,6 +33,7 @@ "mqttPassword": "str", "includeRoomsAsLights": "bool", "preferCachedApiResponse": "bool", + "updatePlejdClock": "bool", "logLevel": "list(error|warn|info|debug|verbose|silly)", "connectionTimeout": "int", "writeQueueWaitTime": "int"