From 65b877bb77b04fbaeff796087389befd62c4b9e9 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 5 Apr 2023 12:17:00 +0200 Subject: [PATCH] Add entity name translations to prusalink entities (#90833) --- homeassistant/components/prusalink/button.py | 6 ++-- homeassistant/components/prusalink/camera.py | 2 +- homeassistant/components/prusalink/sensor.py | 12 +++---- .../components/prusalink/strings.json | 34 +++++++++++++++++++ tests/components/prusalink/test_camera.py | 10 +++--- tests/components/prusalink/test_sensor.py | 2 +- 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/prusalink/button.py b/homeassistant/components/prusalink/button.py index f2dd939122b..7e95b209bad 100644 --- a/homeassistant/components/prusalink/button.py +++ b/homeassistant/components/prusalink/button.py @@ -38,7 +38,7 @@ BUTTONS: dict[str, tuple[PrusaLinkButtonEntityDescription, ...]] = { "printer": ( PrusaLinkButtonEntityDescription[PrinterInfo]( key="printer.cancel_job", - name="Cancel Job", + translation_key="cancel_job", icon="mdi:cancel", press_fn=lambda api: cast(Coroutine, api.cancel_job()), available_fn=lambda data: any( @@ -48,7 +48,7 @@ BUTTONS: dict[str, tuple[PrusaLinkButtonEntityDescription, ...]] = { ), PrusaLinkButtonEntityDescription[PrinterInfo]( key="job.pause_job", - name="Pause Job", + translation_key="pause_job", icon="mdi:pause", press_fn=lambda api: cast(Coroutine, api.pause_job()), available_fn=lambda data: ( @@ -58,7 +58,7 @@ BUTTONS: dict[str, tuple[PrusaLinkButtonEntityDescription, ...]] = { ), PrusaLinkButtonEntityDescription[PrinterInfo]( key="job.resume_job", - name="Resume Job", + translation_key="resume_job", icon="mdi:play", press_fn=lambda api: cast(Coroutine, api.resume_job()), available_fn=lambda data: cast(bool, data["state"]["flags"]["paused"]), diff --git a/homeassistant/components/prusalink/camera.py b/homeassistant/components/prusalink/camera.py index a6c16e2f5f2..a8b8f387eff 100644 --- a/homeassistant/components/prusalink/camera.py +++ b/homeassistant/components/prusalink/camera.py @@ -24,7 +24,7 @@ class PrusaLinkJobPreviewEntity(PrusaLinkEntity, Camera): last_path = "" last_image: bytes - _attr_name = "Job Preview" + _attr_translation_key = "job_preview" def __init__(self, coordinator: JobUpdateCoordinator) -> None: """Initialize a PrusaLink camera entity.""" diff --git a/homeassistant/components/prusalink/sensor.py b/homeassistant/components/prusalink/sensor.py index 9edd09f0ff1..bcfadb29166 100644 --- a/homeassistant/components/prusalink/sensor.py +++ b/homeassistant/components/prusalink/sensor.py @@ -65,7 +65,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { ), PrusaLinkSensorEntityDescription[PrinterInfo]( key="printer.telemetry.temp-bed", - name="Heatbed", + translation_key="heatbed_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -74,7 +74,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { ), PrusaLinkSensorEntityDescription[PrinterInfo]( key="printer.telemetry.temp-nozzle", - name="Nozzle Temperature", + translation_key="nozzle_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -85,7 +85,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { "job": ( PrusaLinkSensorEntityDescription[JobInfo]( key="job.progress", - name="Progress", + translation_key="progress", icon="mdi:progress-clock", native_unit_of_measurement=PERCENTAGE, value_fn=lambda data: cast(float, data["progress"]["completion"]) * 100, @@ -93,14 +93,14 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { ), PrusaLinkSensorEntityDescription[JobInfo]( key="job.filename", - name="Filename", + translation_key="filename", icon="mdi:file-image-outline", value_fn=lambda data: cast(str, data["job"]["file"]["display"]), available_fn=lambda data: data.get("job") is not None, ), PrusaLinkSensorEntityDescription[JobInfo]( key="job.start", - name="Print Start", + translation_key="print_start", device_class=SensorDeviceClass.TIMESTAMP, icon="mdi:clock-start", value_fn=ignore_variance( @@ -113,7 +113,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { ), PrusaLinkSensorEntityDescription[JobInfo]( key="job.finish", - name="Print Finish", + translation_key="print_finish", icon="mdi:clock-end", device_class=SensorDeviceClass.TIMESTAMP, value_fn=ignore_variance( diff --git a/homeassistant/components/prusalink/strings.json b/homeassistant/components/prusalink/strings.json index 9d6a1a2ed53..34611e4fffb 100644 --- a/homeassistant/components/prusalink/strings.json +++ b/homeassistant/components/prusalink/strings.json @@ -25,6 +25,40 @@ "pausing": "Pausing", "printing": "Printing" } + }, + "heatbed_temperature": { + "name": "Heatbed temperature" + }, + "nozzle_temperature": { + "name": "Nozzle temperature" + }, + "progress": { + "name": "Progress" + }, + "filename": { + "name": "Filename" + }, + "print_start": { + "name": "Print start" + }, + "print_finish": { + "name": "Print finish" + } + }, + "button": { + "cancel_job": { + "name": "Cancel job" + }, + "pause_job": { + "name": "Pause job" + }, + "resume_job": { + "name": "Resume job" + } + }, + "camera": { + "job_preview": { + "name": "Preview" } } } diff --git a/tests/components/prusalink/test_camera.py b/tests/components/prusalink/test_camera.py index 1695a7f14dd..010758bcca8 100644 --- a/tests/components/prusalink/test_camera.py +++ b/tests/components/prusalink/test_camera.py @@ -25,12 +25,12 @@ async def test_camera_no_job( ) -> None: """Test camera while no job active.""" assert await async_setup_component(hass, "prusalink", {}) - state = hass.states.get("camera.mock_title_job_preview") + state = hass.states.get("camera.mock_title_preview") assert state is not None assert state.state == "unavailable" client = await hass_client() - resp = await client.get("/api/camera_proxy/camera.mock_title_job_preview") + resp = await client.get("/api/camera_proxy/camera.mock_title_preview") assert resp.status == 500 @@ -43,19 +43,19 @@ async def test_camera_active_job( ) -> None: """Test camera while job active.""" assert await async_setup_component(hass, "prusalink", {}) - state = hass.states.get("camera.mock_title_job_preview") + state = hass.states.get("camera.mock_title_preview") assert state is not None assert state.state == "idle" client = await hass_client() with patch("pyprusalink.PrusaLink.get_large_thumbnail", return_value=b"hello"): - resp = await client.get("/api/camera_proxy/camera.mock_title_job_preview") + resp = await client.get("/api/camera_proxy/camera.mock_title_preview") assert resp.status == 200 assert await resp.read() == b"hello" # Make sure we hit cached value. with patch("pyprusalink.PrusaLink.get_large_thumbnail", side_effect=ValueError): - resp = await client.get("/api/camera_proxy/camera.mock_title_job_preview") + resp = await client.get("/api/camera_proxy/camera.mock_title_preview") assert resp.status == 200 assert await resp.read() == b"hello" diff --git a/tests/components/prusalink/test_sensor.py b/tests/components/prusalink/test_sensor.py index ac690e15342..4f64c3139e1 100644 --- a/tests/components/prusalink/test_sensor.py +++ b/tests/components/prusalink/test_sensor.py @@ -49,7 +49,7 @@ async def test_sensors_no_job(hass: HomeAssistant, mock_config_entry, mock_api) "printing", ] - state = hass.states.get("sensor.mock_title_heatbed") + state = hass.states.get("sensor.mock_title_heatbed_temperature") assert state is not None assert state.state == "41.9" assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS