bloomkd46 / homebridge-iRobot

A homebridge plugin for controlling iRobot devices
Apache License 2.0
61 stars 14 forks source link

Feature Request: Option for No Cloud w/ BLID, Password & IP in Config #22

Open rcoletti116 opened 2 years ago

rcoletti116 commented 2 years ago

Is your feature request related to a problem? Please describe:

I think the ability to log in with the iRobot credentials solves a huge usability problem over the other plugin (Roomba2) as users have a hard time using the discovery script to obtain the BLID and Robot password. However, I would like to suggest a hybrid approach that allows for users to be completely disconnected from the cloud account by storing the BLID, Password, and IP in the config.

Describe the solution you'd like:

1) Users who want to rely on cloud sign-in can do so. 2) Perhaps an option in the logs upon discovery can highlight the BLID and Robot Password for users to save. 3) Users who already have the information, or who choose to add it to the config can do so and remove their irobot cloud credentials. 4) If there are config fields for blid, robot password, and ip are blank -> use cloud. If they are present and if cloud credentials are missing, use local only.

A good example of this is the Meross plugin.

Describe alternatives you've considered:

The homebridge-roomba2 plugin is the full-swing alternative. I think there can be a hybrid approach that benefits more users.

Additional context:

Ideally, the plugin would support the ability to use the irobot device 100% locally with no cloud dependencies.

Node Version (optional):

No response

NPM Version (optional):

No response

Homebridge Version (optional):

No response

Plugin Version:

2.1.9

Operating System (optional):

No response

bloomkd46 commented 2 years ago

I will definitely look into this. Additionally you can view your Roomba IP, blid, and password in plugins -> homebridge-iRobot settings -> devices

rcoletti116 commented 2 years ago

Nice feature. That definitely makes this request more appealing, and solves the discovery issues of previous plugins.

bloomkd46 commented 2 years ago

I have released a beta release with these features. please try it out and let me know if you have any suggestions. PS let me know if you need help installing the beta

rcoletti116 commented 2 years ago

Tried the beta. Works at first, but eventually it loses connection to the bot and I get the same flow of errors as in #35. It doesn't recover unless I reboot homebridge. How is the plugin handling local connection to the bot?

bloomkd46 commented 2 years ago

It just reconnects after 5 seconds when the Roomba is disconnected which occurs after the Roomba goes offline

async configureRoomba() {
    this.roomba = null;
    this.accessory.context.connected = false;
    this.roomba = new dorita980.Local(this.device.blid, this.device.password, this.device.ip,
      this.device.info.ver !== undefined ? parseInt(this.device.info.ver) : 2);
    this.roomba.on('connect', () => {
      this.accessory.context.connected = true;
      this.platform.log.info('Succefully connected to roomba', this.device.name);
    }).on('offline', () => {
      this.accessory.context.connected = false;
      this.platform.log.warn('Roomba', this.device.name, ' went offline, disconnecting...');
      this.roomba.end();
      //throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
    }).on('close', () => {
      this.accessory.context.connected = false;
      this.roomba.removeAllListeners();
      if (this.shutdown) {
        this.platform.log.info('Roomba', this.device.name, 'connection closed');
      } else {
        this.platform.log.warn('Roomba', this.device.name, ' connection closed, reconnecting in 5 seconds');
        setTimeout(() => {
          this.platform.log.warn('Attempting To Reconnect To Roomba', this.device.name);
          this.configureRoomba();
        }, 5000);
        //throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
      }
    }).on('state', this.updateRoombaState.bind(this));
  }
rcoletti116 commented 2 years ago

But does it try to hold an open/persistent connection the robot?

From what I see, when it disconnects (reason unknown) it tries to reconnect as seen in the logs, but never actually does. Once you restart homebridge it discovers the device and connects again.

bloomkd46 commented 2 years ago

That's the weird part. I'm wondering if it isn't fully disconnecting. I am planning on making it so that if it fails to reconnect it will wait a longer period of time (~5 minutes)

bloomkd46 commented 2 years ago

This line is what connects to the robot and connection remains until Roomba goes offline or you call roomba.end()

this.roomba = new dorita980.Local(this.device.blid, this.device.password, this.device.ip,
      this.device.info.ver !== undefined ? parseInt(this.device.info.ver) : 2);
rcoletti116 commented 2 years ago

I'm still seeing this behavior too and the device isn't really going offline to cause a disconnection. I wonder if the issue here is trying to keep an open connection too long. It shouldn't be necessary.

Older versions of the Roomba plugins offered options for Keep-Alive, time-based polling or on-demand, but those all had their own issues. Keeping an open connection kills the battery. The Roomba2 plugin closes the connection when not in use and utilizes sharing connections when one is already open. Might be worth taking a look. https://github.com/karlvr/homebridge-roomba2/blob/main/src/accessory.ts#L329

Is anyone else using the local mode and have feedback?

bloomkd46 commented 2 years ago

I’ve actually been trying to develop a plug-in v3.0 which will only connect to the Roomba’s when requested by HomeKit. It would also take advantage of other Roomba features. Ex. Clean power

rcoletti116 commented 2 years ago

The challenge with that approach becomes speed and waiting for the robot to respond. I think there’s a balance to strike.

I’ve toyed with the idea as well of using custom characteristics to get the other features. Then you could use HomeKit as a 100% local replacement.

bloomkd46 commented 1 year ago

Please try the latest beta: npm