@@ -49,25 +49,13 @@ def __init__(self,
4949 self ._read_batching : int = DEFAULT_READ_BATCHING
5050 self ._write_batching : int = DEFAULT_WRITE_BATCHING
5151 self ._word_order : WordOrder = word_order
52- if read_batching is not None :
53- if read_batching < MIN_BATCHING :
54- logging .warning ("Bad value for read_batching: {}. Enforcing minimum value of {}" .format (read_batching , MIN_BATCHING ))
55- self ._read_batching = MIN_BATCHING
56- elif read_batching > MAX_BATCHING :
57- logging .warning ("Bad value for read_batching: {}. Enforcing maximum value of {}" .format (read_batching , MAX_BATCHING ))
58- self ._read_batching = MAX_BATCHING
59- else :
60- self ._read_batching = read_batching
61- if write_batching is not None :
62- if write_batching < MIN_BATCHING :
63- logging .warning ("Bad value for write_batching: {}. Enforcing minimum value of {}" .format (write_batching , MIN_BATCHING ))
64- self ._write_batching = MIN_BATCHING
65- elif write_batching > MAX_BATCHING :
66- logging .warning ("Bad value for write_batching: {}. Enforcing maximum value of {}" .format (write_batching , MAX_BATCHING ))
67- self ._write_batching = MAX_BATCHING
68- else :
69- self ._write_batching = write_batching
70- if self ._write_mode == WriteMode .Single :
52+ if read_batching is not None and not (MIN_BATCHING <= read_batching <= MAX_BATCHING ):
53+ logging .warning (f"Bad value for read_batching: { read_batching } . Enforcing limits of { MIN_BATCHING } to { MAX_BATCHING } ." )
54+ self ._read_batching = max (MIN_BATCHING , min (MAX_BATCHING , read_batching ))
55+ if write_batching is not None and not (MIN_BATCHING <= write_batching <= MAX_BATCHING ):
56+ logging .warning (f"Bad value for write_batching: { write_batching } . Enforcing limits of { MIN_BATCHING } to { MAX_BATCHING } ." )
57+ self ._write_batching = max (MIN_BATCHING , min (MAX_BATCHING , write_batching ))
58+ if self ._write_mode == WriteMode .Single and self ._write_batching != 1 :
7159 logging .warning ("Overriding write batching to 1 due to single write mode." )
7260 self ._write_batching = 1
7361 self ._tables : dict [str , ModbusTable ] = {
0 commit comments