Skip to content

Commit

Permalink
Remove kwargs client.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Jul 19, 2024
1 parent 552c56e commit c310914
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 254 deletions.
212 changes: 80 additions & 132 deletions pymodbus/client/mixin.py

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions pymodbus/pdu/bit_read_message.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"""Bit Reading Request/Response messages."""

__all__ = [
"ReadBitsResponseBase",
"ReadCoilsRequest",
"ReadCoilsResponse",
"ReadDiscreteInputsRequest",
"ReadDiscreteInputsResponse",
]

# pylint: disable=missing-type-doc
import struct

Expand All @@ -21,7 +13,7 @@ class ReadBitsRequestBase(ModbusRequest):

_rtu_frame_size = 8

def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address, count, slave, transaction, protocol, skip_encode):
"""Initialize the read request data.
:param address: The start address to read from
Expand Down Expand Up @@ -75,7 +67,7 @@ class ReadBitsResponseBase(ModbusResponse):

_rtu_byte_count_pos = 2

def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False):
def __init__(self, values, slave, transaction, protocol, skip_encode):
"""Initialize a new instance.
:param values: The requested values to be returned
Expand Down
6 changes: 0 additions & 6 deletions pymodbus/pdu/bit_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
TODO write mask request/response
"""

__all__ = [
"WriteSingleCoilRequest",
"WriteSingleCoilResponse",
"WriteMultipleCoilsRequest",
"WriteMultipleCoilsResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
38 changes: 0 additions & 38 deletions pymodbus/pdu/diag_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,6 @@
or linked to the appropriate data
"""

