Commit 8f2c6aa
datastore: sparse stores shouldn't need an initial list
Currently, to create a sparse data store, you are required to provide an
initial list/dict. The first entry is then used as a "default" for the
reset() call, which seems rather at odds with the "sparse" nature.
Instead, use a supplied intial value if provided, and use that to
properly reset the store to _that_ value. Similarly don't require an
initial list at all, allowing addresses/registers to be filled in via
follow up calls to .setValues()
Example old code: (We want to register 20 addresses at 0x2000}
# must provide at least one initial value!
hr = ModbusSparseDataBlock({0x2000: 0x55aa})
# actually register what we want using flexible lists.
hr.setValues(0x2000, [0]*20)
Example new code:
hr = ModbusSparseDataBlock()
hr.setValues(0x2000, [0]*20)
Example old code using reset:
hr = ModbusSparseDataBlock({
0x2000: 0x55,
0x3000: 0x66
})
hr.reset()
At this point, the store contained two registers, 0x2000 and 0x2001,
both containing the value 0x55. This hardly seems to have been the
intention of .reset() on a Sparse store, but is obvious for the
sequential store.
Fixes: #566
Signed-off-by: Karl Palsson <[email protected]>1 parent 2ada5c1 commit 8f2c6aa
1 file changed
+10
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
203 | 201 | | |
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
216 | 209 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
220 | 213 | | |
221 | 214 | | |
222 | 215 | | |
| |||
0 commit comments