Skip to content

Commit

Permalink
remove kwargs II. (#2237)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Jul 18, 2024
1 parent 0e2c7e9 commit 52dc16b
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 123 deletions.
1 change: 1 addition & 0 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ API changes 3.7.0
- Framer.<type> renamed to FramerType.<type>
- PDU classes moved to pymodbus/pdu
- Simulator config custom actions kwargs -> parameters
- Non defined parameters (kwargs) no longer valid


API changes 3.6.0
Expand Down
8 changes: 4 additions & 4 deletions examples/client_custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CustomModbusResponse(ModbusResponse):
function_code = 55
_rtu_byte_count_pos = 2

def __init__(self, values=None, **kwargs):
def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize."""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.values = values or []

def encode(self):
Expand Down Expand Up @@ -68,9 +68,9 @@ class CustomModbusRequest(ModbusRequest):
function_code = 55
_rtu_frame_size = 8

def __init__(self, address=None, **kwargs):
def __init__(self, address=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize."""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.count = 16

Expand Down
6 changes: 5 additions & 1 deletion pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ def __init__(
framer, cast(type[ModbusFramer], framer)
)(ClientDecoder(), self)
self.transaction = SyncModbusTransactionManager(
self, retries=retries, retry_on_empty=retry_on_empty, **kwargs
self,
kwargs.get("backoff", 0.3),
retry_on_empty,
kwargs.get("retry_on_invalid", False),
retries,
)
self.reconnect_delay_current = self.params.reconnect_delay or 0
self.use_udp = False
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _helper(self, data: str):
function_code = int(data[0])
if not (request := self.lookup.get(function_code, lambda: None)()):
Log.debug("Factory Request[{}]", function_code)
request = pdu.IllegalFunctionRequest(function_code)
request = pdu.IllegalFunctionRequest(function_code, 0, 0, 0, False)
else:
fc_string = "{}: {}".format( # pylint: disable=consider-using-f-string
str(self.lookup[function_code]) # pylint: disable=use-maxsplit-arg
Expand Down
24 changes: 12 additions & 12 deletions pymodbus/pdu/bit_read_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class ReadBitsRequestBase(ModbusRequest):

_rtu_frame_size = 8

def __init__(self, address, count, slave=0, **kwargs):
def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize the read request data.
:param address: The start address to read from
:param count: The number of bits after "address" to read
:param slave: Modbus slave slave ID
"""
ModbusRequest.__init__(self, slave, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.count = count

Expand Down Expand Up @@ -75,13 +75,13 @@ class ReadBitsResponseBase(ModbusResponse):

_rtu_byte_count_pos = 2

def __init__(self, values, slave=0, **kwargs):
def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param values: The requested values to be returned
:param slave: Modbus slave slave ID
"""
ModbusResponse.__init__(self, slave, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)

#: A list of booleans representing bit values
self.bits = values or []
Expand Down Expand Up @@ -146,14 +146,14 @@ class ReadCoilsRequest(ReadBitsRequestBase):
function_code = 1
function_code_name = "read_coils"

def __init__(self, address=None, count=None, slave=0, **kwargs):
def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param address: The address to start reading from
:param count: The number of bits to read
:param slave: Modbus slave slave ID
"""
ReadBitsRequestBase.__init__(self, address, count, slave, **kwargs)
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode)

async def execute(self, context):
"""Run a read coils request against a datastore.
Expand Down Expand Up @@ -193,13 +193,13 @@ class ReadCoilsResponse(ReadBitsResponseBase):

function_code = 1

def __init__(self, values=None, slave=0, **kwargs):
def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param values: The request values to respond with
:param slave: Modbus slave slave ID
"""
ReadBitsResponseBase.__init__(self, values, slave, **kwargs)
ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode)


class ReadDiscreteInputsRequest(ReadBitsRequestBase):
Expand All @@ -214,14 +214,14 @@ class ReadDiscreteInputsRequest(ReadBitsRequestBase):
function_code = 2
function_code_name = "read_discrete_input"

def __init__(self, address=None, count=None, slave=0, **kwargs):
def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param address: The address to start reading from
:param count: The number of bits to read
:param slave: Modbus slave slave ID
"""
ReadBitsRequestBase.__init__(self, address, count, slave, **kwargs)
ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode)

async def execute(self, context):
"""Run a read discrete input request against a datastore.
Expand Down Expand Up @@ -261,10 +261,10 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase):

function_code = 2

def __init__(self, values=None, slave=0, **kwargs):
def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param values: The request values to respond with
:param slave: Modbus slave slave ID
"""
ReadBitsResponseBase.__init__(self, values, slave, **kwargs)
ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode)
16 changes: 8 additions & 8 deletions pymodbus/pdu/bit_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class WriteSingleCoilRequest(ModbusRequest):

_rtu_frame_size = 8

