webthingsio / gateway-addon-node Goto Github PK
View Code? Open in Web Editor NEWNode bindings for developing add-ons for WebThings Gateway
License: Mozilla Public License 2.0
Node bindings for developing add-ons for WebThings Gateway
License: Mozilla Public License 2.0
The module babel-eslint
seems to be necessary to run eslint
@tim-hellhake I'm thinking we should tag and release v1.0.1 release of this npm package to ship with gateway v1.0.1.
Before we do that I'm wondering if we should reverse de6a33a to use the "v" prefix in version names again, to be consistent with gateway-addon-python.
What do you think?
I've noticed the following behavior while doing some changes on my miLight adapter: if I issue two consecutive REST PUT requests for the same property with the same value, the 2nd request times out, for ex. set the brightness level to 40 via REST and repeat the request.
This is the setValue code for my Property:
setValue(value) {
return new Promise((resolve) => {
const oldValue = this.value;
this.setCachedValue(value);
const hasChanged = (oldValue !== this.value);
if (hasChanged) {
this.device.notifyPropertyChanged(this, oldValue);
}
resolve(this.value);
});
}
As far as I was able to trace the problem, it comes down to the fact that the notifyPropertyChanged
is not getting called and implicitly the notifyPropertyChanged
of the parent Device class is also not getting invoked so the addon manager proxy is not notified.
Any ideas on this?
using version 0.12
as per handleDeviceSaved()
documentation:
* This can be used for keeping track of what devices have previously been * discovered, such that the adapter can rebuild those, clean up old nodes, * etc.
I wanted to use these functions to keep track of user saved devices VS all devices provided by the addon.
If a device is connected (a Device object exists and is present in addon-manager.js
s this.device
map) then an adapter's removeThing(deviceObj)
is called.
If a device is disconnected (its ex Device object was deleted from addon-manager.js
s this.device
map) then AddonManager's removeThing(deviceId)
does not find a valid device
object and and addon's removeThing(deviceObj)
is, of course, not called anymore.
So, if a developer wants to push a device ID in handleDeviceSaved()
into an array, and then use removeThing()
to pop that device ID from that array - to keep track of the devices added/removed by the user from the UI/API, it will not work reliably.
Have I misunderstood how to use these functions?
How can I detect in my addon when a disconnected device is removed by the user from the UI/API?
The gateway log is filled with lines such as the following
2020-04-13 18:58:45.008 INFO : timer-adapter: setCachedValueAndNotify for property seconds from 4 to 4.5 for interval-c4c415fc99b87af0d464d777c94a1c73
This means that the log wraps to 2 or even 3 separate logs per day
I raised an issue in the Timer addon project and, in response, @tim-hellhake referred me to this line of code
Is it possible to throttle the logging so that a frequently changing property is logged, say, once per minute?
thanks :)
The use of set-output in GitHub Actions is deprecated and will be disabled soon.
Since I upgraded the schema submodule to the latest master of gateway-addon-ipc-schema (WebThingsIO/gateway-addon-ipc-schema@d885b01) I'm no longer able to add things to the gateway. This is with the gateway using the latest 2.0.0-alpha.2 release of gateway-addon-node, built from master.
STR:
Expected:
Actual:
I'm trying to figure out which one of my commits in gateway-addon-ipc-schema caused the regression, but I'm a bit confused about which commit the submodule was at before.
It appears that at the time of the 2.0.0-alpha.1 release of the gateway-addon npm package, the schema submodule was set to https://github.com/WebThingsIO/gateway-addon-ipc-schema/tree/7397a0bfcd13ec39ebddea1f8b4dc164dacd3835, but that commit doesn't belong to any branch in the WebThingsIO/gateway-addon-ipc-schema repo.
@tim-hellhake @relu91 Any idea what's going on here?
Since the current API is a little bit free for implementation of actions, there are many things to consider such as control of action lifecycle and asynchronous processing at development time.
As a developer, it is better to implement methods which is empty now on the device base class and reduce the methods that the developer should implement.
I'm implementing an action with my add-on.
This is my implementation of the device class and developer maybe can handle various actions by implementing the following method.
Hi @mrstegeman! Recently I asked you a few questions WebThingsIO/gateway#2248. Now I'm stuck on accessing the gateway in ApiHandler. I understand that I have to do this through the PluginManager or AddonManagerProxy, but I don’t understand how to access it. Сan you help me with this (sample code with access to the list of devices)?
P.S. You will save a lot of my time
P.P.S. I can program only with Googling =)
P.P.P.S gateway wiki is outdated (https://github.com/mozilla-iot/wiki/wiki)
'use strict';
const {APIHandler, APIResponse, Adapter} = require('gateway-addon');
...
class DialogsAPIHandler extends APIHandler {
constructor(addonManager) {
super(addonManager, manifest.id);
addonManager.addAPIHandler(this);
}
async handleRequest(request) {
console.info(JSON.stringify(request))
var baseResponse = ...
if (request.method === 'HEAD' && request.path === '/v1.0/') {
new APIResponse({
status: 200
});
} else if (request.method === 'POST' ...) {
...
} else if (request.method === 'GET' && request.path === '/v1.0/user/devices') {
// Here I need to work with the gateway through some kind of internal mechanism
var gatewayDevices = this.<something>.getDevices();
return new APIResponse({
status: 200,
contentType: 'application/json',
content: JSON.stringify(baseResponse),
});
} else {
return new APIResponse({
status: 404
});
}
}
}
module.exports = DialogsAPIHandler;
Hi,
how I can debug addon in VScode ?
As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:
If you have any questions about this file, or Code of Conduct policies and procedures, please reach out to [email protected].
(Message COC001)
Node.js 12 is going to be deprecated soon, with a target to disable it by summer 2023
May I migrate this project to typescript?
This would also benefit JS developers as VS Code supports code completion from typings.
When only setting a status code on the response, an error is generated.
2020-12-07 13:06:37.107 ERROR : Invalid message received: {
"messageType": 20484,
"data": {
"packageName": "webhook-events",
"messageId": 1,
"response": {
"status": 200
},
"pluginId": "webhook-events"
}
}
2020-12-07 13:06:37.107 ERROR : Validation error: [
{
"keyword": "required",
"dataPath": ".data.response",
"schemaPath": "#/properties/data/properties/response/required",
"params": {
"missingProperty": "contentType"
},
"message": "should have required property 'contentType'"
}
]
@mrstegeman there are several locations in the gateway where we need the latest changes from this repo.
I wonder if we could publish a pre-release.
Depending on the next gateway version, this could be something like 1.1.0-alpha.1
.
Currently the default value for the @context
of new Thing Descriptions is:
"@context": "https://webthings.io/schemas"
It needs to be changed to:
"@context": [
"https://www.w3.org/2022/wot/td/v1.1",
"https://webthings.io/schemas",
]
for W3C compliance.
See also:
In the Adapter class, the field devices
is declared as private. However, in the ThingURLAdapter
the field is accessed directly - https://github.com/WebThingsIO/thing-url-adapter/blob/23b0f08ebc17b9df54c084b5191fa6883f90da01/thing-url-adapter.js#L618. And it's possible only because js simply doesn't care, but we cannot do the same if creating an adapter in ts. So, I would like to propose to change this field to protected or public instead.
The issue appeared while working on the new adapter.
Utils.timestamp() currently generates timestamps in the following format:
2022-01-20T17:21:12+00:00
For some reason the default output of Date().toISOString()
is modified so that it ends in "+00:00" rather than "Z". This is probably because that's the format used by the examples do in the Web Thing API specification.
The latest draft of the W3C WoT Profile specification constrains the date format so that it must end in "Z".
I therefore propose changing the timestamp method to return the raw output of Date().toISOString()
rather than modify it, so that datestamps look like:
2011-10-05T14:48:00.000Z
Before doing this we should check if it breaks anything.
Also, double check that the milliseconds portion of the datestamp is expected by WoT Profile.
Note: These timestamps are used in action resources in the gateway's API to show the requested and completed times of an action, and also for the timestamps of events. I'm not really sure why the gateway uses this utility function from the add-on library and they can probably call Date().toISOString()
directly instead. If this utility function isn't used anywhere else then it could probably just be removed.
Hi,
I have the following setup:
class MyDevice extends Device {
constructor (adapter, id, deviceDescription) {
// ...
this.disconnectTimer = this._startDisconnectTimer()
}
}
How should I clear the timer when MyDevice object is removed/destroyed/deleted?
Right now I'm doing it by:
class MyAdapter extends Adapter {
removeThing (device) {
if (device.disconnectTimer){
clearTimeout(device.disconnectTimer)
device.disconnectTimer = null
}
super.removeThing(device)
}
}
because there is no callback in Device object that I could use.
It's a bit weird to use the MyAdapter object to release resources allocated by MyDevice object. I think Device object should be given a callback so that addon developers could use it to clear resources allocated during its lifetime.
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.