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
|
@ -273,19 +273,19 @@ async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||
class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
|
||||
"""Defines a base System Bridge entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: SystemBridgeDataUpdateCoordinator,
|
||||
api_port: int,
|
||||
key: str,
|
||||
name: str | None,
|
||||
) -> None:
|
||||
"""Initialize the System Bridge entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._hostname = coordinator.data.system.hostname
|
||||
self._key = f"{self._hostname}_{key}"
|
||||
self._name = f"{self._hostname} {name}"
|
||||
self._configuration_url = (
|
||||
f"http://{self._hostname}:{api_port}/app/settings.html"
|
||||
)
|
||||
|
@ -298,11 +298,6 @@ class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
|
|||
"""Return the unique ID for this entity."""
|
||||
return self._key
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this System Bridge instance."""
|
||||
|
|
|
@ -33,7 +33,6 @@ class SystemBridgeBinarySensorEntityDescription(BinarySensorEntityDescription):
|
|||
BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
||||
SystemBridgeBinarySensorEntityDescription(
|
||||
key="version_available",
|
||||
name="New version available",
|
||||
device_class=BinarySensorDeviceClass.UPDATE,
|
||||
value=lambda data: data.system.version_newer_available,
|
||||
),
|
||||
|
@ -42,7 +41,6 @@ BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...]
|
|||
BATTERY_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
||||
SystemBridgeBinarySensorEntityDescription(
|
||||
key="battery_is_charging",
|
||||
name="Battery is charging",
|
||||
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
||||
value=lambda data: data.battery.is_charging,
|
||||
),
|
||||
|
@ -92,7 +90,6 @@ class SystemBridgeBinarySensor(SystemBridgeEntity, BinarySensorEntity):
|
|||
coordinator,
|
||||
api_port,
|
||||
description.key,
|
||||
description.name,
|
||||
)
|
||||
self.entity_description = description
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -28,6 +28,55 @@
|
|||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"boot_time": {
|
||||
"name": "Boot time"
|
||||
},
|
||||
"cpu_power_package": {
|
||||
"name": "CPU package power"
|
||||
},
|
||||
"cpu_speed": {
|
||||
"name": "CPU speed"
|
||||
},
|
||||
"cpu_temperature": {
|
||||
"name": "CPU temperature"
|
||||
},
|
||||
"cpu_voltage": {
|
||||
"name": "CPU voltage"
|
||||
},
|
||||
"kernel": {
|
||||
"name": "Kernel"
|
||||
},
|
||||
"memory_free": {
|
||||
"name": "Memory free"
|
||||
},
|
||||
"memory_used": {
|
||||
"name": "Memory used"
|
||||
},
|
||||
"amount_memory_used": {
|
||||
"name": "Amount of memory used"
|
||||
},
|
||||
"os": {
|
||||
"name": "Operating system"
|
||||
},
|
||||
"load": {
|
||||
"name": "Load"
|
||||
},
|
||||
"version": {
|
||||
"name": "Version"
|
||||
},
|
||||
"version_latest": {
|
||||
"name": "Latest version"
|
||||
},
|
||||
"battery_time_remaining": {
|
||||
"name": "Battery time remaining"
|
||||
},
|
||||
"displays_connected": {
|
||||
"name": "Displays connected"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"open_path": {
|
||||
"name": "Open path",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue