Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call hasCapability and getting error #10

Closed
brianping7 opened this issue Apr 24, 2017 · 3 comments
Closed

call hasCapability and getting error #10

brianping7 opened this issue Apr 24, 2017 · 3 comments

Comments

@brianping7
Copy link

Hi, when i call the function "hasCapability“, i'm getting the following error.
if(this.handle.hasCapability('power')) {
^

TypeError: this.handle.hasCapability is not a function

i think it is because it doesn't initialized successfully, but i don't know why, their is no other log i can check, could you help? thanks.

@aholstenson
Copy link
Owner

How do you create and assign the value to this.handle?

@brianping7
Copy link
Author

this.handle = miio.device({ address: ip, token: token }) .then(console.log(name + ' create')) .catch(console.error(name + ' failed'));

i'm using device function.

@aholstenson
Copy link
Owner

miio.device() returns a promise that asynchronously resolves the device, so this.handle will still be pointing to that promise in the code you posted.

You probably want something like this instead:

miio.device({ address: ip, token: token })
  .then(device => this.handle = device)
  .catch(handleErrorConnectingToDevice);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants