Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -125,7 +125,7 @@ async def _check_service_exists(
options.get(CONF_HOST, "<unknown>"),
service_names,
)
return "service_not_found"
return "docker_service_not_found"


def _build_user_schema(defaults: dict[str, Any]) -> vol.Schema:
Expand Down Expand Up @@ -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", {})

Expand Down
3 changes: 2 additions & 1 deletion strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand All @@ -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)."""
Expand Down
3 changes: 2 additions & 1 deletion translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
Loading