@@ -105,9 +105,22 @@ def fake_execute(_self, _no_response_expected, request):
105
105
(ModbusClientMixin .DATATYPE .STRING , "a" , [0x6100 ], None ),
106
106
(ModbusClientMixin .DATATYPE .UINT16 , 27123 , [0x69F3 ], None ),
107
107
(ModbusClientMixin .DATATYPE .INT16 , - 27123 , [0x960D ], None ),
108
+ (ModbusClientMixin .DATATYPE .INT16 , [- 27123 , 27123 ], [0x960D , 0x69F3 ], None ),
108
109
(ModbusClientMixin .DATATYPE .UINT32 , 27123 , [0x0000 , 0x69F3 ], None ),
109
110
(ModbusClientMixin .DATATYPE .UINT32 , 32145678 , [0x01EA , 0x810E ], None ),
111
+ (
112
+ ModbusClientMixin .DATATYPE .UINT32 ,
113
+ [27123 , 32145678 ],
114
+ [0x0000 , 0x69F3 , 0x01EA , 0x810E ],
115
+ None
116
+ ),
110
117
(ModbusClientMixin .DATATYPE .INT32 , - 32145678 , [0xFE15 , 0x7EF2 ], None ),
118
+ (
119
+ ModbusClientMixin .DATATYPE .INT32 ,
120
+ [32145678 , - 32145678 ],
121
+ [0x01EA , 0x810E , 0xFE15 , 0x7EF2 ],
122
+ None
123
+ ),
111
124
(
112
125
ModbusClientMixin .DATATYPE .UINT64 ,
113
126
1234567890123456789 ,
@@ -120,9 +133,21 @@ def fake_execute(_self, _no_response_expected, request):
120
133
[0xEEDD , 0xEF0B , 0x8216 , 0x7EEB ],
121
134
None ,
122
135
),
136
+ (
137
+ ModbusClientMixin .DATATYPE .INT64 ,
138
+ [1234567890123456789 , - 1234567890123456789 ],
139
+ [0x1122 , 0x10F4 , 0x7DE9 , 0x8115 , 0xEEDD , 0xEF0B , 0x8216 , 0x7EEB ],
140
+ None ,
141
+ ),
123
142
(ModbusClientMixin .DATATYPE .FLOAT32 , 27123.5 , [0x46D3 , 0xE700 ], None ),
124
143
(ModbusClientMixin .DATATYPE .FLOAT32 , 3.141592 , [0x4049 , 0x0FD8 ], None ),
125
144
(ModbusClientMixin .DATATYPE .FLOAT32 , - 3.141592 , [0xC049 , 0x0FD8 ], None ),
145
+ (
146
+ ModbusClientMixin .DATATYPE .FLOAT32 ,
147
+ [27123.5 , 3.141592 , - 3.141592 ],
148
+ [0x46D3 , 0xE700 , 0x4049 , 0x0FD8 , 0xC049 , 0x0FD8 ],
149
+ None
150
+ ),
126
151
(ModbusClientMixin .DATATYPE .FLOAT64 , 27123.5 , [0x40DA , 0x7CE0 , 0x0000 , 0x0000 ], None ),
127
152
(
128
153
ModbusClientMixin .DATATYPE .FLOAT64 ,
@@ -136,6 +161,12 @@ def fake_execute(_self, _no_response_expected, request):
136
161
[0xC009 , 0x21FB , 0x5444 , 0x2D11 ],
137
162
None ,
138
163
),
164
+ (
165
+ ModbusClientMixin .DATATYPE .FLOAT64 ,
166
+ [3.14159265358979 , - 3.14159265358979 ],
167
+ [0x4009 , 0x21FB , 0x5444 , 0x2D11 , 0xC009 , 0x21FB , 0x5444 , 0x2D11 ],
168
+ None ,
169
+ ),
139
170
(
140
171
ModbusClientMixin .DATATYPE .BITS ,
141
172
[True ],
@@ -195,7 +226,16 @@ def fake_execute(_self, _no_response_expected, request):
195
226
def test_client_mixin_convert (self , datatype , word_order , registers , value , string_encoding ):
196
227
"""Test converter methods."""
197
228
if word_order == "little" :
198
- registers = list (reversed (registers ))
229
+ if not (datatype_len := datatype .value [1 ]):
230
+ registers = list (reversed (registers ))
231
+ else :
232
+ reversed_regs : list [int ] = []
233
+ for x in range (0 , len (registers ), datatype_len ):
234
+ single_value_regs = registers [x : x + datatype_len ]
235
+ single_value_regs .reverse ()
236
+ reversed_regs = reversed_regs + single_value_regs
237
+ registers = reversed_regs
238
+
199
239
200
240
kwargs = {** ({"word_order" : word_order } if word_order else {}),
201
241
** ({"string_encoding" : string_encoding } if string_encoding else {})}
@@ -207,7 +247,10 @@ def test_client_mixin_convert(self, datatype, word_order, registers, value, stri
207
247
if (missing := len (value ) % 16 ):
208
248
value = value + [False ] * (16 - missing )
209
249
if datatype == ModbusClientMixin .DATATYPE .FLOAT32 :
210
- result = round (result , 6 )
250
+ if isinstance (result , list ):
251
+ result = [round (v , 6 ) for v in result ]
252
+ else :
253
+ result = round (result , 6 )
211
254
assert result == value
212
255
213
256
@pytest .mark .parametrize (
0 commit comments