GithubHelp home page GithubHelp logo

device.init not reject about miio HOT 4 CLOSED

aholstenson avatar aholstenson commented on May 26, 2024
device.init not reject

from miio.

Comments (4)

aholstenson avatar aholstenson commented on May 26, 2024

Thanks for the report. device.init() is used to setup and load initial properties for most devices. It should load properties from the vacuum as well, at least the first time it is called. Calling init() is considered advanced usage together with miio.createDevice(). In most cases you should use miio.device() if you want to connect via IP.

Can you share how you are creating the initial device handle?

from miio.

rench avatar rench commented on May 26, 2024

//create device
let device = miio.createDevice({
address: this.config.ip,
token: this.config.token,
model: 'rockrobo.vacuum.v1'
});
if (this.config.sid == undefined) {
this.config.sid = this.config.ip; //change sid
}
device.init()
.then(() => {
this.mijia.log.debug('init vacuum done->%s', this.config.ip);
this.mijia.log.debug('Battery->%s,State->%s,Fan->%s', device.battery, device.state, device.fanPower);
if (device.state != undefined) {
this.setVacuum(this.config, device);
this.devices[this.config.sid] = device;
} else {
this.mijia.log.warn('vacuum state undefined, discard to setVacuum');
device.destroy();
}
})
.catch((err) => {
this.mijia.log.error(err);
throw new Error('unable to initialize robot vacuum->%s', this.config.ip);
});

if i config a wrong ip address,like 1.1.1.1 , the then section will always to be call.
so i have to check the state,if device.state!=undefined ,i will register a homekit accessory.otherwise discard it.

i think ,if it can't init success,will goto catch section(promise.reject).

from miio.

aholstenson avatar aholstenson commented on May 26, 2024

Looks like any errors during init are being suppressed right now. I'll do a fix for the next release.

In your use case it looks like you probably want to use miio.device() instead of miio.createDevice() which will connect, resolve the model and initialize the device properly. That method will fail if it can not connect to the device.

from miio.

rench avatar rench commented on May 26, 2024

ok,i see.
thank you ~

from miio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.