-
Notifications
You must be signed in to change notification settings - Fork 2
Model Transformer
Freebird uses two unified data models Device Class and Gadget Class to represent the real-world device and gadget respectively. Thus, a netcore implementer has responsibility to transform any of the raw device and gadget(application) data into the unified model.
<< Important >>:
Freebird leaves two template methods nc._cookRawDev and nc._cookRawGad for the implementers to provide the transformer implementations. The following descriptions describe the signature and behavior of these two methods.
Fill the data required by the dev
instance with netInfoObj and devAttrsObj via dev.set()
method, where netInfoObj and devAttrsObj can be built from the rawDev
data and some additional requests to the remote device.
When transform procedure accomplishes, call done(err, dev)
to pass the fullfilled dev
instance to the framework.
Note:
rawDev
is the raw device data that you commit by calling nc.commitDevIncoming(), therefore the shape of rawDev
is actually planned by you.
Arguments:
-
dev
(Object): Deivce instance. -
rawDev
(Object): Raw device data. -
done
(Function):function (err, dev) {}
. Pass the fullfilleddev
to the framework.
Returns:
- none
Examples:
// An simple implementation of the device model transformer
nc._cookRawDev = function (dev, rawDev, done) {
dev.set('net', {
role: 'router',
maySleep: false,
address: { // Required
permanent: rawDev.ieeeAddr,
dynamic: rawDev.nwkAddr,
}
});
dev.set('attrs', {
manufacturer: rawDev.manufacturerName,
model: rawDev.modelNum
});
done(null, dev);
};
Fill the data required by the gad
instance with pannelInfoObj and gadAttrsObj via gad.set()
method, where pannelInfoObj and gadAttrsObj can be built from the rawGad
data and some additional requests to the remote gadget.
When transform procedure accomplishes, call done(err, gad)
to pass the fullfilled gad
instance to the framework.
Note:
rawGad
is the raw gadget data that you commit by calling nc.commitGadIncoming(), therefore the shape of rawGad
is actually planned by you.
Arguments:
-
gad
(Object): Gadget instance. -
rawGad
(Object): Raw gadget data. -
done
(Function):function (err, gad) {}
. Pass the fullfilledgad
to the framework.
Returns:
- none
Examples:
// An simple implementation of the gadget model transformer
nc._cookRawGad = function (gad, rawGad, done) {
gad.set('panel', {
profile: 'home',
classId: 'presence'
});
gad.set('attrs', {
dInState: rawGad.resources.dInState,
counter: rawGad.resources.counter,
});
done(null, gad);
};
freebird team
Overview
Main Classes
Design Your Own Netcore
- Workflow
- APIs for Implementer
- Unified data model
- What should be implemented
Appendix
- Device data object format
- Gadget data object format