__all__ = [
"DiagnosticStatusRequest",
"DiagnosticStatusResponse",
"ReturnQueryDataRequest",
"ReturnQueryDataResponse",
"RestartCommunicationsOptionRequest",
"RestartCommunicationsOptionResponse",
"ReturnDiagnosticRegisterRequest",
"ReturnDiagnosticRegisterResponse",
"ChangeAsciiInputDelimiterRequest",
"ChangeAsciiInputDelimiterResponse",
"ForceListenOnlyModeRequest",
"ForceListenOnlyModeResponse",
"ClearCountersRequest",
"ClearCountersResponse",
"ReturnBusMessageCountRequest",
"ReturnBusMessageCountResponse",
"ReturnBusCommunicationErrorCountRequest",
"ReturnBusCommunicationErrorCountResponse",
"ReturnBusExceptionErrorCountRequest",
"ReturnBusExceptionErrorCountResponse",
"ReturnSlaveMessageCountRequest",
"ReturnSlaveMessageCountResponse",
"ReturnSlaveNoResponseCountRequest",
"ReturnSlaveNoResponseCountResponse",
"ReturnSlaveNAKCountRequest",
"ReturnSlaveNAKCountResponse",
"ReturnSlaveBusyCountRequest",
"ReturnSlaveBusyCountResponse",
"ReturnSlaveBusCharacterOverrunCountRequest",
"ReturnSlaveBusCharacterOverrunCountResponse",
"ReturnIopOverrunCountRequest",
"ReturnIopOverrunCountResponse",
"ClearOverrunCountRequest",
"ClearOverrunCountResponse",
"GetClearModbusPlusRequest",
"GetClearModbusPlusResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
11 changes: 0 additions & 11 deletions pymodbus/pdu/file_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
"""
from __future__ import annotations


__all__ = [
"FileRecord",
"ReadFileRecordRequest",
"ReadFileRecordResponse",
"WriteFileRecordRequest",
"WriteFileRecordResponse",
"ReadFifoQueueRequest",
"ReadFifoQueueResponse",
]

# pylint: disable=missing-type-doc
import struct

Expand Down
4 changes: 0 additions & 4 deletions pymodbus/pdu/mei_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Encapsulated Interface (MEI) Transport Messages."""

__all__ = [
"ReadDeviceInformationRequest",
"ReadDeviceInformationResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
10 changes: 0 additions & 10 deletions pymodbus/pdu/other_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
Currently not all implemented
"""

__all__ = [
"ReadExceptionStatusRequest",
"ReadExceptionStatusResponse",
"GetCommEventCounterRequest",
"GetCommEventCounterResponse",
"GetCommEventLogRequest",
"GetCommEventLogResponse",
"ReportSlaveIdRequest",
"ReportSlaveIdResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
7 changes: 0 additions & 7 deletions pymodbus/pdu/pdu.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
"""Contains base classes for modbus request/response/error packets."""

__all__ = [
"ModbusRequest",
"ModbusResponse",
"ModbusExceptions",
"ExceptionResponse",
"IllegalFunctionRequest",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
9 changes: 0 additions & 9 deletions pymodbus/pdu/register_read_message.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"""Register Reading Request/Response."""

__all__ = [
"ReadHoldingRegistersRequest",
"ReadHoldingRegistersResponse",
"ReadInputRegistersRequest",
"ReadInputRegistersResponse",
"ReadRegistersResponseBase",
"ReadWriteMultipleRegistersRequest",
"ReadWriteMultipleRegistersResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
8 changes: 0 additions & 8 deletions pymodbus/pdu/register_write_message.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"""Register Writing Request/Response Messages."""

__all__ = [
"WriteSingleRegisterRequest",
"WriteSingleRegisterResponse",
"WriteMultipleRegistersRequest",
"WriteMultipleRegistersResponse",
"MaskWriteRegisterRequest",
"MaskWriteRegisterResponse",
]

# pylint: disable=missing-type-doc
import struct
Expand Down
38 changes: 19 additions & 19 deletions test/sub_function_codes/test_bit_read_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ def tearDown(self):

def test_read_bit_base_class_methods(self):
"""Test basic bit message encoding/decoding."""
handle = ReadBitsRequestBase(1, 1)
handle = ReadBitsRequestBase(1, 1, 0, 0, 0, False)
msg = "ReadBitRequest(1,1)"
assert msg == str(handle)
handle = ReadBitsResponseBase([1, 1])
handle = ReadBitsResponseBase([1, 1], 0, 0, 0, False)
msg = "ReadBitsResponseBase(2)"
assert msg == str(handle)

def test_bit_read_base_request_encoding(self):
"""Test basic bit message encoding/decoding."""
for i in range(20):
handle = ReadBitsRequestBase(i, i)
handle = ReadBitsRequestBase(i, i, 0, 0, 0, False)
result = struct.pack(">HH", i, i)
assert handle.encode() == result
handle.decode(result)
Expand All @@ -60,15 +60,15 @@ def test_bit_read_base_response_encoding(self):
"""Test basic bit message encoding/decoding."""
for i in range(20):
data = [True] * i
handle = ReadBitsResponseBase(data)
handle = ReadBitsResponseBase(data, 0, 0, 0, False)
result = handle.encode()
handle.decode(result)
assert handle.bits[:i] == data

def test_bit_read_base_response_helper_methods(self):
"""Test the extra methods on a ReadBitsResponseBase."""
data = [False] * 8
handle = ReadBitsResponseBase(data)
handle = ReadBitsResponseBase(data, 0, 0, 0, False)
for i in (1, 3, 5):
handle.setBit(i, True)
for i in (1, 3, 5):
Expand All @@ -79,8 +79,8 @@ def test_bit_read_base_response_helper_methods(self):
def test_bit_read_base_requests(self):
"""Test bit read request encoding."""
messages = {
ReadBitsRequestBase(12, 14): b"\x00\x0c\x00\x0e",
ReadBitsResponseBase([1, 0, 1, 1, 0]): b"\x01\x0d",
ReadBitsRequestBase(12, 14, 0, 0, 0, False): b"\x00\x0c\x00\x0e",
ReadBitsResponseBase([1, 0, 1, 1, 0], 0, 0, 0, False): b"\x01\x0d",
}
for request, expected in iter(messages.items()):
assert request.encode() == expected
Expand All @@ -89,8 +89,8 @@ async def test_bit_read_message_execute_value_errors(self):
"""Test bit read request encoding."""
context = MockContext()
requests = [
ReadCoilsRequest(1, 0x800),
ReadDiscreteInputsRequest(1, 0x800),
ReadCoilsRequest(1, 0x800, 0, 0, 0, False),
ReadDiscreteInputsRequest(1, 0x800, 0, 0, 0, False),
]
for request in requests:
result = await request.execute(context)
Expand All @@ -100,8 +100,8 @@ async def test_bit_read_message_execute_address_errors(self):
"""Test bit read request encoding."""
context = MockContext()
requests = [
ReadCoilsRequest(1, 5),
ReadDiscreteInputsRequest(1, 5),
ReadCoilsRequest(1, 5, 0, 0, 0, False),
ReadDiscreteInputsRequest(1, 5, 0, 0, 0, False),
]
for request in requests:
result = await request.execute(context)
Expand All @@ -112,8 +112,8 @@ async def test_bit_read_message_execute_success(self):
context = MockContext()
context.validate = lambda a, b, c: True
requests = [
ReadCoilsRequest(1, 5),
ReadDiscreteInputsRequest(1, 5),
ReadCoilsRequest(1, 5, 0, 0, 0, False),
ReadDiscreteInputsRequest(1, 5, 0, 0, 0, False),
]
for request in requests:
result = await request.execute(context)
Expand All @@ -122,12 +122,12 @@ async def test_bit_read_message_execute_success(self):
def test_bit_read_message_get_response_pdu(self):
"""Test bit read message get response pdu."""
requests = {
ReadCoilsRequest(1, 5): 3,
ReadCoilsRequest(1, 8): 3,
ReadCoilsRequest(0, 16): 4,
ReadDiscreteInputsRequest(1, 21): 5,
ReadDiscreteInputsRequest(1, 24): 5,
ReadDiscreteInputsRequest(1, 1900): 240,
ReadCoilsRequest(1, 5, 0, 0, 0, False): 3,
ReadCoilsRequest(1, 8, 0, 0, 0, False): 3,
ReadCoilsRequest(0, 16, 0, 0, 0, False): 4,
ReadDiscreteInputsRequest(1, 21, 0, 0, 0, False): 5,
ReadDiscreteInputsRequest(1, 24, 0, 0, 0, False): 5,
ReadDiscreteInputsRequest(1, 1900, 0, 0, 0, False): 240,
}
for request, expected in iter(requests.items()):
pdu_len = request.get_response_pdu_size()
Expand Down

0 comments on commit c310914

Please sign in to comment.