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

Function chooseUnit

src/lib/command/util/virtualdevices.ts:181–200  ·  view source on GitHub ↗
(command: APICommand, attribute: CapabilityAttribute)

Source from the content-addressed store, hash-verified

179}
180
181export const chooseUnit = async (command: APICommand, attribute: CapabilityAttribute): Promise<string | undefined> => {
182 let unit
183 const units = attribute.schema.properties.unit?.enum
184 if (units) {
185 const config: SelectFromListConfig<CapabilityUnitItem> = {
186 itemName: 'unit',
187 primaryKeyName: 'unit',
188 sortKeyName: 'unit',
189 listTableFieldDefinitions: ['unit'],
190 }
191
192 const listItems = async (): Promise<CapabilityUnitItem[]> => Promise.resolve(units.map(unit => {
193 return { unit }
194 }))
195
196 const preselectedId = units.length === 1 ? units[0] : undefined
197 unit = await selectFromList(command, config, { preselectedId, listItems })
198 }
199 return unit
200}
201
202export const chooseValue = async (
203 command: APICommand,

Callers 2

getInputFromUserFunction · 0.85

Calls 1

selectFromListFunction · 0.85

Tested by

no test coverage detected