MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/deviceprofiles/view/create.ts:68–106  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

66 }))
67
68const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
69 const command = await apiOrganizationCommand(argv)
70
71 const createWithCustomConfig = async (data: DeviceDefinitionRequest): Promise<DeviceDefinition> => {
72 if (!data.view) {
73 throw Error('View property not defined')
74 }
75
76 // create the device config from the view data
77 const deviceConfig = await command.client.presentation.create(augmentPresentation(data.view))
78
79 // Set the vid and mnmn from the config
80 if (!data.metadata) {
81 data.metadata = {}
82 }
83 data.metadata.vid = deviceConfig.presentationId
84 data.metadata.mnmn = deviceConfig.manufacturerName
85 delete data.view
86
87 // Create the profile
88 const profile = await command.client.deviceProfiles.create(cleanupForCreate(data))
89
90 // Return the composite object
91 return { ...profile, view: prunePresentation(deviceConfig) }
92 }
93
94 const createDeviceDefinition = async (_: void, data: DeviceDefinitionRequest): Promise<DeviceDefinition> => {
95 if (data.view) {
96 return createWithCustomConfig(data)
97 }
98 const profileAndConfig = await createWithDefaultConfig(command.client, data)
99 return { ...profileAndConfig.deviceProfile, view: prunePresentation(profileAndConfig.deviceConfig) }
100 }
101 await inputAndOutputItem(
102 command,
103 { buildTableOutput: data => buildTableOutput(command.tableGenerator, data, { includeViewInfo: true }) },
104 createDeviceDefinition,
105 )
106}
107
108const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
109export default cmd

Callers

nothing calls this directly

Calls 3

apiOrganizationCommandFunction · 0.85
inputAndOutputItemFunction · 0.85
buildTableOutputFunction · 0.50

Tested by

no test coverage detected