Skip to content

Commit

Permalink
sunspec#71 - Populate repeating block groups from file
Browse files Browse the repository at this point in the history
Even though the group_class is being passed the index, it is not
being used at the point level, and any update that I tried to use
it at the point level resulted in the output changing, and lots of tests
failing.

Using the index as part of the _init_repeating_group instead, without
passing it to the group_class, provides the expected results.

Note that this follows the same logic as if the count is available (line
530).
  • Loading branch information
CoRfr committed Oct 26, 2022
1 parent 0c221e4 commit f4e1c15
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sunspec2/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def _init_repeating_group(self, gdef=None, model_offset=None, data=None, data_of
# compute count based on model len if present, otherwise allocate when set
model_len = self.model.len
if model_len:
gdata = self._group_data(data=data, name=gdef[mdef.NAME])
gdata = self._group_data(data=data, name=gdef[mdef.NAME], index=0)
g = self.group_class(gdef=gdef, model=self.model, model_offset=model_offset, data=gdata,
data_offset=data_offset, index=1)
group_points_len = g.points_len
Expand All @@ -560,7 +560,8 @@ def _init_repeating_group(self, gdef=None, model_offset=None, data=None, data_of
model_offset += g.len
data_offset += g.len
for i in range(count - 1):
g = self.group_class(gdef=gdef, model=self.model, model_offset=model_offset, data=data,
gdata = self._group_data(data=data, index=(i+1))
g = self.group_class(gdef=gdef, model=self.model, model_offset=model_offset, data=gdata,
data_offset=data_offset, index=i+2)
model_offset += g.len
data_offset += g.len
Expand Down
213 changes: 213 additions & 0 deletions sunspec2/tests/test_data/inverter_123.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"name": null,
"did": "fa0a9f2d-d503-470e-8ce8-ec9c51428829",
"models": [
{
"ID": 1,
"L": 66,
"Mn": "Device Manufacturer",
"Md": "Inverter 123",
"Opt": null,
"Vr": "v0.0.1",
"SN": "9999abcd",
"DA": null,
"Pad": 32768
},
{
"ID": 129,
"L": 210,
"ActCrv": 1,
"ModEna": 0,
"WinTms": null,
"RvrtTms": null,
"RmpTms": null,
"NCrv": 4,
"NPt": 10,
"Tms_SF": -2,
"V_SF": -1,
"Pad": 32768,
"curve": [
{
"ActPt": 4,
"Tms1": 200,
"V1": 880,
"Tms2": 71,
"V2": 650,
"Tms3": 20,
"V3": 450,
"Tms4": 0,
"V4": 300,
"Tms5": 0,
"V5": 0,
"Tms6": 0,
"V6": 0,
"Tms7": 0,
"V7": 0,
"Tms8": 0,
"V8": 0,
"Tms9": 0,
"V9": 0,
"Tms10": 0,
"V10": 0,
"Tms11": null,
"V11": null,
"Tms12": null,
"V12": null,
"Tms13": null,
"V13": null,
"Tms14": null,
"V14": null,
"Tms15": null,
"V15": null,
"Tms16": null,
"V16": null,
"Tms17": null,
"V17": null,
"Tms18": null,
"V18": null,
"Tms19": null,
"V19": null,
"Tms20": null,
"V20": null,
"CrvNam": null,
"ReadOnly": 1
},
{
"ActPt": 0,
"Tms1": 0,
"V1": 0,
"Tms2": 0,
"V2": 0,
"Tms3": 0,
"V3": 0,
"Tms4": 0,
"V4": 0,
"Tms5": 0,
"V5": 0,
"Tms6": 0,
"V6": 0,
"Tms7": 0,
"V7": 0,
"Tms8": 0,
"V8": 0,
"Tms9": 0,
"V9": 0,
"Tms10": 0,
"V10": 0,
"Tms11": null,
"V11": null,
"Tms12": null,
"V12": null,
"Tms13": null,
"V13": null,
"Tms14": null,
"V14": null,
"Tms15": null,
"V15": null,
"Tms16": null,
"V16": null,
"Tms17": null,
"V17": null,
"Tms18": null,
"V18": null,
"Tms19": null,
"V19": null,
"Tms20": null,
"V20": null,
"CrvNam": null,
"ReadOnly": 0
},
{
"ActPt": 0,
"Tms1": 0,
"V1": 0,
"Tms2": 0,
"V2": 0,
"Tms3": 0,
"V3": 0,
"Tms4": 0,
"V4": 0,
"Tms5": 0,
"V5": 0,
"Tms6": 0,
"V6": 0,
"Tms7": 0,
"V7": 0,
"Tms8": 0,
"V8": 0,
"Tms9": 0,
"V9": 0,
"Tms10": 0,
"V10": 0,
"Tms11": null,
"V11": null,
"Tms12": null,
"V12": null,
"Tms13": null,
"V13": null,
"Tms14": null,
"V14": null,
"Tms15": null,
"V15": null,
"Tms16": null,
"V16": null,
"Tms17": null,
"V17": null,
"Tms18": null,
"V18": null,
"Tms19": null,
"V19": null,
"Tms20": null,
"V20": null,
"CrvNam": null,
"ReadOnly": 0
},
{
"ActPt": 0,
"Tms1": 0,
"V1": 0,
"Tms2": 0,
"V2": 0,
"Tms3": 0,
"V3": 0,
"Tms4": 0,
"V4": 0,
"Tms5": 0,
"V5": 0,
"Tms6": 0,
"V6": 0,
"Tms7": 0,
"V7": 0,
"Tms8": 0,
"V8": 0,
"Tms9": 0,
"V9": 0,
"Tms10": 0,
"V10": 0,
"Tms11": null,
"V11": null,
"Tms12": null,
"V12": null,
"Tms13": null,
"V13": null,
"Tms14": null,
"V14": null,
"Tms15": null,
"V15": null,
"Tms16": null,
"V16": null,
"Tms17": null,
"V17": null,
"Tms18": null,
"V18": null,
"Tms19": null,
"V19": null,
"Tms20": null,
"V20": null,
"CrvNam": null,
"ReadOnly": 0
}
]
}
]
}
7 changes: 7 additions & 0 deletions sunspec2/tests/test_file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,13 @@ def test_scan(self):
assert d.common
assert d.DERMeasureAC

def test_repeating_point(self):
d = file_client.FileClientDevice('sunspec2/tests/test_data/inverter_123.json')
d.scan()
assert d.models[129][-1].curve[0].Tms1.value == 200
assert d.models[129][-1].curve[1].Tms1.value == 0
assert d.models[129][-1].curve[2].Tms11.value is None

def test_get_text(self, model_705_data):
d = file_client.FileClientDevice()
m = file_client.FileClientModel(705, data=model_705_data)
Expand Down

0 comments on commit f4e1c15

Please sign in to comment.