mirror of
https://github.com/home-assistant/core.git
synced 2025-06-09 23:57:08 +00:00
Add translation key for IPP printer integration (#84441)
* Add translation key for IPP printer integration * Add tests
This commit is contained in:
parent
516cb31635
commit
dd0f11a062
@ -66,11 +66,13 @@ class IPPSensor(IPPEntity, SensorEntity):
|
|||||||
key: str,
|
key: str,
|
||||||
name: str,
|
name: str,
|
||||||
unit_of_measurement: str | None = None,
|
unit_of_measurement: str | None = None,
|
||||||
|
translation_key: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize IPP sensor."""
|
"""Initialize IPP sensor."""
|
||||||
self._key = key
|
self._key = key
|
||||||
self._attr_unique_id = f"{unique_id}_{key}"
|
self._attr_unique_id = f"{unique_id}_{key}"
|
||||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||||
|
self._attr_translation_key = translation_key
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
entry_id=entry_id,
|
entry_id=entry_id,
|
||||||
@ -136,6 +138,9 @@ class IPPMarkerSensor(IPPSensor):
|
|||||||
class IPPPrinterSensor(IPPSensor):
|
class IPPPrinterSensor(IPPSensor):
|
||||||
"""Defines an IPP printer sensor."""
|
"""Defines an IPP printer sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = SensorDeviceClass.ENUM
|
||||||
|
_attr_options = ["idle", "printing", "stopped"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, entry_id: str, unique_id: str, coordinator: IPPDataUpdateCoordinator
|
self, entry_id: str, unique_id: str, coordinator: IPPDataUpdateCoordinator
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -148,6 +153,7 @@ class IPPPrinterSensor(IPPSensor):
|
|||||||
key="printer",
|
key="printer",
|
||||||
name=coordinator.data.info.name,
|
name=coordinator.data.info.name,
|
||||||
unit_of_measurement=None,
|
unit_of_measurement=None,
|
||||||
|
translation_key="printer",
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -31,5 +31,16 @@
|
|||||||
"parse_error": "Failed to parse response from printer.",
|
"parse_error": "Failed to parse response from printer.",
|
||||||
"unique_id_required": "Device missing unique identification required for discovery."
|
"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"
|
"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 unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.ipp.const import DOMAIN
|
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.const import ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
@ -41,6 +44,11 @@ async def test_sensors(
|
|||||||
assert state
|
assert state
|
||||||
assert state.attributes.get(ATTR_ICON) == "mdi:printer"
|
assert state.attributes.get(ATTR_ICON) == "mdi:printer"
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
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")
|
state = hass.states.get("sensor.epson_xp_6000_series_black_ink")
|
||||||
assert state
|
assert state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user