mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add entity translations to System bridge (#98959)
This commit is contained in:
parent
61ff53fcf7
commit
a6788208fe
@ -273,19 +273,19 @@ async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||||||
class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
|
class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
|
||||||
"""Defines a base System Bridge entity."""
|
"""Defines a base System Bridge entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: SystemBridgeDataUpdateCoordinator,
|
coordinator: SystemBridgeDataUpdateCoordinator,
|
||||||
api_port: int,
|
api_port: int,
|
||||||
key: str,
|
key: str,
|
||||||
name: str | None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the System Bridge entity."""
|
"""Initialize the System Bridge entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self._hostname = coordinator.data.system.hostname
|
self._hostname = coordinator.data.system.hostname
|
||||||
self._key = f"{self._hostname}_{key}"
|
self._key = f"{self._hostname}_{key}"
|
||||||
self._name = f"{self._hostname} {name}"
|
|
||||||
self._configuration_url = (
|
self._configuration_url = (
|
||||||
f"http://{self._hostname}:{api_port}/app/settings.html"
|
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 the unique ID for this entity."""
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return device information about this System Bridge instance."""
|
"""Return device information about this System Bridge instance."""
|
||||||
|
@ -33,7 +33,6 @@ class SystemBridgeBinarySensorEntityDescription(BinarySensorEntityDescription):
|
|||||||
BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
||||||
SystemBridgeBinarySensorEntityDescription(
|
SystemBridgeBinarySensorEntityDescription(
|
||||||
key="version_available",
|
key="version_available",
|
||||||
name="New version available",
|
|
||||||
device_class=BinarySensorDeviceClass.UPDATE,
|
device_class=BinarySensorDeviceClass.UPDATE,
|
||||||
value=lambda data: data.system.version_newer_available,
|
value=lambda data: data.system.version_newer_available,
|
||||||
),
|
),
|
||||||
@ -42,7 +41,6 @@ BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...]
|
|||||||
BATTERY_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
BATTERY_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
|
||||||
SystemBridgeBinarySensorEntityDescription(
|
SystemBridgeBinarySensorEntityDescription(
|
||||||
key="battery_is_charging",
|
key="battery_is_charging",
|
||||||
name="Battery is charging",
|
|
||||||
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
||||||
value=lambda data: data.battery.is_charging,
|
value=lambda data: data.battery.is_charging,
|
||||||
),
|
),
|
||||||
@ -92,7 +90,6 @@ class SystemBridgeBinarySensor(SystemBridgeEntity, BinarySensorEntity):
|
|||||||
coordinator,
|
coordinator,
|
||||||
api_port,
|
api_port,
|
||||||
description.key,
|
description.key,
|
||||||
description.name,
|
|
||||||
)
|
)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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 homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from . import SystemBridgeEntity
|
from . import SystemBridgeEntity
|
||||||
@ -46,10 +46,6 @@ PIXELS: Final = "px"
|
|||||||
class SystemBridgeSensorEntityDescription(SensorEntityDescription):
|
class SystemBridgeSensorEntityDescription(SensorEntityDescription):
|
||||||
"""Class describing System Bridge sensor entities."""
|
"""Class describing System Bridge sensor entities."""
|
||||||
|
|
||||||
# SystemBridgeSensor does not support UNDEFINED or None,
|
|
||||||
# restrict the type to str.
|
|
||||||
name: str = ""
|
|
||||||
|
|
||||||
value: Callable = round
|
value: Callable = round
|
||||||
|
|
||||||
|
|
||||||
@ -143,14 +139,14 @@ def memory_used(data: SystemBridgeCoordinatorData) -> float | None:
|
|||||||
BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="boot_time",
|
key="boot_time",
|
||||||
name="Boot time",
|
translation_key="boot_time",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
icon="mdi:av-timer",
|
icon="mdi:av-timer",
|
||||||
value=lambda data: datetime.fromtimestamp(data.system.boot_time, tz=UTC),
|
value=lambda data: datetime.fromtimestamp(data.system.boot_time, tz=UTC),
|
||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="cpu_power_package",
|
key="cpu_power_package",
|
||||||
name="CPU Package Power",
|
translation_key="cpu_power_package",
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
suggested_display_precision=2,
|
suggested_display_precision=2,
|
||||||
@ -159,7 +155,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="cpu_speed",
|
key="cpu_speed",
|
||||||
name="CPU speed",
|
translation_key="cpu_speed",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfFrequency.GIGAHERTZ,
|
native_unit_of_measurement=UnitOfFrequency.GIGAHERTZ,
|
||||||
device_class=SensorDeviceClass.FREQUENCY,
|
device_class=SensorDeviceClass.FREQUENCY,
|
||||||
@ -168,7 +164,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="cpu_temperature",
|
key="cpu_temperature",
|
||||||
name="CPU temperature",
|
translation_key="cpu_temperature",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
@ -177,7 +173,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="cpu_voltage",
|
key="cpu_voltage",
|
||||||
name="CPU voltage",
|
translation_key="cpu_voltage",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
@ -186,13 +182,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="kernel",
|
key="kernel",
|
||||||
name="Kernel",
|
translation_key="kernel",
|
||||||
icon="mdi:devices",
|
icon="mdi:devices",
|
||||||
value=lambda data: data.system.platform,
|
value=lambda data: data.system.platform,
|
||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="memory_free",
|
key="memory_free",
|
||||||
name="Memory free",
|
translation_key="memory_free",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
@ -201,7 +197,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="memory_used_percentage",
|
key="memory_used_percentage",
|
||||||
name="Memory used %",
|
translation_key="memory_used",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
icon="mdi:memory",
|
icon="mdi:memory",
|
||||||
@ -209,7 +205,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="memory_used",
|
key="memory_used",
|
||||||
name="Memory used",
|
translation_key="amount_memory_used",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||||
@ -219,13 +215,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="os",
|
key="os",
|
||||||
name="Operating system",
|
translation_key="os",
|
||||||
icon="mdi:devices",
|
icon="mdi:devices",
|
||||||
value=lambda data: f"{data.system.platform} {data.system.platform_version}",
|
value=lambda data: f"{data.system.platform} {data.system.platform_version}",
|
||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="processes_load",
|
key="processes_load",
|
||||||
name="Load",
|
translation_key="load",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
icon="mdi:percent",
|
icon="mdi:percent",
|
||||||
@ -233,13 +229,13 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="version",
|
key="version",
|
||||||
name="Version",
|
translation_key="version",
|
||||||
icon="mdi:counter",
|
icon="mdi:counter",
|
||||||
value=lambda data: data.system.version,
|
value=lambda data: data.system.version,
|
||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="version_latest",
|
key="version_latest",
|
||||||
name="Latest version",
|
translation_key="version_latest",
|
||||||
icon="mdi:counter",
|
icon="mdi:counter",
|
||||||
value=lambda data: data.system.version_latest,
|
value=lambda data: data.system.version_latest,
|
||||||
),
|
),
|
||||||
@ -248,7 +244,6 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
BATTERY_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
BATTERY_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="battery",
|
key="battery",
|
||||||
name="Battery",
|
|
||||||
device_class=SensorDeviceClass.BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
@ -256,7 +251,7 @@ BATTERY_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="battery_time_remaining",
|
key="battery_time_remaining",
|
||||||
name="Battery time remaining",
|
translation_key="battery_time_remaining",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
value=battery_time_remaining,
|
value=battery_time_remaining,
|
||||||
),
|
),
|
||||||
@ -324,7 +319,7 @@ async def async_setup_entry(
|
|||||||
coordinator,
|
coordinator,
|
||||||
SystemBridgeSensorEntityDescription(
|
SystemBridgeSensorEntityDescription(
|
||||||
key="displays_connected",
|
key="displays_connected",
|
||||||
name="Displays connected",
|
translation_key="displays_connected",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
icon="mdi:monitor",
|
icon="mdi:monitor",
|
||||||
value=lambda _, count=display_count: count,
|
value=lambda _, count=display_count: count,
|
||||||
@ -578,9 +573,10 @@ class SystemBridgeSensor(SystemBridgeEntity, SensorEntity):
|
|||||||
coordinator,
|
coordinator,
|
||||||
api_port,
|
api_port,
|
||||||
description.key,
|
description.key,
|
||||||
description.name,
|
|
||||||
)
|
)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
if description.name != UNDEFINED:
|
||||||
|
self._attr_has_entity_name = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
|
@ -28,6 +28,55 @@
|
|||||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
"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": {
|
"services": {
|
||||||
"open_path": {
|
"open_path": {
|
||||||
"name": "Open path",
|
"name": "Open path",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user