Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a route to get a list of devices by serial and network id #118

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/modules/Resources/Devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,38 @@ class Devices extends TagoIOModule<GenericModuleParams> {
return result;
}

/**
* Retrieves a list with all devices from profile filtered by serial and network.
*
* @param serial Device Token Serial.
* @param queryParams Query parameters to select fields and order the results.
* @param networkId Device network ID.
*
*/
public async getDeviceBySerial<T extends DeviceQuery>(serial: string, networkId?: string, queryObj?: T) {
let result = await this.doRequest<
DeviceListItem<
T["fields"] extends DeviceQuery["fields"]
? T["fields"][number]
: "id" | "name" | "network" | "connector" | "type" | "tags"
>[]
>({
path: `/device/find/${serial}`,
method: "GET",
params: {
page: queryObj?.page || 1,
fields: queryObj?.fields || ["id", "name", "network", "connector", "type", "tags"],
filter: networkId ? { network: networkId } : {},
amount: queryObj?.amount || 20,
orderBy: queryObj?.orderBy ? `${queryObj.orderBy[0]},${queryObj.orderBy[1]}` : "name,asc",
},
});

result = result.map((data) => dateParser(data, ["last_input", "updated_at", "created_at"]));

return result;
}

/**
* Get data from all variables in the device.
*
Expand Down