Giter Club home page Giter Club logo

Comments (9)

brianping7 avatar brianping7 commented on August 11, 2024

this.device = {"domain":null,"_events":{},"_eventsCount":0,"type":"gateway","model":"lumi.gateway.v3","capabilities":[],"address":"192.168.2.250","port":54321,

from miio.

aholstenson avatar aholstenson commented on August 11, 2024

Devices become available asynchronously for the gateway, you need to listen for the events deviceAvailable and deviceUnavailable to keep track of devices being found and removed.

device.on('deviceAvailable', subdevice => doSomethingWithSubdeviceHere)

When deviceAvailable has triggered the device should be available in devices but it will not be available directly after connecting to the gateway.

from miio.

brianping7 avatar brianping7 commented on August 11, 2024

i try to set power off of a power-plug by using following code:
that.device.on('deviceAvailable', subDevice => { if (subDevice.type == 'power-plug') { subDevice.setPower(1, false) .then(console.log(subDevice.name + " Power " + subDevice.power())) .catch(console.error(subDevice.name + " Failed to Power Off")); }
i got following error..

`json.sid = options.sid;
^

TypeError: Cannot create property 'sid' on string '{"id":2,"method":"toggle_plug","params":["neutral_1","off"]}'
at Gateway.call (/home/brianping7/work/home-jarvis/plugin/miHome/lib/device.js:173:13)
`

from miio.

aholstenson avatar aholstenson commented on August 11, 2024

Thanks. The sub device code was broken in 0.11.0. Can you try 0.11.1 and see if works for you?

from miio.

brianping7 avatar brianping7 commented on August 11, 2024

above error not exist anymore,but still get some error.
gateway init success power-plug Failed :Error power-plug Failed :Error
am i using the right input?
code:
`that.device.on('deviceAvailable', subDevice => {
if (subDevice.type == 'power-plug') {
subDevice.setPower(1, false)
.then(power => console.log(subDevice.type + " Power " + power))
.catch(err => console.error(subDevice.type + " Failed :" + err));
}

    return;
  });`

from miio.

brianping7 avatar brianping7 commented on August 11, 2024

i use 0 as channel id to try, failed again
subDevice.setPower(0, false)

from miio.

aholstenson avatar aholstenson commented on August 11, 2024

Hmm, I don't have access to the plug so hard for me to test any fixes.

What type of plug is it? There seems to be both a version that plugs into a socket and one that is an actual socket.

Could you try running setPower and log either err.message or err as its own argument? Something like this:

.catch(err => console.error(subDevice.type + " Failed :", err));

Hopefully one of those will output a more detailed error message that can help with figuring out what has gone wrong.

from miio.

brianping7 avatar brianping7 commented on August 11, 2024

Hi, i use subDevice.setPower("0", false) , the problem got fixed, thanks.

from miio.

aholstenson avatar aholstenson commented on August 11, 2024

Good! Thank you for your issue reports!

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.