plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.02k stars 141 forks source link

TypeError: Cannot read property 'alias' of undefined #116

Closed miso-develop closed 3 years ago

miso-develop commented 3 years ago

When running examples/plug-turn-on-off.js on Smart Plug HS105, the following error occurs.

.\node_modules\tplink-smarthome-api\lib\device\index.js:98
        this.log.debug('[%s] device sysInfo set', sysInfo.alias || this.alias);
                                                          ^

TypeError: Cannot read property 'alias' of undefined
    at Plug.setSysInfo (.\node_modules\tplink-smarthome-api
\lib\device\index.js:98:59)
    at Plug.setSysInfo (.\node_modules\tplink-smarthome-api\lib\plug\index.js:182:15)
    at new Plug (.\node_modules\tplink-smarthome-api\lib\plug\index.js:166:14)
    at Client.getPlug (.\node_modules\tplink-smarthome-api\lib\client.js:179:16)
    at Object.<anonymous> (.\index.js:7:21)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)

Version

Execution environment

Workaround

Install v2.0.0

etc

CLI(npx tplink-smarthome-api search) also worked with v3.1.0.

jbhelfrich commented 3 years ago

Getting the same trying to connect to a bulb. const bulb = client.getBulb({host: '192.168.1.244'})

Uncaught TypeError: Cannot read property 'alias' of undefined
    at Bulb.setSysInfo (C:\Users\joe\WebstormProjects\untitled\node_modules\tplink-smarthome-api\lib\device\index.js:98:59)
    at Bulb.setSysInfo (C:\Users\joe\WebstormProjects\untitled\node_modules\tplink-smarthome-api\lib\bulb\index.js:123:15)
    at new Bulb (C:\Users\joe\WebstormProjects\untitled\node_modules\tplink-smarthome-api\lib\bulb\index.js:109:14)
    at Client.getBulb (C:\Users\joe\WebstormProjects\untitled\node_modules\tplink-smarthome-api\lib\client.js:166:16)
plasticrake commented 3 years ago

Since v3, using getPlug or getBulb require you to pass in the sysinfo for the device. Its preferred to use client#getDevice which does not have that requirement. I've corrected the example that was broken since v3.