Aymkdn / assistant-plugins

Des plugins pour les Assistant (comme Google Home, Cortana, Alexa)
https://aymkdn.github.io/assistant-plugins/
MIT License
92 stars 21 forks source link

"port" option should be a number or string dans assistant-notifier #230

Closed Aymkdn closed 5 years ago

Aymkdn commented 5 years ago

Bonjour à tous, J'ai un problème à peu prêt similaire je pense, j'ai installer Assistant-Plugins sur mon rasberry dans le but d'envoyer à mon google home des notifications audio depuis Domoticz. Je passe donc une requête Webhooks dans iftt, malheureusement j'obtient le message d'erreur ci dessous :

[assistant] Assistant v2.0.12 : Chargement en cours...
[assistant] 1 plugin trouvé.
[assistant] Chargement du plugin 'notifier' (v2.1.6)
[assistant-notifier] Plugin chargé et prêt.
[assistant] Connexion au flux de PushBullet...
[assistant] (2019-02-19 16:26:41) Connecté ! Prêt à exécuter les ordres.
[assistant] (2019-02-19 16:26:48) Commande reçue:  [ 'notifier_{host} \'ceci est un test\'' ]
[assistant] (2019-02-19 16:26:48) Appel du plugin 'notifier'
[assistant-notifier] (host) Lecture du message : 'ceci est un test'
(node:8647) UnhandledPromiseRejectionWarning: TypeError: "port" option should be a number or string: function (err, result) {
      if (err) rej(err);
      else res(result);
    }
    at lookupAndConnect (net.js:1060:13)
    at TLSSocket.Socket.connect (net.js:1037:5)
    at Object.exports.connect (_tls_wrap.js:1077:12)
    at Client.connect (/home/pi/assistant-plugins/node_modules/assistant-notifier/node_modules/castv2-client/node_modules/castv2/lib/client.js:35:21)
    at PlatformSender.connect (/home/pi/assistant-plugins/node_modules/assistant-notifier/node_modules/castv2-client/lib/senders/platform.js:27:15)
    at /home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:33:13
    at new Promise (<anonymous>)
    at AssistantNotifier.prom (/home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:28:10)
    at /home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:78:15
    at Array.forEach (<anonymous>)
(node:8647) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:8647) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Je ne comprend pas vraiment d'ou vient le problème, quelqu'un pourrait il m'aider svp ? Merci d'avance, Julien

Originally posted by @jth62 in https://github.com/Aymkdn/assistant-notifier/issues/1#issuecomment-464782594

Aymkdn commented 5 years ago

Dans ton fichier /home/pi/assistant-plugins/node_modules/node-castv2/lib/client.js, ajoute le code suivant sur la ligne 32 :

console.debug(options);

Puis relance assistant-plugins et montre moi ce que dit ta console.

jth62 commented 5 years ago

Bonjour Aymkdn et merci pour ton aide ! :)

Étrange , j'ai l'impression que ce module et simplement inexistant ? 2019-02-18_17-14-44

Je suis en version de node 8.11.1 => je test un update

Aymkdn commented 5 years ago

Ah oui, t'as une vieille version. C'est là en fait :

/home/pi/assistant-plugins/node_modules/assistant-notifier/node_modules/castv2-client/node_modules/castv2/lib/client.js
jth62 commented 5 years ago

C'est exact ! Voici le résultat :

pi@raspberrypi:~/assistant-plugins $ node index.js
[assistant] Assistant v2.0.12 : Chargement en cours...
[assistant] 1 plugin trouvé.
[assistant] Chargement du plugin 'notifier' (v2.1.6)
[assistant-notifier] Plugin chargé et prêt.
[assistant] Connexion au flux de PushBullet...
[assistant] (2019-02-19 17:20:35) Connecté ! Prêt à exécuter les ordres.
[assistant] (2019-02-19 17:21:55) Commande reçue:  [ "notifier_{host} 'ceci est un test'" ]
[assistant] (2019-02-19 17:21:55) Appel du plugin 'notifier'
[assistant-notifier] (host) Lecture du message : 'ceci est un test'
{ [Function: callback] port: 8009, rejectUnauthorized: false }
(node:10699) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "options.port" property must be one of type number or string. Received type function
    at lookupAndConnect (net.js:934:13)
    at TLSSocket.Socket.connect (net.js:914:5)
    at Object.connect (_tls_wrap.js:1298:13)
    at Client.connect (/home/pi/assistant-plugins/node_modules/assistant-notifier/node_modules/castv2-client/node_modules/castv2/lib/client.js:35:21)
    at PlatformSender.connect (/home/pi/assistant-plugins/node_modules/assistant-notifier/node_modules/castv2-client/lib/senders/platform.js:27:15)
    at /home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:33:13
    at new Promise (<anonymous>)
    at AssistantNotifier.prom (/home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:28:10)
    at /home/pi/assistant-plugins/node_modules/assistant-notifier/notifier.js:78:15
    at Array.forEach (<anonymous>)
(node:10699) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:10699) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Aymkdn commented 5 years ago

Compliqué de debugguer puisque le problème via d'un module tiers et que je n'ai pas le problème chez moi...

Essaie de commenter la ligne 31 et vois ce que ça donne :

