(argv: ArgumentsCamelCase<CommandArgs>)
| 52 | .epilog(buildEpilog({ command, apiDocs: 'updateHubDevice' })) |
| 53 | |
| 54 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 55 | const command = await apiCommand(argv) |
| 56 | |
| 57 | const hubId = await chooseHub( |
| 58 | command, |
| 59 | argv.hub, |
| 60 | { promptMessage: 'Which hub is the device connected to?', useConfigDefault: true }, |
| 61 | ) |
| 62 | const deviceListFilter = (device: Device): boolean => |
| 63 | device.type === DeviceIntegrationType.LAN && device.lan?.hubId === hubId || |
| 64 | device.type === DeviceIntegrationType.MATTER && device.matter?.hubId === hubId || |
| 65 | device.type === DeviceIntegrationType.ZIGBEE && device.zigbee?.hubId === hubId || |
| 66 | device.type === DeviceIntegrationType.ZWAVE && device.zwave?.hubId === hubId |
| 67 | |
| 68 | const deviceListOptions = { |
| 69 | type: edgeDeviceTypes, |
| 70 | } |
| 71 | const deviceId = await chooseDeviceFn(deviceListOptions)( |
| 72 | command, |
| 73 | argv.deviceId, |
| 74 | { listFilter: deviceListFilter }, |
| 75 | ) |
| 76 | |
| 77 | const matchingDrivers = await listMatchingDrivers(command.client, deviceId, hubId) |
| 78 | const listItems = argv.includeNonMatching |
| 79 | ? () => listAllAvailableDrivers(command.client, deviceId, hubId) |
| 80 | : async () => matchingDrivers |
| 81 | const driverId = await chooseDriver( |
| 82 | command, |
| 83 | argv.driver, |
| 84 | { promptMessage: 'Choose a driver to use.', listItems }, |
| 85 | ) |
| 86 | const forceUpdate = argv.includeNonMatching && !matchingDrivers.find(driver => driver.driverId === driverId) |
| 87 | |
| 88 | await command.client.hubdevices.switchDriver(driverId, hubId, deviceId, forceUpdate) |
| 89 | console.log(`Updated driver for device ${deviceId} to ${driverId}.`) |
| 90 | } |
| 91 | |
| 92 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 93 | export default cmd |
nothing calls this directly
no test coverage detected