DoorController: Fix schedule getting/sending

This commit is contained in:
Adam Goldsmith 2018-10-18 20:15:27 -04:00
parent ee4898eaf3
commit 067555376b

View File

@ -1,3 +1,5 @@
import csv
from io import StringIO
from lxml import etree from lxml import etree
from lxml.builder import ElementMaker from lxml.builder import ElementMaker
import requests import requests
@ -5,6 +7,8 @@ import requests
E_plain = ElementMaker(nsmap={"hid": "http://www.hidglobal.com/VertX"}) E_plain = ElementMaker(nsmap={"hid": "http://www.hidglobal.com/VertX"})
E = ElementMaker(namespace="http://www.hidglobal.com/VertX", E = ElementMaker(namespace="http://www.hidglobal.com/VertX",
nsmap={"hid": "http://www.hidglobal.com/VertX"}) nsmap={"hid": "http://www.hidglobal.com/VertX"})
E_corp = ElementMaker(namespace="http://www.hidcorp.com/VertX", #stupid
nsmap={"hid": "http://www.hidcorp.com/VertX"})
ROOT = E_plain.VertXMessage ROOT = E_plain.VertXMessage
fieldnames = "CardNumber,CardFormat,PinRequired,PinCode,ExtendedAccess,ExpiryDate,Forename,Initial,Surname,Email,Phone,Custom1,Custom2,Schedule1,Schedule2,Schedule3,Schedule4,Schedule5,Schedule6,Schedule7,Schedule8".split(",") fieldnames = "CardNumber,CardFormat,PinRequired,PinCode,ExtendedAccess,ExpiryDate,Forename,Initial,Surname,Email,Phone,Custom1,Custom2,Schedule1,Schedule2,Schedule3,Schedule4,Schedule5,Schedule6,Schedule7,Schedule8".split(",")
@ -57,7 +61,7 @@ class DoorController():
raise RemoteError(r) raise RemoteError(r)
return resp_xml return resp_xml
def sendSchedules(self): def sendSchedules(self, schedules):
# clear all people # clear all people
outString = StringIO() outString = StringIO()
writer = csv.DictWriter(outString, fieldnames) writer = csv.DictWriter(outString, fieldnames)
@ -70,14 +74,30 @@ class DoorController():
delXML = ROOT( delXML = ROOT(
*[E.Schedules({"action": "DD", "scheduleID": str(ii)}) *[E.Schedules({"action": "DD", "scheduleID": str(ii)})
for ii in range(1, 8)]) for ii in range(1, 8)])
try:
self.doXMLRequest(delXML) self.doXMLRequest(delXML)
except RemoteError:
# don't care about failure to delete, they probably just didn't exist
pass
# load new schedules # load new schedules
with open("schedules.xml", "rb") as f: self.doXMLRequest(schedules)
self.doXMLRequest(f.read())
def getSchedules(self):
# TODO: might be able to do in one request
schedules = self.doXMLRequest(ROOT(
E.Schedules({"action": "LR"})))
etree.dump(schedules)
data = self.doXMLRequest(ROOT(
*[E.Schedules({"action": "LR",
"scheduleID": schedule.attrib["scheduleID"]})
for schedule in schedules[0]]))
return ROOT(E_corp.Schedules({"action": "AD"},
*[s[0] for s in data]))
def sendCardFormat(self, formatName, templateID, facilityCode): def sendCardFormat(self, formatName, templateID, facilityCode):
# TODO: add delete formats # TODO: add ability to delete formats
# delete example: <hid:CardFormats action="DD" formatID="7-1-244"/> # delete example: <hid:CardFormats action="DD" formatID="7-1-244"/>
el = ROOT( el = ROOT(