Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/spotify

src/exports/get-devices.ts

20 lines · 806 B · TypeScript
import { getAvailableDevices, normalizeDeviceSummary } from '../lib/spotify-api.ts'
import type { GetDevicesParams } from '../lib/export-types.ts'

/**
 * List Spotify Connect devices for the connected account.
 * Prefer passing `name` (as `deviceName`) into playback helpers rather than copying `id`.
 * @example
 * import getDevices from 'kody:@kody/spotify/get-devices'
 * import playContext from 'kody:@kody/spotify/play-context'
 * const devices = await getDevices()
 * await playContext({
 *   contextUri: 'spotify:playlist:37i9dQZF1DX0XUsuxWHRQd',
 *   deviceName: devices[0]?.name,
 *   dryRun: true,
 * })
 */
export default async function getDevices(params: GetDevicesParams = {}) {
	const devices = await getAvailableDevices(params)
	return devices.map(normalizeDeviceSummary).filter(Boolean)
}