GithubHelp home page GithubHelp logo

webthingsio / example-adapter Goto Github PK

View Code? Open in Web Editor NEW
34.0 34.0 20.0 1.82 MB

Example adapter add-on for WebThings Gateway

License: Mozilla Public License 2.0

JavaScript 52.27% Shell 2.48% CSS 3.14% HTML 1.01% TypeScript 41.10%

example-adapter's People

Contributors

dhylands avatar jaller94 avatar mozilla-github-standards avatar mrstegeman avatar tim-hellhake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

example-adapter's Issues

Add example code for handling bundled dependencies in package.sh

The package.sh script currently just packages the essential files from this example add-on, so it took me a while to figure out that I needed to also include any run-time dependencies in node_modules as well, while also not including devDependencies (based on other add-on source code, ie the zwave addon).

I came up with a script that utilizes npm's pack function to do the packaging. It's not perfect, as this method relies on bundledDependencies to be defined in package.json, which is just an array of all module names in the dependencies object. I'm using a globally-installed node module bundle-deps to automatically generate the bundledDependencies array. Seems redundant now that I'm writing this up... maybe using tar directly would make more sense and have less dependencies.

Anyways, here are my modifications:

#!/bin/bash

# Uses node module bundle-deps to create bundledDependencies in package.json
bundle-deps

# Remove the old SHA256SUMS file
rm -f SHA256SUMS

# Remove node_modules and reinstall only production dependencies
npm ci --only=prod

# Create SHA256SUMS file and include main files
sha256sum package.json *.js LICENSE README.md > SHA256SUMS

# Add any node_module dependencies
find node_modules -type f -exec sha256sum {} \; >> SHA256SUMS

# Create dist folder to put the tar.gz package
mkdir dist
cd dist
package=$(npm pack ../)

echo "#### Packaging complete: dist/${package}"
echo "#### Run 'npm install' again to resume development"

If yarn is preferred, instead of npm ci --only=prod you could do rm -rf node_modules; yarn install --production.

PropertyChanged triggered twice

Hello there,
the PropertyChanged event is triggered twice with this example. when the onOff is clicked, to fix i had to update the below as shown:

async setValue(value: boolean): Promise<boolean> {
    return new Promise((resolve, reject) => {
        //super
        //.setValue(value)
        // .then((updatedValue) => {
        // resolve(updatedValue);
        // this.getDevice().notifyPropertyChanged(this);
        //   })
        //   .catch((err) => {
        //       reject(err);
        //   });
        this.setCachedValue(value);
        resolve(value);
        this.getDevice().notifyPropertyChanged(this);
    });
}

Correct license links

I'm probably wrong but license links seem broken.
In fact this link doesn't work while this one works.
(http://mozilla.org/MPL/2.0/.* ➡️ http://mozilla.org/MPL/2.0/)

CODE_OF_CONDUCT.md file missing

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:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please reach out to [email protected].

(Message COC001)

Adapter or add-on?

The url of this project is "example adapter", but the subtitle says it's an example add-on.

Example is broken

Is anyone using WebThings anymore? I mean, this is a pretty fundamental building block and it won't build today.

I'm using Ubuntu 22.04.1 LTS, npm 8.19.2, node v16.18.1.

$ sqlite3 -version
3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1

Here's the tail of my build log....

979 timing build:link:node_modules/which Completed in 5ms
980 timing build:link Completed in 6ms
981 info run [email protected] install node_modules/sqlite3 node-pre-gyp install --fallback-to-build
982 info run [email protected] install { code: 1, signal: null }
983 timing reify:rollback:createSparse Completed in 269ms
984 timing reify:rollback:retireShallow Completed in 0ms
985 timing command:ci Completed in 2766ms
986 verbose stack Error: command failed
986 verbose stack     at ChildProcess.<anonymous> (/snap/node/6895/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:63:27)
986 verbose stack     at ChildProcess.emit (node:events:513:28)
986 verbose stack     at maybeClose (node:internal/child_process:1100:16)
986 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
987 verbose pkgid [email protected]
988 verbose cwd /home/jkridner/workspace/ew2023-webthings-demo
989 verbose Linux 5.15.0-58-generic
990 verbose node v16.18.1
991 verbose npm  v8.19.2
992 error code 1
993 error path /home/jkridner/workspace/ew2023-webthings-demo/node_modules/sqlite3
994 error command failed
995 error command sh -c -- node-pre-gyp install --fallback-to-build
996 verbose exit 1
997 timing npm Completed in 2845ms
998 verbose unfinished npm timer reify 1675307263886
999 verbose unfinished npm timer reify:build 1675307265346
1000 verbose unfinished npm timer build 1675307265346
1001 verbose unfinished npm timer build:deps 1675307265346
1002 verbose unfinished npm timer build:run:install 1675307265356
1003 verbose unfinished npm timer build:run:install:node_modules/sqlite3 1675307265356
1004 verbose code 1
1005 error A complete log of this run can be found in:
1005 error     /home/jkridner/.npm/_logs/2023-02-02T03_07_42_889Z-debug-0.log

how send new value

Hello,
I will try to create an adapter for DHT22 (AM2302).
I use this library to read data from the DHT sensor. => node-dht-sensor

var sensor = require('node-dht-sensor');
sensor.read(22, 4, function(err, temperature, humidity) {
if (!err) {
console.log('temp: ' + temperature.toFixed(1) + '°C, ' +
'humidity: ' + humidity.toFixed(1) + '%'
);
}
});
The temperature.toFixed variable (1) contains the temperature number.

Now I downloaded example-adapter code. But I do not know where to put the temperature.toFixed (1) into the example-adapter code.

Will you please help me?

unable to build this under ubuntu

Hello there,
i'm running a gteway under an ubuntu vm for testing purposes, and when i cloned the example under the addons folder and ran npm run build i get an errro about cannot find 'XMLHttpRequest and whole lots of others...

../../../node_modules/@types/event-to-promise/index.d.ts:10:35 - error TS2304: Cannot find name 'EventTarget'.

i did run npm install on the folder which zipped through it fine ..

any idea what i'm doing wrong?

Import classes in a standard way

The add-on classes (Adapter, Device, etc) are being imported in a strange way that doesn't seem to be relevant to externally-developed (3rd party) add-ons.

The documentation specifies that imports should be done like so:

const { Adapter, Device, Property } = require('gateway-addon');

Currently it looks like the code is looking for the modules in a parent folder, but these files do not exist in the context of the addons folder that our 3rd party addons are meant to live in.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.