|
4 | 4 |
|
5 | 5 | Interactive test environment for Home Assistant MCP Server development. |
6 | 6 | Uses testcontainers to manage a Home Assistant instance for testing. |
| 7 | +
|
| 8 | +Environment Variables: |
| 9 | + HA_TEST_PORT: Optional fixed port for Home Assistant container (default: random) |
| 10 | + Example: HA_TEST_PORT=8123 |
7 | 11 | """ |
8 | 12 |
|
9 | 13 | import logging |
@@ -97,11 +101,25 @@ def start_container(self) -> None: |
97 | 101 | # Set up config directory |
98 | 102 | config_dir = self._setup_config_directory() |
99 | 103 |
|
100 | | - # Create and start container |
| 104 | + # Create container with port configuration |
| 105 | + # renovate: datasource=docker depName=ghcr.io/home-assistant/home-assistant |
| 106 | + container = DockerContainer("ghcr.io/home-assistant/home-assistant:2025.11.3") |
| 107 | + |
| 108 | + # Check for custom port via environment variable |
| 109 | + custom_port = os.environ.get("HA_TEST_PORT") |
| 110 | + if custom_port: |
| 111 | + try: |
| 112 | + port = int(custom_port) |
| 113 | + container = container.with_bind_ports(8123, port) |
| 114 | + logger.info(f"🔌 Using fixed port {port} (from HA_TEST_PORT)") |
| 115 | + except ValueError: |
| 116 | + logger.warning(f"⚠️ Invalid HA_TEST_PORT '{custom_port}', using random port") |
| 117 | + container = container.with_bind_ports(8123, None) |
| 118 | + else: |
| 119 | + container = container.with_bind_ports(8123, None) # Random host port |
| 120 | + |
101 | 121 | self.container = ( |
102 | | - # renovate: datasource=docker depName=ghcr.io/home-assistant/home-assistant |
103 | | - DockerContainer("ghcr.io/home-assistant/home-assistant:2025.11.3") |
104 | | - .with_bind_ports(8123, None) # Random host port |
| 122 | + container |
105 | 123 | .with_volume_mapping(str(config_dir), "/config", "rw") |
106 | 124 | .with_env("TZ", "UTC") |
107 | 125 | .with_kwargs(privileged=True) |
|
0 commit comments