# Devices search

**URL:** <https://community.homey.app/t/devices-search/31756>\
**Category:** Developers\
**Created:** [June 28, 2020, 8:29am UTC](https://community.homey.app/t/devices-search/31756 "2020-06-28T08:29:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marwan\_Magdy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marwan_magdy/32/17200_2.png) [@Marwan\_Magdy](https://community.homey.app/u/Marwan_Magdy)\
**Post date:** [June 28, 2020, 8:29am UTC](https://community.homey.app/t/devices-search/31756/1 "2020-06-28T08:29:41Z")

</div>

hello everyone,  
I am new here actually and i was working of an app to communicate with eWelink supported devices but locally. I tested the concept and it works, my problem is with Homey app development i cant get it to to search for devices like any other app. when i installed it to add the devices which i created driver for it shows that there’s no devices listed. below is the driver.js code

‘use strict’;

const Homey = require(‘homey’);  
const ewelink = require(‘ewelink-api’);  
const {ManagerDrivers} = require(‘homey’);

module.exports = class S26Driver extends Homey.Driver {

```
async device_cash(email, password) {
	const connection = new ewelink({ email, password });
	const cash_file = await connection.getDevices();
	let results = [];
	for(var i = 0; i < cash_file.length; i++){
		if(cash_file[i]["productModel"] == 'TX3C'){
			// this.log(cash_file[i])
			results = (cash_file[i]);
			break;
		};
	};
	// this.log("results", results);
	return results;
}

onPairListDevices() {

    const devices = await this.device_cash();
    const pairs = ManagerDrivers.getDrivers();
    
}

async onInit() {
    this.log('MyDriver has been inited');
	// this.log(devices);
	this.onPairListDevices();
}

```

}

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [June 28, 2020, 8:40am UTC](https://community.homey.app/t/devices-search/31756/2 "2020-06-28T08:40:34Z")

</div>

You don’t have to call `onPairListDevices` manually, it will be called automatically. When you have gathered all the discovered devices, you need to call the passed-in callback with your list:

```auto
async onPairListDevices(data, callback) {
  callback(null, await this.device_cash());
}

```

Documented (somewhat) here: [https://developer.athom.com/docs/apps/tutorial-Drivers-Pairing-System%20Views-Devices%20List.html](https://developer.athom.com/docs/apps/tutorial-Drivers-Pairing-System%20Views-Devices%20List.html)

By the way, this doesn’t do what you think it does:

```auto
results = (cash_file[i]);

```

`results` is declared an array, but you’re setting it to an object in the above line, so `device_cash` actually returns an object, not an array. That may also break `onPairListDevices` because (AFAIK) the callback requires an array.

---

<div class="post-metadata">

**Author:** ![Marwan\_Magdy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marwan_magdy/32/17200_2.png) [@Marwan\_Magdy](https://community.homey.app/u/Marwan_Magdy)\
**Post date:** [June 28, 2020, 1:48pm UTC](https://community.homey.app/t/devices-search/31756/3 "2020-06-28T13:48:34Z")

</div>

Thanks a lot, robertklep,  
i guess i missed that  
.  
i have an error regarding the callback function

async onPairListDevices(data, callback) {  
const connection = new ewelink({  
email, password,  
region: ‘eu’,  
});

```
	callback(null, await connection.getDevices());
	// this.log("smart", devices);
}

```

TypeError: callback is not a function

---

<div class="post-metadata">

**Author:** ![Chris\_nl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chris_nl/32/27194_2.png) [@Chris\_nl](https://community.homey.app/u/Chris_nl)\
**Post date:** [June 29, 2020, 1:12pm UTC](https://community.homey.app/t/devices-search/31756/4 "2020-06-29T13:12:39Z")

</div>

You might want to get some information in your message removed (like the password), it’s a security issue.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [June 29, 2020, 1:14pm UTC](https://community.homey.app/t/devices-search/31756/5 "2020-06-29T13:14:54Z")

</div>

Are you sure you’re not still calling `this.onPairListDevices()` from `onInit()`?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [June 29, 2020, 2:39pm UTC](https://community.homey.app/t/devices-search/31756/7 "2020-06-29T14:39:36Z")

</div>

What does `this.log( await connection.getDevices() )` show?

---

<div class="post-metadata">

**Author:** ![Marwan\_Magdy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marwan_magdy/32/17200_2.png) [@Marwan\_Magdy](https://community.homey.app/u/Marwan_Magdy)\
**Post date:** [June 29, 2020, 3:25pm UTC](https://community.homey.app/t/devices-search/31756/8 "2020-06-29T15:25:41Z")

</div>

{  
settings: {  
opsNotify: 0,  
opsHistory: 1,  
alarmNotify: 1,  
wxAlarmNotify: 0,  
wxOpsNotify: 0,  
wxDoorbellNotify: 0,  
appDoorbellNotify: 1  
},  
family: { room: [Object], id: ‘5ed5fe75c38b630008558b8c’, index: -2 },  
group: ‘’,  
online: false,  
shareUsersInfo: [[Object] ],  
groups: ,  
devGroups: ,  
\_id: ‘’,  
deviceid: ‘’,  
name: ‘My Room’,  
type: ‘10’,  
apikey: ‘386c-4432-836c-f891e9c0ed07’,  
extra: { extra: [Object], \_id: ‘5d4bd9d9b9fe4f5’ },  
createdAt: ‘2020-06-02T18:34:00.236Z’,  
\_\_v: 0,  
onlineTime: ‘2020-06-18T00:39:50.977Z’,  
params: {  
version: 8,  
sledOnline: ‘on’,  
fwVersion: ‘3.4.0’,  
staMac: ‘D8:F1:5B:8D:F3:F7’,  
rssi: -55,  
init: 1,  
lock: 0,  
configure: [Array],  
pulses: [Array],  
switches: [Array],  
timers: [Array]  
},  
ip: ‘197.xx.xx.xxx’,  
location: ‘’,  
tags: { },  
offlineTime: ‘2020-06-18T09:00:10.235Z’,  
sharedBy: {  
email: ‘’,  
apikey: ‘’,  
permit: 15,  
shareTime: 1591867892792  
},

it prints device cash like this above

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [June 29, 2020, 6:22pm UTC](https://community.homey.app/t/devices-search/31756/9 "2020-06-29T18:22:10Z")

</div>

Perhaps you should start with creating a simpler app, just to get an idea how apps (and drivers, and devices) work in general.
