Use enum sensor device class in PrusaLink (#83107)

This commit is contained in:
Franck Nijhof 2022-12-03 11:22:36 +01:00 committed by GitHub
parent a63dd811dd
commit b40923a4cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 12 deletions

View File

@ -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",

View File

@ -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"
}
}
}
}
}

View File

@ -1,11 +0,0 @@
{
"state": {
"prusalink__printer_state": {
"pausing": "Pausing",
"cancelling": "Cancelling",
"paused": "Paused",
"printing": "Printing",
"idle": "Idle"
}
}
}

View File

@ -14,5 +14,18 @@
}
}
}
},
"entity": {
"sensor": {
"printer_state": {
"state": {
"cancelling": "Cancelling",
"idle": "Idle",
"paused": "Paused",
"pausing": "Pausing",
"printing": "Printing"
}
}
}
}
}

View File

@ -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