From b40923a4cdc05c543a323e3e2920199dc76b2ef7 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 3 Dec 2022 11:22:36 +0100 Subject: [PATCH] Use enum sensor device class in PrusaLink (#83107) --- homeassistant/components/prusalink/sensor.py | 4 +++- homeassistant/components/prusalink/strings.json | 13 +++++++++++++ .../components/prusalink/strings.sensor.json | 11 ----------- .../components/prusalink/translations/en.json | 13 +++++++++++++ tests/components/prusalink/test_sensor.py | 9 +++++++++ 5 files changed, 38 insertions(+), 12 deletions(-) delete mode 100644 homeassistant/components/prusalink/strings.sensor.json diff --git a/homeassistant/components/prusalink/sensor.py b/homeassistant/components/prusalink/sensor.py index f2a4f2fec81..366d9dd9883 100644 --- a/homeassistant/components/prusalink/sensor.py +++ b/homeassistant/components/prusalink/sensor.py @@ -59,7 +59,9 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = { if flags["printing"] else "idle" ), - device_class="prusalink__printer_state", + device_class=SensorDeviceClass.ENUM, + options=["cancelling", "idle", "paused", "pausing", "printing"], + translation_key="printer_state", ), PrusaLinkSensorEntityDescription[PrinterInfo]( key="printer.telemetry.temp-bed", diff --git a/homeassistant/components/prusalink/strings.json b/homeassistant/components/prusalink/strings.json index 24835324e18..9d6a1a2ed53 100644 --- a/homeassistant/components/prusalink/strings.json +++ b/homeassistant/components/prusalink/strings.json @@ -14,5 +14,18 @@ "unknown": "[%key:common::config_flow::error::unknown%]", "not_supported": "Only PrusaLink API v2 is supported" } + }, + "entity": { + "sensor": { + "printer_state": { + "state": { + "cancelling": "Cancelling", + "idle": "Idle", + "paused": "Paused", + "pausing": "Pausing", + "printing": "Printing" + } + } + } } } diff --git a/homeassistant/components/prusalink/strings.sensor.json b/homeassistant/components/prusalink/strings.sensor.json deleted file mode 100644 index 6e1fe62e7f5..00000000000 --- a/homeassistant/components/prusalink/strings.sensor.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "state": { - "prusalink__printer_state": { - "pausing": "Pausing", - "cancelling": "Cancelling", - "paused": "Paused", - "printing": "Printing", - "idle": "Idle" - } - } -} diff --git a/homeassistant/components/prusalink/translations/en.json b/homeassistant/components/prusalink/translations/en.json index ad52d4082de..6edf12e1001 100644 --- a/homeassistant/components/prusalink/translations/en.json +++ b/homeassistant/components/prusalink/translations/en.json @@ -14,5 +14,18 @@ } } } + }, + "entity": { + "sensor": { + "printer_state": { + "state": { + "cancelling": "Cancelling", + "idle": "Idle", + "paused": "Paused", + "pausing": "Pausing", + "printing": "Printing" + } + } + } } } \ No newline at end of file diff --git a/tests/components/prusalink/test_sensor.py b/tests/components/prusalink/test_sensor.py index 3e08b2b8b53..f5e4b801d30 100644 --- a/tests/components/prusalink/test_sensor.py +++ b/tests/components/prusalink/test_sensor.py @@ -6,6 +6,7 @@ from unittest.mock import PropertyMock, patch import pytest from homeassistant.components.sensor import ( + ATTR_OPTIONS, ATTR_STATE_CLASS, SensorDeviceClass, SensorStateClass, @@ -39,6 +40,14 @@ async def test_sensors_no_job(hass: HomeAssistant, mock_config_entry, mock_api): state = hass.states.get("sensor.mock_title") assert state is not None assert state.state == "idle" + assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM + assert state.attributes[ATTR_OPTIONS] == [ + "cancelling", + "idle", + "paused", + "pausing", + "printing", + ] state = hass.states.get("sensor.mock_title_heatbed") assert state is not None