Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Jan 4, 2023
1 parent 0ccfeda commit 865cc3f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ 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.3.16] - (04.01.2023)
## Changes
- fix wrong state after power Off
- fix display current app
- fix save target visibility
- fix save custom names

## [2.3.15] - (04.01.2023)
## Changes
- fix #147 #148

## [2.3.14] - (03.01.2023)
## Changes
Expand Down
39 changes: 19 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class XBOXDEVICE {
})
.on('stateChanged', (power, titleId, inputReference, volume, mute, mediaState) => {
const inputIdentifier = this.inputsReference.indexOf(inputReference) >= 0 ? this.inputsReference.indexOf(inputReference) : this.inputsTitleId.indexOf(titleId) >= 0 ? this.inputsTitleId.indexOf(titleId) : this.inputIdentifier;

const obj = JSON.stringify({
'power': power,
'titleId': titleId,
Expand Down Expand Up @@ -611,7 +612,7 @@ class XBOXDEVICE {
const inputOneStoreProductId = this.inputsOneStoreProductId[inputIdentifier];
const setDashboard = (inputOneStoreProductId === 'Dashboard' || inputOneStoreProductId === 'Settings' || inputOneStoreProductId === 'SettingsTv' || inputOneStoreProductId === 'Accessory' || inputOneStoreProductId === 'Screensaver' || inputOneStoreProductId === 'NetworkTroubleshooter' || inputOneStoreProductId === 'XboxGuide');
const setTelevision = (inputOneStoreProductId === 'Television');
const setApp = ((inputOneStoreProductId !== undefined && inputOneStoreProductId !== '0') && !setDashboard && !setTelevision);
const setApp = ((inputOneStoreProductId && inputOneStoreProductId !== '0') && !setDashboard && !setTelevision);
try {
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) : false : false;
const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set Input successful, input: %s, reference: %s, product Id: %s', this.host, accessoryName, inputName, inputReference, inputOneStoreProductId);
Expand Down Expand Up @@ -867,25 +868,25 @@ class XBOXDEVICE {
const input = inputs[j];

//get title Id
const inputTitleId = (input.titleId !== undefined) ? input.titleId : undefined;
const inputTitleId = (input.titleId) ? input.titleId : undefined;

//get input reference
const inputReference = (input.reference !== undefined) ? input.reference : undefined;
const inputReference = (input.reference) ? input.reference : undefined;

//get input oneStoreProductId
const inputOneStoreProductId = (input.oneStoreProductId !== undefined) ? input.oneStoreProductId : undefined;
const inputOneStoreProductId = (input.oneStoreProductId) ? input.oneStoreProductId : undefined;

//get input name
const inputName = (savedInputsNames[inputTitleId] !== undefined) ? savedInputsNames[inputTitleId] : (savedInputsNames[inputReference] !== undefined) ? savedInputsNames[inputReference] : (savedInputsNames[inputOneStoreProductId] !== undefined) ? savedInputsNames[inputOneStoreProductId] : input.name;
const inputName = (savedInputsNames[inputTitleId]) ? savedInputsNames[inputTitleId] : (savedInputsNames[inputReference]) ? savedInputsNames[inputReference] : (savedInputsNames[inputOneStoreProductId]) ? savedInputsNames[inputOneStoreProductId] : input.name;

//get input type
const inputType = (input.type !== undefined) ? CONSTANS.InputSourceTypes.indexOf(input.type) : 10;
const inputType = (input.type) ? CONSTANS.InputSourceTypes.indexOf(input.type) : 10;

//get input configured
const isConfigured = 1;

//get input visibility state
const currentVisibility = (savedTargetVisibility[inputTitleId] !== undefined) ? savedTargetVisibility[inputTitleId] : (savedTargetVisibility[inputReference] !== undefined) ? savedTargetVisibility[inputReference] : (savedTargetVisibility[inputOneStoreProductId] !== undefined) ? savedTargetVisibility[inputOneStoreProductId] : 0;
const currentVisibility = (savedTargetVisibility[inputTitleId]) ? savedTargetVisibility[inputTitleId] : (savedTargetVisibility[inputReference]) ? savedTargetVisibility[inputReference] : (savedTargetVisibility[inputOneStoreProductId]) ? savedTargetVisibility[inputOneStoreProductId] : 0;
const targetVisibility = currentVisibility;

const inputService = new Service.InputSource(inputName, `Input ${j}`);
Expand All @@ -900,10 +901,9 @@ class XBOXDEVICE {
inputService
.getCharacteristic(Characteristic.ConfiguredName)
.onSet(async (name) => {
const nameIdentifier = (inputTitleId !== undefined) ? inputTitleId : (inputReference !== undefined) ? inputReference : (inputOneStoreProductId !== undefined) ? inputOneStoreProductId : false;
let newName = savedInputsNames;
newName[nameIdentifier] = name;
const newCustomName = JSON.stringify(newName, null, 2);
const nameIdentifier = (inputTitleId) ? inputTitleId : (inputReference) ? inputReference : (inputOneStoreProductId) ? inputOneStoreProductId : false;
savedInputsNames[nameIdentifier] = name;
const newCustomName = JSON.stringify(savedInputsNames, null, 2);
try {
const writeNewCustomName = nameIdentifier ? await fsPromises.writeFile(this.inputsNamesFile, newCustomName) : false;
const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, saved new Input name successful, name: %s, product Id: %s', this.host, accessoryName, newCustomName, inputOneStoreProductId);
Expand All @@ -915,10 +915,9 @@ class XBOXDEVICE {
inputService
.getCharacteristic(Characteristic.TargetVisibilityState)
.onSet(async (state) => {
const targetVisibilityIdentifier = (inputTitleId !== undefined) ? inputTitleId : (inputReference !== undefined) ? inputReference : (inputOneStoreProductId !== undefined) ? inputOneStoreProductId : false;
let newState = savedTargetVisibility;
newState[targetVisibilityIdentifier] = state;
const newTargetVisibility = JSON.stringify(newState, null, 2);
const targetVisibilityIdentifier = (inputTitleId) ? inputTitleId : (inputReference) ? inputReference : (inputOneStoreProductId) ? inputOneStoreProductId : false;
savedTargetVisibility[targetVisibilityIdentifier] = state;
const newTargetVisibility = JSON.stringify(savedTargetVisibility, null, 2);
try {
const writeNewTargetVisibility = targetVisibilityIdentifier ? await fsPromises.writeFile(this.inputsTargetVisibilityFile, newTargetVisibility) : false;
const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, saved new Target Visibility successful, input: %s, state: %s', this.host, accessoryName, inputName, state ? 'HIDEN' : 'SHOWN');
Expand Down Expand Up @@ -951,13 +950,13 @@ class XBOXDEVICE {
const button = buttons[i];

//get button command
const buttonCommand = (button.command !== undefined) ? button.command : '';
const buttonCommand = (button.command) ? button.command : '';

//get button name
const buttonName = (button.name !== undefined) ? button.name : buttonCommand;
const buttonName = (button.name) ? button.name : buttonCommand;

//get button display type
const buttonDisplayType = (button.displayType !== undefined) ? button.displayType : 0;
const buttonDisplayType = (button.displayType) ? button.displayType : 0;

//get button mode
let buttonMode = 0;
Expand All @@ -984,7 +983,7 @@ class XBOXDEVICE {
};

//get button inputOneStoreProductId
const buttonOneStoreProductId = (button.oneStoreProductId !== undefined) ? button.oneStoreProductId : '0';
const buttonOneStoreProductId = (button.oneStoreProductId) ? button.oneStoreProductId : '0';

const serviceType = [Service.Outlet, Service.Switch][buttonDisplayType];
const buttonService = new serviceType(`${accessoryName} ${buttonName}`, `Button ${i}`);
Expand All @@ -997,7 +996,7 @@ class XBOXDEVICE {
.onSet(async (state) => {
const setDashboard = (buttonOneStoreProductId === 'Dashboard' || buttonOneStoreProductId === 'Settings' || buttonOneStoreProductId === 'SettingsTv' || buttonOneStoreProductId === 'Accessory' || buttonOneStoreProductId === 'Screensaver' || buttonOneStoreProductId === 'NetworkTroubleshooter' || buttonOneStoreProductId === 'XboxGuide');
const setTelevision = (buttonOneStoreProductId === 'Television');
const setApp = ((buttonOneStoreProductId !== undefined && buttonOneStoreProductId !== '0') && !setDashboard && !setTelevision);
const setApp = ((buttonOneStoreProductId && buttonOneStoreProductId !== '0') && !setDashboard && !setTelevision);
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;
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": "2.3.15",
"version": "2.3.16",
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
27 changes: 17 additions & 10 deletions src/xboxlocalapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class XBOXLOCALAPI extends EventEmitter {
this.inputReference = '';
this.mediaState = 0;
this.emitDevInfo = true;
this.closeConnection = false;

//dgram socket
this.socket = new Dgram.createSocket('udp4');
Expand Down Expand Up @@ -119,6 +120,20 @@ class XBOXLOCALAPI extends EventEmitter {
break;
};

if (this.isConnected) {
if (this.closeConnection) {
const debug = this.debugLog ? this.emit('debug', `Clear timeout: ${this.closeConnection} ms`) : false;
clearTimeout(this.closeConnection)
this.closeConnection = false;
} else {
const debug = this.debugLog ? this.emit('debug', `Set timeout to: 12 seconds`) : false;
this.closeConnection = setTimeout(() => {
const debug = this.debugLog ? this.emit('debug', `Last message was: 12 seconds ago, send disconnect.`) : false;
this.disconnect();
}, 12000);
};
};

const debug1 = this.debugLog ? this.emit('debug', `Received event type: ${this.function}`) : false;
this.emit(this.function, this.response);
})
Expand Down Expand Up @@ -229,15 +244,6 @@ class XBOXLOCALAPI extends EventEmitter {
})
.on('acknowledge', async () => {
const debug = this.debugLog ? this.emit('debug', 'Packet needs to be acknowledged, send acknowledge.') : false;
if (this.isConnected) {
this.closeConnection = setTimeout(() => {
const debug = this.debugLog ? this.emit('debug', `Last message was: ${this.closeConnection / 1000} seconds ago, send disconnect.`) : false;
this.disconnect();
}, 12000);

const debug = this.debugLog ? this.emit('debug', `Clear timeout: ${this.closeConnection} ms`) : false;
clearTimeout(this.closeConnection);
};

try {
const acknowledge = new Packer('message.acknowledge');
Expand All @@ -252,7 +258,7 @@ class XBOXLOCALAPI extends EventEmitter {
};
})
.on('status', (message) => {
if (message.packetDecoded.protectedPayload !== undefined) {
if (message.packetDecoded.protectedPayload) {
const decodedMessage = message.packetDecoded.protectedPayload;
const debug = this.debugLog ? this.emit('debug', `Status message: ${JSON.stringify(decodedMessage)}`) : false;

Expand Down Expand Up @@ -578,6 +584,7 @@ class XBOXLOCALAPI extends EventEmitter {
async disconnect() {
const debug = this.debugLog ? this.emit('debug', 'Disconnecting...') : false;
clearTimeout(this.closeConnection);
this.closeConnection = false;

try {
const disconnect = new Packer('message.disconnect');
Expand Down

0 comments on commit 865cc3f

Please sign in to comment.