Skip to content

Commit

Permalink
release 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Feb 12, 2023
1 parent 4ab52cc commit 07babab
Show file tree
Hide file tree
Showing 22 changed files with 852 additions and 731 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### NOTE!!!
## After update to 2.x.x the plugin settings (xboxLiveId) need to be updated.

## [2.6.0] - (29.01.2023)
## [2.6.0] - (12.02.2023)
## Changes
- integrate web api library in to the plugin
- simplify the authorization manager process(reduced 1 step, correct some words)
- bump dependencies
- stability improwements
- stability improvements
- config.schema updated
- cleanup

## [2.5.0] - (29.01.2023)
## Changes
Expand Down
109 changes: 61 additions & 48 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,27 +334,29 @@ class XBOXDEVICE {
//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Status', JSON.stringify(consoleStatusData, null, 2)) : false;
})
.on('consolesList', (getConsolesListData, consolesList) => {
.on('consolesList', (consolesList) => {

//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Consoles List', JSON.stringify(consolesList, null, 2)) : false;
})
.on('appsList', async (getInstalledAppsData, appsArr) => {

const obj = JSON.stringify([...CONSTANS.DefaultInputs, ...appsArr], null, 2);
const writeInputs = await fsPromises.writeFile(this.inputsFile, obj);
const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved apps list: ${obj}`) : false;
.on('appsList', async (appsArray) => {
try {
const apps = JSON.stringify([...CONSTANS.DefaultInputs, ...appsArray], null, 2);
await fsPromises.writeFile(this.inputsFile, apps);
const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, saved apps: ${apps}`) : false;

//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Apps', JSON.stringify(appsArr, null, 2)) : false;
//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Apps', JSON.stringify(apps, null, 2)) : false;
} catch (error) {
this.log.error(`Device: ${this.host} ${this.name}, save apps error: ${error}`);
};
})
.on('storageDevices', (getStorageDevicesData, storageDevices) => {
.on('storageDevices', (storageDevices) => {

//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Storages', JSON.stringify(storageDevices, null, 2)) : false;
})
.on('userProfile', (getUserProfileData, profileUsers) => {

.on('userProfile', (profileUsers) => {

//mqtt
const mqtt = this.mqttEnabled ? this.mqtt.send('Profile', JSON.stringify(profileUsers, null, 2)) : false;
Expand Down Expand Up @@ -436,12 +438,21 @@ class XBOXDEVICE {
const inputName = this.inputsName[inputIdentifier];
const inputReference = this.inputsReference[inputIdentifier];
const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
const setDashboard = inputOneStoreProductId === 'Dashboard' || inputOneStoreProductId === 'Settings' || inputOneStoreProductId === 'SettingsTv' || inputOneStoreProductId === 'Accessory' || inputOneStoreProductId === 'Screensaver' || inputOneStoreProductId === 'NetworkTroubleshooter';
const setXboxGuide = inputOneStoreProductId === 'XboxGuide';
const setTelevision = inputOneStoreProductId === 'Television';
const setApp = (inputOneStoreProductId && inputOneStoreProductId !== '0') && !setDashboard && !setTelevision && !setXboxGuide;

const setInput = this.webApiEnabled ? setApp ? await this.xboxWebApi.getProvider('smartglass').launchApp(this.xboxLiveId, inputOneStoreProductId) : setDashboard ? await this.xboxWebApi.getProvider('smartglass').launchDashboard(this.xboxLiveId) : setTelevision ? await this.xboxWebApi.getProvider('smartglass').launchOneGuide(this.xboxLiveId) : setXboxGuide ? await this.xboxWebApi.getProvider('smartglass').openGuideTab(this.xboxLiveId) : false : false;
switch (inputOneStoreProductId) {
case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
await this.xboxWebApi.launchDashboard();
break;
case 'Television':
await this.xboxWebApi.launchOneGuide();
break;
case 'XboxGuide':
await this.xboxWebApi.openGuideTab();
break;
default:
await this.xboxWebApi.launchApp(inputOneStoreProductId);
break;
}
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Input successful, input: ${inputName},, reference: ${inputReference}, product Id: ${inputOneStoreProductId}`);
} catch (error) {
this.log.error(`Device: ${this.host} ${accessoryName}, set Input error: ${JSON.stringify(error, null, 2)}`);
Expand All @@ -451,63 +462,49 @@ class XBOXDEVICE {
this.televisionService.getCharacteristic(Characteristic.RemoteKey)
.onSet(async (command) => {
try {
let channelName;
switch (command) {
case Characteristic.RemoteKey.REWIND:
command = 'rewind';
channelName = 'systemMedia';
break;
case Characteristic.RemoteKey.FAST_FORWARD:
command = 'fastForward';
channelName = 'systemMedia';
break;
case Characteristic.RemoteKey.NEXT_TRACK:
command = 'nextTrack';
channelName = 'systemMedia';
break;
case Characteristic.RemoteKey.PREVIOUS_TRACK:
command = 'prevTrack';
channelName = 'systemMedia';
break;
case Characteristic.RemoteKey.ARROW_UP:
command = 'up';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.ARROW_DOWN:
command = 'down';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.ARROW_LEFT:
command = 'left';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.ARROW_RIGHT:
command = 'right';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.SELECT:
command = 'a';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.BACK:
command = 'b';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.EXIT:
command = 'nexus';
channelName = 'systemInput';
break;
case Characteristic.RemoteKey.PLAY_PAUSE:
command = 'playpause';
channelName = 'systemMedia';
break;
case Characteristic.RemoteKey.INFORMATION:
command = this.infoButtonCommand;
channelName = 'systemInput';
break;
};

const sendCommand = this.power && this.webApiEnabled ? await this.xboxWebApi.getProvider('smartglass').sendButtonPress(this.xboxLiveId, command) : false;
const sendCommand = this.power && this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : false;
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, Remote Key command successful: ${command}`);
} catch (error) {
this.log.error(`Device: ${this.host} ${accessoryName}, set Remote Key command error: ${JSON.stringify(error, null, 2)}`);
Expand Down Expand Up @@ -553,7 +550,7 @@ class XBOXDEVICE {
};

const channelName = 'systemInput';
const setPowerModeSelection = this.power ? this.webApiEnabled ? await this.xboxWebApi.getProvider('smartglass').sendButtonPress(this.xboxLiveId, command) : await this.xboxWebApi.getProvider('smartglass').sendButtonPress(this.xboxLiveId, command) : false//await this.xboxLocalApi.sendCommand(channelName, command) : false;
const setPowerModeSelection = this.power ? this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : await this.xboxWebApi.sendButtonPress(command) : false;
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command successful: ${command}`);
} catch (error) {
this.log.error(`Device: ${this.host} ${accessoryName}, set Power Mode Selection command error: ${error}`);
Expand Down Expand Up @@ -581,7 +578,7 @@ class XBOXDEVICE {
};

const channelName = 'tvRemote';
const setVolume = this.power && this.webApiEnabled ? await this.xboxWebApi.getProvider('smartglass').sendButtonPress(this.xboxLiveId, command) : false;
const setVolume = this.power && this.webApiEnabled ? await this.xboxWebApi.sendButtonPress(command) : false;
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Volume command successful: ${command}`);
} catch (error) {
this.log.error(`Device: ${this.host} ${accessoryName}, set Volume command error: ${error}`);
Expand Down Expand Up @@ -609,7 +606,7 @@ class XBOXDEVICE {
})
.onSet(async (state) => {
try {
const toggleMute = this.power && this.webApiEnabled ? state ? await this.xboxWebApi.getProvider('smartglass').mute(this.xboxLiveId) : await this.xboxWebApi.getProvider('smartglass').unmute(this.xboxLiveId) : false;
const toggleMute = this.power && this.webApiEnabled ? state ? await this.xboxWebApi.mute() : await this.xboxWebApi.unmute() : false;
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set Mute successful: ${state ? 'ON' : 'OFF'}`);
} catch (error) {
this.log.error(`Device: ${this.host} ${accessoryName}, set Mute error: ${error}`);
Expand Down Expand Up @@ -864,19 +861,15 @@ class XBOXDEVICE {
if (buttonDisplayType >= 0) {
//get button mode
let buttonMode = 0;
let channelName = '';
let command = '';
if (buttonCommand in CONSTANS.SystemMediaCommands) {
buttonMode = 0;
channelName = 'systemMedia';
command = buttonCommand;
} else if (buttonCommand in CONSTANS.SystemInputCommands) {
buttonMode = 1;
channelName = 'systemInput';
command = buttonCommand;
} else if (buttonCommand in CONSTANS.TvRemoteCommands) {
buttonMode = 2;
channelName = 'tvRemote';
} else if (buttonCommand === 'recordGameDvr') {
buttonMode = 3;
command = buttonCommand;
Expand All @@ -898,17 +891,37 @@ class XBOXDEVICE {
return state;
})
.onSet(async (state) => {
const setDashboard = buttonOneStoreProductId === 'Dashboard' || buttonOneStoreProductId === 'Settings' || buttonOneStoreProductId === 'SettingsTv' || buttonOneStoreProductId === 'Accessory' || buttonOneStoreProductId === 'Screensaver' || buttonOneStoreProductId === 'NetworkTroubleshooter';
const setXboxGuide = buttonOneStoreProductId === 'XboxGuide';
const setTelevision = buttonOneStoreProductId === 'Television';
const setApp = (buttonOneStoreProductId && buttonOneStoreProductId !== '0') && !setDashboard && !setTelevision && !setXboxGuide;
try {
const setCommand = this.power && state && this.webApiEnabled && buttonMode <= 2 ? await this.xboxWebApi.getProvider('smartglass').sendButtonPress(this.xboxLiveId, command) : false
const recordGameDvr = this.power && state && buttonMode === 3 ? await this.xboxLocalApi.recordGameDvr() : false;
const rebootConsole = this.power && state && this.webApiEnabled && buttonMode === 4 ? await this.xboxWebApi.getProvider('smartglass').reboot(this.xboxLiveId) : false;
const setAppInput = this.power && state && this.webApiEnabled && buttonMode === 5 ? setApp ? await this.xboxWebApi.getProvider('smartglass').launchApp(this.xboxLiveId, buttonOneStoreProductId) : setDashboard ? await this.xboxWebApi.getProvider('smartglass').launchDashboard(this.xboxLiveId) : setTelevision ? await this.xboxWebApi.getProvider('smartglass').launchOneGuide(this.xboxLiveId) : setXboxGuide ? await this.xboxWebApi.getProvider('smartglass').openGuideTab(this.xboxLiveId) : false : false;
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${taccessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`);

if (this.power && state && this.webApiEnabled) {
switch (buttonMode) {
case 0: case 1: case 2:
await this.xboxWebApi.sendButtonPress(command);
break;
case 3:
await this.xboxLocalApi.recordGameDvr();
break;
case 4:
await this.xboxWebApi.reboot();
break;
case 5:
switch (buttonOneStoreProductId) {
case 'Dashboard': case 'Settings': case 'SettingsTv': case 'Accessory': case 'Screensaver': case 'NetworkTroubleshooter': case 'MicrosoftStore':
await this.xboxWebApi.launchDashboard();
break;
case 'Television':
await this.xboxWebApi.launchOneGuide();
break;
case 'XboxGuide':
await this.xboxWebApi.openGuideTab();
break;
default:
await this.xboxWebApi.launchApp(buttonOneStoreProductId);
break;
}
break;
}
}
const logInfo = this.disableLogInfo || this.firstRun ? false : this.log(`Device: ${this.host} ${accessoryName}, set button successful, name: ${buttonName}, command: ${buttonCommand}`);
await new Promise(resolve => setTimeout(resolve, 300));
const setChar = (state && this.power) ? buttonService.updateCharacteristic(Characteristic.On, false) : false;
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Xbox TV",
"name": "homebridge-xbox-tv",
"version": "2.6.0-beta.150",
"version": "2.6.0",
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
"license": "MIT",
"author": "grzegorz914",
Expand All @@ -26,7 +26,7 @@
],
"engines": {
"node": ">=16.0.0",
"homebridge": ">=1.6.0"
"homebridge": ">=1.5.0"
},
"dependencies": {
"@homebridge/plugin-ui-utils": "^0.0.19",
Expand Down
Loading

0 comments on commit 07babab

Please sign in to comment.