smartthingscommunity / st-schema-nodejs Goto Github PK
View Code? Open in Web Editor NEWST Schema helper library for NodeJS
License: Apache License 2.0
ST Schema helper library for NodeJS
License: Apache License 2.0
setError(detail, errorEnum = "UNKNOWN-ERROR") {
this.deviceError = {errorNum, detail};
return this;
}
errorEnum
>> errorNum
If setError
is called, the Response
should ignore further calls to other convenience methods and it should take precedence.
If called from a loop, the method can then be used to ignore previous or future calls to other methods without a need to prevent them using a check on isError
.
devices.forEach(device => {
if (/* something */) {
response.setError(`Something happened, let's leave it at that.`);
}
});
Hi,
I would like to know the reason of 6 hours polling time.
why schema connector works per 6 hours for polling ? what's the background of this number ?
Connector app structure
const connector = new SchemaConnector()
.discoveryHandler((accessToken, response) => {
/**
* Discovery request. Respond with a list of devices. Called after installation of the
* connector and every six hours after that.
* @accesstoken External cloud access token
* @response {DiscoveryResponse} Discovery response object
*/
})
The code example here https://github.com/SmartThingsCommunity/st-schema-nodejs#serverjs-1 is the same as the above code example, even though it discusses a change to the server code. I therefore expected an example of something added to the express code.
There seem to be no support in st-schema-nodejs for adding deviceCookie as part of discoveryResponse. Please refer properties supported currently in the "class Device: in DiscoveryDevice.js
/*
Please update st-schema-nodejs lib with support for deviceCookie.
If you run the framework without handling the certain phase, such as the discovery phase, your connector will print out the following message:
ERROR: {"headers":{"schema":"st-schema","version":"1.0","interactionType":"interactionResult","requestId":"C29856C5-B6F8-4374-ABD0-E42A41C9F1CF"},"globalError":{"detail":"Unsupported interactionType: 'interactionResult'","errorEnum":"INVALID-INTERACTION-TYPE"}}
This seems to occur when a required interaction does not have a corresponding & responding handler.
This SDK needs documentation for available APIs to catalog all usable classes and their respective methods.
Example:
https://nodejs.org/api/http.html
This would help a lot to figure out all its possibilities without digging through code yourself.
According to the SmartThings documentation, the state refresh incoming request contains the list of devices which require a state update:
https://smartthings.developer.samsung.com/docs/devices/smartthings-schema/smartthings-schema-reference.html#State-Refresh
However, this framework's state refresh handler fails to make these available to the dev:
.stateRefreshHandler((accessToken, response) => {
/**
* State refresh request. Respond with the current states of all devices. Called after
* device discovery runs.
* @accessToken External cloud access token
* @response {StateRefreshResponse} StateRefresh response object
*/
})
Unlike the handler for commands, which does:
.commandHandler((accessToken, response, devices) => {})
Provide a trace
option/property with default value console.log
to handle any logging alternatively.
Hi,
in the SchemaConnector file, for each interaction type, the token
is directly taken from the body.authentication
, but if it don't exist, the error TypeError: Cannot read property 'token' of undefined
is thrown.
Accord to SmartThings documentation, this case can throw a specific error :
{
...
"globalError": {
"errorEnum": "BAD-REQUEST",
"detail": "missing st-schema authentication"
},
...
}
It will improve the schema compliance.
This SDK could benefit from having a SmartThings API framework as a dependency to simplify making calls from the connector to SmartThings, such as when trying to update the state of a device outside of a connector interaction.
This could simply be a suggestion in the README, as these calls are not a requirement for integrations to operate, thus the package could be optional.
Unfortunately, there is no public SmartThings API framework at the moment (which isnt outdated). The one from https://github.com/SmartThingsCommunity/smartapp-sdk-nodejs should be extracted, and both SDKs should make it a dependency (separately maintained).
When I tested lifx-connector(https://github.com/SmartThingsCommunity/st-schema-connectors/tree/master/lifx-connector) in aws lambda, request object is undefined.
st-schema-nodejs/lib/lambda.js
Line 80 in c9482af
So I met below error message.
2019-05-26T23:53:19.544Z 32ad93e2-0f34-49e9-837f-6c4993444593 interactionType discoveryRequest
2019-05-26T23:53:19.545Z 32ad93e2-0f34-49e9-837f-6c4993444593 ERROR IN ST-SCHEMA HELPER TypeError: Cannot read property 'authentication' of undefined
at Object.discoveryRequest (/var/task/index.js:9:84)
at /var/task/node_modules/st-schema/lib/lambda.js:82:34 await opts[interactionType](request, response);
I think below line is needed before line 80.
request = event;
What do you think?
Currently it's really hard to parse what's changed between different versions of this package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.