Mathieu2301 / Tuya-Cloud-API

API For Tuya Cloud
4 stars 1 forks source link

Suggestion for new method: userDevices #2

Open hyppoCom opened 2 years ago

hyppoCom commented 2 years ago

There is an interesting function to list users' devices. If you like it, here's the change. Thanks for your class.

--- node_modules/tuya-cloud/main.js 2021-12-01 14:55:16.840267542 +0100
+++ main.js 2021-12-01 14:56:50.377182428 +0100
@@ -61,7 +61,8 @@
       const t = Date.now();
       const sign = calcSign(t, session.token);

-      return request(method, `devices/${deviceId}${path}`, {
+      if(deviceId) path=`devices/${deviceId}${path}`;
+      return request(method, path, {
         client_id: clientID,
         t, sign,
         access_token: session.token,
@@ -110,6 +111,9 @@
             },
           }
         },
+        async userDevices(uuid) {
+       return (await requester.rq(null,`users/${uuid}/devices`,'GET'));
+        }
       });
     });
   },