Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Type check with zuban
if: matrix.run_lint == true
run: |
uv run zuban check pymodbus examples
uv run zuban check pymodbus examples test

- name: ruff
if: matrix.run_lint == true
Expand Down
2 changes: 1 addition & 1 deletion check_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
codespell
ruff check --fix --exit-non-zero-on-fix .
pylint --recursive=y examples pymodbus test
zuban check pymodbus examples
zuban check pymodbus examples test
pytest -x --cov --numprocesses auto
echo "Ready to push"
2 changes: 1 addition & 1 deletion examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
_logger.setLevel("DEBUG")


def setup_async_client(description: str | None =None, cmdline: str | None = None) -> modbusClient.ModbusBaseClient:
def setup_async_client(description: str | None =None, cmdline: list[str] | None = None) -> modbusClient.ModbusBaseClient:
"""Run client setup."""
args = helper.get_commandline(
server=False, description=description, cmdline=cmdline
Expand Down
2 changes: 1 addition & 1 deletion examples/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_logger = logging.getLogger(__file__)


def get_commandline(server: bool = False, description: str | None = None, extras: Any = None, cmdline: str | None = None):
def get_commandline(server: bool = False, description: str | None = None, extras: Any = None, cmdline: list[str] | None = None):
"""Read and check command line arguments."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/client/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import enum
import struct
from abc import abstractmethod
from typing import Generic, Literal, TypeVar, cast

from ..constants import ModbusStatus
Expand Down Expand Up @@ -49,9 +48,10 @@ class ModbusClientMixin(Generic[T]): # pylint: disable=too-many-public-methods
def __init__(self):
"""Initialize."""

@abstractmethod
def execute(self, no_response_expected: bool, request: ModbusPDU) -> T:
"""Execute request."""
_ = no_response_expected, request
return cast(T, None)

def read_coils(self, address: int, *, count: int = 1, device_id: int = 1, no_response_expected: bool = False) -> T:
"""Read coils (code 0x01).
Expand Down
4 changes: 1 addition & 3 deletions pymodbus/pdu/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import asyncio
import struct
from abc import abstractmethod

from ..datastore import ModbusServerContext
from ..exceptions import ModbusIOException, NotImplementedException
Expand Down Expand Up @@ -82,11 +81,10 @@ def get_response_pdu_size(self) -> int:
"""Calculate response pdu size."""
return 0

@abstractmethod
def encode(self) -> bytes:
"""Encode the message."""
return b''

@abstractmethod
def decode(self, data: bytes) -> None:
"""Decode data part of the message."""

Expand Down
25 changes: 16 additions & 9 deletions test/client/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test client sync."""
import socket
import ssl
from typing import cast
from unittest import mock

import pytest
Expand Down Expand Up @@ -250,7 +251,7 @@ def test_client_mixin_convert(self, datatype, word_order, registers, value, stri
if isinstance(result, list):
result = [round(v, 6) for v in result]
else:
result = round(result, 6)
result = round(cast(float, result), 6)
assert result == value

@pytest.mark.parametrize(
Expand Down Expand Up @@ -283,7 +284,7 @@ def test_client_mixin_convert_1234(self, datatype, registers, value):
regs = ModbusClientMixin.convert_to_registers(value, datatype)
result = ModbusClientMixin.convert_from_registers(regs, datatype)
if datatype == ModbusClientMixin.DATATYPE.FLOAT32 or datatype == ModbusClientMixin.DATATYPE.FLOAT64:
result = round(result, 6)
result = round(cast(float, result), 6)
assert result == value
assert regs == registers

Expand All @@ -296,15 +297,21 @@ def test_client_mixin_convert_fail(self):
ModbusClientMixin.convert_from_registers([123], ModbusClientMixin.DATATYPE.FLOAT64)

with pytest.raises(TypeError):
ModbusClientMixin.convert_to_registers(bool, ModbusClientMixin.DATATYPE.BITS)
ModbusClientMixin.convert_to_registers(bool, ModbusClientMixin.DATATYPE.BITS) # type: ignore[arg-type]

def test_client_mixin_convert_datatype_fail(self):
"""Test convert fail."""
with pytest.raises(TypeError):
ModbusClientMixin.convert_to_registers(123, ("s", 0))
ModbusClientMixin.convert_to_registers(123, ("s", 0)) # type: ignore[arg-type]

with pytest.raises(TypeError):
ModbusClientMixin.convert_from_registers([123], ("d", 4))
ModbusClientMixin.convert_from_registers([123], ("d", 4)) # type: ignore[arg-type]

def test_client_mixin_execute(self):
"""Test mixin execute."""
a = ModbusClientMixin()
a.execute(False, cast(ModbusPDU, None))



class TestClientBase:
Expand Down Expand Up @@ -618,7 +625,7 @@ def test_client_tls_connect2(self):
def test_tcp_client_register(self):
"""Test tcp client."""

class CustomRequest: # pylint: disable=too-few-public-methods
class CustomRequest(ModbusPDU): # pylint: disable=too-few-public-methods
"""Dummy custom request."""

function_code = 79
Expand All @@ -636,12 +643,12 @@ def test_sync_block(self):
def test_sync_execute(self):
"""Test sync execute."""
client = lib_client.ModbusTcpClient("127.0.0.1")
client.connect = mock.Mock(return_value=False)
client.connect = mock.Mock(return_value=False) # type: ignore[method-assign]
with pytest.raises(ConnectionException):
client.execute(False, None)
client.execute(False, None) # type: ignore[arg-type]
client.transaction = mock.Mock()
client.connect.return_value = True
client.execute(False, None)
client.execute(False, None) # type: ignore[arg-type]

@pytest.mark.parametrize(
("client_class"),
Expand Down
Loading