add function set_user

This commit is contained in:
Fanani M. Ihsan 2016-05-25 01:32:06 +07:00
parent 79b856f448
commit 5d3aae3884
2 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,9 @@ if conn.get('status'):
print conn
print zk.disable_device()
print 'Firmware Version: : {}'.format(zk.get_firmware_version())
# Load test create 1000 users
for i in range(1, 1000+1):
zk.set_user(uid=i, user_id='{}'.format(i), name='user #{}'.format(i), password='123456', privilege=14)
# print 'Restarting device'
# print zk.restart()
# print 'Turning off device'

View File

@ -202,6 +202,17 @@ class ZK(object):
else:
return cmd_response
def set_user(self, uid, privilege, password='', name='', card_num=chr(1), group='', timezone='', user_id=''):
command = const.CMD_USER_WRQ
command_string = pack('sss8s28ss7sx8s16s', chr(uid % 256), chr(uid >> 8), chr(privilege), password, name, card_num, group, user_id, timezone )
cmd_response = self.__send_command(command=command, command_string=command_string, response_size=1024)
cmd_response['data'] = ''
if cmd_response.get('status'):
cmd_response['message'] = 'new user created'
return cmd_response
else:
return cmd_response
# def __get_size_user(self):
# """Checks a returned packet to see if it returned CMD_PREPARE_DATA,
# indicating that data packets are to be sent