main.js
/**
     * CreateOrUpdateDevice
     *
     * Creates the base device information
     *
     * @param device  {object} data for the current device which are not provided by Web-API (IP-Address, MQTT-Password)
     */
CreateOrUpdateDevice
Creates the base device information

@param device  {object} data for the current device which are not provided by Web-API (IP-Address, MQTT-Password)
CreateOrUpdateDevice Creates the base device information @param device { object } data for the current device which are not provided by Web - API ( IP - Address MQTT - Password )
async CreateOrUpdateDevice(device){
        try {
            this.log.debug('Creating device folder.');
            this.createOrExtendObject(device.Serial, {
                type: 'device',
                common: {name: products[device.ProductType]},
                native: {}
            }, null);
            this.createOrExtendObject(device.Serial + '.Firmware', {
                type: 'channel',
                common: {name: 'Information on device\'s firmware', 'read': true, 'write': false},
                native: {}
            }, null);
            this.createOrExtendObject(device.Serial + '.Firmware.Version', {
                type: 'state',
                common: {
                    name: 'Current firmware version',
                    'read': true,
                    'write': false,
                    'role': 'value',
                    'type': 'string'
                },
                native: {}
            }, device.Version);
            this.createOrExtendObject(device.Serial + '.Firmware.Autoupdate', {
                type: 'state',
                common: {
                    name: 'Shows whether the device updates it\'s firmware automatically if update is available.',
                    'read': true,
                    'write': true,
                    'role': 'indicator',
                    'type': 'boolean'
                },
                native: {}
            }, device.AutoUpdate);
            this.createOrExtendObject(device.Serial + '.Firmware.NewVersionAvailable', {
                type: 'state',
                common: {
                    name: 'Shows whether a firmware update for this device is available online.',
                    'read': true,
                    'write': false,
                    'role': 'indicator',
                    'type': 'boolean'
                },
                native: {}
            }, device.NewVersionAvailable);
            this.createOrExtendObject(device.Serial + '.ProductType', {
                type: 'state',
                common: {
                    name: 'dyson internal productType.',
                    'read': true,
                    'write': false,
                    'role': 'value',
                    'type': 'number'
                },
                native: {}
            }, device.ProductType);
            this.createOrExtendObject(device.Serial + '.ConnectionType', {
                type: 'state',
                common: {
                    name: 'Type of connection.',
                    'read': true,
                    'write': false,
                    'role': 'value',
                    'type': 'string'
                },
                native: {}
            }, device.ConnectionType);
            this.createOrExtendObject(device.Serial + '.Name', {
                type: 'state',
                common: {name: 'Name of device.', 'read': true, 'write': true, 'role': 'value', 'type': 'string'},
                native: {}
            }, device.Name);
            this.log.debug('Querying Host-Address of device: ' + device.Serial);
            this.getStateAsync(device.Serial + '.Hostaddress')
                .then((state) => {
                    if (state  && state.val !== '') {
                        this.log.debug('Found valid Host-Address.val [' + state.val + '] for device: ' + device.Serial);
                        device.hostAddress = state.val;
                        this.createOrExtendObject(device.Serial + '.Hostaddress', {
                            type: 'state',
                            common: {
                                name: 'Local host address (or IP) of device.',
                                'read': true,
                                'write': true,
                                'role': 'value',
                                'type': 'string'
                            },
                            native: {}
                        }, device.hostAddress);
                    } else {
                        this.createOrExtendObject(device.Serial + '.Hostaddress', {
                            type: 'state',
                            common: {
                                name: 'Local host address (IP) of device.',
                                'read': true,
                                'write': true,
                                'role': 'value',
                                'type': 'string'
                            },
                            native: {}
                        }, undefined);
                        this.log.error(`IP-Address (${device.hostAddress}) of device [${device.Serial}] is invalid or can't be resolved. Please enter the valid IP of this device in your LAN to the device tree.`);
                        this.setState('info.connection', false);
                        this.terminate('Terminating Adapter due to missing or invalid device IP.', 11);
                    }
                })
                .catch( (error) => {
                    this.log.error('[CreateOrUpdateDevice-getSateAsync] Error: ' + error + ', Callstack: ' + error.stack);
                });
        } catch(error){
            this.log.error('[CreateOrUpdateDevice] Error: ' + error + ', Callstack: ' + error.stack);
        }
    }
