From e0d12e073b494bc56fbc789223b4a4daee907164 Mon Sep 17 00:00:00 2001 From: Antony Male Date: Mon, 3 Feb 2025 09:01:35 +0000 Subject: [PATCH 1/4] Update KH invalid registers The KH_PRE133 reads register 31054, but this is in one of the invalid ranges. Extend the range upwards a bit to accommodate: this shouldn't affect any other inverter versions, as the range stops us bridging up to 32000 anyway, so we won't read registers 31045-31054 unless we need to. See: #762 --- custom_components/foxess_modbus/inverter_profiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/foxess_modbus/inverter_profiles.py b/custom_components/foxess_modbus/inverter_profiles.py index ae9e0558..da597516 100644 --- a/custom_components/foxess_modbus/inverter_profiles.py +++ b/custom_components/foxess_modbus/inverter_profiles.py @@ -84,7 +84,7 @@ def __init__( ) # See https://github.com/nathanmarlor/foxess_modbus/pull/512 KH_REGISTERS = SpecialRegisterConfig( - invalid_register_ranges=[(41001, 41006), (41012, 41012), (41019, 43999), (31045, 31999)], + invalid_register_ranges=[(41001, 41006), (41012, 41012), (41019, 43999), (31055, 31999)], individual_read_register_ranges=[(41000, 41999)], ) # See https://github.com/nathanmarlor/foxess_modbus/discussions/553 From 1c83c92166b478bd5a958596169e090aa639cc3e Mon Sep 17 00:00:00 2001 From: Antony Male Date: Mon, 3 Feb 2025 09:01:43 +0000 Subject: [PATCH 2/4] Fix spelling of '_LOGGER.exception' See: #762 --- custom_components/foxess_modbus/modbus_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/foxess_modbus/modbus_controller.py b/custom_components/foxess_modbus/modbus_controller.py index a984627c..06c6e945 100644 --- a/custom_components/foxess_modbus/modbus_controller.py +++ b/custom_components/foxess_modbus/modbus_controller.py @@ -538,7 +538,7 @@ async def autodetect(client: ModbusClient, slave: int, adapter_config: dict[str, _LOGGER.error("Did not recognise inverter model '%s' (%s)", full_model, register_values) raise UnsupportedInverterError(full_model) except Exception as ex: - _LOGGER.exceptino("Autodetect: failed to connect to (%s)", client) + _LOGGER.exception("Autodetect: failed to connect to (%s)", client) raise AutoconnectFailedError(spy_handler.records) from ex finally: pymodbus_logger.removeHandler(spy_handler) From 3c7c25e874f9160ca96a4a56b0f7982746e65f5c Mon Sep 17 00:00:00 2001 From: Antony Male Date: Mon, 3 Feb 2025 09:02:00 +0000 Subject: [PATCH 3/4] Fix H3_PRO slave version address --- .../foxess_modbus/entities/entity_descriptions.py | 5 ++--- .../test_entity_descriptions_for_model[Inv.H3_PRO].json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/custom_components/foxess_modbus/entities/entity_descriptions.py b/custom_components/foxess_modbus/entities/entity_descriptions.py index ae200293..6e109e80 100644 --- a/custom_components/foxess_modbus/entities/entity_descriptions.py +++ b/custom_components/foxess_modbus/entities/entity_descriptions.py @@ -70,8 +70,7 @@ def _master_version(address: list[ModbusAddressSpec], is_hex: bool) -> ModbusVer yield _master_version( address=[ ModbusAddressSpec(holding=30016, models=Inv.KH_PRE133), - ModbusAddressSpec(holding=36001, models=Inv.KH_133), - ModbusAddressSpec(holding=36001, models=Inv.H1_G2_SET), + ModbusAddressSpec(holding=36001, models=Inv.H1_G2_SET | Inv.KH_133), ], is_hex=True, ) @@ -89,7 +88,7 @@ def _slave_version(address: list[ModbusAddressSpec], is_hex: bool) -> ModbusVers address=[ ModbusAddressSpec(input=10017, models=Inv.H1_G1 | Inv.KH_PRE119), ModbusAddressSpec(holding=30017, models=Inv.H1_G1 | Inv.H1_LAN | Inv.H3_SET), - ModbusAddressSpec(holding=36001, models=Inv.H3_PRO), + ModbusAddressSpec(holding=36002, models=Inv.H3_PRO), ], is_hex=False, ) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3_PRO].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3_PRO].json index f91a9653..8baec652 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3_PRO].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3_PRO].json @@ -1664,7 +1664,7 @@ { "addresses": { "holding": [ - 36001 + 36002 ] }, "is_hex": false, From c15ca1af91b09887c052a0d4c4535d7bfa35d8fd Mon Sep 17 00:00:00 2001 From: Antony Male Date: Mon, 3 Feb 2025 09:02:21 +0000 Subject: [PATCH 4/4] Set the default formatter in VSCode to ruff --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 59db7c07..654bd74a 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,7 +25,8 @@ "[python]": { "editor.codeActionsOnSave": { "source.fixAll": "explicit" - } + }, + "editor.defaultFormatter": "charliermarsh.ruff" }, "python.analysis.extraPaths": [ "./custom_components/foxess_modbus/vendor/pymodbus/pymodbus-3.6.9"