You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
692 B
JavaScript

4 years ago
class DeviceRegistry {
constructor() {
this.Devices = {}
this.DeviceStates = {} // for keeping device states
4 years ago
}
register(device) {
this.Devices[ device.name ] = device
}
getDevices() {
return Object.values(this.Devices)
}
stateSet(deviceType, deviceId, stateData) {
const key = `${ deviceType }:${ deviceId }`
if (!this.DeviceStates[ key ])
this.DeviceStates[ key ] = {}
Object.assign(this.DeviceStates[ key], stateData)
}
/*tryReceive(deviceName, data) {
return this.Devices[ deviceName ].tryReceive(data)
}*/
4 years ago
}
const registry = new DeviceRegistry()
module.exports = registry