Add entity name translations to KNX system sensors (#91396)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
pull/85314/head^2
Matthias Alphart 2023-04-23 01:31:59 +02:00 committed by GitHub
parent 82340907c2
commit 33808cd268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 20 deletions

View File

@ -53,7 +53,6 @@ class KNXSystemEntityDescription(SensorEntityDescription):
SYSTEM_ENTITY_DESCRIPTIONS = (
KNXSystemEntityDescription(
key="individual_address",
name="Individual Address",
always_available=False,
icon="mdi:router-network",
should_poll=False,
@ -61,7 +60,6 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
),
KNXSystemEntityDescription(
key="connected_since",
name="Connected since",
always_available=False,
device_class=SensorDeviceClass.TIMESTAMP,
should_poll=False,
@ -69,7 +67,6 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
),
KNXSystemEntityDescription(
key="connection_type",
name="Connection type",
always_available=False,
device_class=SensorDeviceClass.ENUM,
options=[opt.value for opt in XknxConnectionType],
@ -78,7 +75,6 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
),
KNXSystemEntityDescription(
key="telegrams_incoming",
name="Telegrams incoming",
icon="mdi:upload-network",
entity_registry_enabled_default=False,
force_update=True,
@ -87,14 +83,12 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
),
KNXSystemEntityDescription(
key="telegrams_incoming_error",
name="Telegrams incoming Error",
icon="mdi:help-network",
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda knx: knx.xknx.connection_manager.cemi_count_incoming_error,
),
KNXSystemEntityDescription(
key="telegrams_outgoing",
name="Telegrams outgoing",
icon="mdi:download-network",
entity_registry_enabled_default=False,
force_update=True,
@ -103,14 +97,12 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
),
KNXSystemEntityDescription(
key="telegrams_outgoing_error",
name="Telegrams outgoing Error",
icon="mdi:close-network",
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda knx: knx.xknx.connection_manager.cemi_count_outgoing_error,
),
KNXSystemEntityDescription(
key="telegram_count",
name="Telegrams",
icon="mdi:plus-network",
force_update=True,
state_class=SensorStateClass.TOTAL_INCREASING,
@ -192,6 +184,8 @@ class KNXSensor(KnxEntity, SensorEntity):
class KNXSystemSensor(SensorEntity):
"""Representation of a KNX system sensor."""
_attr_has_entity_name = True
def __init__(
self,
knx: KNXModule,
@ -203,6 +197,7 @@ class KNXSystemSensor(SensorEntity):
self._attr_device_info = knx.interface_device.device_info
self._attr_should_poll = description.should_poll
self._attr_translation_key = description.key
self._attr_unique_id = f"_{knx.entry.entry_id}_{description.key}"
@property

View File

@ -253,5 +253,33 @@
"no_tunnel_discovered": "[%key:component::knx::config::error::no_tunnel_discovered%]",
"unsupported_tunnel_type": "[%key:component::knx::config::error::unsupported_tunnel_type%]"
}
},
"entity": {
"sensor": {
"individual_address": {
"name": "Individual address"
},
"connected_since": {
"name": "Connection established"
},
"connection_type": {
"name": "Connection type"
},
"telegrams_incoming": {
"name": "Incoming telegrams"
},
"telegrams_incoming_error": {
"name": "Incoming telegram errors"
},
"telegrams_outgoing": {
"name": "Outgoing telegrams"
},
"telegrams_outgoing_error": {
"name": "Outgoing telegram errors"
},
"telegram_count": {
"name": "Telegrams"
}
}
}
}

View File

@ -23,20 +23,20 @@ async def test_diagnostic_entities(
for entity_id in [
"sensor.knx_interface_individual_address",
"sensor.knx_interface_connected_since",
"sensor.knx_interface_connection_established",
"sensor.knx_interface_connection_type",
"sensor.knx_interface_telegrams_incoming",
"sensor.knx_interface_telegrams_incoming_error",
"sensor.knx_interface_telegrams_outgoing",
"sensor.knx_interface_telegrams_outgoing_error",
"sensor.knx_interface_incoming_telegrams",
"sensor.knx_interface_incoming_telegram_errors",
"sensor.knx_interface_outgoing_telegrams",
"sensor.knx_interface_outgoing_telegram_errors",
"sensor.knx_interface_telegrams",
]:
entity = entity_registry.async_get(entity_id)
assert entity.entity_category is EntityCategory.DIAGNOSTIC
for entity_id in [
"sensor.knx_interface_telegrams_incoming",
"sensor.knx_interface_telegrams_outgoing",
"sensor.knx_interface_incoming_telegrams",
"sensor.knx_interface_outgoing_telegrams",
]:
entity = entity_registry.async_get(entity_id)
assert entity.disabled is True
@ -57,8 +57,8 @@ async def test_diagnostic_entities(
("sensor.knx_interface_individual_address", "0.0.0"),
("sensor.knx_interface_connection_type", "Tunnel TCP"),
# skipping connected_since timestamp
("sensor.knx_interface_telegrams_incoming_error", "1"),
("sensor.knx_interface_telegrams_outgoing_error", "2"),
("sensor.knx_interface_incoming_telegram_errors", "1"),
("sensor.knx_interface_outgoing_telegram_errors", "2"),
("sensor.knx_interface_telegrams", "31"),
]:
assert hass.states.get(entity_id).state == test_state
@ -88,8 +88,8 @@ async def test_diagnostic_entities(
("sensor.knx_interface_individual_address", "1.1.1"),
("sensor.knx_interface_connection_type", "Tunnel UDP"),
# skipping connected_since timestamp
("sensor.knx_interface_telegrams_incoming_error", "0"),
("sensor.knx_interface_telegrams_outgoing_error", "0"),
("sensor.knx_interface_incoming_telegram_errors", "0"),
("sensor.knx_interface_outgoing_telegram_errors", "0"),
("sensor.knx_interface_telegrams", "0"),
]:
assert hass.states.get(entity_id).state == test_state
@ -105,7 +105,7 @@ async def test_removed_entity(
knx.xknx.connection_manager, "unregister_connection_state_changed_cb"
) as unregister_mock:
entity_registry.async_update_entity(
"sensor.knx_interface_connected_since",
"sensor.knx_interface_connection_established",
disabled_by=er.RegistryEntryDisabler.USER,
)
await hass.async_block_till_done()