Add entity name translations to prusalink entities (#90833)
parent
2a23583d67
commit
65b877bb77
|
@ -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"]),
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue