From f4e1c15d4b180f4af4ff891f75cd1980942e5fbb Mon Sep 17 00:00:00 2001 From: Bertrand Roussel Date: Tue, 25 Oct 2022 21:11:13 -0700 Subject: [PATCH] #71 - Populate repeating block groups from file 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). --- sunspec2/device.py | 5 +- sunspec2/tests/test_data/inverter_123.json | 213 +++++++++++++++++++++ sunspec2/tests/test_file_client.py | 7 + 3 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 sunspec2/tests/test_data/inverter_123.json diff --git a/sunspec2/device.py b/sunspec2/device.py index 62fd438..86c903c 100644 --- a/sunspec2/device.py +++ b/sunspec2/device.py @@ -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 @@ -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 diff --git a/sunspec2/tests/test_data/inverter_123.json b/sunspec2/tests/test_data/inverter_123.json new file mode 100644 index 0000000..e262fcc --- /dev/null +++ b/sunspec2/tests/test_data/inverter_123.json @@ -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 + } + ] + } + ] +} diff --git a/sunspec2/tests/test_file_client.py b/sunspec2/tests/test_file_client.py index 65f972c..943df17 100644 --- a/sunspec2/tests/test_file_client.py +++ b/sunspec2/tests/test_file_client.py @@ -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)