constructor (data, onUpdate, deviceOn, deviceEmit, save) {
this.id = data.id || uuidV4();
this.type = this.constructor.type || data.type;
this.device_id = data.device_id;
this.events = new EventEmitter2({wildcard: true, newListener: false, maxListeners: 0});
this.deviceOn = (event, callback) => deviceOn(event, callback, this.id, this.type);
this.deviceEmit = (event, data, callback) => deviceEmit(event, data, callback, this.id, this.type);
this.onUpdate = onUpdate;
try {
this.state_definitions = new Map(data.state_definitions);
} catch (error) {
this.state_definitions = new Map(...this.constructor.state_definitions);
}
this.settings = new DeviceSettings(
data.settings,
data.settings_definitions,
this.constructor.settings_definitions,
this.deviceEmit,
save
);
this.setState(data.state);
this.subscribeToDevice();
}