Change naming of MQTT entities to correspond with HA guidelines (#95159)

* Set has_entity_name if device_name is set

* revert unneeded formatting change

* Add image platform

* Follow up comment

* Don't set `has_entity_name` without device name

* Only set has_entity_name if a valid name is set

* Follow device_class name and add tests

* Follow up comments add extra tests

* Move to helper - Log a warning

* fix test

* Allow to assign None as name explictly

* Refactor

* Log info messages when device name is not set

* Revert scene schema change - no device link

* Always set has_entity_name with device mapping

* Always set `_attr_has_entity_name`

* Cleanup
This commit is contained in:
Jan Bouwhuis 2023-07-21 12:52:10 +02:00 committed by GitHub
parent 747f4d4a73
commit 447fbf58c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 433 additions and 66 deletions

View file

@ -53,6 +53,7 @@ from .test_common import (
help_test_entity_disabled_by_default,
help_test_entity_id_update_discovery_update,
help_test_entity_id_update_subscriptions,
help_test_entity_name,
help_test_reload_with_config,
help_test_reloadable,
help_test_setting_attribute_via_mqtt_json_message,
@ -1409,3 +1410,21 @@ async def test_unload_entry(
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry, domain, config
)
@pytest.mark.parametrize(
("expected_friendly_name", "device_class"),
[("test", None), ("Humidity", "humidity"), ("Temperature", "temperature")],
)
async def test_entity_name(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
expected_friendly_name: str | None,
device_class: str | None,
) -> None:
"""Test the entity name setup."""
domain = sensor.DOMAIN
config = DEFAULT_CONFIG
await help_test_entity_name(
hass, mqtt_mock_entry, domain, config, expected_friendly_name, device_class
)