| 123456789101112131415161718192021222324252627282930313233343536 |
- class Scanner {
- constructor({ controllers }) {
- this._controllers = controllers
- }
- get _controllersByType() {
- return this._controllers.reduce((byType, controller)=> {
- const type = controller.type
- if(byType[type].length < 1) byType[type] = []
- byType[type].push(controller)
- return byType
- }, {})
- }
- /**
- * Example: only temp controllers in range?
- * const tempControlsOK = allInRange('temp')
- *
- * Example: every controller in range?
- * const everythingOK = allInRange()
- */
- allInRange(type) {
- const all = type ? this._controllersByType[type] : this._controllers
- return all.every(controller => controller.inRange === true)
- }
- readAll() {
- const completeReadout = {}
- this._controllers.forEach(controller => {
- const readout = controller.readout()
- completeReadout[readout.from] = readout
- })
- return completeReadout
- }
- }
-
- module.exports = {
- Scanner
- }
|