TuyaAPI / cli

🔧 A CLI for Tuya devices
MIT License
261 stars 44 forks source link

`tuya-cli wizard` should output valid JSON for better usability and interoperability #82

Closed SidShetye closed 3 years ago

SidShetye commented 3 years ago

At present tuya-cli wizard outputs an object like

[
  {
    name: 'Kitchen 1',
    id: '00000000000000000000',
    key: 'aaaaaaaaaaaaaaaa'
  },
  {
    name: 'Kitchen 2',
    id: '00000000000000000000',
    key: 'aaaaaaaaaaaaaaaa'
  }
]

but it would be far more useful to have it print out valid JSON instead (e.g. homebridge wants this JSON, tedious for >5 devices) like

[
  {
    "name": "Kitchen 1",
    "id": "00000000000000000000",
    "key": "aaaaaaaaaaaaaaaa"
  },
  {
    "name": "Kitchen 2",
    "id": "00000000000000000000",
    "key": "aaaaaaaaaaaaaaaa"
  }
]

The fix is simple, at wizard.js ~ line 93

from

console.log(devices.map(device => ({name: device.name, id: device.id, key: device.local_key})));

to

let devs = devices.map(device => ({name: device.name, id: device.id, key: device.local_key}))
console.log(JSON.stringify(devs, null, 2));

or something similar

codetheweb commented 3 years ago

Great idea, happy to accept a PR for this. 👍

milo526 commented 3 years ago

I believe this was already fixed in a recent commit right?

https://github.com/TuyaAPI/cli/commit/2bdd195a5479b581e0d2572a9da8febf8c7d5ff1

Specifically with the new -s option.

codetheweb commented 3 years ago

Yep, forgot to link this issue to https://github.com/codetheweb/tuyapi/issues/390.

Thanks for the reminder.

Included in v1.15.0 of @tuyapi/cli.