async CreateOrUpdateDevice ( device ) { try { this . log . debug ( 'Creating device folder.' ) ; this . createOrExtendObject ( device . Serial , { type : 'device' , common : { name : products [ device . ProductType ] } , native : { } } , null ) ; this . createOrExtendObject ( device . Serial + '.Firmware' , { type : 'channel' , common : { name : 'Information on device\'s firmware' , 'read' : true , 'write' : false } , native : { } } , null ) ; this . createOrExtendObject ( device . Serial + '.Firmware.Version' , { type : 'state' , common : { name : 'Current firmware version' , 'read' : true , 'write' : false , 'role' : 'value' , 'type' : 'string' } , native : { } } , device . Version ) ; this . createOrExtendObject ( device . Serial + '.Firmware.Autoupdate' , { type : 'state' , common : { name : 'Shows whether the device updates it\'s firmware automatically if update is available.' , 'read' : true , 'write' : true , 'role' : 'indicator' , 'type' : 'boolean' } , native : { } } , device . AutoUpdate ) ; this . createOrExtendObject ( device . Serial + '.Firmware.NewVersionAvailable' , { type : 'state' , common : { name : 'Shows whether a firmware update for this device is available online.' , 'read' : true , 'write' : false , 'role' : 'indicator' , 'type' : 'boolean' } , native : { } } , device . NewVersionAvailable ) ; this . createOrExtendObject ( device . Serial + '.ProductType' , { type : 'state' , common : { name : 'dyson internal productType.' , 'read' : true , 'write' : false , 'role' : 'value' , 'type' : 'number' } , native : { } } , device . ProductType ) ; this . createOrExtendObject ( device . Serial + '.ConnectionType' , { type : 'state' , common : { name : 'Type of connection.' , 'read' : true , 'write' : false , 'role' : 'value' , 'type' : 'string' } , native : { } } , device . ConnectionType ) ; this . createOrExtendObject ( device . Serial + '.Name' , { type : 'state' , common : { name : 'Name of device.' , 'read' : true , 'write' : true , 'role' : 'value' , 'type' : 'string' } , native : { } } , device . Name ) ; this . log . debug ( 'Querying Host-Address of device: ' + device . Serial ) ; this . getStateAsync ( device . Serial + '.Hostaddress' ) . then ( ( state ) => { if ( state && state . val !== '' ) { this . log . debug ( 'Found valid Host-Address.val [' + state . val + '] for device: ' + device . Serial ) ; device . hostAddress = state . val ; this . createOrExtendObject ( device . Serial + '.Hostaddress' , { type : 'state' , common : { name : 'Local host address (or IP) of device.' , 'read' : true , 'write' : true , 'role' : 'value' , 'type' : 'string' } , native : { } } , device . hostAddress ) ; } else { this . createOrExtendObject ( device . Serial + '.Hostaddress' , { type : 'state' , common : { name : 'Local host address (IP) of device.' , 'read' : true , 'write' : true , 'role' : 'value' , 'type' : 'string' } , native : { } } , undefined ) ; this . log . error ( ` ${ device . hostAddress } ${ device . Serial } ` ) ; this . setState ( 'info.connection' , false ) ; this . terminate ( 'Terminating Adapter due to missing or invalid device IP.' , 11 ) ; } } ) . catch ( ( error ) => { this . log . error ( '[CreateOrUpdateDevice-getSateAsync] Error: ' + error + ', Callstack: ' + error . stack ) ; } ) ; } catch ( error ) { this . log . error ( '[CreateOrUpdateDevice] Error: ' + error + ', Callstack: ' + error . stack ) ; } }
CreateOrUpdateDevice
 Creates the base device information
CreateOrUpdateDevice Creates the base device information
// create device folder // No valid IP address of device found. Without we can't proceed. So terminate adapter.