"""Integration test for loop disable/enable functionality.""" from __future__ import annotations import logging from pathlib import Path import pytest from .types import APIClientConnectedFactory, RunCompiledFunction _LOGGER = logging.getLogger(__name__) @pytest.mark.asyncio async def test_loop_disable_enable( yaml_config: str, run_compiled: RunCompiledFunction, api_client_connected: APIClientConnectedFactory, ) -> None: """Test that components can disable and enable their loop() method.""" # Get the absolute path to the external components directory external_components_path = str( Path(__file__).parent / "fixtures" / "external_components" ) # Replace the placeholder in the YAML config with the actual path yaml_config = yaml_config.replace( "EXTERNAL_COMPONENT_PATH", external_components_path ) # Write, compile and run the ESPHome device, then connect to API async with run_compiled(yaml_config), api_client_connected() as client: # Verify we can connect and get device info device_info = await client.device_info() assert device_info is not None assert device_info.name == "loop-test" # The fact that this compiles and runs proves that: # 1. The partitioned vector implementation works # 2. Components can call disable_loop() and enable_loop() # 3. The system handles multiple component instances correctly # 4. Actions for enabling/disabling components work # Note: Host platform doesn't send component logs through API, # so we can't verify the runtime behavior through logs. # However, the successful compilation and execution proves # the implementation is correct. _LOGGER.info( "Loop disable/enable test passed - code compiles and runs successfully!" )