Set mqtt entity name to `null` when it is a duplicate of the device name (#97304)
parent
c2bbb0b5db
commit
3fcfe7d0c6
|
@ -1135,7 +1135,16 @@ class MqttEntity(
|
||||||
"MQTT device information always needs to include a name, got %s, "
|
"MQTT device information always needs to include a name, got %s, "
|
||||||
"if device information is shared between multiple entities, the device "
|
"if device information is shared between multiple entities, the device "
|
||||||
"name must be included in each entity's device configuration",
|
"name must be included in each entity's device configuration",
|
||||||
|
config,
|
||||||
)
|
)
|
||||||
|
elif config[CONF_DEVICE][CONF_NAME] == entity_name:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"MQTT device name is equal to entity name in your config %s, "
|
||||||
|
"this is not expected. Please correct your configuration. "
|
||||||
|
"The entity name will be set to `null`",
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
self._attr_name = None
|
||||||
|
|
||||||
def _setup_common_attributes_from_config(self, config: ConfigType) -> None:
|
def _setup_common_attributes_from_config(self, config: ConfigType) -> None:
|
||||||
"""(Re)Setup the common attributes for the entity."""
|
"""(Re)Setup the common attributes for the entity."""
|
||||||
|
|
|
@ -212,6 +212,26 @@ async def test_availability_with_shared_state_topic(
|
||||||
None,
|
None,
|
||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
|
( # entity_name_and_device_name_the_sane
|
||||||
|
{
|
||||||
|
mqtt.DOMAIN: {
|
||||||
|
sensor.DOMAIN: {
|
||||||
|
"name": "Hello world",
|
||||||
|
"state_topic": "test-topic",
|
||||||
|
"unique_id": "veryunique",
|
||||||
|
"device_class": "humidity",
|
||||||
|
"device": {
|
||||||
|
"identifiers": ["helloworld"],
|
||||||
|
"name": "Hello world",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sensor.hello_world",
|
||||||
|
"Hello world",
|
||||||
|
"Hello world",
|
||||||
|
False,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
ids=[
|
ids=[
|
||||||
"default_entity_name_without_device_name",
|
"default_entity_name_without_device_name",
|
||||||
|
@ -222,6 +242,7 @@ async def test_availability_with_shared_state_topic(
|
||||||
"name_set_no_device_name_set",
|
"name_set_no_device_name_set",
|
||||||
"none_entity_name_with_device_name",
|
"none_entity_name_with_device_name",
|
||||||
"none_entity_name_without_device_name",
|
"none_entity_name_without_device_name",
|
||||||
|
"entity_name_and_device_name_the_sane",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||||
|
|
Loading…
Reference in New Issue