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
8 changes: 8 additions & 0 deletions homeassistant/components/prusalink/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class PrusaLinkButtonEntityDescription(
bool, data["printer"]["state"] == PrinterState.PAUSED.value
),
),
PrusaLinkButtonEntityDescription[PrinterStatus](
key="job.continue_job",
translation_key="continue_job",
press_fn=lambda api: api.continue_job,
available_fn=lambda data: cast(
bool, data["printer"]["state"] == PrinterState.ATTENTION.value
),
),
),
}

Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/prusalink/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"cancel_job": {
"default": "mdi:cancel"
},
"continue_job": {
"default": "mdi:play-circle"
},
"pause_job": {
"default": "mdi:pause"
},
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/prusalink/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"cancel_job": {
"name": "Cancel job"
},
"continue_job": {
"name": "Continue job"
},
"pause_job": {
"name": "Pause job"
},
Expand Down
9 changes: 9 additions & 0 deletions tests/components/prusalink/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ def mock_job_api_paused(
mock_get_status_printing["printer"]["state"] = "PAUSED"


@pytest.fixture
def mock_job_api_attention(
mock_get_status_printing: dict[str, Any], mock_job_api_printing: dict[str, Any]
) -> None:
"""Mock PrusaLink printing in ATTENTION state (e.g. timelapse capture)."""
mock_job_api_printing["state"] = "ATTENTION"
mock_get_status_printing["printer"]["state"] = "ATTENTION"


@pytest.fixture
def mock_api(
mock_version_api: dict[str, str],
Expand Down
56 changes: 56 additions & 0 deletions tests/components/prusalink/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,59 @@ async def test_button_resume_cancel(
{"entity_id": entity_id},
blocking=True,
)


async def test_button_continue(
hass: HomeAssistant,
mock_config_entry,
mock_api,
hass_client: ClientSessionGenerator,
mock_job_api_attention,
) -> None:
"""Test continue button is enabled in ATTENTION state and calls continue_job."""
entity_id = "button.mock_title_continue_job"
assert await async_setup_component(hass, "prusalink", {})
state = hass.states.get(entity_id)
assert state is not None
assert state.state == "unknown"
Comment thread
heikkih marked this conversation as resolved.

with (
patch("pyprusalink.PrusaLink.continue_job") as mock_meth,
patch(
"homeassistant.components.prusalink.coordinator.PrusaLinkUpdateCoordinator._fetch_data"
),
):
await hass.services.async_call(
"button",
"press",
{"entity_id": entity_id},
blocking=True,
)

assert len(mock_meth.mock_calls) == 1

# Verify error handling — Conflict raised by API surfaces as HomeAssistantError
with (
pytest.raises(HomeAssistantError),
patch("pyprusalink.PrusaLink.continue_job", side_effect=Conflict),
):
await hass.services.async_call(
"button",
"press",
{"entity_id": entity_id},
blocking=True,
)


async def test_button_continue_unavailable_when_printing(
hass: HomeAssistant,
mock_config_entry,
mock_api,
mock_job_api_printing,
mock_get_status_printing,
) -> None:
"""Continue button is unavailable when printer is not in ATTENTION state."""
assert await async_setup_component(hass, "prusalink", {})
state = hass.states.get("button.mock_title_continue_job")
assert state is not None
assert state.state == "unavailable"
Loading