( client: SmartThingsClient, locationId?: string, )
| 5 | |
| 6 | |
| 7 | export 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 | } |
no test coverage detected