-
Notifications
You must be signed in to change notification settings - Fork 128
feat: add support for virtual devices #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for virtual devices #318
Conversation
🦋 Changeset detectedLatest commit: e8879ab The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
eca9d38 to
d809e05
Compare
d809e05 to
e8879ab
Compare
| @@ -0,0 +1,7 @@ | |||
| --- | |||
| "@smartthings/cli": minor | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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.' |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
| '$ 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', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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'}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| export interface DeviceProfileDefinition { | ||
| deviceProfileId?: string | ||
| deviceProfile?: DeviceProfileCreateRequest | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
|
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. |
Added commands for creating virtual devices and generating events on their behalf.
Checklist
npm run lintproduces no warnings/errors)