From 0ce39ef2748cfe464bec2a2b9ed1bacb37997f83 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Sun, 19 Jan 2025 16:32:01 +0000 Subject: [PATCH 1/9] Add Peak Shaving work mode for H3 Inverters & H1 (Gen 2) --- .../entities/entity_descriptions.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/custom_components/foxess_modbus/entities/entity_descriptions.py b/custom_components/foxess_modbus/entities/entity_descriptions.py index 09f6e29..2f8406b 100644 --- a/custom_components/foxess_modbus/entities/entity_descriptions.py +++ b/custom_components/foxess_modbus/entities/entity_descriptions.py @@ -2095,7 +2095,7 @@ def _configuration_entities() -> Iterable[EntityFactory]: key="work_mode", address=[ ModbusAddressSpec(input=41000, models=Inv.H1_G1 | Inv.KH_PRE119), - ModbusAddressSpec(holding=41000, models=Inv.H1_G1 | Inv.H1_G2 | Inv.KH_119 | Inv.H3_SET), + ModbusAddressSpec(holding=41000, models=Inv.H1_G1 | Inv.KH_119), ], name="Work Mode", options_map={0: "Self Use", 1: "Feed-in First", 2: "Back-up"}, @@ -2115,6 +2115,20 @@ def _configuration_entities() -> Iterable[EntityFactory]: }, ) + yield ModbusWorkModeSelectDescription( + key="work_mode", + address=[ + ModbusAddressSpec(holding=41000, models=Inv.H1_G2 | Inv.H3_SET), + ], + name="Work Mode", + options_map={ + 0: "Self Use", + 1: "Feed-in First", + 2: "Back-up", + 4: "Peak Shaving" + }, + ) + # Sensors are a bit nicer to look at: keep for consistency with other numbers yield ModbusSensorDescription( key="max_charge_current", From bc0f020b8ae6188377ff39737ae96bfce54d5b27 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Sun, 19 Jan 2025 16:56:17 +0000 Subject: [PATCH 2/9] Update test_entity_descriptions_for_model[Inv.AIO_H3].json --- .../test_entity_descriptions_for_model[Inv.AIO_H3].json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.AIO_H3].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.AIO_H3].json index e5d14d6..f1fcc17 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.AIO_H3].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.AIO_H3].json @@ -1035,7 +1035,8 @@ "values": { "0": "Self Use", "1": "Feed-in First", - "2": "Back-up" + "2": "Back-up", + "4": "Peak Shaving" } } ] From c402b68f39708fcd8e4bff6c4a22d8180f106f9c Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Sun, 19 Jan 2025 16:56:44 +0000 Subject: [PATCH 3/9] Update test_entity_descriptions_for_model[Inv.H1_G2].json --- .../test_entity_descriptions_for_model[Inv.H1_G2].json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json index 3ba3da0..b5ed424 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json @@ -879,8 +879,7 @@ "type": "select", "values": { "0": "Self Use", - "1": "Feed-in First", - "2": "Back-up" + "1": "Feed-in First" } } ] From fad2a52e22356dbe54b4f16e970050b09d6ad89b Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Sun, 19 Jan 2025 16:57:14 +0000 Subject: [PATCH 4/9] Update test_entity_descriptions_for_model[Inv.KUARA_H3].json --- .../test_entity_descriptions_for_model[Inv.KUARA_H3].json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.KUARA_H3].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.KUARA_H3].json index e5d14d6..f1fcc17 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.KUARA_H3].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.KUARA_H3].json @@ -1035,7 +1035,8 @@ "values": { "0": "Self Use", "1": "Feed-in First", - "2": "Back-up" + "2": "Back-up", + "4": "Peak Shaving" } } ] From acf1b759763530b913ee5c37041f3525bb830b82 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Sun, 19 Jan 2025 17:11:57 +0000 Subject: [PATCH 5/9] Update entity_descriptions.py --- .../foxess_modbus/entities/entity_descriptions.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/custom_components/foxess_modbus/entities/entity_descriptions.py b/custom_components/foxess_modbus/entities/entity_descriptions.py index 2f8406b..6208b99 100644 --- a/custom_components/foxess_modbus/entities/entity_descriptions.py +++ b/custom_components/foxess_modbus/entities/entity_descriptions.py @@ -2121,12 +2121,7 @@ def _configuration_entities() -> Iterable[EntityFactory]: ModbusAddressSpec(holding=41000, models=Inv.H1_G2 | Inv.H3_SET), ], name="Work Mode", - options_map={ - 0: "Self Use", - 1: "Feed-in First", - 2: "Back-up", - 4: "Peak Shaving" - }, + options_map={0: "Self Use", 1: "Feed-in First", 2: "Back-up", 4: "Peak Shaving"}, ) # Sensors are a bit nicer to look at: keep for consistency with other numbers From 77b1fc6d1955ae1034b6627c45076c00f02bacde Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Mon, 20 Jan 2025 10:07:55 +0000 Subject: [PATCH 6/9] Update test_entity_descriptions.py to fix runtime error from dict changing keys during iteration added copy() to avoid the iteration changing the desired dict The snapshot tests now run correctly --- tests/test_entity_descriptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_entity_descriptions.py b/tests/test_entity_descriptions.py index 73708d8..0ab4152 100644 --- a/tests/test_entity_descriptions.py +++ b/tests/test_entity_descriptions.py @@ -54,7 +54,7 @@ def test_entity_descriptions_for_model(model: Inv, snapshot_json: SnapshotAssert # syrupy doesn't like keys which aren't strings def _process(d: Any) -> None: if isinstance(d, dict): - for k, v in d.items(): + for k, v in d.copy().items(): if not isinstance(k, str): del d[k] d[str(k)] = v From 1a3881a2b96e475964116a687387d793caadb8b9 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Mon, 20 Jan 2025 10:09:51 +0000 Subject: [PATCH 7/9] Update test_entity_descriptions_for_model[Inv.H1_G2].json correctly updated snapshot --- .../test_entity_descriptions_for_model[Inv.H1_G2].json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json index b5ed424..32de430 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H1_G2].json @@ -879,7 +879,9 @@ "type": "select", "values": { "0": "Self Use", - "1": "Feed-in First" + "1": "Feed-in First", + "2": "Back-up", + "4": "Peak Shaving" } } ] From ab8b758f720b510667d1101c64bde7db7a738483 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Mon, 20 Jan 2025 10:10:29 +0000 Subject: [PATCH 8/9] Update test_entity_descriptions_for_model[Inv.H3_PRO].json --- .../test_entity_descriptions_for_model[Inv.H3_PRO].json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 f853170..7a862ca 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 @@ -1735,7 +1735,9 @@ "type": "select", "values": { "1": "Self Use", - "2": "Feed-in First" + "2": "Feed-in First", + "3": "Back-up", + "4": "Peak Shaving" } } ] From 1edf5eb6b2b459e02e7c0efda62fd67b1a065c34 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Mon, 20 Jan 2025 10:10:55 +0000 Subject: [PATCH 9/9] Update test_entity_descriptions_for_model[Inv.H3].json correctly updated snapshots --- .../test_entity_descriptions_for_model[Inv.H3].json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3].json b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3].json index e5d14d6..f1fcc17 100644 --- a/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3].json +++ b/tests/__snapshots__/test_entity_descriptions/test_entity_descriptions_for_model[Inv.H3].json @@ -1035,7 +1035,8 @@ "values": { "0": "Self Use", "1": "Feed-in First", - "2": "Back-up" + "2": "Back-up", + "4": "Peak Shaving" } } ]