Add native Sonos integration

This commit is contained in:
2026-05-05 12:23:14 +00:00
parent e91176fb9b
commit 5efb2f6760
13 changed files with 711 additions and 42 deletions
+17
View File
@@ -0,0 +1,17 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createSonosDiscoveryDescriptor } from '../../ts/integrations/sonos/index.js';
tap.test('matches Sonos SSDP ZonePlayer records', async () => {
const descriptor = createSonosDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({
st: 'urn:schemas-upnp-org:device:ZonePlayer:1',
usn: 'uuid:RINCON_000E58ABCDEF01400::urn:schemas-upnp-org:device:ZonePlayer:1',
location: 'http://192.168.1.55:1400/xml/device_description.xml',
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.host).toEqual('192.168.1.55');
expect(result.normalizedDeviceId).toEqual('RINCON_000E58ABCDEF01400');
});
export default tap.start();
+33
View File
@@ -0,0 +1,33 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { SonosMapper } from '../../ts/integrations/sonos/index.js';
const snapshot = {
speakerInfo: {
uid: 'RINCON_000E58ABCDEF01400',
zoneName: 'Kitchen',
modelName: 'Sonos One',
manufacturer: 'Sonos',
},
transportInfo: {
currentTransportState: 'PLAYING',
},
positionInfo: {
title: 'Example Track',
artist: 'Example Artist',
album: 'Example Album',
trackUri: 'x-sonos-http:track',
},
volume: 35,
muted: false,
};
tap.test('maps Sonos speaker snapshots to canonical media devices and entities', async () => {
const devices = SonosMapper.toDevices(snapshot);
const entities = SonosMapper.toEntities(snapshot);
expect(devices[0].id).toEqual('sonos.player.rincon_000e58abcdef01400');
expect(devices[0].features.some((featureArg) => featureArg.id === 'volume')).toBeTrue();
expect(entities[0].platform).toEqual('media_player');
expect(entities[0].state).toEqual('playing');
});
export default tap.start();