diff --git a/config_flow.py b/config_flow.py index 11dc8aa..4ef84be 100644 --- a/config_flow.py +++ b/config_flow.py @@ -50,7 +50,7 @@ async def _check_service_exists( Returns ``None`` when the service is found *or* when the check cannot be performed (SSH unreachable, empty output, etc.). Returns - ``"service_not_found"`` only when a non-empty list was retrieved and the + ``"docker_service_not_found"`` only when a non-empty list was retrieved and the requested name is absent from it. """ docker_cmd = options.get(CONF_DOCKER_COMMAND, DEFAULT_DOCKER_COMMAND) @@ -125,7 +125,7 @@ async def _check_service_exists( options.get(CONF_HOST, ""), service_names, ) - return "service_not_found" + return "docker_service_not_found" def _build_user_schema(defaults: dict[str, Any]) -> vol.Schema: @@ -168,6 +168,11 @@ async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Handle the initial step.""" + if not self.hass.services.has_service(SSH_COMMAND_DOMAIN, SSH_COMMAND_SERVICE_EXECUTE): + return self.async_abort( + reason="service_not_found", + ) + errors: dict[str, str] = {} discovery = getattr(self, "_discovery_info", {}) diff --git a/strings.json b/strings.json index 255f8d8..1323c20 100644 --- a/strings.json +++ b/strings.json @@ -40,9 +40,10 @@ "login_failed": "SSH login failed. Check username and password/key file.", "host_not_reachable": "Host is not reachable.", "connection_timed_out": "Connection to the host timed out.", - "service_not_found": "The service name was not found on the remote host. Check the name and make sure the container exists." + "docker_service_not_found": "The service name was not found on the remote host. Check the name and make sure the container exists." }, "abort": { + "service_not_found": "The service ssh_command.execute was not found. Please install SSH Command through HACS and add it as an integration.", "already_configured": "This docker container on this host is already configured.", "already_in_progress": "A setup flow for this docker container on this host is already in progress." } diff --git a/tests/unit_tests/test_config_flow.py b/tests/unit_tests/test_config_flow.py index 22b4d09..623c7f8 100644 --- a/tests/unit_tests/test_config_flow.py +++ b/tests/unit_tests/test_config_flow.py @@ -97,12 +97,12 @@ async def test_shows_error_when_service_not_found(self): new=AsyncMock(return_value=({"host": "192.168.1.100"}, None)), ), unittest.mock.patch( "ssh_docker.config_flow._check_service_exists", - new=AsyncMock(return_value="service_not_found"), + new=AsyncMock(return_value="docker_service_not_found"), ): result = await flow.async_step_user(user_input) self.assertEqual(result["type"], "form") - self.assertEqual(result["errors"]["base"], "service_not_found") + self.assertEqual(result["errors"]["base"], "docker_service_not_found") async def test_shows_error_when_password_key_file_missing(self): """Test that an error is shown when neither password nor key_file is provided.""" @@ -278,7 +278,7 @@ async def test_returns_error_when_service_not_in_json_list(self): {SSH_CONF_OUTPUT: '["container_a", "container_b"]', SSH_CONF_EXIT_STATUS: 0} ) result = await _check_service_exists(hass, self._base_options(), "missing_container") - self.assertEqual(result, "service_not_found") + self.assertEqual(result, "docker_service_not_found") async def test_returns_none_when_service_found_in_line_output(self): """Service is in the line-by-line fallback output of docker ps -a.""" @@ -294,7 +294,7 @@ async def test_returns_error_when_service_not_in_line_output(self): {SSH_CONF_OUTPUT: "container_a\ncontainer_b", SSH_CONF_EXIT_STATUS: 0} ) result = await _check_service_exists(hass, self._base_options(), "other_container") - self.assertEqual(result, "service_not_found") + self.assertEqual(result, "docker_service_not_found") async def test_returns_none_when_ssh_fails(self): """If the SSH call raises an exception, the check is skipped (returns None).""" diff --git a/translations/de.json b/translations/de.json index a649522..44f86a9 100644 --- a/translations/de.json +++ b/translations/de.json @@ -40,9 +40,10 @@ "login_failed": "SSH-Anmeldung fehlgeschlagen. Überprüfen Sie Benutzername und Passwort/Schlüsseldatei.", "host_not_reachable": "Host ist nicht erreichbar.", "connection_timed_out": "Die Verbindung zum Host hat das Zeitlimit überschritten.", - "service_not_found": "Der Dienstname wurde auf dem entfernten Host nicht gefunden. Überprüfen Sie den Namen und stellen Sie sicher, dass der Container existiert." + "docker_service_not_found": "Der Dienstname wurde auf dem entfernten Host nicht gefunden. Überprüfen Sie den Namen und stellen Sie sicher, dass der Container existiert." }, "abort": { + "service_not_found": "Der Service ssh_command.execute wurde nicht gefunden. Bitte installiere SSH Command in HACS und füge die Integration hinzu.", "already_configured": "Dieser Docker-Container auf diesem Host ist bereits konfiguriert.", "already_in_progress": "Ein Einrichtungsvorgang für diesen Docker-Container auf diesem Host ist bereits aktiv." } diff --git a/translations/en.json b/translations/en.json index 255f8d8..1323c20 100644 --- a/translations/en.json +++ b/translations/en.json @@ -40,9 +40,10 @@ "login_failed": "SSH login failed. Check username and password/key file.", "host_not_reachable": "Host is not reachable.", "connection_timed_out": "Connection to the host timed out.", - "service_not_found": "The service name was not found on the remote host. Check the name and make sure the container exists." + "docker_service_not_found": "The service name was not found on the remote host. Check the name and make sure the container exists." }, "abort": { + "service_not_found": "The service ssh_command.execute was not found. Please install SSH Command through HACS and add it as an integration.", "already_configured": "This docker container on this host is already configured.", "already_in_progress": "A setup flow for this docker container on this host is already in progress." }