Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Sep 6, 2024
1 parent c0a300c commit d4ebc0d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/localApi/xboxlocalapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 9 additions & 21 deletions src/webApi/xboxwebapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d4ebc0d

Please sign in to comment.