Skip to content

Conversation

@bflorian
Copy link
Contributor

@bflorian bflorian commented Jun 8, 2022

Added support for creating and generating events for virtual devices.

Note: Because of all the file name changes, this is a new PR replaces #318, which will be closed.

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 8, 2022

🦋 Changeset detected

Latest commit: e0d5422

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

This PR includes changesets to release 2 packages
Name Type
@smartthings/cli Patch
@smartthings/cli-lib 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-phase1A branch 3 times, most recently from 6d87aa7 to 9143ca8 Compare June 8, 2022 14:18
@bflorian bflorian requested a review from john-u June 8, 2022 14:31
Comment on lines 90 to 113
id: 'switch',
version: 1,
status: CustomCapabilityStatus.LIVE,
name: 'Switch',
attributes: {
switch: {
schema: {
type: 'object',
properties: {
value: {
title: 'IntegerPercent',
type: 'string',
enum: ['on', 'off'],
},
},
additionalProperties: false,
required: [
CapabilitySchemaPropertyName.VALUE,
],
},
enumCommands: [],
},
},
commands: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of including all properties, we have also been using a pattern of stubbing an object with only the properties required by the test case and casting the result to the required type. Here is an example.

It makes the tests less verbose and easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 , though for some reason I had to cast the shortened version to unknown before casting it to Capability. Not sure I understand what that wasn't necessary for the Device example

Copy link
Contributor

@john-u john-u Jun 14, 2022

Choose a reason for hiding this comment

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

This is expected. TypeScripts assertion rules are conservative and more complex objects will hit this. Documented here.

export type SelectingConfig<L> = Sorting & Naming & CommonListOutputProducer<L>

export const indefiniteArticleFor = (name: string): string => name.match(/^[aeiou]/i) ? 'an' : 'a'
export const indefiniteArticleFor = (name: string): string => name.match(/^[aeio]/i) ? 'an' : 'a'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 good catch.

Copy link
Contributor

@john-u john-u left a comment

Choose a reason for hiding this comment

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

Please perform a Format Modified Lines on these changes.

@bflorian bflorian force-pushed the virtual-devices-phase1A branch from 9143ca8 to 4c84d6b Compare June 14, 2022 14:34
@bflorian bflorian requested a review from john-u June 14, 2022 14:56
},
},
},
} as unknown
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure to finish the cast in these cases. as unknown as <type>

},
},
},
} as unknown
Copy link
Contributor

Choose a reason for hiding this comment

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

as unknown as <type>

},
},
},
} as unknown
Copy link
Contributor

Choose a reason for hiding this comment

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

as unknown as <type>

@john-u
Copy link
Contributor

john-u commented Jun 14, 2022

Please perform a Format Modified Lines on these changes.

This can be disregarded since we merged #330

@bflorian bflorian force-pushed the virtual-devices-phase1A branch from 4c84d6b to a700daf Compare June 14, 2022 18:37
@bflorian
Copy link
Contributor Author

I pushed the lint fixes

@bflorian bflorian requested a review from john-u June 14, 2022 18:44
export const locallyExecutingPrototypes = [
{ name: 'Switch', id: 'VIRTUAL_SWITCH' },
{ name: 'Dimmer', id: 'VIRTUAL_DIMMER_SWITCH' },
{ name: 'More...', id: '' },
Copy link
Contributor

Choose a reason for hiding this comment

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

The omission of an id here causes the selection to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dang! Good catch. I went back and forth on whether to have a value there and managed to wind up in an inconsistent state. Just pushed the fix

@bflorian bflorian force-pushed the virtual-devices-phase1A branch from a700daf to e0d5422 Compare June 14, 2022 20:32
@bflorian bflorian requested a review from john-u June 14, 2022 20:40
@bflorian bflorian merged commit 82652c9 into SmartThingsCommunity:master Jun 14, 2022
@bflorian bflorian deleted the virtual-devices-phase1A branch August 3, 2022 21:11
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.

2 participants