diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 78db0890ab1..61569b7cf53 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -35,10 +35,10 @@ def generate_entity_id(entity_id_format: str, name: Optional[str], current_ids, hass ).result() - name = (name or DEVICE_DEFAULT_NAME).lower() + name = (slugify(name) or slugify(DEVICE_DEFAULT_NAME)).lower() return ensure_unique_string( - entity_id_format.format(slugify(name)), current_ids) + entity_id_format.format(name), current_ids) @callback diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index a4c8b03daa0..637644ca5b3 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -31,6 +31,14 @@ def test_generate_entity_id_given_keys(): 'test.another_entity']) == 'test.overwrite_hidden_true' +def test_generate_entity_id_with_nonlatin_name(): + """Test generate_entity_id given a name containing non-latin characters.""" + fmt = 'test.{}' + assert entity.generate_entity_id( + fmt, 'ホームアシスタント', current_ids=[] + ) == 'test.unnamed_device' + + def test_async_update_support(hass): """Test async update getting called.""" sync_update = []