I’m trying to write a cloud connected smartthings device using st-schema in nodejs. I set up the example and it adds the device to my smartthings app. However it doesn’t seem to update correctly, it gives the error “This device hasn’t updated all of its status information yet. Check again later” its state is also empty, when it should have a starting state as defined in the code.
I am using the following code for the connector:
const { SchemaConnector, DeviceErrorTypes } = require('st-schema')
const deviceStates = { switch: 'off', level: 100 }
const connector = new SchemaConnector()
.discoveryHandler((accessToken, response) => {
response.addDevice('external-device-1', 'Test Dimmer', 'c2c-dimmer')
.manufacturerName('Example Connector')
.modelName('Virtual Dimmer');
})
.stateRefreshHandler((accessToken, response) => {
response.addDevice('external-device-1', [
{
component: 'main',
capability: 'st.switch',
attribute: 'switch',
value: deviceStates.switch
},
{
component: 'main',
capability: 'st.switchLevel',
attribute: 'level',
value: deviceStates.level
}
])
})
.commandHandler((accessToken, response, devices) => {
for (const device of devices) {
const deviceResponse = response.addDevice(device.externalDeviceId);
for (cmd of device.commands) {
const state = {
component: cmd.component,
capability: cmd.capability
};
if (cmd.capability === 'st.switchLevel' && cmd.command === 'setLevel') {
state.attribute = 'level';
state.value = deviceStates.level = cmd.arguments[0];
deviceResponse.addState(state);
} else if (cmd.capability === 'st.switch') {
state.attribute = 'switch';
state.value = deviceStates.switch = cmd.command === 'on' ? 'on' : 'off';
deviceResponse.addState(state);
} else {
deviceResponse.setError(
`Command '${cmd.command} of capability '${cmd.capability}' not supported`,
DeviceErrorTypes.CAPABILITY_NOT_SUPPORTED)
}
}
}
});
module.exports = connector
and the following code for the server
require('dotenv').config()
const express = require('express');
const connector = require('./connector');
const server = express();
const port = 4040
server.use(express.json());
server.post('/', (req, res) => {
if (accessTokenIsValid(req)) {
connector.handleHttpCallback(req, res)
}
});
function accessTokenIsValid(req) {
// Replace with proper validation of issued access token
if (req.body.authentication.token) {
return true;
}
res.status(401).send('Unauthorized')
return false;
}
server.listen(port, "0.0.0.0");
console.log(`Listening on port ${port}`)

