Skip to content

Commit

Permalink
feat: allow multiple type flags in devices command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sitlintac committed Jul 12, 2022
1 parent 38d8b95 commit e8852ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-rocks-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartthings/cli": patch
---

enable multiple types when filtering devices
23 changes: 22 additions & 1 deletion packages/cli/src/__tests__/commands/devices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,31 @@ describe('DevicesCommand', () => {
expect(await listDevices()).toBe(devices)

expect(listSpy).toHaveBeenCalledTimes(1)
expect(listSpy).toHaveBeenCalledWith(expect.objectContaining({ type: 'VIRTUAL' }))
expect(listSpy).toHaveBeenCalledWith(expect.objectContaining({ type: ['VIRTUAL'] }))
expect(listSpy).toHaveBeenCalledWith(expect.objectContaining({ capability: undefined }))
expect(withLocationsAndRoomsMock).toHaveBeenCalledTimes(0)
})

it('allows multiple types', async () => {
await expect(DevicesCommand.run([
'--type', 'VIRTUAL',
'--type', 'ZWAVE',
])).resolves.not.toThrow()

expect(outputListingMock).toHaveBeenCalledTimes(1)
expect(outputListingMock.mock.calls[0][1].listTableFieldDefinitions)
.toEqual(['label', 'name', 'type', 'deviceId'])

const listDevices = outputListingMock.mock.calls[0][3]

expect(await listDevices()).toBe(devices)

expect(listSpy).toHaveBeenCalledTimes(1)
expect(listSpy).toHaveBeenCalledWith(expect.objectContaining({ type: ['VIRTUAL', 'ZWAVE'] }))
expect(listSpy).toHaveBeenCalledWith(expect.objectContaining({ capability: undefined }))
expect(withLocationsAndRoomsMock).toHaveBeenCalledTimes(0)

})
})

it('uses devices.get to get device', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class DevicesCommand extends APICommand<typeof DevicesCommand.fla
type: Flags.string({
description: 'filter results by device type',
options: Object.values(DeviceIntegrationType),
multiple: true,
}),
verbose: Flags.boolean({
description: 'include location name in output',
Expand Down Expand Up @@ -70,7 +71,7 @@ export default class DevicesCommand extends APICommand<typeof DevicesCommand.fla
locationId: this.flags['location-id'],
deviceId: this.flags['device-id'],
installedAppId: this.flags['installed-app-id'],
type: this.flags.type as DeviceIntegrationType | undefined,
type: this.flags.type as DeviceIntegrationType[] | undefined,
}

await outputListing(this, config, this.args.id,
Expand Down

0 comments on commit e8852ab

Please sign in to comment.