diff --git a/devices/media.html b/devices/media.html index 570db177..91115d58 100644 --- a/devices/media.html +++ b/devices/media.html @@ -508,7 +508,7 @@

References

Smart Home streaming box Guide.

Smart Home streaming soundbar Guide.

Smart Home streaming stick Guide.

-

Smart Home TV Guide.

+

Smart Home Television Guide.

Node Information.

diff --git a/devices/media.js b/devices/media.js index d16eadc5..4eb80ffc 100644 --- a/devices/media.js +++ b/devices/media.js @@ -165,7 +165,7 @@ module.exports = function(RED) { } } else { this.available_applications = undefined; - RED.log.debug("Applications disabled"); + this.debug(".constructor: Applications disabled"); } if (this.has_channels) { @@ -176,7 +176,7 @@ module.exports = function(RED) { } } else { this.available_channels = undefined; - RED.log.debug("Channels disabled"); + this.debug(".constructor: Channels disabled"); } if (this.has_inputs) { @@ -187,7 +187,7 @@ module.exports = function(RED) { } } else { this.available_inputs = undefined; - RED.log.debug("Inputs disabled"); + this.debug(".constructor Inputs disabled"); } if (this.has_modes) { @@ -198,7 +198,7 @@ module.exports = function(RED) { } } else { this.available_modes = undefined; - RED.log.debug("Modes disabled"); + this.debug(".constructor: Modes disabled"); } if (this.has_toggles) { @@ -209,7 +209,7 @@ module.exports = function(RED) { } } else { this.available_toggles = undefined; - RED.log.debug("Toggles disabled"); + this.debug(".constructor: Toggles disabled"); } this.states = this.clientConn.register(this, 'media', config.name, this); @@ -225,6 +225,7 @@ module.exports = function(RED) { } debug(msg) { + msg = 'google-smarthome:MediaNode' + msg; if (this.clientConn && typeof this.clientConn.debug === 'function') { this.clientConn.debug(msg); } else { @@ -237,7 +238,7 @@ module.exports = function(RED) { * */ registerDevice(client, name, me) { - RED.log.debug("MediaNode(registerDevice) device_type " + me.device_type); + me.debug(".registerDevice: device_type " + me.device_type); let states = { online: true }; @@ -273,7 +274,7 @@ module.exports = function(RED) { this.updateAttributesForTraits(me, device); this.updateStatesForTraits(me, device); - RED.log.debug("MediaNode(registerDevice): device = " + JSON.stringify(device)); + me.debug(".registerDevice: device = " + JSON.stringify(device)); return device; } @@ -370,10 +371,12 @@ module.exports = function(RED) { * called when state is updated from Google Assistant * */ - updated(device, params) { + updated(device, params, original_params) { let states = device.states; let command = device.command; - RED.log.debug("MediaNode(updated): states = " + JSON.stringify(states)); + this.debug(".updated: states = " + JSON.stringify(states)); + this.debug(".updated: params = " + JSON.stringify(params)); + this.debug(".updated: original_params = " + JSON.stringify(original_params)); Object.assign(this.states, states); @@ -398,6 +401,16 @@ module.exports = function(RED) { } }); + if (command === 'action.devices.commands.mediaSeekRelative') { + if (original_params.hasOwnProperty('relativePositionMs')) { + msg.payload.relativePositionMs = original_params.relativePositionMs; + } + } else if (command === 'action.devices.commands.mediaSeekToPosition') { + if (original_params.hasOwnProperty('absPositionMs')) { + msg.payload.absPositionMs = original_params.absPositionMs; + } + } + this.send(msg); }; @@ -407,12 +420,11 @@ module.exports = function(RED) { */ onInput(msg) { const me = this; - RED.log.debug("MediaNode(input)"); + me.debug(".input: topic = " + msg.topic); let topicArr = String(msg.topic).split(this.topicDelim); let topic = topicArr[topicArr.length - 1]; // get last part of topic - RED.log.debug("MediaNode(input): topic = " + topic); try { if (topic.toUpperCase() === 'APPLICATIONS') { if (this.has_apps) { @@ -515,14 +527,14 @@ module.exports = function(RED) { Object.keys(this.states).forEach(function (key) { if (topic.toUpperCase() == key.toUpperCase()) { state_key = key; - RED.log.debug("MediaNode(input): found state " + key); + me.debug(".input: found state " + key); } }); if (state_key !== '') { const differs = me.setState(state_key, msg.payload, this.states); if (differs) { - RED.log.debug("MediaNode(input): " + state_key + ' ' + msg.payload); + me.debug(".input: " + state_key + ' ' + msg.payload); this.clientConn.setState(this, this.states); // tell Google ... if (this.passthru) { @@ -533,11 +545,11 @@ module.exports = function(RED) { this.updateStatusIcon(); } } else { - RED.log.debug("MediaNode(input): some other topic"); + me.debug(".input: some other topic"); let differs = false; Object.keys(this.states).forEach(function (key) { if (msg.payload.hasOwnProperty(key)) { - RED.log.debug("MediaNode(input): set state " + key + ' to ' + msg.payload[key]); + me.debug(".input: set state " + key + ' to ' + msg.payload[key]); if (me.setState(key, msg.payload[key], me.states)) { differs = true; } @@ -590,7 +602,7 @@ module.exports = function(RED) { updateModesState(me, device) { // Key/value pair with the mode name of the device as the key, and the current setting_name as the value. - RED.log.debug("Update Modes device"); + me.debug(".updateModesState"); let states = device.states || {}; const currentModeSettings = states['currentModeSettings'] let new_modes = {}; @@ -690,7 +702,7 @@ module.exports = function(RED) { const userDir = RED.settings.userDir; filename = path.join(userDir, filename); } - RED.log.debug('MediaNode:loadJson(): loading ' + filename); + this.debug('.loadJson: filename ' + filename); try { let jsonFile = fs.readFileSync( @@ -701,12 +713,12 @@ module.exports = function(RED) { }); if (jsonFile === '') { - RED.log.debug('MediaNode:loadJson(): empty data'); + this.debug('.loadJson: empty data'); return defaultValue; } else { - RED.log.debug('MediaNode:loadJson(): data loaded'); + this.debug('.loadJson: data loaded'); const json = JSON.parse(jsonFile); - RED.log.debug('MediaNode:loadJson(): json = ' + JSON.stringify(json)); + this.debug('.loadJson: json = ' + JSON.stringify(json)); return json; } } @@ -721,7 +733,7 @@ module.exports = function(RED) { const userDir = RED.settings.userDir; filename = path.join(userDir, filename); } - RED.log.debug('MediaNode:writeJson(): writing ' + filename); + this.debug('.writeJson: filename ' + filename); if (typeof value === 'object') { value = JSON.stringify(value); } @@ -734,7 +746,7 @@ module.exports = function(RED) { 'flag': fs.constants.W_OK | fs.constants.O_CREAT | fs.constants.O_TRUNC }); - RED.log.debug('MediaNode:writeJson(): data saved'); + this.debug('writeJson: data saved'); return true; } catch (err) { @@ -752,18 +764,10 @@ module.exports = function(RED) { 'executionStates': executionStates }; - RED.log.debug("MediaNode:execCommand(command) " + JSON.stringify(command)); - RED.log.debug("MediaNode:execCommand(states) " + JSON.stringify(this.states)); - // RED.log.debug("MediaNode:execCommand(device) " + JSON.stringify(device)); + me.debug(".execCommand: command " + JSON.stringify(command)); + me.debug(".execCommand: states " + JSON.stringify(this.states)); + // me.debug(".execCommand: device " + JSON.stringify(device)); - if (!command.hasOwnProperty('params')) { - // TransportControl - if (command.command == 'action.devices.commands.mediaClosedCaptioningOff') { - executionStates.push('online', 'playbackState'); - return ok_result; - } - return false; - } // Applications if ((command.command == 'action.devices.commands.appInstall') || (command.command == 'action.devices.commands.appSearch') || @@ -922,6 +926,10 @@ module.exports = function(RED) { executionStates.push('online', 'playbackState'); return ok_result; } + else if (command.command == 'action.devices.commands.mediaClosedCaptioningOff') { + executionStates.push('online', 'playbackState'); + return ok_result; + } // Volume else if (command.command == 'action.devices.commands.mute') { if (command.params.hasOwnProperty('mute')) { diff --git a/lib/Devices.js b/lib/Devices.js index 8dc5a024..4d265e71 100755 --- a/lib/Devices.js +++ b/lib/Devices.js @@ -129,7 +129,7 @@ class Devices { // // // - execDevice(device, doUpdate, params) { + execDevice(device, doUpdate, params, original_params) { let me = this; me.debug('Device:execDevice(): BEGIN'); @@ -177,7 +177,7 @@ class Devices { if (doUpdate) { me.debug('Device:execDevice(): doUpdate'); - this._nodes[device.id].updated(this._devices[device.id], params); + this._nodes[device.id].updated(this._devices[device.id], params, original_params); } me.debug('Device:execDevice(): END'); diff --git a/lib/HttpActions.js b/lib/HttpActions.js index 1c482ce7..74b7f81b 100755 --- a/lib/HttpActions.js +++ b/lib/HttpActions.js @@ -376,6 +376,7 @@ class HttpActions { _execDevice(command, device) { this.debug('HttpActions:_execDevice(): command = ' + JSON.stringify(command)); + const params = command.hasOwnProperty('params') ? command.params : {}; let curDevice = { id: device.id, states: {}, @@ -421,7 +422,7 @@ class HttpActions { states: {}, }; - this.execDevice(curDevice, true, command.params); + this.execDevice(curDevice, true, command.params, params); let execDevice = this.getStatus([curDevice.id]); this.debug('HttpActions:_execDevice(): execDevice = ' + JSON.stringify(execDevice));