Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
109 changes: 0 additions & 109 deletions packages/edge/src/__tests__/lib/commands/drivers-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,112 +225,3 @@ test('chooseInstalledDriver presents user with list of drivers with names', asyn
expect(apiHubdevicesListInstalledMock).toHaveBeenCalledTimes(1)
expect(apiHubdevicesListInstalledMock).toHaveBeenCalledWith('hub-id')
})

describe('getDriverDevices', () => {
it('includes only edge device types', async () => {
const hubDevices = [
{ deviceId: 'hub-device-id', label: 'Hub Label' },
] as Device[]
const edgeDevices = [
{
type: DeviceIntegrationType.LAN,
deviceId: 'lan-device-id',
label: 'LAN Device',
lan: {
driverId: 'lan-driver-id',
hubId: 'hub-device-id',
},
},
{
type: DeviceIntegrationType.MATTER,
deviceId: 'matter-device-id',
label: 'Matter Device',
matter: {
driverId: 'matter-driver-id',
hubId: 'hub-device-id',
},
},
{
type: DeviceIntegrationType.ZIGBEE,
deviceId: 'zigbee-device-id',
label: 'Zigbee Device',
zigbee: {
driverId: 'zigbee-driver-id',
hubId: 'hub-device-id',
},
},
{
type: DeviceIntegrationType.ZWAVE,
deviceId: 'zwave-device-id',
label: 'Z-Wave Device',
zwave: {
driverId: 'zwave-driver-id',
hubId: 'bad-hub-device-id',
},
},
] as Device[]
const driverDevices: driversUtil.DeviceDriverInfo[] = [
{
type: DeviceIntegrationType.LAN,
label: 'LAN Device',
deviceId: 'lan-device-id',
driverId: 'lan-driver-id',
hubId: 'hub-device-id',
hubLabel: 'Hub Label',
},
{
type: DeviceIntegrationType.MATTER,
label: 'Matter Device',
deviceId: 'matter-device-id',
driverId: 'matter-driver-id',
hubId: 'hub-device-id',
hubLabel: 'Hub Label',
},
{
type: DeviceIntegrationType.ZIGBEE,
label: 'Zigbee Device',
deviceId: 'zigbee-device-id',
driverId: 'zigbee-driver-id',
hubId: 'hub-device-id',
hubLabel: 'Hub Label',
},
{
type: DeviceIntegrationType.ZWAVE,
label: 'Z-Wave Device',
deviceId: 'zwave-device-id',
driverId: 'zwave-driver-id',
hubId: 'bad-hub-device-id',
hubLabel: undefined,
},
]

apiDevicesListMock.mockResolvedValueOnce(hubDevices)
apiDevicesListMock.mockResolvedValueOnce(edgeDevices)

expect(await getDriverDevices(client)).toStrictEqual(driverDevices)

expect(apiDevicesListMock).toHaveBeenCalledTimes(2)
expect(apiDevicesListMock).toHaveBeenCalledWith({ type: DeviceIntegrationType.HUB })
expect(apiDevicesListMock).toHaveBeenCalledWith({ type: driversUtil.edgeDeviceTypes })
})

it('throws exception for invalid device input', async () => {
const hubDevices = [{ deviceId: 'hub-device-id', label: 'Hub Label' }] as Device[]
const edgeDevices = [
{
type: DeviceIntegrationType.LAN,
deviceId: 'lan-device-id',
label: 'LAN Device',
},
] as Device[]

apiDevicesListMock.mockResolvedValueOnce(hubDevices)
apiDevicesListMock.mockResolvedValueOnce(edgeDevices)

await expect(getDriverDevices(client)).rejects.toThrow('unexpected device type LAN or missing type info')

expect(apiDevicesListMock).toHaveBeenCalledTimes(2)
expect(apiDevicesListMock).toHaveBeenCalledWith({ type: DeviceIntegrationType.HUB })
expect(apiDevicesListMock).toHaveBeenCalledWith({ type: driversUtil.edgeDeviceTypes })
})
})
80 changes: 0 additions & 80 deletions packages/edge/src/commands/edge/drivers/devices.ts

This file was deleted.

53 changes: 0 additions & 53 deletions packages/edge/src/lib/commands/drivers-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,56 +57,3 @@ export const chooseInstalledDriver = async (command: APICommand<typeof APIComman
const preselectedId = await stringTranslateToId(config, commandLineDriverId, listItems)
return selectFromList(command, config, { preselectedId, listItems, promptMessage })
}

export const edgeDeviceTypes = [
DeviceIntegrationType.LAN,
DeviceIntegrationType.MATTER,
DeviceIntegrationType.ZIGBEE,
DeviceIntegrationType.ZWAVE,
]

export type DeviceDriverInfo = {
label?: string
type: DeviceIntegrationType
deviceId: string
driverId?: string
hubId?: string
hubLabel?: string
}

type DeviceTypeInfo = Pick<LanDeviceDetails, 'driverId' | 'hubId'>

const deviceTypeInfo = (device: Device): DeviceTypeInfo => {
if (device.type === DeviceIntegrationType.LAN && device.lan) {
return device.lan
}
if (device.type === DeviceIntegrationType.MATTER && device.matter) {
return device.matter
}
if (device.type === DeviceIntegrationType.ZIGBEE && device.zigbee) {
return device.zigbee
}
if (device.type === DeviceIntegrationType.ZWAVE && device.zwave) {
return device.zwave
}
throw Error(`unexpected device type ${device.type} or missing type info`)
}

const deviceToDeviceDriverInfo = (device: Device, hubDevices: Device[]): DeviceDriverInfo => {
const typeInfo = deviceTypeInfo(device)
const hubDevice = hubDevices.find(hub => typeInfo.hubId && hub.deviceId === typeInfo.hubId)
return {
type: device.type,
label: device.label,
deviceId: device.deviceId,
driverId: typeInfo.driverId,
hubId: typeInfo.hubId,
hubLabel: hubDevice?.label,
}
}

export const getDriverDevices = async (client: SmartThingsClient): Promise<DeviceDriverInfo[]> => {
const hubDevices = await client.devices.list({ type: DeviceIntegrationType.HUB })
return (await client.devices.list({ type: edgeDeviceTypes }))
.map(device => deviceToDeviceDriverInfo(device, hubDevices))
}
Loading