From d47b9d6b988f1dee892326ac901170fc42678062 Mon Sep 17 00:00:00 2001 From: smirko-dev <64351017+smirko-dev@users.noreply.github.com> Date: Tue, 16 Nov 2021 14:54:44 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 67a549b..55f15ca 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,7 @@ npm add --also=dev @fitbit/sdk-cli npx fitbit-build generate-appid npx fitbit-build ``` + +## Known issues + +- Doesn't work with [Nabu Casa](https://www.nabucasa.com/) From e3ee4ce836c7382332f5618189dfa7f3fed19969 Mon Sep 17 00:00:00 2001 From: smirko-dev Date: Wed, 17 Nov 2021 16:17:54 +0100 Subject: [PATCH 2/2] Fixed force status --- app/index.js | 8 +++++++- companion/index.js | 33 +++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/index.js b/app/index.js index b5f2579..807b8f7 100644 --- a/app/index.js +++ b/app/index.js @@ -94,6 +94,10 @@ messaging.peerSocket.onmessage = (evt) => { settings.token = evt.data.value; sendData({key: "token", value: settings.token}); } + else if (evt.data.key === "force") { + settings.force = evt.data.value; + sendData({key: "force", value: settings.force}); + } } // Message socket opens @@ -103,6 +107,7 @@ messaging.peerSocket.onopen = () => { sendData({key: "port", value: settings.port}); sendData({key: "token", value: settings.token}); sendData({key: "entities", value: settings.entities}); + sendData({key: "force", value: settings.force}); }; // Message socket closes @@ -121,7 +126,8 @@ function loadSettings() { return { url: "localhost", port: "8123", - token: "" + token: "", + force: false }; } } diff --git a/companion/index.js b/companion/index.js index 0e6bc99..8d5f210 100644 --- a/companion/index.js +++ b/companion/index.js @@ -8,7 +8,7 @@ import { sendData, isEmpty } from "../common/utils"; let URL = ""; let Port = "8123"; let Token = ""; -let Force = "false"; +let Force = false; // Return address as URL + Port function address() { @@ -36,7 +36,8 @@ settingsStorage.onchange = function(evt) { }) } else if (evt.key === "force") { - Force = JSON.parse(evt.newValue); + let data = JSON.parse(evt.newValue); + sendData({key: "force", value: data}); } } @@ -135,8 +136,19 @@ function changeEntity(url, token, entity, state) { }) .then(async(response) => { let data = await response.json(); - //DEBUG console.log('RECEIVED ' + JSON.stringify(data)); - if (!isEmpty(data)) { + if (Force) { + let msgData = { + key: "change", + id: entity, + state: state === 'turn_on' ? 'on' : 'off' + }; + if (!entity.startsWith("script") && !entity.startsWith("automation")) { + //DEBUG console.log('FORCE ' + JSON.stringify(msgData)); + sendData(msgData); + } + } + else if (!isEmpty(data)) { + //DEBUG console.log('RECEIVED ' + JSON.stringify(data)); data.forEach(element => { if (element["entity_id"] === entity) { let msgData = { @@ -150,16 +162,6 @@ function changeEntity(url, token, entity, state) { } }) } - else if (Force === "true") { - let msgData = { - key: "change", - id: entity, - state: state === 'turn_on' ? 'on' : 'off' - }; - if (!entity.startsWith("script") && !entity.startsWith("automation")) { - sendData(msgData); - } - } }) .catch(err => console.log('[FETCH]: ' + err)); } @@ -206,4 +208,7 @@ messaging.peerSocket.onmessage = evt => { }) } } + else if (evt.data.key === "force") { + Force = evt.data.value; + } };