Advertisement
Guest User

harmony-hub-util-mod.js

a guest
Nov 9th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function executeDeviceCommand(device, commandx) {
  2. var deferred = Q.defer(),
  3. self = this;
  4. //console.log("XXXXX: " + device + "==" + commandx)
  5. self._harmonyClient.getAvailableCommands()
  6. .then(function (commands) {
  7. commands.device.filter(function (dev) {
  8. var command_array = commandx.split(',');
  9. for(var i = 0; i < command_array.length; i++) {
  10. if (dev.label === device) {
  11. dev.controlGroup.filter(function (group) {
  12. group['function'].filter(function (action) {
  13. var encodedAction, dt;
  14. if (JSON.parse(action.action).command === command_array[i]) {
  15. console.log("Triggering On device " + device + " command " + command_array[i]);
  16. encodedAction = action.action.replace(/\:/g, '::');
  17. dt = 'action=' + encodedAction + ':status=press';
  18. //console.log("Sending Action = " + dt);
  19. self._harmonyClient.send('holdAction', dt).then(function () {
  20. deferred.resolve(true);
  21. });
  22. //console.log("XXXXX: Return 1")
  23. var sleep = require('sleep');
  24. sleep.sleep(1);
  25. return;
  26. }
  27. });
  28. });
  29. }//if(dev.label)
  30. } //for
  31. });
  32. });
  33. //console.log("XXXXX: Return 2")
  34. return deferred.promise;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement