Appliances
Appliances is a JavaScript library with abstract base classes for building
libraries that interact with smart appliances and devices. It helps with
mapping many common appliances to a standarized API built around the type of
appliance and its capabilities.
Types and capabilities
Devices from different manufacturers often support different things which makes
creating a unified API hard. This library tries to solve this by both keeping
track of the type of a smart appliance, such as if its a light or a sensor,
and what actual capabilities it has, such as if it its power can be controlled
or if it can dimmed.
Any appliance should have one or more types that describes what it is. In
addition it should have capabilities that describes what it can do.
Building appliances
In your Node project do:
npm install appliances
Creating a light that can powered on or off via some random API:
const { Light, Switchable } = require('appliances');
class LightExample extends Light.with(Switchable) {
constructor(externalLightApi) {
super();
this.externalLightApi = externalLightApi;
this.id = 'light-example:' + externalLightApi.id;
this.updatePower(externalLightApi.on);
}
changePower(power) {
return this.externalLightApi.setPower(power)
.then(result => this.updatePower(result.on));
}
}