Skip to content

question: design limitation precludes a common event handler? #226

Open
@toddaustin07

Description

@toddaustin07

When defining device subscription handlers, you cannot name a common handler across subscriptions. The SDK design seems to impose a unique handler name for each subscription. If I want to support nearly all SmartThings capabilities, I would have a potentially LARGE number of subscriptions to handle, but the current design forces me to declare a unique handler for each, resulting in an unnecessary proliferation of code.

What I want to do is this:

context.api.subscriptions.subscribeToDevices(context.config.buttonList, 'button', 'button', 'commonhandler'))
context.api.subscriptions.subscribeToDevices(context.config.contactList, contactSensor', contact', 'commonhandler'))
.
.
.
context.api.subscriptions.subscribeToDevices(context.config.motionList, 'motionSensor', motion', 'commonhandler'))

subscribedEventHandler('commonHandler', (context, deviceEvent) => {
   <do common stuff>
}

However, I get a subscriptionName conflict error if I try to do that. What I seem to be forced to do is define unique handlers for each like this:

context.api.subscriptions.subscribeToDevices(context.config.buttonList, 'button', 'button', 'buttonhandler'))
context.api.subscriptions.subscribeToDevices(context.config.contactList, contactSensor', contact', 'contacthandler'))
.
.
.
context.api.subscriptions.subscribeToDevices(context.config.motionList, 'motionSensor', motion', 'motionhandler'))

subscribedEventHandler('buttonHandler', (context, deviceEvent) => {
   <do same stuff, or call a common do-stuff routine here>
}

subscribedEventHandler('contactHandler', (context, deviceEvent) => {
   <do same stuff, or call a common do-stuff routine here>
}
.
.
.
subscribedEventHandler('motionHandler', (context, deviceEvent) => {
   <do same stuff, or call a common do-stuff routine here>
}

Is there a better way to accomplish this or perhaps this is a needed design change in the SDK?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageNeeds investigation and prioritizationquestionFurther information is requestedreviewed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions