MCPcopy Index your code
hub / github.com/SmartThingsCommunity/smartthings-cli / getModesWithLocation

Function getModesWithLocation

src/lib/command/util/modes.ts:7–22  ·  view source on GitHub ↗
(
		client: SmartThingsClient,
		locationId?: string,
)

Source from the content-addressed store, hash-verified

5
6
7export async function getModesWithLocation(
8 client: SmartThingsClient,
9 locationId?: string,
10): Promise<(Mode & WithNamedLocation)[]> {
11 const locations = locationId ? [await client.locations.get(locationId)] : await client.locations.list()
12
13 if (!locations || locations.length == 0) {
14 return fatalError('Could not find any locations for your account. Perhaps ' +
15 "you haven't created any locations yet.")
16 }
17
18 return (await Promise.all(locations.map(async location => {
19 const locationModes = await client.modes.list(location.locationId)
20 return locationModes.map(mode => ({ ...mode, locationId: location.locationId, location: location.name }) )
21 }))).flat()
22}

Callers 3

handlerFunction · 0.85
chooseModeFunction · 0.85
modes.test.tsFile · 0.85

Calls 1

fatalErrorFunction · 0.85

Tested by

no test coverage detected