pyztk/test.py

52 lines
1.5 KiB
Python
Raw Normal View History

2016-05-23 13:50:54 +07:00
# -*- coding: utf-8 -*-
import sys
sys.path.append("zk")
import zk
2016-05-26 13:06:33 +07:00
from zk import const
2016-05-23 13:50:54 +07:00
2016-05-30 09:59:39 +07:00
conn = False
2016-05-26 23:58:48 +07:00
zk = zk.ZK('192.168.1.201', port=4370, timeout=5)
2016-05-30 09:59:39 +07:00
try:
print 'Connecting to device ...'
conn = zk.connect()
2016-05-25 16:28:55 +07:00
print 'Disabling device ...'
2016-05-29 20:27:01 +07:00
zk.disable_device()
2016-05-23 14:41:39 +07:00
print 'Firmware Version: : {}'.format(zk.get_firmware_version())
# Load test create 2000 users
2016-05-25 15:35:45 +07:00
# for i in range(1, 2000+1):
# privilege = const.USER_DEFAULT
# if i == 1:
# privilege = const.USER_ADMIN
# print zk.set_user(uid=i, name='user #{}'.format(i), privilege=privilege, password='12345678', group_id='', user_id='{}'.format(i))
2016-05-29 20:27:01 +07:00
# print '--- Get User ---'
2016-05-25 16:28:55 +07:00
users = zk.get_users()
2016-05-29 20:27:01 +07:00
for user in users:
privilege = 'User'
if user.privilege == const.USER_ADMIN:
privilege = 'Admin'
2016-05-25 16:28:55 +07:00
2016-05-29 20:27:01 +07:00
print '- UID #{}'.format(user.uid)
print ' Name : {}'.format(user.name)
print ' Privilege : {}'.format(privilege)
print ' Password : {}'.format(user.password)
print ' Group ID : {}'.format(user.group_id)
print ' User ID : {}'.format(user.user_id)
2016-05-23 19:49:36 +07:00
2016-05-25 16:28:55 +07:00
print "Voice Test ..."
2016-05-29 20:27:01 +07:00
zk.test_voice()
2016-05-25 16:28:55 +07:00
# print 'Restarting device ...'
2016-05-29 20:27:01 +07:00
# zk.restart()
2016-05-25 16:28:55 +07:00
# print 'Turning off device ...'
2016-05-29 20:27:01 +07:00
# zk.power_off()
2016-05-25 16:28:55 +07:00
print 'Enabling device ...'
2016-05-29 20:27:01 +07:00
zk.enable_device()
2016-05-25 16:28:55 +07:00
print 'Disconnecting to device ...'
2016-05-29 20:27:01 +07:00
zk.disconnect()
2016-05-23 23:59:43 +07:00
2016-05-30 09:59:39 +07:00
except Exception, e:
print "Process terminate : {}".format(e)
finally:
if conn:
zk.disconnect()