Skip to content

Commit 90561de

Browse files
johanzanderclaude
andauthored
Refactor Growatt Server integration tests (home-assistant#156413)
Co-authored-by: Claude <[email protected]>
1 parent aedd48c commit 90561de

File tree

10 files changed

+288
-4538
lines changed

10 files changed

+288
-4538
lines changed

tests/components/growatt_server/conftest.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def mock_growatt_v1_api():
3737
Methods mocked for switch and number operations:
3838
- min_write_parameter: Called by switch/number entities to change settings
3939
"""
40-
with patch("growattServer.OpenApiV1", autospec=True) as mock_v1_api_class:
40+
with patch(
41+
"homeassistant.components.growatt_server.config_flow.growattServer.OpenApiV1",
42+
autospec=True,
43+
) as mock_v1_api_class:
4144
mock_v1_api = mock_v1_api_class.return_value
4245

4346
# Called during setup to discover devices
@@ -119,7 +122,10 @@ def mock_growatt_classic_api():
119122
Methods mocked for device-specific tests:
120123
- tlx_detail: Provides TLX device data (kept for potential future tests)
121124
"""
122-
with patch("growattServer.GrowattApi", autospec=True) as mock_classic_api_class:
125+
with patch(
126+
"homeassistant.components.growatt_server.config_flow.growattServer.GrowattApi",
127+
autospec=True,
128+
) as mock_classic_api_class:
123129
# Use the autospec'd mock instance instead of creating a new Mock()
124130
mock_classic_api = mock_classic_api_class.return_value
125131

@@ -167,10 +173,10 @@ def mock_config_entry() -> MockConfigEntry:
167173
CONF_TOKEN: "test_token_123",
168174
CONF_URL: DEFAULT_URL,
169175
"user_id": "12345",
170-
CONF_PLANT_ID: "plant_123",
176+
CONF_PLANT_ID: "123456",
171177
"name": "Test Plant",
172178
},
173-
unique_id="plant_123",
179+
unique_id="123456",
174180
)
175181

176182

@@ -188,10 +194,10 @@ def mock_config_entry_classic() -> MockConfigEntry:
188194
CONF_USERNAME: "test_user",
189195
CONF_PASSWORD: "test_password",
190196
CONF_URL: DEFAULT_URL,
191-
CONF_PLANT_ID: "12345",
197+
CONF_PLANT_ID: "123456",
192198
"name": "Test Plant",
193199
},
194-
unique_id="12345",
200+
unique_id="123456",
195201
)
196202

197203

@@ -215,3 +221,13 @@ async def init_integration(
215221
await hass.config_entries.async_setup(mock_config_entry.entry_id)
216222
await hass.async_block_till_done()
217223
return mock_config_entry
224+
225+
226+
@pytest.fixture
227+
def mock_setup_entry():
228+
"""Mock async_setup_entry to prevent actual setup during config flow tests."""
229+
with patch(
230+
"homeassistant.components.growatt_server.async_setup_entry",
231+
return_value=True,
232+
) as mock:
233+
yield mock

tests/components/growatt_server/snapshots/test_init.ambr

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,65 +61,3 @@
6161
'via_device_id': None,
6262
})
6363
# ---
64-
# name: test_multiple_devices_discovered[device_min123456]
65-
DeviceRegistryEntrySnapshot({
66-
'area_id': None,
67-
'config_entries': <ANY>,
68-
'config_entries_subentries': <ANY>,
69-
'configuration_url': None,
70-
'connections': set({
71-
}),
72-
'disabled_by': None,
73-
'entry_type': None,
74-
'hw_version': None,
75-
'id': <ANY>,
76-
'identifiers': set({
77-
tuple(
78-
'growatt_server',
79-
'MIN123456',
80-
),
81-
}),
82-
'labels': set({
83-
}),
84-
'manufacturer': 'Growatt',
85-
'model': None,
86-
'model_id': None,
87-
'name': 'MIN123456',
88-
'name_by_user': None,
89-
'primary_config_entry': <ANY>,
90-
'serial_number': None,
91-
'sw_version': None,
92-
'via_device_id': None,
93-
})
94-
# ---
95-
# name: test_multiple_devices_discovered[device_min789012]
96-
DeviceRegistryEntrySnapshot({
97-
'area_id': None,
98-
'config_entries': <ANY>,
99-
'config_entries_subentries': <ANY>,
100-
'configuration_url': None,
101-
'connections': set({
102-
}),
103-
'disabled_by': None,
104-
'entry_type': None,
105-
'hw_version': None,
106-
'id': <ANY>,
107-
'identifiers': set({
108-
tuple(
109-
'growatt_server',
110-
'MIN789012',
111-
),
112-
}),
113-
'labels': set({
114-
}),
115-
'manufacturer': 'Growatt',
116-
'model': None,
117-
'model_id': None,
118-
'name': 'MIN789012',
119-
'name_by_user': None,
120-
'primary_config_entry': <ANY>,
121-
'serial_number': None,
122-
'sw_version': None,
123-
'via_device_id': None,
124-
})
125-
# ---

tests/components/growatt_server/snapshots/test_number.ambr

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
# serializer version: 1
2-
# name: test_number_device_registry
3-
DeviceRegistryEntrySnapshot({
4-
'area_id': None,
5-
'config_entries': <ANY>,
6-
'config_entries_subentries': <ANY>,
7-
'configuration_url': None,
8-
'connections': set({
9-
}),
10-
'disabled_by': None,
11-
'entry_type': None,
12-
'hw_version': None,
13-
'id': <ANY>,
14-
'identifiers': set({
15-
tuple(
16-
'growatt_server',
17-
'MIN123456',
18-
),
19-
}),
20-
'labels': set({
21-
}),
22-
'manufacturer': 'Growatt',
23-
'model': None,
24-
'model_id': None,
25-
'name': 'MIN123456',
26-
'name_by_user': None,
27-
'primary_config_entry': <ANY>,
28-
'serial_number': None,
29-
'sw_version': None,
30-
'via_device_id': None,
31-
})
32-
# ---
332
# name: test_number_entities[number.min123456_battery_charge_power_limit-entry]
343
EntityRegistryEntrySnapshot({
354
'aliases': set({

0 commit comments

Comments
 (0)