Add entity translations to NZBGet (#98805)

This commit is contained in:
Joost Lekkerkerker 2023-08-29 18:15:44 +02:00 committed by GitHub
parent fe713cec8f
commit e2dd7f2069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 20 deletions

View File

@ -5,6 +5,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, Platform from homeassistant.const import CONF_SCAN_INTERVAL, Platform
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
@ -107,15 +108,20 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> Non
class NZBGetEntity(CoordinatorEntity[NZBGetDataUpdateCoordinator]): class NZBGetEntity(CoordinatorEntity[NZBGetDataUpdateCoordinator]):
"""Defines a base NZBGet entity.""" """Defines a base NZBGet entity."""
_attr_has_entity_name = True
def __init__( def __init__(
self, *, entry_id: str, name: str, coordinator: NZBGetDataUpdateCoordinator self,
*,
entry_id: str,
entry_name: str,
coordinator: NZBGetDataUpdateCoordinator,
) -> None: ) -> None:
"""Initialize the NZBGet entity.""" """Initialize the NZBGet entity."""
super().__init__(coordinator) super().__init__(coordinator)
self._name = name
self._entry_id = entry_id self._entry_id = entry_id
self._attr_device_info = DeviceInfo(
@property identifiers={(DOMAIN, entry_id)},
def name(self) -> str: name=entry_name,
"""Return the name of the entity.""" entry_type=DeviceEntryType.SERVICE,
return self._name )

View File

@ -25,63 +25,63 @@ _LOGGER = logging.getLogger(__name__)
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="ArticleCacheMB", key="ArticleCacheMB",
name="Article Cache", translation_key="article_cache",
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="AverageDownloadRate", key="AverageDownloadRate",
name="Average Speed", translation_key="average_speed",
device_class=SensorDeviceClass.DATA_RATE, device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND, native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND,
suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND, suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
), ),
SensorEntityDescription( SensorEntityDescription(
key="DownloadPaused", key="DownloadPaused",
name="Download Paused", translation_key="download_paused",
), ),
SensorEntityDescription( SensorEntityDescription(
key="DownloadRate", key="DownloadRate",
name="Speed", translation_key="speed",
device_class=SensorDeviceClass.DATA_RATE, device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND, native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND,
suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND, suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
), ),
SensorEntityDescription( SensorEntityDescription(
key="DownloadedSizeMB", key="DownloadedSizeMB",
name="Size", translation_key="size",
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="FreeDiskSpaceMB", key="FreeDiskSpaceMB",
name="Disk Free", translation_key="disk_free",
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="PostJobCount", key="PostJobCount",
name="Post Processing Jobs", translation_key="post_processing_jobs",
native_unit_of_measurement="Jobs", native_unit_of_measurement="Jobs",
), ),
SensorEntityDescription( SensorEntityDescription(
key="PostPaused", key="PostPaused",
name="Post Processing Paused", translation_key="post_processing_paused",
), ),
SensorEntityDescription( SensorEntityDescription(
key="RemainingSizeMB", key="RemainingSizeMB",
name="Queue Size", translation_key="queue_size",
native_unit_of_measurement=UnitOfInformation.MEGABYTES, native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE, device_class=SensorDeviceClass.DATA_SIZE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="UpTimeSec", key="UpTimeSec",
name="Uptime", translation_key="uptime",
device_class=SensorDeviceClass.TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
), ),
SensorEntityDescription( SensorEntityDescription(
key="DownloadLimit", key="DownloadLimit",
name="Speed Limit", translation_key="speed_limit",
device_class=SensorDeviceClass.DATA_RATE, device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND, native_unit_of_measurement=UnitOfDataRate.BYTES_PER_SECOND,
suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND, suggested_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
@ -120,7 +120,7 @@ class NZBGetSensor(NZBGetEntity, SensorEntity):
super().__init__( super().__init__(
coordinator=coordinator, coordinator=coordinator,
entry_id=entry_id, entry_id=entry_id,
name=f"{entry_name} {description.name}", entry_name=entry_name,
) )
self.entity_description = description self.entity_description = description

View File

@ -32,6 +32,48 @@
} }
} }
}, },
"entity": {
"sensor": {
"article_cache": {
"name": "Article cache"
},
"average_speed": {
"name": "Average speed"
},
"download_paused": {
"name": "Download paused"
},
"speed": {
"name": "Speed"
},
"size": {
"name": "Size"
},
"disk_free": {
"name": "Disk free"
},
"post_processing_jobs": {
"name": "Post processing jobs"
},
"post_processing_paused": {
"name": "Post processing paused"
},
"queue_size": {
"name": "Queue size"
},
"uptime": {
"name": "Uptime"
},
"speed_limit": {
"name": "Speed limit"
}
},
"switch": {
"download": {
"name": "Download"
}
}
},
"services": { "services": {
"pause": { "pause": {
"name": "[%key:common::action::pause%]", "name": "[%key:common::action::pause%]",

View File

@ -38,6 +38,8 @@ async def async_setup_entry(
class NZBGetDownloadSwitch(NZBGetEntity, SwitchEntity): class NZBGetDownloadSwitch(NZBGetEntity, SwitchEntity):
"""Representation of a NZBGet download switch.""" """Representation of a NZBGet download switch."""
_attr_translation_key = "download"
def __init__( def __init__(
self, self,
coordinator: NZBGetDataUpdateCoordinator, coordinator: NZBGetDataUpdateCoordinator,
@ -50,7 +52,7 @@ class NZBGetDownloadSwitch(NZBGetEntity, SwitchEntity):
super().__init__( super().__init__(
coordinator=coordinator, coordinator=coordinator,
entry_id=entry_id, entry_id=entry_id,
name=f"{entry_name} Download", entry_name=entry_name,
) )
@property @property