import {EventEmitter} from 'events';
import {System} from './system';

export class Nextion extends EventEmitter {
  constructor (uart) {
    super();

    if (!uart) {
      throw new TypeError('"uart" must be a UART instance');
    }
    this.uart = uart.bind()
      .on('event', (...args) => {
        this.emit('event', ...args);
      });

    this.system = new System(uart);
  }

  async setValue (variableName, value) {
    return await this.uart.setValue(variableName, value);
  }

  async setComponentValue (componentName, value) {
    return await this.setVariableValue(`${componentName}.val`, value);
  }
}

Nextion.prototype.setVariableValue = Nextion.prototype.setValue;

@@ -62,16 +62,85 @@
 system';
+%0Aimport debug from 'debug';%0A%0Aconst nDebug = debug('nextion:Nextion');
 %0A%0Aexport
@@ -443,16 +443,46 @@
 m(uart);
+%0A%0A    nDebug('Nextion ready');
 %0A  %7D%0A%0A  

add a debug