-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
The type hints and tests for write_registers() in ModbusClientMixin indicate this method only accepts lists of values.
pymodbus/pymodbus/client/mixin.py
Lines 422 to 442 in d2c7c77
| def write_registers( | |
| self, | |
| address: int, | |
| values: List[Union[int, float, str]], | |
| slave: int = 0, | |
| **kwargs: Any | |
| ) -> pdu_req_write.WriteMultipleRegistersResponse: | |
| """Write registers (code 0x10). | |
| :param address: Start address to write to | |
| :param values: List of booleans to write | |
| :param slave: (optional) Modbus slave unit ID | |
| :param kwargs: (optional) Experimental parameters. | |
| :returns: A deferred response handle | |
| :raises ModbusException: | |
| """ | |
| return self.execute( | |
| pdu_req_write.WriteMultipleRegistersRequest( | |
| address, values, slave, **kwargs | |
| ) | |
| ) |
However, for at least a decade (66bd765) the underlying WriteMultipleRegistersRequest will actually accept single values and convert to a list.
pymodbus/pymodbus/register_write_message.py
Lines 149 to 160 in d2c7c77
| def __init__(self, address=None, values=None, unit=None, **kwargs): | |
| """Initialize a new instance. | |
| :param address: The address to start writing to | |
| :param values: The values to write | |
| """ | |
| super().__init__(unit=unit, **kwargs) | |
| self.address = address | |
| if values is None: | |
| values = [] | |
| elif not hasattr(values, "__iter__"): | |
| values = [values] |
(1) Should this functionality be retained for write_registers()?
If no, we're technically breaking backwards compatibility although it's unclear if anyone uses it. pymodbus itself does not appear to.
If yes, we should
- update docstrings
- Type hints become (
Union[int, float, str, List[Union[int, float, str]]]Union[List[int], int) - Add tests for this functionality
(2) Same for readwrite_registers()
(3) Same for write_multiple_coils()write_coils(values: Union[List[bool], bool])`