plasticrake / tplink-smarthome-api

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

Fix #124 "TypeError: Found non-callable @@iterator" error and various… #125

Closed iva2k closed 2 years ago

iva2k commented 3 years ago

… other cli issues

  1. Add explicit sendOptions arg to sendCommandDynamic() (also correctly log transport if set in sendOptions)
  2. Fix commander action arguments for commands in CommandSetup array
  3. Above changes fix #124 "TypeError: Found non-callable @@iterator" error for all commands in CommandSetup array
  4. Allow explicit optional params in CommandSetup type and use it in commander setup
  5. Fix setAlias command to have string parameter
  6. Define setPowerState parameter as optional

Background:

Call logic of API methods in sendCommandDynamic() may have worked at some point (when there were fewer methods), but got broken when more methods were added to the API. When Object[variable] pattern is used to select which method to call by name, TypeScript composes a compound type for all signatures of all methods, and refuses to call the selected method since the provided arguments don't match the compound signature, even if they match the specific method. Solution implemented to wipe out call arguments signature and use func.apply().

Further, sendCommandDynamic() was not receiving correct arguments due to the problem how the command.action() callback arguments were done. This logic needed complete revamp.

Few minor issues were noticed and fixed as well - always optional parameters in CommandSetup array, missing setAlias parameter.

codecov[bot] commented 3 years ago

Codecov Report

Merging #125 (b60d18f) into master (c27040d) will decrease coverage by 0.11%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #125      +/-   ##
==========================================
- Coverage   75.68%   75.57%   -0.12%     
==========================================
  Files          25       25              
  Lines        1345     1347       +2     
  Branches      307      310       +3     
==========================================
  Hits         1018     1018              
- Misses        250      252       +2     
  Partials       77       77              
Impacted Files Coverage Δ
src/cli.ts 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c27040d...b60d18f. Read the comment docs.

iva2k commented 3 years ago

Wow, fixing lint errors and running prettier wrapped one longer line, which increased line count by 4 and failed code coverage check by 0.2%. How do we get around it? Real coverage did not diminish.

plasticrake commented 3 years ago

Thank you! I took a quick look here but I'll need to pull this into my local machine and test things before merging

iva2k commented 3 years ago

I have a way to increase coverage by 2-3%. But it does not make sense to do it in this PR.

plasticrake commented 2 years ago

Much appreciated! Made a few tweaks and reverted the part where setPowerState had an optional parameter.