plasticrake / homebridge-tplink-smarthome

TP-Link Smarthome Plugin for Homebridge
MIT License
474 stars 70 forks source link

Support Apostrophes in Alias #35

Closed wzaatar closed 7 years ago

wzaatar commented 7 years ago

Hi @plasticrake,

Thanks for all your efforts with this plugin.

I recently installed it on my PI3 and noticed that the exec generates this recurring error:

homebridge[9649]: [10/10/2017, 1:30:34 PM] [TPLink.API] client.startDiscovery(): Error parsing JSON: SyntaxError: Unexpected token

Furthermore, I have 5 TPLink devices, 3 bulbs and two plugs. The bulbs are getting detected successfully whereas the plugs are not appearing although I can "see" them in and control them in Kasa without any issue.

The config I use in my config.json file is a copy of your own, with minor mods to include the "bulb" type under deviceTypes as well as fix the missing comma between inUseThreshold and timeout (That I suggest you update in your README.md file) as per the below:

"platforms": [ { "platform": "Hs100", "name": "TPLink", "deviceTypes": ["plug", "bulb"], "pollingInterval": 10, "switchModels": ["HS200"], "addCustomCharacteristics": true, "inUseThreshold": 0, // missing comma here "timeout": 5 }

Any insight you can provide will be much appreciated.

plasticrake commented 7 years ago

Do you have any other tplink devices on your network? Can you please try this: npm install -g hs100-api and run this command and paste the output: hs100-api search

wzaatar commented 7 years ago

It's throwing an error:

module.js:472 throw err; ^

Error: Cannot find module 'babel-runtime/helpers/slicedToArray' at Function.Module._resolveFilename (module.js:470:15) at Function.Module._load (module.js:418:25) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object. (/usr/lib/node_modules/hs100-api/lib/cli.js:4:23) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3)

wzaatar commented 7 years ago

I did a npm install babel-runtime and the binary runs now.

It sees the 3 bulbs successfully then throws the following errors:

client.startDiscovery(): Error parsing JSON: SyntaxError: Unexpected token in JSON at position 366 From: [IP ADDRESS OF PLUG] Original: A lot of random ASCII text Decrypted: [{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.1.2 Build 161014 Rel.164426","hw_ver":"1.0","type":"IOT.SMARTPLUGSWITCH","model":"HS100(US)","mac":"MY PLUG'S MAC ADDRESS","deviceId":"MASKEDID","hwId":"MASKEDID","fwId":"MASKEDID","oemId":"MASKEDID","alias":"MY NICKNAME FOR THE PLUG","dev_name":"Wi-Fi Smart Plug","icon_hash":"","relay_state":0,"on_time":0,"active_mode":"schedule","feature":"TIM","updating":0,"rssi":-62,"led_off":0,"latitude":masked,"longitude":masked}}}]

It looks like the plugs are being discovered but a code crash is occurring on line 366...

wzaatar commented 7 years ago

And I found what the issue is from the dump...

My alias includes a ' (apostrophe)... Looks like your parser is not digesting it.

As soon as I removed it from the alias, the 5 devices appeared and the error disappeared...

plasticrake commented 7 years ago

Whoops, I just updated hs100-api with the missing dependency (thanks!).

I'll do some testing with apostrophe's. They should be escaped when in JSON, so that means the TP-Link devices are not emitting valid JSON. I'll have to fix those before parsing. Thanks for the info!

:raised_hands:

plasticrake commented 7 years ago

This should be fixed in 3.6.0. You can now even put emoji in the name if you like!