From 641b9a2779edf613c910fc1be06af76acba0a73a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 21 Feb 2020 16:19:46 -0500 Subject: [PATCH] lib/hid: Work around HID bug in returned XML records Includes: - lib/hid: Don't send recordCount as -1, fixes #4 --- lib/hid/DoorController.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/hid/DoorController.py b/lib/hid/DoorController.py index f62395e..88a9260 100644 --- a/lib/hid/DoorController.py +++ b/lib/hid/DoorController.py @@ -135,17 +135,24 @@ class DoorController(): recordCount = 0 moreRecords = True + # note: all the "+/-1" bits are to work around a bug where the + # last returned entry is incomplete. There is probably a + # better way to do this, but for now I just get the last entry + # again in the next request. I suspect this probably ends + # poorly if the numbers line up poorly (ie an exact multiple + # of the returned record limit) while moreRecords: res = self.doXMLRequest(ROOT( req({ "action": "LR", - "recordCount": str(count - recordCount), - "recordOffset": str(recordCount), + "recordCount": str(count - recordCount + 1), + "recordOffset": str(recordCount - 1 + if recordCount > 0 else 0), **params }))) - result += list(res[0]) + result = result[:-1] + list(res[0]) - recordCount += int(res[0].get('recordCount')) + recordCount += int(res[0].get('recordCount')) - 1 moreRecords = res[0].get('moreRecords') == 'true' return result