vizio-speaker
Advanced tools
Comparing version 1.1.0 to 1.2.0
50
index.js
@@ -55,3 +55,3 @@ let EventEmitter = require('events') | ||
let res = await this.sendRequest('put', ENDPOINTS.KEY_PRESS, data) | ||
return res?.STATUS?.RESULT | ||
return res && res.STATUS && res.STATUS.RESULT | ||
} | ||
@@ -68,3 +68,3 @@ | ||
if (res?.STATUS?.RESULT) { | ||
if (res && res.STATUS && res.STATUS.RESULT) { | ||
return res.STATUS.RESULT | ||
@@ -79,3 +79,3 @@ } else { | ||
let res = await this.sendRequest('get', ENDPOINTS.POWER_MODE) | ||
let val = res?.ITEMS?.[0]?.VALUE | ||
let val = res && res.ITEMS && res.ITEMS[0] && res.ITEMS[0].VALUE | ||
return val === 1 ? 'On' : val === 0 ? 'Off' : undefined | ||
@@ -91,7 +91,9 @@ }, | ||
let res = await this.sendRequest('get', ENDPOINTS.INPUTS) | ||
return res?.ITEMS?.map(item => item.NAME).filter(name => name != 'Current Input') | ||
return ( | ||
res && res.ITEMS && res.ITEMS.map(item => item.NAME).filter(name => name != 'Current Input') | ||
) | ||
}, | ||
get: async () => { | ||
let res = await this.sendRequest('get', ENDPOINTS.CURRENT_INPUT) | ||
return res?.ITEMS?.[0]?.VALUE | ||
return res && res.ITEMS && res.ITEMS[0] && res.ITEMS[0].VALUE | ||
}, | ||
@@ -105,7 +107,10 @@ set: async name => { | ||
let inputName = inputList.ITEMS?.find( | ||
item => | ||
item.NAME.toLowerCase() === name.toLowerCase() || | ||
item.VALUE.NAME.toLowerCase() === name.toLowerCase() | ||
)?.NAME | ||
let inputItem = | ||
inputList.ITEMS && | ||
inputList.ITEMS.find( | ||
item => | ||
item.NAME.toLowerCase() === name.toLowerCase() || | ||
item.VALUE.NAME.toLowerCase() === name.toLowerCase() | ||
) | ||
let inputName = inputItem && itemItem.NAME | ||
@@ -120,3 +125,3 @@ if (!inputName) throw Error(`Input: ${name} not found in list:`, inputList) | ||
let res = await this.sendRequest('put', ENDPOINTS.CURRENT_INPUT, data) | ||
return res?.STATUS?.RESULT | ||
return res && res.STATUS && res.STATUS.RESULT | ||
} | ||
@@ -130,3 +135,3 @@ } | ||
let res = await this.sendRequest('get', ENDPOINTS.VOLUME) | ||
return res?.ITEMS?.[0]?.VALUE | ||
return res && res.ITEMS && res.ITEMS[0] && res.ITEMS[0].VALUE | ||
}, | ||
@@ -139,3 +144,3 @@ set: async value => { | ||
let settings = await this.settings.audio.get() | ||
let volume = settings.ITEMS?.find(i => i.CNAME === 'volume') | ||
let volume = settings.ITEMS && settings.ITEMS.find(i => i.CNAME === 'volume') | ||
if (!volume) throw Error('no volume setting found') | ||
@@ -149,7 +154,7 @@ | ||
let res = await this.sendRequest('put', ENDPOINTS.VOLUME, data) | ||
return res?.STATUS?.RESULT | ||
return res && res.STATUS && res.STATUS.RESULT | ||
}, | ||
getMute: async () => { | ||
let res = await this.sendRequest('get', ENDPOINTS.MUTE) | ||
return res?.ITEMS?.[0]?.VALUE | ||
return res && res.ITEMS && res.ITEMS[0] && res.ITEMS[0].VALUE | ||
}, | ||
@@ -212,6 +217,7 @@ unmute: () => this.keyCommand(KEYS.MUTE_OFF), | ||
let obj = {} | ||
this.items?.forEach(itemName => { | ||
let val = this[itemName]?.cache | ||
if (val) obj[itemName] = val | ||
}) | ||
this.items && | ||
this.items.forEach(itemName => { | ||
let val = this[itemName] && this[itemName].cache | ||
if (val) obj[itemName] = val | ||
}) | ||
return obj | ||
@@ -223,3 +229,3 @@ } | ||
// If is menu | ||
if (this._lastResult.TYPE?.match(/MENU/)) { | ||
if (this._lastResult.TYPE && this._lastResult.TYPE.match(/MENU/)) { | ||
// Make array of next endpoints | ||
@@ -256,3 +262,3 @@ this.items = this._lastResult.ITEMS.map(item => item.CNAME) | ||
checkIfReady() { | ||
if (this.items?.every(name => this[name]?.isReady)) this.ready() | ||
if (this.items && this.items.every(name => this[name] && this[name].isReady)) this.ready() | ||
} | ||
@@ -270,3 +276,3 @@ } | ||
let item = this._lastResult | ||
return item?.VALUE?.NAME == '' ? item?.NAME : item?.VALUE | ||
return item && item.VALUE && item.VALUE.NAME == '' ? item.NAME : item.VALUE | ||
} | ||
@@ -273,0 +279,0 @@ async get() { |
{ | ||
"name": "vizio-speaker", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Communicate with Vizio SmartCast speakers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14487
295