// if(callback) this.once('connect', callback);
jth62 commented 5 years ago

Bonjour, après test le problème se reproduit toujours. Je vais essayer de creuser au niveau de module castv2

Aymkdn commented 5 years ago

Le truc bizarre c'est qu'il voit port comme étant la fonction callback on dirait ({ [Function: callback] port: 8009, rejectUnauthorized: false })

Donc faudrait faire différents tests.... Par exemple changer la variable "port" par "8009“ dans l'appel de la fonction (c'est-à-dire une valeur en dur), et autres tentatives de ce type pour réussir à isoler l'origine du problème.

Si tu trouves, merci de partager ici car tu es le deuxième à qui cela arrive.

jth62 commented 5 years ago

Bonjour Aymkdn, j'ai bidouillé pas mal le client.js => toujours le même résultat J'ai réinstallé l'ensemble sur une VM => pareil

Je viens de testé sous windows avec comme nodejs 8.9.1 et la config suivante :

{
  "main": {
    "pushbullet_token": "o.MONPUSH"
  },
  "plugins": {
    "bluetooth": {
      "host": "192.168.1.103"
    },
    "ifttt": {
      "key": "MYKEY"
    },
    "notifier": {
      "host": "192.168.1.103"
    }
  }
}

Cela génère ce message :

[assistant-wait] Plugin chargé et prêt.
[assistant] Connexion au flux de PushBullet...
[assistant] (2019-02-21 14:50:43) Connecté ! Prêt à exécuter les ordres.
[assistant] (2019-02-21 14:50:58) Commande reçue:  [ 'notifier_{host} \'ceci est un test\'' ]
[assistant] (2019-02-21 14:50:58) Appel du plugin 'notifier'
[assistant-notifier] (host) Lecture du message : 'ceci est un test'
(node:5808) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: "port" option should be a number or string: function (err, result) {
      if (err) rej(err);
      else res(result);
    }
(node:5808) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.[assistant] (2019-02-21 14:51:26) Commande reçue:  [ 'notifier_{host} \'ceci est un test\'' ]
[assistant] (2019-02-21 14:51:26) Appel du plugin 'notifier'
[assistant-notifier] (host) Lecture du message : 'ceci est un test'
(node:5808) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): TypeError: "port" option should be a number or string: function (err, result) {
      if (err) rej(err);
      else res(result);
    }

Le problème peut il venir coté google home?

Aymkdn commented 5 years ago

Je viens de testé sous windows avec comme nodejs 8.9.1 Le problème peut il venir coté google home?

Sous Windows, essaie plutôt d'installer la dernière version de Node (v10.15.1), pour éliminer ça d'abord.

jth62 commented 5 years ago

Re,

C:\scripts\assistant-plugins>node -v v10.15.1

Le problème semble persister :

[assistant] Connexion au flux de PushBullet... [assistant] (2019-02-21 15:29:17) Connecté ! Prêt à exécuter les ordres. [assistant] (2019-02-21 15:30:02) Commande reçue: [ 'notifier_{host} \'ceci est un test\'' ] [assistant] (2019-02-21 15:30:02) Appel du plugin 'notifier' [assistant-notifier] (host) Lecture du message : 'ceci est un test' (node:4336) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "options.port" property must be one of type number or string. Received type function at lookupAndConnect (net.js:951:13) at TLSSocket.Socket.connect (net.js:931:5) at Object.connect (_tls_wrap.js:1150:12) at Client.connect (C:\scripts\assistant-plugins\node_modules\castv2\lib\client.js:35:21) at PlatformSender.connect (C:\scripts\assistant-plugins\node_modules\castv2-client\lib\senders\platform.js:27:15) at C:\scripts\assistant-plugins\node_modules\assistant-notifier\notifier.js:33:13 at new Promise () at AssistantNotifier.prom (C:\scripts\assistant-plugins\node_modules\assistant-notifier\notifier.js:28:10) at C:\scripts\assistant-plugins\node_modules\assistant-notifier\notifier.js:78:15 at Array.forEach () (node:4336) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:4336) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Aymkdn commented 5 years ago

OK, donc on peut déjà éliminer la version de Node.

Tu as plusieurs Google Home chez toi ?

jth62 commented 5 years ago

Exact, j'ai : Google-Home => 192.168.1.103 Google-Home-Mini => 192.168.1.140

Aymkdn commented 5 years ago

Je ne vois pas pourquoi le problème viendrait du Google Home, puisque on a l'erreur :

The "options.port" property must be one of type number or string. Received type function

Le port est reconnu comme une fonction... C'est ça qui est super chelou.

Pour moi le problème vient de https://github.com/thibauts/node-castv2/blob/master/lib/client.js#L35 ... Essaie de remplacer cette ligne par :

this.socket = tls.connect({port:8009, host:"192.168.1.103"}, function() {
Aymkdn commented 5 years ago

Question : ta box est bien sur le même réseau que les Google Home (c'est-à-dire que là où tourne Node a une IP 192.168.1.x) ?

no-response[bot] commented 5 years ago

Cette issue a été automatiquement fermée car il n'y a eu aucune réponse complémentaire de la part de l'auteur. N'hésite pas à reposter ici si tu as d'autres questions.