Skip to content

Commit

Permalink
fix #130
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Jun 13, 2022
1 parent cb303fe commit e30e90e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
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/)

## [1.11.7] - (13.06.2022)
## Changes
- fix [#130](https://github.com/grzegorz914/homebridge-lgwebos-tv/issues/130)

## [1.11.6] - (05.05.2022)
## Changes
- fix [#127](https://github.com/grzegorz914/homebridge-lgwebos-tv/issues/127)
Expand Down
Binary file added graphics/.homekit.png.icloud
Binary file not shown.
Binary file removed graphics/homekit.png
Binary file not shown.
94 changes: 44 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,60 +286,54 @@ class lgwebosTvDevice {
this.webOS = webOS;
})
.on('installedApps', async (installedApps) => {
if (installedApps.apps != undefined) {
const inputsArr = new Array();
const inputsData = installedApps.apps;
const inputsCount = inputsData.length;
for (let i = 0; i < inputsCount; i++) {
const name = inputsData[i].title;
const reference = inputsData[i].id;
const type = 'APPLICATION';
const mode = 0;
const inputsObj = {
'name': name,
'reference': reference,
'type': type,
'mode': mode
}
inputsArr.push(inputsObj);
};
const obj = JSON.stringify(inputsArr, null, 2);
try {
const writeInputs = await fsPromises.writeFile(this.inputsFile, obj);
const debug = this.enableDebugMode ? this.log('Device: %s %s, saved inputs/apps list: %s', this.host, this.name, obj) : false;
} catch (error) {
this.log.error('Device: %s %s, save inputs/apps error: %s', this.host, accessoryName, error);
};
const inputsArr = new Array();
const inputsCount = installedApps.length;
for (let i = 0; i < inputsCount; i++) {
const name = installedApps[i].title;
const reference = installedApps[i].id;
const type = 'APPLICATION';
const mode = 0;
const inputsObj = {
'name': name,
'reference': reference,
'type': type,
'mode': mode
}
inputsArr.push(inputsObj);
};
const obj = JSON.stringify(inputsArr, null, 2);
try {
const writeInputs = await fsPromises.writeFile(this.inputsFile, obj);
const debug = this.enableDebugMode ? this.log('Device: %s %s, saved inputs/apps list: %s', this.host, this.name, obj) : false;
} catch (error) {
this.log.error('Device: %s %s, save inputs/apps error: %s', this.host, accessoryName, error);
};
})
.on('channelList', async (channelList) => {
if (channelList.channelList != undefined && channelList.channelList != null) {
const channelsArr = new Array();
const channelsData = channelList.channelList;
const channelsCount = channelsData.length;
for (let i = 0; i < channelsCount; i++) {
const name = channelsData[i].channelName;
const reference = channelsData[i].channelId;
const number = channelsData[i].channelNumber;
const type = 'TUNER';
const mode = 1;
const channelsObj = {
'name': name,
'reference': reference,
'number': number,
'type': type,
'mode': mode
}
channelsArr.push(channelsObj);
const channelsArr = new Array();
const channelsCount = channelList.length;
for (let i = 0; i < channelsCount; i++) {
const name = channelList[i].channelName;
const reference = channelList[i].channelId;
const number = channelList[i].channelNumber;
const type = 'TUNER';
const mode = 1;
const channelsObj = {
'name': name,
'reference': reference,
'number': number,
'type': type,
'mode': mode
}
const obj = JSON.stringify(channelsArr, null, 2);
try {
const writeChannels = await fsPromises.writeFile(this.channelsFile, obj);
const debug = this.enableDebugMode ? this.log('Device: %s %s, write channels list: %s', this.host, this.name, obj) : false;
} catch (error) {
this.log.error('Device: %s %s, save inputs/apps error: %s', this.host, accessoryName, error);
};
channelsArr.push(channelsObj);
}
const obj = JSON.stringify(channelsArr, null, 2);
try {
const writeChannels = await fsPromises.writeFile(this.channelsFile, obj);
const debug = this.enableDebugMode ? this.log('Device: %s %s, write channels list: %s', this.host, this.name, obj) : false;
} catch (error) {
this.log.error('Device: %s %s, save inputs/apps error: %s', this.host, accessoryName, error);
};
})
.on('powerState', (isConnected, power, pixelRefresh, screenState) => {
const powerState = (isConnected && power);
Expand Down Expand Up @@ -1015,7 +1009,7 @@ class lgwebosTvDevice {
}
try {
const setPictureMode = (state && this.powerState) ? this.lgtv.send('request', API_URL.SetSystemSettings, payload) : false;
const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set Picture Mode successful, Mode: %s', this.host, accessoryName, pictureModeName, response);
const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set Picture Mode successful, Mode: %s', this.host, accessoryName, pictureModeName);
} catch (error) {
this.log.error('Device: %s %s %s, set Picture Mode error: %s', this.host, accessoryName, error);
};
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": "LG webOS TV",
"name": "homebridge-lgwebos-tv",
"version": "1.11.6",
"version": "1.11.7",
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control LG webOS TV.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
32 changes: 18 additions & 14 deletions src/lgwebos.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ class LGTV extends EventEmitter {
return new Promise((resolve, reject) => {
this.send('request', API_URL.GetSystemInfo, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `System info error: ${error}`)
this.emit('error', `System info error: ${error}, ${response.errorCode}`)
}
const debug = this.debugLog ? this.emit('debug', `System info: ${JSON.stringify(response, null, 2)}`) : false;

this.send('request', API_URL.GetSoftwareInfo, (error, response1) => {
if (error || response.errorCode) {
this.emit('error', `Software info error: ${error}`)
this.emit('error', `Software info error: ${error}, ${response.errorCode}`)
}
const debug = this.debugLog ? this.emit('debug', `Software info: ${JSON.stringify(response1, null, 2)}`) : false;

Expand All @@ -193,14 +193,16 @@ class LGTV extends EventEmitter {

this.send('subscribe', API_URL.GetChannelList, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Channel list error: ${error}`)
this.emit('error', `Channel list error: ${error}, ${response.errorCode}`)
}
if (response.channelList != undefined) {
this.emit('channelList', response.channelList);
const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Channel List', JSON.stringify(response.channelList, null, 2)) : false;
}
this.emit('channelList', response);
const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Channel List', JSON.stringify(response, null, 2)) : false;
});
this.send('subscribe', API_URL.GetCurrentChannel, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Current channel error: ${error}`)
this.emit('error', `Current channel error: ${error}, ${response.errorCode}`)
}
const channelName = response.channelName;
const channelNumber = response.channelNumber;
Expand All @@ -210,22 +212,24 @@ class LGTV extends EventEmitter {
});
this.send('subscribe', API_URL.GetInstalledApps, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Installed apps error: ${error}`)
this.emit('error', `Installed apps error: ${error}, ${response.errorCode}`)
}
if (response.apps != undefined) {
this.emit('installedApps', response.apps);
const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Apps List', JSON.stringify(response.apps, null, 2)) : false;
}
this.emit('installedApps', response);
const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Apps List', JSON.stringify(response, null, 2)) : false;
});
this.send('subscribe', API_URL.GetForegroundAppInfo, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Foreground app error: ${error}`)
this.emit('error', `Foreground app error: ${error}, ${response.errorCode}`)
}
const reference = response.appId;
this.emit('currentApp', reference);
const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Current App', JSON.stringify(response, null, 2)) : false;
});
this.send('subscribe', API_URL.GetPowerState, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Power state error: ${error}`)
this.emit('error', `Power state error: ${error}, ${response.errorCode}`)
}
//screen On
const prepareScreenOn = ((response.state == 'Suspend' && response.processing == 'Screen On') || (response.state == 'Screen Saver' && response.processing == 'Screen On') || (response.state == 'Active Standby' && response.processing == 'Screen On'));
Expand Down Expand Up @@ -263,7 +267,7 @@ class LGTV extends EventEmitter {
});
this.send('subscribe', API_URL.GetAudioStatus, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `Audio state error: ${error}`)
this.emit('error', `Audio state error: ${error}, ${response.errorCode}`)
}
const volume = response.volume;
const mute = (response.mute == true);
Expand All @@ -278,7 +282,7 @@ class LGTV extends EventEmitter {
}
this.send('subscribe', API_URL.GetSystemSettings, payload, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `System settings error: ${error}`)
this.emit('error', `System settings error: ${error}, ${response.errorCode}`)
}
const brightness = response.settings.brightness;
const backlight = response.settings.backlight;
Expand All @@ -291,7 +295,7 @@ class LGTV extends EventEmitter {
};
this.send('subscribe', API_URL.GetAppState, (error, response) => {
if (error || response.errorCode) {
this.emit('error', `App state error: ${error}`)
this.emit('error', `App state error: ${error}, ${response.errorCode}`)
};
this.emit('appState');
});
Expand Down

0 comments on commit e30e90e

Please sign in to comment.