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

Function listOwnedHubs

src/lib/command/util/hubs.ts:10–32  ·  view source on GitHub ↗
(command: APICommand)

Source from the content-addressed store, hash-verified

8 * drivers cannot be managed on them.
9 */
10export const listOwnedHubs = async (command: APICommand): Promise<Device[]> => {
11 const hubs = await command.client.devices.list({ type: DeviceIntegrationType.HUB })
12 const locationIds = new Set<string>()
13 hubs.forEach(hub => {
14 if (hub.locationId !== undefined) {
15 locationIds.add(hub.locationId)
16 } else {
17 command.logger.warn('hub record found without locationId', hub)
18 }
19 })
20
21 // remove shared locations
22 for (const locationId of locationIds) {
23 const location = await command.client.locations.get(locationId, { allowed: true })
24
25 if (!location.allowed?.includes('d:locations')) {
26 command.logger.warn('filtering out location', location)
27 locationIds.delete(location.locationId)
28 }
29 }
30
31 return hubs.filter(hub => hub.locationId && locationIds.has(hub.locationId))
32}

Callers 3

listItemsFunction · 0.85
listItemsFunction · 0.85
hubs.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected