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.
|
|
|
class DeviceRegistry {
|
|
|
|
constructor() {
|
|
|
|
this.Devices = {}
|
|
|
|
this.DeviceStates = {} // for keeping device states
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
const registry = new DeviceRegistry()
|
|
|
|
module.exports = registry
|