nocmt / ewelink-api-next

CoolKit v2 API Official Library
MIT License
22 stars 5 forks source link

Refactoring of things type #7

Closed deunlee closed 1 year ago

deunlee commented 1 year ago

Since the things type used in functions such as getThingStatus() is a number, it may be difficult to understand the code.

/**
* Get Device Status
*
* @param options - The things information.
* @param options.type - The things type. 1: user's own device, 2: devices shared by others.
* @param options.id - The things id.
* @param options.params - option, The things params.
* @returns response - Please refer to the online API documentation
*/

So, I think it would be a good idea to change the things type to a string. I suggest replacing type: number | 1 | 2; with type: 'own' | 'shared';.

Also, since most devices are owned by the user, it seems good to set the default to own.

async getThingStatus(options: thingInfo) {
    const params = {
      type: options.type ?? 1, // or 'own'
      id: options.id,
      params: options?.params
    };
    // ...
}
nocmt commented 1 year ago

own

I will consider this matter

ghost commented 1 year ago

The modifications have been completed, please update to the latest version