Merge branch 'master' of github.com:fananimi/pyzk

This commit is contained in:
Fanani M. Ihsan 2019-04-25 16:41:06 +07:00
commit b70c8dcbff
4 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,6 @@
language: python
python:
- "2.7"
- "3.6"
# command to run tests
script: python test.py

View File

@ -413,6 +413,10 @@ DeviceName : K20 (latest checked correctly!)
Firmware Version : Ver 6.60 Aug 23 2014
Platform : ZEM600_TFT
DeviceName : VF680 (face device only, but we read the user and attendance list!)
Firmware Version : Ver 6.70 Feb 16 2017
Platform : ZLM30_TFT
DeviceName : RSP10k1 (latest checked correctly!)
```

View File

@ -5,7 +5,12 @@ import sys
import os
import unittest
import codecs
from mock import patch, Mock, MagicMock
if sys.version_info[0] < 3:
from mock import patch, Mock, MagicMock
else:
from unittest.mock import patch, Mock, MagicMock
mock_socket = MagicMock(name='zk.socket')
sys.modules['zk.socket'] = mock_socket
from zk import ZK, const

View File

@ -5,11 +5,11 @@ from socket import AF_INET, SOCK_DGRAM, SOCK_STREAM, socket, timeout
from struct import pack, unpack
import codecs
from zk import const
from zk.attendance import Attendance
from zk.exception import ZKErrorConnection, ZKErrorResponse, ZKNetworkError
from zk.user import User
from zk.finger import Finger
from . import const
from .attendance import Attendance
from .exception import ZKErrorConnection, ZKErrorResponse, ZKNetworkError
from .user import User
from .finger import Finger
def safe_cast(val, to_type, default=None):
@ -302,7 +302,7 @@ class ZK(object):
def __reverse_hex(self, hex):
data = ''
for i in reversed(xrange(len(hex) / 2)):
for i in reversed(range(len(hex) / 2)):
data += hex[i * 2:(i * 2) + 2]
return data
@ -878,7 +878,7 @@ class ZK(object):
raise ZKErrorResponse("Can't pack user")
else:
name_pad = name.encode(self.encoding, errors='ignore').ljust(24, b'\x00')[:24]
card_str = pack('i', int(card))[:4]
card_str = pack('<I', int(card))[:4]
command_string = pack('HB8s24s4sx7sx24s', uid, privilege, password.encode(self.encoding, errors='ignore'), name_pad, card_str, group_id.encode(), user_id.encode())
response_size = 1024 #TODO check response?
cmd_response = self.__send_command(command, command_string, response_size)
@ -1616,4 +1616,3 @@ class ZK(object):
return True
else:
raise ZKErrorResponse("Can't clear response")