mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Add entity name translations to System Monitor (#107952)
This commit is contained in:
parent
60ab360fe7
commit
0ba0f57439
@ -79,12 +79,14 @@ class SysMonitorSensorEntityDescription(SensorEntityDescription):
|
||||
"""Description for System Monitor sensor entities."""
|
||||
|
||||
mandatory_arg: bool = False
|
||||
placeholder: str | None = None
|
||||
|
||||
|
||||
SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
"disk_free": SysMonitorSensorEntityDescription(
|
||||
key="disk_free",
|
||||
name="Disk free",
|
||||
translation_key="disk_free",
|
||||
placeholder="mount_point",
|
||||
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:harddisk",
|
||||
@ -92,7 +94,8 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"disk_use": SysMonitorSensorEntityDescription(
|
||||
key="disk_use",
|
||||
name="Disk use",
|
||||
translation_key="disk_use",
|
||||
placeholder="mount_point",
|
||||
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:harddisk",
|
||||
@ -100,49 +103,52 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"disk_use_percent": SysMonitorSensorEntityDescription(
|
||||
key="disk_use_percent",
|
||||
name="Disk use (percent)",
|
||||
translation_key="disk_use_percent",
|
||||
placeholder="mount_point",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:harddisk",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"ipv4_address": SysMonitorSensorEntityDescription(
|
||||
key="ipv4_address",
|
||||
name="IPv4 address",
|
||||
translation_key="ipv4_address",
|
||||
placeholder="ip_address",
|
||||
icon="mdi:ip-network",
|
||||
mandatory_arg=True,
|
||||
),
|
||||
"ipv6_address": SysMonitorSensorEntityDescription(
|
||||
key="ipv6_address",
|
||||
name="IPv6 address",
|
||||
translation_key="ipv6_address",
|
||||
placeholder="ip_address",
|
||||
icon="mdi:ip-network",
|
||||
mandatory_arg=True,
|
||||
),
|
||||
"last_boot": SysMonitorSensorEntityDescription(
|
||||
key="last_boot",
|
||||
name="Last boot",
|
||||
translation_key="last_boot",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
),
|
||||
"load_15m": SysMonitorSensorEntityDescription(
|
||||
key="load_15m",
|
||||
name="Load (15m)",
|
||||
translation_key="load_15m",
|
||||
icon=get_cpu_icon(),
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"load_1m": SysMonitorSensorEntityDescription(
|
||||
key="load_1m",
|
||||
name="Load (1m)",
|
||||
translation_key="load_1m",
|
||||
icon=get_cpu_icon(),
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"load_5m": SysMonitorSensorEntityDescription(
|
||||
key="load_5m",
|
||||
name="Load (5m)",
|
||||
translation_key="load_5m",
|
||||
icon=get_cpu_icon(),
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"memory_free": SysMonitorSensorEntityDescription(
|
||||
key="memory_free",
|
||||
name="Memory free",
|
||||
translation_key="memory_free",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:memory",
|
||||
@ -150,7 +156,7 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"memory_use": SysMonitorSensorEntityDescription(
|
||||
key="memory_use",
|
||||
name="Memory use",
|
||||
translation_key="memory_use",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:memory",
|
||||
@ -158,14 +164,15 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"memory_use_percent": SysMonitorSensorEntityDescription(
|
||||
key="memory_use_percent",
|
||||
name="Memory use (percent)",
|
||||
translation_key="memory_use_percent",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:memory",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"network_in": SysMonitorSensorEntityDescription(
|
||||
key="network_in",
|
||||
name="Network in",
|
||||
translation_key="network_in",
|
||||
placeholder="interface",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:server-network",
|
||||
@ -174,7 +181,8 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"network_out": SysMonitorSensorEntityDescription(
|
||||
key="network_out",
|
||||
name="Network out",
|
||||
translation_key="network_out",
|
||||
placeholder="interface",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:server-network",
|
||||
@ -183,21 +191,24 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"packets_in": SysMonitorSensorEntityDescription(
|
||||
key="packets_in",
|
||||
name="Packets in",
|
||||
translation_key="packets_in",
|
||||
placeholder="interface",
|
||||
icon="mdi:server-network",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
mandatory_arg=True,
|
||||
),
|
||||
"packets_out": SysMonitorSensorEntityDescription(
|
||||
key="packets_out",
|
||||
name="Packets out",
|
||||
translation_key="packets_out",
|
||||
placeholder="interface",
|
||||
icon="mdi:server-network",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
mandatory_arg=True,
|
||||
),
|
||||
"throughput_network_in": SysMonitorSensorEntityDescription(
|
||||
key="throughput_network_in",
|
||||
name="Network throughput in",
|
||||
translation_key="throughput_network_in",
|
||||
placeholder="interface",
|
||||
native_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
|
||||
device_class=SensorDeviceClass.DATA_RATE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@ -205,7 +216,8 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"throughput_network_out": SysMonitorSensorEntityDescription(
|
||||
key="throughput_network_out",
|
||||
name="Network throughput out",
|
||||
translation_key="throughput_network_out",
|
||||
placeholder="interface",
|
||||
native_unit_of_measurement=UnitOfDataRate.MEGABYTES_PER_SECOND,
|
||||
device_class=SensorDeviceClass.DATA_RATE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@ -213,27 +225,28 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"process": SysMonitorSensorEntityDescription(
|
||||
key="process",
|
||||
name="Process",
|
||||
translation_key="process",
|
||||
placeholder="process",
|
||||
icon=get_cpu_icon(),
|
||||
mandatory_arg=True,
|
||||
),
|
||||
"processor_use": SysMonitorSensorEntityDescription(
|
||||
key="processor_use",
|
||||
name="Processor use",
|
||||
translation_key="processor_use",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon=get_cpu_icon(),
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"processor_temperature": SysMonitorSensorEntityDescription(
|
||||
key="processor_temperature",
|
||||
name="Processor temperature",
|
||||
translation_key="processor_temperature",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
"swap_free": SysMonitorSensorEntityDescription(
|
||||
key="swap_free",
|
||||
name="Swap free",
|
||||
translation_key="swap_free",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:harddisk",
|
||||
@ -241,7 +254,7 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"swap_use": SysMonitorSensorEntityDescription(
|
||||
key="swap_use",
|
||||
name="Swap use",
|
||||
translation_key="swap_use",
|
||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
icon="mdi:harddisk",
|
||||
@ -249,7 +262,7 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
||||
),
|
||||
"swap_use_percent": SysMonitorSensorEntityDescription(
|
||||
key="swap_use_percent",
|
||||
name="Swap use (percent)",
|
||||
translation_key="swap_use_percent",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:harddisk",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
@ -587,7 +600,10 @@ class SystemMonitorSensor(SensorEntity):
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
self.entity_description = sensor_description
|
||||
self._attr_name: str = f"{sensor_description.name} {argument}".rstrip()
|
||||
if self.entity_description.placeholder:
|
||||
self._attr_translation_placeholders = {
|
||||
self.entity_description.placeholder: argument
|
||||
}
|
||||
self._attr_unique_id: str = slugify(f"{sensor_description.key}_{argument}")
|
||||
self._sensor_registry = sensor_registry
|
||||
self._argument: str = argument
|
||||
|
@ -21,5 +21,81 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"disk_free": {
|
||||
"name": "Disk free {mount_point}"
|
||||
},
|
||||
"disk_use": {
|
||||
"name": "Disk use {mount_point}"
|
||||
},
|
||||
"disk_use_percent": {
|
||||
"name": "Disk usage {mount_point}"
|
||||
},
|
||||
"ipv4_address": {
|
||||
"name": "IPv4 address {ip_address}"
|
||||
},
|
||||
"ipv6_address": {
|
||||
"name": "IPv6 address {ip_address}"
|
||||
},
|
||||
"last_boot": {
|
||||
"name": "Last boot"
|
||||
},
|
||||
"load_15m": {
|
||||
"name": "Load (15m)"
|
||||
},
|
||||
"load_1m": {
|
||||
"name": "Load (1m)"
|
||||
},
|
||||
"load_5m": {
|
||||
"name": "Load (5m)"
|
||||
},
|
||||
"memory_free": {
|
||||
"name": "Memory free"
|
||||
},
|
||||
"memory_use": {
|
||||
"name": "Memory use"
|
||||
},
|
||||
"memory_use_percent": {
|
||||
"name": "Memory usage"
|
||||
},
|
||||
"network_in": {
|
||||
"name": "Network in {interface}"
|
||||
},
|
||||
"network_out": {
|
||||
"name": "Network out {interface}"
|
||||
},
|
||||
"packets_in": {
|
||||
"name": "Packets in {interface}"
|
||||
},
|
||||
"packets_out": {
|
||||
"name": "Packets out {interface}"
|
||||
},
|
||||
"throughput_network_in": {
|
||||
"name": "Network throughput in {interface}"
|
||||
},
|
||||
"throughput_network_out": {
|
||||
"name": "Network throughput out {interface}"
|
||||
},
|
||||
"process": {
|
||||
"name": "Process {process}"
|
||||
},
|
||||
"processor_use": {
|
||||
"name": "Processor use"
|
||||
},
|
||||
"processor_temperature": {
|
||||
"name": "Processor temperature"
|
||||
},
|
||||
"swap_free": {
|
||||
"name": "Swap free"
|
||||
},
|
||||
"swap_use": {
|
||||
"name": "Swap use"
|
||||
},
|
||||
"swap_use_percent": {
|
||||
"name": "Swap usage"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,37 +23,37 @@
|
||||
# name: test_sensor[System Monitor Disk free /media/share - state]
|
||||
'0.2'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) / - attributes]
|
||||
# name: test_sensor[System Monitor Disk usage / - attributes]
|
||||
ReadOnlyDict({
|
||||
'friendly_name': 'System Monitor Disk use (percent) /',
|
||||
'friendly_name': 'System Monitor Disk usage /',
|
||||
'icon': 'mdi:harddisk',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) / - state]
|
||||
# name: test_sensor[System Monitor Disk usage / - state]
|
||||
'60.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) /home/notexist/ - attributes]
|
||||
# name: test_sensor[System Monitor Disk usage /home/notexist/ - attributes]
|
||||
ReadOnlyDict({
|
||||
'friendly_name': 'System Monitor Disk use (percent) /home/notexist/',
|
||||
'friendly_name': 'System Monitor Disk usage /home/notexist/',
|
||||
'icon': 'mdi:harddisk',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) /home/notexist/ - state]
|
||||
# name: test_sensor[System Monitor Disk usage /home/notexist/ - state]
|
||||
'60.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) /media/share - attributes]
|
||||
# name: test_sensor[System Monitor Disk usage /media/share - attributes]
|
||||
ReadOnlyDict({
|
||||
'friendly_name': 'System Monitor Disk use (percent) /media/share',
|
||||
'friendly_name': 'System Monitor Disk usage /media/share',
|
||||
'icon': 'mdi:harddisk',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use (percent) /media/share - state]
|
||||
# name: test_sensor[System Monitor Disk usage /media/share - state]
|
||||
'60.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Disk use / - attributes]
|
||||
@ -167,15 +167,15 @@
|
||||
# name: test_sensor[System Monitor Memory free - state]
|
||||
'40.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Memory use (percent) - attributes]
|
||||
# name: test_sensor[System Monitor Memory usage - attributes]
|
||||
ReadOnlyDict({
|
||||
'friendly_name': 'System Monitor Memory use (percent)',
|
||||
'friendly_name': 'System Monitor Memory usage',
|
||||
'icon': 'mdi:memory',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Memory use (percent) - state]
|
||||
# name: test_sensor[System Monitor Memory usage - state]
|
||||
'40.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Memory use - attributes]
|
||||
@ -374,15 +374,15 @@
|
||||
# name: test_sensor[System Monitor Swap free - state]
|
||||
'40.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Swap use (percent) - attributes]
|
||||
# name: test_sensor[System Monitor Swap usage - attributes]
|
||||
ReadOnlyDict({
|
||||
'friendly_name': 'System Monitor Swap use (percent)',
|
||||
'friendly_name': 'System Monitor Swap usage',
|
||||
'icon': 'mdi:harddisk',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Swap use (percent) - state]
|
||||
# name: test_sensor[System Monitor Swap usage - state]
|
||||
'60.0'
|
||||
# ---
|
||||
# name: test_sensor[System Monitor Swap use - attributes]
|
||||
|
Loading…
x
Reference in New Issue
Block a user