How configuration is stored on AWS for smartapp?

I’m playing with the smartapp example which allows to specify sensor and control lights. The general idea is quite clear. I cannot understand how/where the selected sensor and lights are stored when the smartapp is running on AWS. It looks like that is related to ContextStore type and I saw mentioning of DynamoDB but I don’t see where the code implementing ContextStore interface storing retrieving the information is.

Why I need that? Partially for better understanding of the system, partially to figure out if I can do this, instead of selecting sensor and lights I’d like to find what I need in code. Let’s say I need to control all lights having “livingroom” in the name. Then, I’d like to store them in the ContextStore as if they we selected.

It’s not mandatory you use the ContextStore to work with a SmartApp. This is mostly used when:

  • You want to make API calls from the Config page
  • You have an integration that creates several SmartApps for different users. Eg. An OAuth integration
  • You want to access this configuration from outside the SmartApp itself

I believe there’s no option to filter the devices by name so far but I can think of this flow:

  1. From the configuration page, you can make an API call to get the rooms list (for this you should install once the smartApp to get an Authorization Token and save the context)
  2. Then, next time you open the SmartApp, you could make an API call to get all the devices in the room or even add the capability parameter to filter those that have one in particular. Eg.
    This you would get all the device IDs you need and you can handle them as you want.

I’m not sure if it’s possible to change the context manually, but I can confirm that. What do you think of the flow above?

This is what I approximately thought it should be, I just hoped to have more a coding example. I believe I already got quite familiar with all the REST APIs and now I’m trying to rethink all that in terms of SmartApp nodejs SDK. I can try to rephrase my question using that example from SmartThings. There is a section in the code

      page.section('sensors', (section: Section) => {
      page.section('lights', (section: Section) => {

when the SmartApp is installed that section is responsible for displaying two dropdowns one for the sensors and one for the lights where a user is supposed to choose devices. What I’m thinking of doing is instead of displaying those dropdowns or maybe along with them, find some devices automatically using “an algorithm”. Yes, I’ll need to get a list of devices. It looks like that it will be a call similar to this one, right?

    const deviceList: Device[] = await context.api.devices.list();

Then I iterate over devices and find what I need. One of the main things that I don’t understand is if the config data is persisted anywhere by the SmartApp framework. Let’s look at this line

    await context.api.subscriptions.subscribeToDevices(context.config.contactSensor, 'contactSensor', 'contact', 'myDeviceEventHandler');

It subscribes to the context.config.contactSensor events. I understand that. All that is hosted in AWS. What will happen if the AWS function is stopped and then started again. Will context.config.contactSensor contain the sensor information if I try to read it in a handler, for example? I guess I can test all that but I saw in the SDK code hints that the config information is supposed to be persisted, presumably in the DynamoDB, I just cannot find that very code which would do the persistence and I would like to understand was it intended to be persisted as well?