Skip to content

Commit

Permalink
Report ping state when HTTP request is failing #535
Browse files Browse the repository at this point in the history
  • Loading branch information
tavicu committed Jul 14, 2022
1 parent b6643ab commit db72fa0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/methods/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = class Base {
getState() {
return this.cache.get('state', () => this.getStatePing().then(status => {
if (status && this.device.storage.powerstate !== false) {
return this.cache.get('state-http', () => this.getStateHttp(), 2500);
return this.cache.get('state-http', () => this.getStateHttp(status), 2500);
} else {
this.cache.forget('state-http');
}
Expand All @@ -56,17 +56,18 @@ module.exports = class Base {

/**
* Get state of TV from PowerState response
* @param {boolean} fallback
* @return {Promise}
*/
getStateHttp() {
getStateHttp(fallback = false) {
return this.getInfo().then(data => {
if (data.device && data.device.PowerState) {
return data.device.PowerState == 'on';
}

return true;
})
.catch(() => false);
.catch(() => fallback);
}

/**
Expand Down

0 comments on commit db72fa0

Please sign in to comment.