Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import locationsRoomsUpdateCommand from './locations/rooms/update.js'
import logoutCommand from './logout.js'
import organizationsCommand from './organizations.js'
import organizationsCurrentCommand from './organizations/current.js'
import presentationCommand from './presentation.js'
import presentationDeviceConfigCommand from './presentation/device-config.js'
import presentationDeviceConfigCreateCommand from './presentation/device-config/create.js'
import presentationDeviceConfigGenerateCommand from './presentation/device-config/generate.js'
Expand Down Expand Up @@ -196,6 +197,7 @@ export const commands: CommandModule<object, any>[] = [
logoutCommand,
organizationsCommand,
organizationsCurrentCommand,
presentationCommand,
presentationDeviceConfigCommand,
presentationDeviceConfigCreateCommand,
presentationDeviceConfigGenerateCommand,
Expand Down
67 changes: 67 additions & 0 deletions src/commands/presentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { type PresentationDevicePresentation } from '@smartthings/core-sdk'

import { apiCommand, apiCommandBuilder, apiDocsURL, type APICommandFlags } from '../lib/command/api-command.js'
import { outputItem, outputItemBuilder, type OutputItemFlags } from '../lib/command/output-item.js'
import { buildTableOutput } from '../lib/command/util/presentation-table.js'


export type CommandArgs =
& APICommandFlags
& OutputItemFlags
& {
presentationId?: string
manufacturerName?: string
}

const command = 'presentation <presentationId> [manufacturer-name]'

const describe = 'query device presentation by presentation id'

const builder = (yargs: Argv): Argv<CommandArgs> =>
outputItemBuilder(apiCommandBuilder(yargs))
.positional(
'presentation-id',
{
describe: 'system generated identifier that corresponds to a device presentation',
type: 'string',
required: true,
},
)
.positional(
'manufacturer-name',
{
describe: 'manufacturer name, defaults to SmartThingsCommunity',
type: 'string',
},
)
.example([
[
'$0 presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf',
'display the specified presentation, which is associated with the SmartThingsCommunity manufacturer id'],
[
'$0 devices presentation 4ea31e30-2aba-41c7-a3ec-8f97423d565a DoodadsInc',
'display the specified presentation, which is associated with the DoodadsInc manufacturer id',
],
])
.epilog('The language can be overridden by specifying an ISO language code with the "--language" option. If' +
' "NONE" is specified for the language code then no language header is specified in the API request.\n\n' +
apiDocsURL('getDevicePresentation'))

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = await apiCommand(argv)

const config = {
buildTableOutput: (data: PresentationDevicePresentation) => buildTableOutput(command.tableGenerator, data),
}
await outputItem(
command,
config,
// presentationId is required in the `positional` argument above so it will always be set here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
() => command.client.presentation.getPresentation(argv.presentationId!, argv.manufacturerName))
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
5 changes: 2 additions & 3 deletions src/commands/presentation/device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CommandArgs =

const command = 'presentation:device-config <presentationId> [manufacturer-name]'

const describe = 'query device config by presentationId'
const describe = 'query device config by presentation id'

const builder = (yargs: Argv): Argv<CommandArgs> =>
outputItemBuilder(apiCommandBuilder(yargs))
Expand All @@ -25,9 +25,8 @@ const builder = (yargs: Argv): Argv<CommandArgs> =>
required: true,
})
.positional('manufacturer-name', {
describe: 'manufacturer name',
describe: 'manufacturer name, defaults to SmartThingsCommunity',
type: 'string',
default: 'SmartThingsCommunity',
})
.example([
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { PresentationDevicePresentation } from '@smartthings/core-sdk'
import { type PresentationDevicePresentation } from '@smartthings/core-sdk'

import { APICommand, outputItem, TableGenerator } from '@smartthings/cli-lib'
import { type TableGenerator } from '../../table-generator.js'


export function buildTableOutput(tableGenerator: TableGenerator, presentation: PresentationDevicePresentation): string {
const basicInfo = tableGenerator.buildTableFromItem(presentation, [
{ prop: 'presentationId', label: 'Presentation ID' }, { prop: 'manufacturerName', label: 'Manufacturer Name' }, 'iconUrl',
])
export const buildTableOutput = (
tableGenerator: TableGenerator,
presentation: PresentationDevicePresentation,
): string => {
const basicInfo = tableGenerator.buildTableFromItem(
presentation,
[
{ prop: 'presentationId', label: 'Presentation ID' },
{ prop: 'manufacturerName', label: 'Manufacturer Name' },
'iconUrl',
],
)

let dashboardStates = 'No dashboard states'
if (presentation.dashboard?.states && presentation.dashboard.states.length > 0) {
Expand All @@ -24,15 +32,15 @@ export function buildTableOutput(tableGenerator: TableGenerator, presentation: P
dashboardStates = `Dashboard States\n${subTable.toString()}`
}

function buildDisplayTypeTable(items: { displayType: string }[]): string {
const buildDisplayTypeTable = (items: { displayType: string }[]): string => {
const subTable = tableGenerator.newOutputTable({ head: ['Display Type'] })
for (const item of items) {
subTable.push([item.displayType])
}
return subTable.toString()
}

function buildLabelDisplayTypeTable(items: { label: string; displayType: string }[]): string {
const buildLabelDisplayTypeTable = (items: { label: string; displayType: string }[]): string => {
const subTable = tableGenerator.newOutputTable({ head: ['Label', 'Display Type'] })
for (const item of items) {
subTable.push([item.label, item.displayType])
Expand Down Expand Up @@ -81,46 +89,3 @@ export function buildTableOutput(tableGenerator: TableGenerator, presentation: P
`${automationConditions}\n\n` +
automationActions
}

export default class PresentationCommand extends APICommand<typeof PresentationCommand.flags> {
static description = 'query device presentation by vid' +
this.apiDocsURL('getDevicePresentation')

static flags = {
...APICommand.flags,
...outputItem.flags,
}

static args = [
{
name: 'presentationId',
description: 'system generated identifier that corresponds to a device presentation',
required: true,
},
{
name: 'manufacturerName',
description: 'manufacturer name. Defaults to SmartThingsCommunity',
required: false,
},
]

static examples = [
'$ smartthings presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf',
'$ smartthings presentation 4ea31e30-2aba-41c7-a3ec-8f97423d565a SmartThings',
'$ smartthings presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language=ko',
'$ smartthings presentation fd4adb7f-4a23-4134-9b39-05ed889a03cf --language=NONE',
'',
'Specifying only the presentationId defaults to the "SmartThingsCommunity" manufacturer',
'name and the language set for the computer\'s operating system. The language can be',
'overridden by specifying an ISO language code. If "NONE" is specified for the language',
'flag then no language header is specified in the API request',
]

async run(): Promise<void> {
const config = {
buildTableOutput: (data: PresentationDevicePresentation) => buildTableOutput(this.tableGenerator, data),
}
await outputItem(this, config,
() => this.client.presentation.getPresentation(this.args.presentationId, this.args.manufacturerName))
}
}