@@ -272,7 +272,7 @@ def async_create_task(coroutine, name=None):
272
272
"homeassistant.helpers.restore_state.RestoreStateData.async_setup_dump" ,
273
273
return_value = None ,
274
274
), patch (
275
- "homeassistant.helpers.restore_state.start.async_at_start"
275
+ "homeassistant.helpers.restore_state.start.async_at_start" ,
276
276
):
277
277
await asyncio .gather (
278
278
ar .async_load (hass ),
@@ -302,6 +302,7 @@ def async_mock_service(
302
302
schema : vol .Schema | None = None ,
303
303
response : ServiceResponse = None ,
304
304
supports_response : SupportsResponse | None = None ,
305
+ raise_exception : Exception | None = None ,
305
306
) -> list [ServiceCall ]:
306
307
"""Set up a fake service & return a calls log list to this service."""
307
308
calls = []
@@ -310,10 +311,15 @@ def async_mock_service(
310
311
def mock_service_log (call ): # pylint: disable=unnecessary-lambda
311
312
"""Mock service call."""
312
313
calls .append (call )
314
+ if raise_exception is not None :
315
+ raise raise_exception
313
316
return response
314
317
315
- if supports_response is None and response is not None :
316
- supports_response = SupportsResponse .OPTIONAL
318
+ if supports_response is None :
319
+ if response is not None :
320
+ supports_response = SupportsResponse .OPTIONAL
321
+ else :
322
+ supports_response = SupportsResponse .NONE
317
323
318
324
hass .services .async_register (
319
325
domain ,
@@ -987,15 +993,18 @@ def assert_setup_component(count, domain=None):
987
993
async def mock_psc (hass , config_input , integration ):
988
994
"""Mock the prepare_setup_component to capture config."""
989
995
domain_input = integration .domain
990
- res = await async_process_component_config (hass , config_input , integration )
996
+ integration_config_info = await async_process_component_config (
997
+ hass , config_input , integration
998
+ )
999
+ res = integration_config_info .config
991
1000
config [domain_input ] = None if res is None else res .get (domain_input )
992
1001
_LOGGER .debug (
993
1002
"Configuration for %s, Validated: %s, Original %s" ,
994
1003
domain_input ,
995
1004
config [domain_input ],
996
1005
config_input .get (domain_input ),
997
1006
)
998
- return res
1007
+ return integration_config_info
999
1008
1000
1009
assert isinstance (config , dict )
1001
1010
with patch ("homeassistant.config.async_process_component_config" , mock_psc ):
@@ -1304,11 +1313,12 @@ async def get_system_health_info(hass: HomeAssistant, domain: str) -> dict[str,
1304
1313
@contextmanager
1305
1314
def mock_config_flow (domain : str , config_flow : type [ConfigFlow ]) -> None :
1306
1315
"""Mock a config flow handler."""
1307
- assert domain not in config_entries .HANDLERS
1316
+ handler = config_entries .HANDLERS . get ( domain )
1308
1317
config_entries .HANDLERS [domain ] = config_flow
1309
1318
_LOGGER .info ("Adding mock config flow: %s" , domain )
1310
1319
yield
1311
- config_entries .HANDLERS .pop (domain )
1320
+ if handler :
1321
+ config_entries .HANDLERS [domain ] = handler
1312
1322
1313
1323
1314
1324
def mock_integration (
@@ -1342,18 +1352,6 @@ def mock_import_platform(platform_name: str) -> NoReturn:
1342
1352
return integration
1343
1353
1344
1354
1345
- def mock_entity_platform (
1346
- hass : HomeAssistant , platform_path : str , module : MockPlatform | None
1347
- ) -> None :
1348
- """Mock a entity platform.
1349
-
1350
- platform_path is in form light.hue. Will create platform
1351
- hue.light.
1352
- """
1353
- domain , platform_name = platform_path .split ("." )
1354
- mock_platform (hass , f"{ platform_name } .{ domain } " , module )
1355
-
1356
-
1357
1355
def mock_platform (
1358
1356
hass : HomeAssistant , platform_path : str , module : Mock | MockPlatform | None = None
1359
1357
) -> None :
0 commit comments