Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entity translations to Sabnzbd #98923

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 14 additions & 19 deletions homeassistant/components/sabnzbd/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

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
Expand All @@ -37,75 +37,75 @@ class SabnzbdSensorEntityDescription(SensorEntityDescription, SabnzbdRequiredKey
SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
SabnzbdSensorEntityDescription(
key="status",
name="Status",
translation_key="status",
),
SabnzbdSensorEntityDescription(
key=SPEED_KEY,
name="Speed",
translation_key="speed",
device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="mb",
name="Queue",
translation_key="queue",
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="mbleft",
name="Left",
translation_key="left",
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="diskspacetotal1",
name="Disk",
translation_key="total_disk_space",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="diskspace1",
name="Disk Free",
translation_key="free_disk_space",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="noofslots_total",
name="Queue Count",
translation_key="queue_count",
state_class=SensorStateClass.TOTAL,
),
SabnzbdSensorEntityDescription(
key="day_size",
name="Daily Total",
translation_key="daily_total",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="week_size",
name="Weekly Total",
translation_key="weekly_total",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="month_size",
name="Monthly Total",
translation_key="monthly_total",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="total_size",
name="Total",
translation_key="overall_total",
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.TOTAL_INCREASING,
Expand Down Expand Up @@ -137,13 +137,9 @@ async def async_setup_entry(
entry_id = config_entry.entry_id

sab_api_data = hass.data[DOMAIN][entry_id][KEY_API_DATA]
client_name = hass.data[DOMAIN][entry_id][KEY_NAME]

async_add_entities(
[
SabnzbdSensor(sab_api_data, client_name, sensor, entry_id)
for sensor in SENSOR_TYPES
]
[SabnzbdSensor(sab_api_data, sensor, entry_id) for sensor in SENSOR_TYPES]
)


Expand All @@ -152,11 +148,11 @@ class SabnzbdSensor(SensorEntity):

entity_description: SabnzbdSensorEntityDescription
_attr_should_poll = False
_attr_has_entity_name = True

def __init__(
self,
sabnzbd_api_data,
client_name,
description: SabnzbdSensorEntityDescription,
entry_id,
) -> None:
Expand All @@ -165,7 +161,6 @@ def __init__(
self._attr_unique_id = f"{entry_id}_{description.key}"
self.entity_description = description
self._sabnzbd_api = sabnzbd_api_data
self._attr_name = f"{client_name} {description.name}"
self._attr_device_info = DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, entry_id)},
Expand Down
37 changes: 37 additions & 0 deletions homeassistant/components/sabnzbd/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,43 @@
"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": {
"pause": {
"name": "[%key:common::action::pause%]",
Expand Down