Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/adapters/http/adminApi/transports/transportsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ async function handleSonosDiscovery(
const payload = devices.map((device) => ({
id: device.udn || device.host,
host: device.host,
name: device.name ?? device.roomName,
name: [device.roomName ?? device.name, device.model, device.host].filter(Boolean).join(' · '),
model: device.model,
roomName: device.roomName,
householdId: device.householdId,
active: activeHost ? device.host === activeHost : undefined,
Expand Down
19 changes: 15 additions & 4 deletions src/adapters/outputs/sonos/sonosDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,19 @@ async function resolveDeviceFromLocation(
if (!host) {
return null;
}
const name = matchTag(xml, 'friendlyName');
const friendlyName = matchTag(xml, 'friendlyName');
// S2 device descriptions carry the user-configured room name directly; /status/zp
// no longer has <RoomName> and its <ZoneName> carries a channel suffix like "(LF,RF)".
const descRoomName = matchTag(xml, 'roomName');
const model = matchTag(xml, 'modelName') ?? undefined;
const udn = matchTag(xml, 'UDN')?.replace(/^uuid:/i, '');
const status = await fetchStatus(host, householdId);
const roomName = descRoomName ?? status?.roomName ?? undefined;
return {
host,
name: name ?? status?.roomName ?? undefined,
roomName: status?.roomName,
name: roomName ?? friendlyName ?? undefined,
roomName,
model,
udn,
householdId: status?.householdId,
};
Expand Down Expand Up @@ -340,7 +346,7 @@ async function fetchStatus(
return null;
}
return {
roomName: matchTag(xml, 'RoomName') ?? matchTag(xml, 'ZoneName') ?? undefined,
roomName: matchTag(xml, 'RoomName') ?? stripChannelSuffix(matchTag(xml, 'ZoneName')) ?? undefined,
householdId: household ?? undefined,
};
} catch {
Expand Down Expand Up @@ -454,6 +460,11 @@ function buildSearchRequest(mx: number, target: string): Buffer {
return Buffer.from(payload);
}

function stripChannelSuffix(value: string | null): string | null {
if (!value) return null;
return value.replace(/\s*\([A-Z,+]+\)\s*$/, '').trim() || null;
}

function matchTag(xml: string, tag: string): string | null {
const match = xml.match(new RegExp(`<${tag}>([^<]+)</${tag}>`, 'i'));
return match?.[1]?.trim() ?? null;
Expand Down
2 changes: 2 additions & 0 deletions src/ports/OutputDiscoveryPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface SonosDiscoveredDevice {
host: string;
name?: string;
roomName?: string;
/** Model from the UPnP device description, e.g. "Sonos Beam". */
model?: string;
udn?: string;
householdId?: string;
/**
Expand Down