diff --git a/homeassistant/components/config/auth.py b/homeassistant/components/config/auth.py index d5bbb60e27d..440ac05cef4 100644 --- a/homeassistant/components/config/auth.py +++ b/homeassistant/components/config/auth.py @@ -123,8 +123,19 @@ async def websocket_update(hass, connection, msg): def _user_info(user): """Format a user.""" + + ha_username = next( + ( + cred.data.get("username") + for cred in user.credentials + if cred.auth_provider_type == "homeassistant" + ), + None, + ) + return { "id": user.id, + "username": ha_username, "name": user.name, "is_owner": user.is_owner, "is_active": user.is_active, diff --git a/tests/components/config/test_auth.py b/tests/components/config/test_auth.py index 53defb4cd6e..e7e3c67e5d8 100644 --- a/tests/components/config/test_auth.py +++ b/tests/components/config/test_auth.py @@ -34,7 +34,9 @@ async def test_list(hass, hass_ws_client, hass_admin_user): owner.credentials.append( auth_models.Credentials( - auth_provider_type="homeassistant", auth_provider_id=None, data={} + auth_provider_type="homeassistant", + auth_provider_id=None, + data={"username": "test-owner"}, ) ) @@ -58,6 +60,7 @@ async def test_list(hass, hass_ws_client, hass_admin_user): assert len(data) == 4 assert data[0] == { "id": hass_admin_user.id, + "username": None, "name": "Mock User", "is_owner": False, "is_active": True, @@ -67,6 +70,7 @@ async def test_list(hass, hass_ws_client, hass_admin_user): } assert data[1] == { "id": owner.id, + "username": "test-owner", "name": "Test Owner", "is_owner": True, "is_active": True, @@ -76,6 +80,7 @@ async def test_list(hass, hass_ws_client, hass_admin_user): } assert data[2] == { "id": system.id, + "username": None, "name": "Test Hass.io", "is_owner": False, "is_active": True, @@ -85,6 +90,7 @@ async def test_list(hass, hass_ws_client, hass_admin_user): } assert data[3] == { "id": inactive.id, + "username": None, "name": "Inactive User", "is_owner": False, "is_active": False,