diff --git a/dbus_service.py b/dbus_service.py index d39f8c1..05cbfdb 100644 --- a/dbus_service.py +++ b/dbus_service.py @@ -409,13 +409,15 @@ def check_and_enrich_ahoy_data(self, meter_data): raise ValueError("Response from OpenDTU does not contain ch0_fld_names data") # not needed: meter_data["record"] = self.fetch_ahoy_record_data() + # add the field "inverter" to meter_data: + # This will contain an array of the "iv" data from all inverters. meter_data["inverter"] = [] for inverter_number in range(len(meter_data["iv"])): if is_true(meter_data["iv"][inverter_number]): iv_data = self.fetch_ahoy_iv_data(inverter_number) while len(meter_data["inverter"]) < inverter_number: - # there was a gap - meter_data.append({}) + # there was a gap in the sequence of inverter numbers -> fill in a dummy value + meter_data["inverter"].append({}) meter_data["inverter"].append(iv_data) def check_opendtu_data(self, meter_data): diff --git a/docs/ahoy_0.5.93_inverter-id-1.json b/docs/ahoy_0.5.93_inverter-id-1.json new file mode 100644 index 0000000..084e221 --- /dev/null +++ b/docs/ahoy_0.5.93_inverter-id-1.json @@ -0,0 +1,70 @@ +{ + "id": 0, + "enabled": true, + "name": "MC1", + "serial": "116199999999", + "version": "10018", + "power_limit_read": 65535, + "ts_last_success": 1680176747, + "ch": [ + [ + 229.5, + 0.98, + 223.7, + 50, + 0.997, + 34.2, + 422.603, + 2223, + 234.3, + 95.476, + 18.7 + ], + [ + 33.3, + 1.75, + 58.1, + 547, + 103.553, + 15.493 + ], + [ + 33.3, + 1.77, + 59, + 561, + 106.497, + 15.733 + ], + [ + 33.2, + 1.76, + 58.5, + 558, + 106.357, + 15.6 + ], + [ + 33.2, + 1.77, + 58.7, + 557, + 106.196, + 15.653 + ] + ], + "ch_name": [ + "AC", + "11", + "12", + "13", + "14" + ], + "ch_max_pwr": [ + null, + 375, + 375, + 375, + 375 + ] +} diff --git a/docs/ahoy_0.7.36_live_gap_in_inverter_sequence.json b/docs/ahoy_0.7.36_live_gap_in_inverter_sequence.json new file mode 100644 index 0000000..f1d7412 --- /dev/null +++ b/docs/ahoy_0.7.36_live_gap_in_inverter_sequence.json @@ -0,0 +1,66 @@ +{ + "generic": { + "wifi_rssi": -92, + "ts_uptime": 2777, + "ts_now": 1694698541, + "version": "0.7.36", + "build": "ba218ed", + "menu_prot": false, + "menu_mask": 61, + "menu_protEn": false, + "esp_type": "ESP8266" + }, + "refresh": 30, + "ch0_fld_units": [ + "V", + "A", + "W", + "Hz", + "", + "°C", + "kWh", + "Wh", + "W", + "%", + "var", + "W" + ], + "ch0_fld_names": [ + "U_AC", + "I_AC", + "P_AC", + "F_AC", + "PF_AC", + "Temp", + "YieldTotal", + "YieldDay", + "P_DC", + "Efficiency", + "Q_AC", + "MaxPower" + ], + "fld_units": [ + "V", + "A", + "W", + "Wh", + "kWh", + "%", + "W" + ], + "fld_names": [ + "U_DC", + "I_DC", + "P_DC", + "YieldDay", + "YieldTotal", + "Irradiation", + "MaxPower" + ], + "iv": [ + false, + true, + false, + false + ] +} \ No newline at end of file diff --git a/test_helpers.py b/test_helpers.py index 2b3d984..7e9789e 100644 --- a/test_helpers.py +++ b/test_helpers.py @@ -24,13 +24,16 @@ def get_ahoy_meterdata(filename): ''' Load the meter data from the json file. ''' with open(filename, encoding="utf-8") as file_json: json_meter_data = json.load(file_json) + + # add the field "inverter" to meter_data: + # This will contain an array of the "iv" data from all inverters. json_meter_data["inverter"] = [] for inverter_number in range(len(json_meter_data["iv"])): if is_true(json_meter_data["iv"][inverter_number]): iv_data = fetch_ahoy_iv_data(inverter_number) while len(json_meter_data["inverter"]) < inverter_number: - # there was a gap - json_meter_data.append({}) + # there was a gap in the sequence of inverter numbers -> fill in a dummy value + json_meter_data["inverter"].append({}) json_meter_data["inverter"].append(iv_data) return json_meter_data @@ -129,6 +132,12 @@ def test_get_ahoy_field_by_name(self): self.assertEqual(get_ahoy_field_by_name(meter_data_ahoy, 0, "I_DC", False), 1.75) self.assertEqual(get_ahoy_field_by_name(meter_data_ahoy, 0, "P_DC", False), 58.1) + def test_get_ahoy_gap_in_inverter_sequence(self): + ''' Test the special case when there is a gap in the sequence of inverters IDs.''' + meter_data_ahoy_bad_sequence = get_ahoy_meterdata( + filename='./docs/ahoy_0.7.36_live_gap_in_inverter_sequence.json') + self.assertEqual(get_ahoy_field_by_name(meter_data_ahoy_bad_sequence, 1, "P_AC"), 223.7) + def test_is_true(self): ''' Test the is_true() function. ''' self.assertEqual(is_true("1"), True)