From d4ebc0d9d2e7dc086f325239389141d014a1b8a2 Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Fri, 6 Sep 2024 19:40:09 +0200 Subject: [PATCH] cleanup --- CHANGELOG.md | 2 +- package.json | 2 +- src/localApi/xboxlocalapi.js | 6 +++--- src/webApi/xboxwebapi.js | 30 +++++++++--------------------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4b2dab..7dedad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -### NOTE +### NOTE!!! - After update to 2.x.x the plugin settings (xboxLiveId) need to be updated - After update to v3.0.0 RESTFull and MQTT config settings need to be updated diff --git a/package.json b/package.json index aa527a3..3675e76 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Xbox TV", "name": "homebridge-xbox-tv", - "version": "3.1.4", + "version": "3.1.5", "description": "Homebridge plugin to control Xbox game consoles.", "license": "MIT", "author": "grzegorz914", diff --git a/src/localApi/xboxlocalapi.js b/src/localApi/xboxlocalapi.js index 62a35f5..3d9b4a2 100644 --- a/src/localApi/xboxlocalapi.js +++ b/src/localApi/xboxlocalapi.js @@ -398,9 +398,9 @@ class XBOXLOCALAPI extends EventEmitter { async saveData(path, data) { try { - await fsPromises.writeFile(path, JSON.stringify(data, null, 2)); - const debug = this.debugLog ? this.emit('debug', `Saved data: ${JSON.stringify(data, null, 2)}`) : false; - + data = JSON.stringify(data, null, 2); + await fsPromises.writeFile(path, data); + const debug = this.debugLog ? this.emit('debug', `Saved data: ${data}`) : false; return true; } catch (error) { throw new Error(error); diff --git a/src/webApi/xboxwebapi.js b/src/webApi/xboxwebapi.js index 919d656..85906fa 100644 --- a/src/webApi/xboxwebapi.js +++ b/src/webApi/xboxwebapi.js @@ -244,11 +244,12 @@ class XBOXWEBAPI extends EventEmitter { 'name': name, 'contentType': contentType }; - appsArray.push(inputsObj); + const duplicatedInput = appsArray.some(input => input.reference === aumid); + const push = name && aumid && !duplicatedInput ? appsArray.push(inputsObj) : false; }; - //save apps to the file - await this.saveInputs(this.inputsFile, appsArray); + //save inputs + await this.saveData(this.inputsFile, appsArray); //emit restFul and mqtt this.emit('restFul', 'apps', apps); @@ -346,28 +347,15 @@ class XBOXWEBAPI extends EventEmitter { }; } - async saveInputs(path, appsArray) { + async saveData(path, data) { try { - const inputs = [...CONSTANTS.DefaultInputs, ...appsArray]; - - //chack duplicated inputs - const inputsArr = []; - for (const input of inputs) { - const inputName = input.name; - const inputReference = input.reference; - const duplicatedInput = inputsArr.some(input => input.reference === inputReference); - const push = inputName && inputReference && !duplicatedInput ? inputsArr.push(input) : false; - } - - //save inputs - const allInputs = JSON.stringify(inputsArr, null, 2); - await fsPromises.writeFile(path, allInputs); - const debug = this.debugLog ? this.emit('debug', `Saved apps: ${allInputs}`) : false; - + data = JSON.stringify(data, null, 2); + await fsPromises.writeFile(path, data); + const debug = this.debugLog ? this.emit('debug', `Saved data: ${data}`) : false; return true; } catch (error) { throw new Error(error); - } + }; }; async next() {