Make Sonarr component's units translatable (#139254)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
pull/138962/head
Dan Bishop 2025-02-25 14:26:22 +00:00 committed by GitHub
parent 1633700a58
commit 1f93d2cefb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 15 deletions

View File

@ -90,7 +90,6 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
"commands": SonarrSensorEntityDescription[list[Command]](
key="commands",
translation_key="commands",
native_unit_of_measurement="Commands",
entity_registry_enabled_default=False,
value_fn=len,
attributes_fn=lambda data: {c.name: c.status for c in data},
@ -107,7 +106,6 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
"queue": SonarrSensorEntityDescription[SonarrQueue](
key="queue",
translation_key="queue",
native_unit_of_measurement="Episodes",
entity_registry_enabled_default=False,
value_fn=lambda data: data.totalRecords,
attributes_fn=get_queue_attr,
@ -115,7 +113,6 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
"series": SonarrSensorEntityDescription[list[SonarrSeries]](
key="series",
translation_key="series",
native_unit_of_measurement="Series",
entity_registry_enabled_default=False,
value_fn=len,
attributes_fn=lambda data: {
@ -129,7 +126,6 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
"upcoming": SonarrSensorEntityDescription[list[SonarrCalendar]](
key="upcoming",
translation_key="upcoming",
native_unit_of_measurement="Episodes",
value_fn=len,
attributes_fn=lambda data: {
e.series.title: f"S{e.seasonNumber:02d}E{e.episodeNumber:02d}" for e in data
@ -138,7 +134,6 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
"wanted": SonarrSensorEntityDescription[SonarrWantedMissing](
key="wanted",
translation_key="wanted",
native_unit_of_measurement="Episodes",
entity_registry_enabled_default=False,
value_fn=lambda data: data.totalRecords,
attributes_fn=get_wanted_attr,

View File

@ -37,22 +37,27 @@
"entity": {
"sensor": {
"commands": {
"name": "Commands"
"name": "Commands",
"unit_of_measurement": "commands"
},
"diskspace": {
"name": "Disk space"
},
"queue": {
"name": "Queue"
"name": "Queue",
"unit_of_measurement": "episodes"
},
"series": {
"name": "Shows"
"name": "Shows",
"unit_of_measurement": "series"
},
"upcoming": {
"name": "Upcoming"
"name": "Upcoming",
"unit_of_measurement": "[%key:component::sonarr::entity::sensor::queue::unit_of_measurement%]"
},
"wanted": {
"name": "Wanted"
"name": "Wanted",
"unit_of_measurement": "[%key:component::sonarr::entity::sensor::queue::unit_of_measurement%]"
}
}
}

View File

@ -49,7 +49,7 @@ async def test_sensors(
state = hass.states.get("sensor.sonarr_commands")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "Commands"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "commands"
assert state.state == "2"
state = hass.states.get("sensor.sonarr_disk_space")
@ -60,25 +60,25 @@ async def test_sensors(
state = hass.states.get("sensor.sonarr_queue")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "Episodes"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "episodes"
assert state.attributes.get("The Andy Griffith Show S01E01") == "100.00%"
assert state.state == "1"
state = hass.states.get("sensor.sonarr_shows")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "Series"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "series"
assert state.attributes.get("The Andy Griffith Show") == "0/0 Episodes"
assert state.state == "1"
state = hass.states.get("sensor.sonarr_upcoming")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "Episodes"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "episodes"
assert state.attributes.get("Bob's Burgers") == "S04E11"
assert state.state == "1"
state = hass.states.get("sensor.sonarr_wanted")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "Episodes"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "episodes"
assert state.attributes.get("Bob's Burgers S04E11") == "2014-01-26T17:30:00-08:00"
assert (
state.attributes.get("The Andy Griffith Show S01E01")