Skip to content

Commit

Permalink
Fixed typo refs #3; linter python code
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhz committed May 21, 2020
1 parent 11ef50e commit 4fbb047
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 180 deletions.
26 changes: 18 additions & 8 deletions osdp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Python OSDP Module.

"""
Expand All @@ -14,18 +11,31 @@
"""


from ._types import ReplyType, SecurityBlockType, Control, ErrorCode, Nak, DeviceIdentification, CapabilityFunction, DeviceCapability, DeviceCapabilities, InputStatus, OutputStatus, LocalStatus, ReaderTamperStatus, ReaderStatus, OutputControlCode, OutputControl, OutputControls, TemporaryReaderControlCode, PermanentReaderControlCode, LedColor, ReaderLedControl, ReaderLedControls, ToneCode, ReaderBuzzerControl, TextCommand, ReaderTextOutput, FormatCode, RawCardData, KeypadData, DataEvent
from ._connection import OsdpConnection, SerialPortOsdpConnection, TcpClientOsdpConnection, TcpServerOsdpConnection
from ._types import (
ReplyType, SecurityBlockType, Control, ErrorCode, Nak, DeviceIdentification, CapabilityFunction,
DeviceCapability, DeviceCapabilities, InputStatus, OutputStatus, LocalStatus, ReaderTamperStatus,
ReaderStatus, OutputControlCode, OutputControl, OutputControls, TemporaryReaderControlCode,
PermanentReaderControlCode, LedColor, ReaderLedControl, ReaderLedControls, ToneCode, ReaderBuzzerControl,
TextCommand, ReaderTextOutput, FormatCode, RawCardData, KeypadData, DataEvent
)
from ._connection import (
OsdpConnection, SerialPortOsdpConnection, TcpClientOsdpConnection, TcpServerOsdpConnection
)
from ._device import Device
from ._message import Message
from ._command import Command, PollCommand, IdReportCommand, DeviceCapabilitiesCommand, LocalStatusReportCommand, InputStatusReportCommand, OutputStatusReportCommand, ReaderStatusReportCommand, OutputControlCommand, ReaderLedControlCommand, ReaderBuzzerControlCommand, ReaderTextOutputCommand, SetDateTimeCommand, SecurityInitializationRequestCommand, ServerCryptogramCommand, ManufacturerSpecificCommand
from ._command import (
Command, PollCommand, IdReportCommand, DeviceCapabilitiesCommand, LocalStatusReportCommand,
InputStatusReportCommand, OutputStatusReportCommand, ReaderStatusReportCommand,
OutputControlCommand, ReaderLedControlCommand, ReaderBuzzerControlCommand,
ReaderTextOutputCommand, SetDateTimeCommand, SecurityInitializationRequestCommand,
ServerCryptogramCommand, ManufacturerSpecificCommand
)
from ._reply import Reply, AckReply, UnknownReply
from ._secure_channel import SecureChannel
from ._bus import Bus
from ._control_panel import ControlPanel



__author__ = 'Ryan Hu<[email protected]>'
__copyright__ = 'Copyright 2019 Ryan Hu and Contributors'
__license__ = 'Apache License, Version 2.0'
__license__ = 'Apache License, Version 2.0'
34 changes: 16 additions & 18 deletions osdp/_bus.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from datetime import datetime, timedelta
import time
from queue import Queue
from threading import Lock
from uuid import UUID, uuid4
from uuid import uuid4

from ._types import *
from ._types import ReplyType, ErrorCode
from ._connection import OsdpConnection
from ._device import Device
from ._message import Message
Expand All @@ -14,11 +13,11 @@

log = logging.getLogger('osdp')

'''
A group of OSDP devices sharing communications
'''
class Bus:

class Bus:
'''
A group of OSDP devices sharing communications
'''
DRIVER_BYTE = 0xFF

def __init__(self, connection: OsdpConnection, on_reply_received):
Expand All @@ -32,7 +31,7 @@ def __init__(self, connection: OsdpConnection, on_reply_received):

@property
def idle_line_delay(self) -> timedelta:
return timedelta(milliseconds=(1000.0/self._connection.baud_rate * 16.0) * 100)
return timedelta(milliseconds=(1000.0 / self._connection.baud_rate * 16.0) * 100)

def close(self):
self._is_shutting_down = True
Expand Down Expand Up @@ -124,12 +123,12 @@ def process_reply(self, reply: Reply, device: Device):
if reply.type == ReplyType.Nak:
extract_reply_data = reply.extract_reply_data
error_code = ErrorCode(extract_reply_data[0])
if error_code==ErrorCode.DoesNotSupportSecurityBlock or error_code==ErrorCode.DoesNotSupportSecurityBlock:
if error_code == ErrorCode.DoesNotSupportSecurityBlock or error_code == ErrorCode.DoesNotSupportSecurityBlock:
device.reset_security()

if reply.type==ReplyType.CrypticData:
if reply.type == ReplyType.CrypticData:
device.initialize_secure_channel(reply)
elif reply.type==ReplyType.InitialRMac:
elif reply.type == ReplyType.InitialRMac:
device.validate_secure_channel_establishment(reply)

if self._on_reply_received is not None:
Expand Down Expand Up @@ -168,8 +167,8 @@ def extract_message_length(self, reply_buffer: bytearray) -> int:

def wait_for_rest_of_message(self, buffer: bytearray, reply_length: int):
while len(buffer) < reply_length:
bytes_read = self._connection.read(reply_length-len(buffer))
if len(bytes_read)>0:
bytes_read = self._connection.read(reply_length - len(buffer))
if len(bytes_read) > 0:
buffer.extend(bytes_read)
else:
return False
Expand All @@ -178,7 +177,7 @@ def wait_for_rest_of_message(self, buffer: bytearray, reply_length: int):
def wait_for_message_length(self, buffer: bytearray) -> bool:
while len(buffer) < 4:
bytes_read = self._connection.read(4)
if len(bytes_read)>0:
if len(bytes_read) > 0:
buffer.extend(bytes_read)
else:
return False
Expand All @@ -187,13 +186,12 @@ def wait_for_message_length(self, buffer: bytearray) -> bool:
def wait_for_start_of_message(self, buffer: bytearray) -> bool:
while True:
bytes_read = self._connection.read(1)
if len(bytes_read)==0:
if len(bytes_read) == 0:
return False

if bytes_read[0]!=Message.SOM:
if bytes_read[0] != Message.SOM:
continue

buffer.extend(bytes_read)
break
return True

return True
Loading

0 comments on commit 4fbb047

Please sign in to comment.