var td = require('..');

var deviceCallback = null;
var deviceChangeCallback = null;
var rawDeviceCallback = null;
var sensorCallback = null;
var controllerCallback = null;

td.on('device', deviceEvent = function (deviceId, method, data) {
    td.removeListener('device', deviceEvent);
    console.log('Device event received:', {
        deviceId: deviceId,
        method: method,
        data: data,
    });
});

td.on('deviceChange', deviceChangeCallback = function (deviceId, changeEvent, changeType) {
    td.removeListener('deviceChange', deviceChangeCallback);
    console.log('Device change event received:', {
        deviceId: deviceId,
        changeEvent: changeEvent,
        changeType: changeType,
    });
});

td.on('rawDevice', rawDeviceCallback = function (data, controllerId) {
    td.removeListener('rawDevice', rawDeviceCallback);
    console.log('Raw device event received:', {
        data: data,
        controllerId: controllerId,
    });
});

td.on('sensor', sensorCallback = function (protocol, model, id, dataType, value, timestamp) {
    td.removeListener('sensor', sensorCallback);
    console.log('Sensor event received:', {
        protocol: protocol,
        model: model,
        id: id,
        dataType: dataType,
        value: value,
        timestamp: timestamp,
    });
});

td.on('controller', controllerCallback = function (controllerId, changeEvent, changeType, newValue) {
    td.removeListener('controller', controllerCallback);
    console.log('Controller event received:', {
        controllerId: controllerId,
        changeEvent: changeEvent,
        changeType: changeType,
        newValue: newValue,
    });
});
