Add entity translations to System bridge (#98959)
This commit is contained in:
parent
61ff53fcf7
commit
a6788208fe
4 changed files with 69 additions and 32 deletions
|
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.typing import UNDEFINED, StateType
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import SystemBridgeEntity
|
||||
|
@ -46,10 +46,6 @@ PIXELS: Final = "px"
|
|||
class SystemBridgeSensorEntityDescription(SensorEntityDescription):
|
||||
"""Class describing System Bridge sensor entities."""
|
||||
|
||||
# SystemBridgeSensor does not support UNDEFINED or None,
|
||||
# restrict the type to str.
|
||||
name: str = ""
|
||||
|
||||
value: Callable = round
|
||||
|
||||
|
||||
|
@ -143,14 +139,14 @@ def memory_used(data: SystemBridgeCoordinatorData) -> float | None:
|
|||
BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="boot_time",
|
||||
name="Boot time",
|
||||
translation_key="boot_time",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:av-timer",
|
||||
value=lambda data: datetime.fromtimestamp(data.system.boot_time, tz=UTC),
|
||||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="cpu_power_package",
|
||||
name="CPU Package Power",
|
||||
translation_key="cpu_power_package",
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=2,
|
||||
|
@ -159,7 +155,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="cpu_speed",
|
||||
name="CPU speed",
|
||||
translation_key="cpu_speed",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfFrequency.GIGAHERTZ,
|
||||
device_class=SensorDeviceClass.FREQUENCY,
|
||||
|
@ -168,7 +164,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="cpu_temperature",
|
||||
name="CPU temperature",
|
||||
translation_key="cpu_temperature",
|
||||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -177,7 +173,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="cpu_voltage",
|
||||
name="CPU voltage",
|
||||
translation_key="cpu_voltage",
|
||||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -186,13 +182,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="kernel",
|
||||
name="Kernel",
|
||||
translation_key="kernel",
|
||||
icon="mdi:devices",
|
||||
value=lambda data: data.system.platform,
|
||||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="memory_free",
|
||||
name="Memory free",
|
||||
translation_key="memory_free",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
|
@ -201,7 +197,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="memory_used_percentage",
|
||||
name="Memory used %",
|
||||
translation_key="memory_used",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:memory",
|
||||
|
@ -209,7 +205,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="memory_used",
|
||||
name="Memory used",
|
||||
translation_key="amount_memory_used",
|
||||
entity_registry_enabled_default=False,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
|
@ -219,13 +215,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="os",
|
||||
name="Operating system",
|
||||
translation_key="os",
|
||||
icon="mdi:devices",
|
||||
value=lambda data: f"{data.system.platform} {data.system.platform_version}",
|
||||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="processes_load",
|
||||
name="Load",
|
||||
translation_key="load",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:percent",
|
||||
|
@ -233,13 +229,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="version",
|
||||
name="Version",
|
||||
translation_key="version",
|
||||
icon="mdi:counter",
|
||||
value=lambda data: data.system.version,
|
||||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="version_latest",
|
||||
name="Latest version",
|
||||
translation_key="version_latest",
|
||||
icon="mdi:counter",
|
||||
value=lambda data: data.system.version_latest,
|
||||
),
|
||||
|
@ -248,7 +244,6 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
BATTERY_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="battery",
|
||||
name="Battery",
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -256,7 +251,7 @@ BATTERY_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="battery_time_remaining",
|
||||
name="Battery time remaining",
|
||||
translation_key="battery_time_remaining",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
value=battery_time_remaining,
|
||||
),
|
||||
|
@ -324,7 +319,7 @@ async def async_setup_entry(
|
|||
coordinator,
|
||||
SystemBridgeSensorEntityDescription(
|
||||
key="displays_connected",
|
||||
name="Displays connected",
|
||||
translation_key="displays_connected",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
icon="mdi:monitor",
|
||||
value=lambda _, count=display_count: count,
|
||||
|
@ -578,9 +573,10 @@ class SystemBridgeSensor(SystemBridgeEntity, SensorEntity):
|
|||
coordinator,
|
||||
api_port,
|
||||
description.key,
|
||||
description.name,
|
||||
)
|
||||
self.entity_description = description
|
||||
if description.name != UNDEFINED:
|
||||
self._attr_has_entity_name = False
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue