@@ -874,7 +874,7 @@ def _transform_graphql_device_to_rest(
874874 "hilo_id" : gql_device .get ("hiloId" , "" ),
875875 "identifier" : gql_device .get ("physicalAddress" , "" ),
876876 "type" : rest_type ,
877- "name" : f"{ rest_type } { device_id } " ,
877+ "name" : gql_device . get ( "name" , f"{ rest_type } { device_id } " ), # Use GraphQL name or fallback
878878 "category" : rest_type ,
879879 "supportedAttributes" : "" ,
880880 "settableAttributes" : "" ,
@@ -977,6 +977,43 @@ async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
977977 try :
978978 LOG .debug ("Fetching devices via GraphQL for URN: %s" , self .urn )
979979 devices = await self .get_devices_graphql (self .urn )
980+
981+ # WORKAROUND: Fetch REST device IDs and names for attribute setting
982+ # This is needed because:
983+ # 1. The attribute endpoint still uses numeric IDs
984+ # 2. GraphQL doesn't provide device names in the base query
985+ try :
986+ url = self ._get_url ("Devices" , location_id = location_id )
987+ rest_devices = await self .async_request ("get" , url )
988+
989+ # Build mapping of identifier -> (id, name)
990+ device_mapping = {
991+ d .get ("identifier" ): {
992+ "id" : d .get ("id" ),
993+ "name" : d .get ("name" , "" )
994+ }
995+ for d in rest_devices if d .get ("identifier" )
996+ }
997+
998+ # Update GraphQL devices with real REST IDs and names
999+ for device in devices :
1000+ identifier = device .get ("identifier" )
1001+ if identifier in device_mapping :
1002+ device ["id" ] = device_mapping [identifier ]["id" ]
1003+ # Only update name if GraphQL didn't provide one
1004+ if not device .get ("name" ) or device .get ("name" ).startswith (device .get ("type" , "" )):
1005+ device ["name" ] = device_mapping [identifier ]["name" ]
1006+ LOG .debug (
1007+ "Mapped device %s (id=%d, name=%s)" ,
1008+ identifier ,
1009+ device ["id" ],
1010+ device .get ("name" )
1011+ )
1012+
1013+ except Exception as e :
1014+ LOG .warning ("Failed to fetch device ID/name mapping from REST: %s" , e )
1015+ # Continue without mapping - devices will work read-only
1016+
9801017 except Exception as e :
9811018 LOG .warning (
9821019 "GraphQL device fetch failed, falling back to REST: %s" , e
0 commit comments