def __init__(self, address=None, value=None, slave=None, **kwargs):
def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0, **_kwargs):
"""Initialize a new instance.
:param address: The variable address to write
:param value: The value to write at address
"""
ModbusRequest.__init__(self, slave=slave, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.value = bool(value)

Expand Down Expand Up @@ -119,13 +119,13 @@ class WriteSingleCoilResponse(ModbusResponse):
function_code = 5
_rtu_frame_size = 8

def __init__(self, address=None, value=None, **kwargs):
def __init__(self, address=None, value=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param address: The variable address written to
:param value: The value written at address
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.value = value

Expand Down Expand Up @@ -173,13 +173,13 @@ class WriteMultipleCoilsRequest(ModbusRequest):
function_code_name = "write_coils"
_rtu_byte_count_pos = 6

def __init__(self, address=None, values=None, slave=None, **kwargs):
def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0, **_kwargs):
"""Initialize a new instance.
:param address: The starting request address
:param values: The values to write
"""
ModbusRequest.__init__(self, slave=slave, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
if values is None:
values = []
Expand Down Expand Up @@ -256,13 +256,13 @@ class WriteMultipleCoilsResponse(ModbusResponse):
function_code = 15
_rtu_frame_size = 8

def __init__(self, address=None, count=None, **kwargs):
def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param address: The starting variable address written to
:param count: The number of values written
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.count = count

Expand Down
8 changes: 4 additions & 4 deletions pymodbus/pdu/diag_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class DiagnosticStatusRequest(ModbusRequest):
function_code_name = "diagnostic_status"
_rtu_frame_size = 8

def __init__(self, **kwargs):
def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a diagnostic request."""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.message = None

def encode(self):
Expand Down Expand Up @@ -131,9 +131,9 @@ class DiagnosticStatusResponse(ModbusResponse):
function_code = 0x08
_rtu_frame_size = 8

def __init__(self, **kwargs):
def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a diagnostic response."""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.message = None

def encode(self):
Expand Down
24 changes: 12 additions & 12 deletions pymodbus/pdu/file_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class ReadFileRecordRequest(ModbusRequest):
function_code_name = "read_file_record"
_rtu_byte_count_pos = 2

def __init__(self, records=None, **kwargs):
def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param records: The file record requests to be read
"""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.records = records or []

def encode(self):
Expand Down Expand Up @@ -165,12 +165,12 @@ class ReadFileRecordResponse(ModbusResponse):
function_code = 0x14
_rtu_byte_count_pos = 2

def __init__(self, records=None, **kwargs):
def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param records: The requested file records
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.records = records or []

def encode(self):
Expand Down Expand Up @@ -218,12 +218,12 @@ class WriteFileRecordRequest(ModbusRequest):
function_code_name = "write_file_record"
_rtu_byte_count_pos = 2

def __init__(self, records=None, **kwargs):
def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param records: The file record requests to be read
"""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.records = records or []

def encode(self):
Expand Down Expand Up @@ -282,12 +282,12 @@ class WriteFileRecordResponse(ModbusResponse):
function_code = 0x15
_rtu_byte_count_pos = 2

def __init__(self, records=None, **kwargs):
def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param records: The file record requests to be read
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.records = records or []

def encode(self):
Expand Down Expand Up @@ -347,12 +347,12 @@ class ReadFifoQueueRequest(ModbusRequest):
function_code_name = "read_fifo_queue"
_rtu_frame_size = 6

def __init__(self, address=0x0000, **kwargs):
def __init__(self, address=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param address: The fifo pointer address (0x0000 to 0xffff)
"""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
self.values = [] # this should be added to the context

Expand Down Expand Up @@ -408,12 +408,12 @@ def calculateRtuFrameSize(cls, buffer):
lo_byte = int(buffer[3])
return (hi_byte << 16) + lo_byte + 6

def __init__(self, values=None, **kwargs):
def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param values: The list of values of the fifo to return
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.values = values or []

def encode(self):
Expand Down
8 changes: 4 additions & 4 deletions pymodbus/pdu/mei_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class ReadDeviceInformationRequest(ModbusRequest):
function_code_name = "read_device_information"
_rtu_frame_size = 7

def __init__(self, read_code=None, object_id=0x00, **kwargs):
def __init__(self, read_code=None, object_id=0x00, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param read_code: The device information read code
:param object_id: The object to read from
"""
ModbusRequest.__init__(self, **kwargs)
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.read_code = read_code or DeviceInformation.BASIC
self.object_id = object_id

Expand Down Expand Up @@ -134,13 +134,13 @@ def calculateRtuFrameSize(cls, buffer):
except struct.error as exc:
raise IndexError from exc

def __init__(self, read_code=None, information=None, **kwargs):
def __init__(self, read_code=None, information=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs):
"""Initialize a new instance.
:param read_code: The device information read code
:param information: The requested information request
"""
ModbusResponse.__init__(self, **kwargs)
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.read_code = read_code or DeviceInformation.BASIC
self.information = information or {}
self.number_of_objects = 0
Expand Down
Loading

0 comments on commit 52dc16b

Please sign in to comment.