ryanleesmith / homebridge-litter-robot-connect

Litter-Robot Connect Homebridge Plugin
MIT License
14 stars 3 forks source link

Plugin sees two robots when there is only one #5

Closed canadaohcanada closed 4 years ago

canadaohcanada commented 4 years ago

First, thank you for this plugin, it is exactly what I was looking for! In the call seen in lib/litter-robot-connect.js around where connect.log('Syncing robots'); is printed my API returns TWO robots instead of one. I believe there are two robots on my account as I am on my second device after returning the first one for repairs. Would it be possible to exclude (or make a config option to exclude) any device with a isOnboarded value of false?

Here is my current response from the API call you're using to determine the number of robots:

[
  {
    "powerStatus": "AC",
    "sleepModeStartTime": "0",
    "lastSeen": "2019-06-20T05:25:08.062571",
    "sleepModeEndTime": "0",
    "autoOfflineDisabled": false,
    "setupDate": "2019-06-20T05:21:54.798017",
    "DFICycleCount": "0",
    "cleanCycleWaitTimeMinutes": "3",
    "unitStatus": "OFFLINE",
    "isOnboarded": false,   <------ this is my old/returned device
    "deviceType": "udp",
    "litterRobotNickname": "Shitty Kitty",
    "cycleCount": "0",
    "panelLockActive": "0",
    "cyclesAfterDrawerFull": "0",
    "litterRobotSerial": "...",
    "cycleCapacity": "36",
    "litterRobotId": "...",
    "nightLightActive": "0",
    "didNotifyOffline": null,
    "isDFITriggered": "0",
    "sleepModeActive": "0"
  },
  {
    "powerStatus": "AC",
    "sleepModeStartTime": "0",
    "lastSeen": "2020-05-04T14:44:45.486355",
    "sleepModeEndTime": "0",
    "autoOfflineDisabled": true,
    "setupDate": "2019-07-05T18:42:53.563359",
    "DFICycleCount": "0",
    "cleanCycleWaitTimeMinutes": "7",
    "unitStatus": "RDY",
    "isOnboarded": true,   <------ this is my current device
    "deviceType": "udp",
    "litterRobotNickname": "Shitty Kitty",
    "cycleCount": "19",
    "panelLockActive": "0",
    "cyclesAfterDrawerFull": "0",
    "litterRobotSerial": "...",
    "cycleCapacity": "20",
    "litterRobotId": "...",
    "nightLightActive": "1",
    "didNotifyOffline": false,
    "isDFITriggered": "0",
    "sleepModeActive": "0"
  }
]

Finally, having two robots in the Home app is really confusing without a means to tell them apart. In my instance both devices have the same name. If this occurs it might be nice to have two devices Shitty Kitty 1 and Shitty Kitty 2 in case the names are otherwise identical.

Thanks again for this wonderful plugin, it's really great!

canadaohcanada commented 4 years ago

I found that adding a simple if check around the line in question solves my issue. Could we please wire this up as an config option or make it a permanent part of the source?

From /lib/litter-robot-connect.js line 105

response.data.forEach(robot => {
    if (robot.isOnboarded) {
        let device = new LitterRobotDevice(connect, platform, robot);
        connect.devices.push(device);
    }
});
ryanleesmith commented 4 years ago

Sorry, didn’t get the notification for this. Thanks for reporting - I didn’t realize they had this. I’ll put together a fix tomorrow.

ryanleesmith commented 4 years ago

I pushed 1.1.0 which should resolve this. By the way - do you happen to know how/why your deviceType is UDP? Mine is IOT which I assume is why I have to go through their REST API. If there is really a UDP mode, this could be much more efficient and accurate instead of having to poll remotely.