mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Add entity translations to Sabnzbd (#98923)
This commit is contained in:
parent
602a80c35c
commit
fe164d06a7
@ -17,7 +17,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import DOMAIN, SIGNAL_SABNZBD_UPDATED
|
from . import DOMAIN, SIGNAL_SABNZBD_UPDATED
|
||||||
from .const import DEFAULT_NAME, KEY_API_DATA, KEY_NAME
|
from .const import DEFAULT_NAME, KEY_API_DATA
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -37,51 +37,51 @@ SPEED_KEY = "kbpersec"
|
|||||||
SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="status",
|
key="status",
|
||||||
name="Status",
|
translation_key="status",
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key=SPEED_KEY,
|
key=SPEED_KEY,
|
||||||
name="Speed",
|
translation_key="speed",
|
||||||
device_class=SensorDeviceClass.DATA_RATE,
|
device_class=SensorDeviceClass.DATA_RATE,
|
||||||
native_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
|
native_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="mb",
|
key="mb",
|
||||||
name="Queue",
|
translation_key="queue",
|
||||||
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="mbleft",
|
key="mbleft",
|
||||||
name="Left",
|
translation_key="left",
|
||||||
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="diskspacetotal1",
|
key="diskspacetotal1",
|
||||||
name="Disk",
|
translation_key="total_disk_space",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="diskspace1",
|
key="diskspace1",
|
||||||
name="Disk Free",
|
translation_key="free_disk_space",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="noofslots_total",
|
key="noofslots_total",
|
||||||
name="Queue Count",
|
translation_key="queue_count",
|
||||||
state_class=SensorStateClass.TOTAL,
|
state_class=SensorStateClass.TOTAL,
|
||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="day_size",
|
key="day_size",
|
||||||
name="Daily Total",
|
translation_key="daily_total",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
@ -89,7 +89,7 @@ SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="week_size",
|
key="week_size",
|
||||||
name="Weekly Total",
|
translation_key="weekly_total",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
@ -97,7 +97,7 @@ SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="month_size",
|
key="month_size",
|
||||||
name="Monthly Total",
|
translation_key="monthly_total",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
@ -105,7 +105,7 @@ SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SabnzbdSensorEntityDescription(
|
SabnzbdSensorEntityDescription(
|
||||||
key="total_size",
|
key="total_size",
|
||||||
name="Total",
|
translation_key="overall_total",
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
@ -137,13 +137,9 @@ async def async_setup_entry(
|
|||||||
entry_id = config_entry.entry_id
|
entry_id = config_entry.entry_id
|
||||||
|
|
||||||
sab_api_data = hass.data[DOMAIN][entry_id][KEY_API_DATA]
|
sab_api_data = hass.data[DOMAIN][entry_id][KEY_API_DATA]
|
||||||
client_name = hass.data[DOMAIN][entry_id][KEY_NAME]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[SabnzbdSensor(sab_api_data, sensor, entry_id) for sensor in SENSOR_TYPES]
|
||||||
SabnzbdSensor(sab_api_data, client_name, sensor, entry_id)
|
|
||||||
for sensor in SENSOR_TYPES
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -152,11 +148,11 @@ class SabnzbdSensor(SensorEntity):
|
|||||||
|
|
||||||
entity_description: SabnzbdSensorEntityDescription
|
entity_description: SabnzbdSensorEntityDescription
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
sabnzbd_api_data,
|
sabnzbd_api_data,
|
||||||
client_name,
|
|
||||||
description: SabnzbdSensorEntityDescription,
|
description: SabnzbdSensorEntityDescription,
|
||||||
entry_id,
|
entry_id,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -165,7 +161,6 @@ class SabnzbdSensor(SensorEntity):
|
|||||||
self._attr_unique_id = f"{entry_id}_{description.key}"
|
self._attr_unique_id = f"{entry_id}_{description.key}"
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._sabnzbd_api = sabnzbd_api_data
|
self._sabnzbd_api = sabnzbd_api_data
|
||||||
self._attr_name = f"{client_name} {description.name}"
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, entry_id)},
|
identifiers={(DOMAIN, entry_id)},
|
||||||
|
@ -14,6 +14,43 @@
|
|||||||
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]"
|
"invalid_api_key": "[%key:common::config_flow::error::invalid_api_key%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"status": {
|
||||||
|
"name": "Status"
|
||||||
|
},
|
||||||
|
"speed": {
|
||||||
|
"name": "Speed"
|
||||||
|
},
|
||||||
|
"queue": {
|
||||||
|
"name": "Queue"
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"name": "Left"
|
||||||
|
},
|
||||||
|
"total_disk_space": {
|
||||||
|
"name": "Total disk space"
|
||||||
|
},
|
||||||
|
"free_disk_space": {
|
||||||
|
"name": "Free disk space"
|
||||||
|
},
|
||||||
|
"queue_count": {
|
||||||
|
"name": "Queue count"
|
||||||
|
},
|
||||||
|
"daily_total": {
|
||||||
|
"name": "Daily total"
|
||||||
|
},
|
||||||
|
"weekly_total": {
|
||||||
|
"name": "Weekly total"
|
||||||
|
},
|
||||||
|
"monthly_total": {
|
||||||
|
"name": "Monthly total"
|
||||||
|
},
|
||||||
|
"overall_total": {
|
||||||
|
"name": "Overall total"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"pause": {
|
"pause": {
|
||||||
"name": "[%key:common::action::pause%]",
|
"name": "[%key:common::action::pause%]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user