-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smart Coffee Machine - Fixes/Updates/Proposal #331
Comments
relates to eclipse-thingweb/website#19 |
Some other things I have seen:
|
Also, links to examples return 404: E.g. at "The full script is available at node-wot GitHub repository. " |
This is my fault given I renamed the examples consistently to "smart-coffee-machine". Hence we need to fix the links as well... |
No worries, I've made a PR for that as I said - eclipse-thingweb/website#23. |
@danielpeintner @egekorkan In the first case, a user sees what is wrong. In the second, a user just infinitely awaits a response and has no clue what's wrong. But if you insist I will rewrite it now with the |
The problem is that if you Note: if your REST tools works correctly and the code is working correctly (there are issues also as I mentioned) the tools should show you the error just fine. This is not because I am insisting to do so ;-) |
I also don't understand how reject is not delivered but it can be also because you are not wrapping the logic inside a promise |
I get the same behavior in the Chrome browser and Insomnia REST client, so no doubt they work correctly. Apparently, there is a bug somewhere else or this code is not 100% correct.
No, I do wrap it in the second case. |
Part of eclipse-thingweb#331 Signed-off-by: fatadel <[email protected]>
Ah I see, my bad. This must be some error in node-wot then :/ |
I am still not 100% convinced that it is actually an issue in node-wot since I recall getting rejects. @fatadel is this behavior still the case for your recent updates in https://github.com/eclipse/thingweb.node-wot/pull/337/files ? If so, please provide a simple a simple test cases for https://github.com/eclipse/thingweb.node-wot/blob/master/packages/core/test/ServerTest.ts that shows the issue |
Part of eclipse-thingweb#331 Signed-off-by: fatadel <[email protected]>
Done! |
FYI: using async and await makes the code much more cleaner: thing.setPropertyWriteHandler('availableResourceLevel', async (val, options) => {
// Check if uriVariables are provided
if (options && typeof options === 'object' && 'uriVariables' in options) {
const uriVariables: any = options['uriVariables'];
if ('id' in uriVariables) {
const resources = await thing.readProperty('allAvailableResources');
const id = uriVariables['id'];
resources[id] = val;
return thing.writeProperty('allAvailableResources', resources);
} else {
throw new Error('...');
}
else {
throw new Error('Please specify id variable as uriVariables.');
}
}); |
I would like to split the issue in 4 sections about the smart-coffee-machine samples in https://github.com/eclipse/thingweb.node-wot/tree/master/packages/examples/src/scripts
1. Bugs
The code uses promises in the wrong way (see here or here, ..).
There should be one promise and errors should return
reject
and not resolve.Note: I did not check the code for validity but I think you get the problem (difference to your code).
2. Best Practices
Should we actually propose using uriVariables. I think this is something WoT needs to support given it exists but I suggest using variables in the body.
3. Improvements
It would be nice IF the
makeDrink
action is a longer running process. Hence a coffee should not be ready immediately. Moreover... in realitymakeDrink
quickly one after the other should fail given that the coffee machine is not ready yet.Hence I also propose to remove the
maintenanceNeeded
property and use a more genericstatus
that could be an enumeration like ["maintenanceNeeded", "inUse/brewing..", ...]Doing so would also allow modelling the brewing process that takes some time and would refuse new drinks till the old on is ready or the machine is maintained...
4. WebUI improvements
With the addition of a
status
property we can also improve the UI hosted here: http://plugfest.thingweb.io/examples/smart-coffee-machine.htmlThe machine could be blinking while brewing the coffee.
Note: It is also necessary that you put the link where you get the SVG file for the coffee machine.
@fatadel can you take a look (I think 1. should be fixed. I don't feel strongly about the rest)
@sebastiankb @egekorkan @relu91 others, please comment if you have another opinion
The text was updated successfully, but these errors were encountered: