Skip to content

Conversation

@bflorian
Copy link
Contributor

@bflorian bflorian commented Jun 2, 2022

Added commands for creating virtual devices and generating events on their behalf.

Checklist

  • I have read the CONTRIBUTING document
  • Any required documentation has been added
  • My code follows the code style of this project (npm run lint produces no warnings/errors)
  • I have added tests to cover my changes

@changeset-bot
Copy link

changeset-bot bot commented Jun 2, 2022

🦋 Changeset detected

Latest commit: e8879ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@smartthings/cli Minor
@smartthings/cli-lib Patch
@smartthings/cli-testlib Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bflorian bflorian force-pushed the virtual-devices-phase1 branch from eca9d38 to d809e05 Compare June 2, 2022 13:55
@bflorian bflorian requested review from Sitlintac, john-u and rossiam June 2, 2022 14:17
@bflorian bflorian force-pushed the virtual-devices-phase1 branch from d809e05 to e8879ab Compare June 7, 2022 11:50
@@ -0,0 +1,7 @@
---
"@smartthings/cli": minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to stick with patch for all commits so no versions get bumped while we're still considering the CLI beta. @john-u is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will matter while in prerelease, it should not touch the major.minor.patch version number until we promote out of beta.

Comment on lines +19 to +23
static description = 'Creates a virtual device from a device profile ID or definition\n' +
'The command can be run interactively, in question & answer mode, with command line parameters,\n' +
'or with input from a file or standard in. You can also combine command line input with file input\n' +
'so that you can create multiple devices with different names in different locations and rooms using\n' +
'the same input file.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oclif adds two newlines when you include a newline but word wraps on spaces so this looks better if all but the first \n are replaced with spaces.

(Same for other commands that have longer descriptions.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this text made me think the command would make multiple devices in one go:

You can also combine command line input with file input so that you can create multiple devices with different names in different locations and rooms using the same input file.

I wonder if it wouldn't be better to say something like:

You can also run this command multiple times with the same input file but different command line arguments to create multiple devices with different names in different locations and rooms.

Comment on lines +46 to +48
'$ smartthings devices:virtual:events {id} -i data.yml # from a YAML or JSON file',
'$ smartthings devices:virtual:events {id} switch:switch on # command line input',
'$ smartthings devices:virtual:events {id} temperatureMeasurement:temperature 22.5 C # command line input',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other commands we've been using angle brackets to represent ids that need to be filled in rather than curly braces so maybe we should stick to that.

},
{
name: 'unit',
description: 'optional unit of measure',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is optional, it really should be a flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not it is optional depends on the capability and attribute. For example, it is required for the temperatureMeasurement temperature attribute because there is no default temperature unit. It seems strange to make it a flag in that case since the command will fail if it is not provided.

}
await inputAndOutputItem<DeviceEvent[], EventInputOutput>(this, {
buildTableOutput: (data: EventInputOutput) => buildTableOutput(this.tableGenerator, data),
}, createEvents, inputProcessor(() => true, () => this.getInputFromUser(deviceId)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInputFromUser was meant to be the "Q&A" session-type input and getInputFromCommandLine was meant to be for parsing input from the command line. It might be a bigger refactor than you want to do at this point but I think this would be easier to follow and it would be easier to make better error messages if these two were separated, similar to "devices:commands".

import {allPrototypes, locallyExecutingPrototypes} from './virtual/create-standard'


export async function chooseDeviceName(command: APICommand<typeof APICommand.flags>, preselectedName?: string): Promise<string | undefined> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recently, we've been putting functions like this in a corresponding <command>-util.ts file, even when they are only used in one place to make writing unit tests easier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we think any of the utils here would be helpful in the edge-plugin, we could instead export them from packages/lib/src/device-util.ts

return preselectedName
}

export async function chooseRoom(command: APICommand<typeof APICommand.flags>, locationId: string, preselectedId?: string, autoChoose?: boolean): Promise<string> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a chooseRoom in rooms-util.ts. It might be worth adding support for autoChoose to that one. It might be worth adding autoChoose to that one and using it.

export const locallyExecutingPrototypes = [
{name: 'Switch', id: 'VIRTUAL_SWITCH'},
{name: 'Dimmer', id: 'VIRTUAL_DIMMER_SWITCH'},
{name: 'Testing devices...', id: 'more'},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text "Testing devices..." confused me a little when I created a virtual device. Aren't they all testing devices? Would simply "More..." be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well no, virtual switches and dimmers are commonly used in rules for real home applications, whereas the others are only useful for testing, but I agree that "More..." is probably better

---
"@smartthings/cli": minor
"@smartthings/cli-lib": patch
"@smartthings/cli-testlib": patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes don't modify testlib, so it doesn't need a release in the changeset.

Comment on lines +45 to +48
export interface DeviceProfileDefinition {
deviceProfileId?: string
deviceProfile?: DeviceProfileCreateRequest
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be added to the Core SDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange to me to include an interface in the SDK that isn't used by any of the API methods. It's not produced by the swagger code generation, so we'd have to muck around with them to make it something that's used by the methods. It's the design of the CLI command and the way the CLI input flag processing works that makes it necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. I think it should just be exported from the commands corresponding util module then.

@@ -0,0 +1,7 @@
---
"@smartthings/cli": minor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will matter while in prerelease, it should not touch the major.minor.patch version number until we promote out of beta.

import {allPrototypes, locallyExecutingPrototypes} from './virtual/create-standard'


export async function chooseDeviceName(command: APICommand<typeof APICommand.flags>, preselectedName?: string): Promise<string | undefined> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we think any of the utils here would be helpful in the edge-plugin, we could instead export them from packages/lib/src/device-util.ts

@bflorian
Copy link
Contributor Author

bflorian commented Jun 8, 2022

Closing this PR in favor of #327 to preserve the context of these comments since the command name change resulted in so many file names.

@bflorian bflorian closed this Jun 8, 2022
@bflorian bflorian deleted the virtual-devices-phase1 branch August 3, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants