codetheweb / homebridge-tuya-outlet

A plugin for Homebridge for Tuya-based outlets
15 stars 11 forks source link

Add support for more than one device #7

Closed awakenrz closed 6 years ago

awakenrz commented 6 years ago

This PR adds the ability for the homebridge plugin to handle more than one Tuya smart plug devices.

@codetheweb

This will address https://github.com/codetheweb/homebridge-tuya-outlet/issues/4

codetheweb commented 6 years ago

Thanks for your work.

However, I'm a little confused on what this changes. If only one device ID is passed as an argument to the Tuya constructor, consecutive calls to get() and set() will by default use that ID. To successfully implement multiple Tuya devices with one instance, we would have to use Homebridge's Platform API rather than the Accessory API.

awakenrz commented 6 years ago

My understanding is that each accessory will instantiate its own TuyaOutlet object.

Looking at TuyaAPI's implementation of get and set, it looks like it'll try to find the right accessory to talk to given the devId of the accessory.

I've successfully tested my change with two TuyaOutlet accessories in my homebridge config and there hasn't been any issues yet.

codetheweb commented 6 years ago

It should already be possible to use multiple devices by declaring multiple instances in the config file (although you must pass in the IP for each instance).

Did you try using two devices at once before making changes?

awakenrz commented 6 years ago

Ah, thank you! I think I mis-read the issue. I was reading https://github.com/codetheweb/homebridge-tuya-outlet/issues/5. But it looks like in https://github.com/codetheweb/homebridge-tuya-outlet/issues/4, specifying IP seems to be a temporary fix. Yes you're right, it also works without my change.

codetheweb commented 6 years ago

Ok 😄