Add translation key for IPP printer integration (#84441)
* Add translation key for IPP printer integration * Add testspull/85094/head
parent
516cb31635
commit
dd0f11a062
|
@ -66,11 +66,13 @@ class IPPSensor(IPPEntity, SensorEntity):
|
|||
key: str,
|
||||
name: str,
|
||||
unit_of_measurement: str | None = None,
|
||||
translation_key: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize IPP sensor."""
|
||||
self._key = key
|
||||
self._attr_unique_id = f"{unique_id}_{key}"
|
||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||
self._attr_translation_key = translation_key
|
||||
|
||||
super().__init__(
|
||||
entry_id=entry_id,
|
||||
|
@ -136,6 +138,9 @@ class IPPMarkerSensor(IPPSensor):
|
|||
class IPPPrinterSensor(IPPSensor):
|
||||
"""Defines an IPP printer sensor."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.ENUM
|
||||
_attr_options = ["idle", "printing", "stopped"]
|
||||
|
||||
def __init__(
|
||||
self, entry_id: str, unique_id: str, coordinator: IPPDataUpdateCoordinator
|
||||
) -> None:
|
||||
|
@ -148,6 +153,7 @@ class IPPPrinterSensor(IPPSensor):
|
|||
key="printer",
|
||||
name=coordinator.data.info.name,
|
||||
unit_of_measurement=None,
|
||||
translation_key="printer",
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -31,5 +31,16 @@
|
|||
"parse_error": "Failed to parse response from printer.",
|
||||
"unique_id_required": "Device missing unique identification required for discovery."
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"printer": {
|
||||
"state": {
|
||||
"printing": "Printing",
|
||||
"idle": "Idle",
|
||||
"stopped": "Stopped"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,5 +31,16 @@
|
|||
"title": "Discovered printer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"printer": {
|
||||
"state": {
|
||||
"printing": "Printing",
|
||||
"idle": "Idle",
|
||||
"stopped": "Stopped"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,10 @@ from datetime import datetime
|
|||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.ipp.const import DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_OPTIONS as SENSOR_ATTR_OPTIONS,
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
@ -41,6 +44,11 @@ async def test_sensors(
|
|||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:printer"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||
assert state.attributes.get(SENSOR_ATTR_OPTIONS) == ["idle", "printing", "stopped"]
|
||||
|
||||
entry = registry.async_get("sensor.epson_xp_6000_series")
|
||||
assert entry
|
||||
assert entry.translation_key == "printer"
|
||||
|
||||
state = hass.states.get("sensor.epson_xp_6000_series_black_ink")
|
||||
assert state
|
||||
|
|
Loading…
Reference in New Issue