Add native camera and media service integrations

This commit is contained in:
2026-05-05 17:13:54 +00:00
parent 489d9d5243
commit e7441844c9
112 changed files with 18608 additions and 327 deletions
@@ -0,0 +1,32 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createSnapcastDiscoveryDescriptor } from '../../ts/integrations/snapcast/index.js';
tap.test('matches Snapcast mDNS control records', async () => {
const descriptor = createSnapcastDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({
name: 'Snapcast',
type: '_snapcast-ctrl._tcp.local.',
host: 'snapserver.local',
port: 1705,
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('snapcast');
expect(result.candidate?.port).toEqual(1705);
expect(result.metadata?.transport).toEqual('tcp');
});
tap.test('matches and validates manual Snapcast entries', async () => {
const descriptor = createSnapcastDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[1];
const result = await matcher.matches({ host: '192.168.1.20', transport: 'http' }, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.port).toEqual(1780);
const validator = descriptor.getValidators()[0];
const validation = await validator.validate(result.candidate!, {});
expect(validation.matched).toBeTrue();
expect(validation.normalizedDeviceId).toEqual('192.168.1.20:1780');
});
export default tap.start();
@@ -0,0 +1,55 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { SnapcastMapper, type ISnapcastSnapshot } from '../../ts/integrations/snapcast/index.js';
const snapshot: ISnapcastSnapshot = {
capturedAt: '2026-01-01T00:00:00.000Z',
source: 'manual',
server: {
groups: [{
id: 'group-1',
muted: false,
name: 'Kitchen Group',
stream_id: 'music',
clients: [{
id: 'client-1',
connected: true,
host: { name: 'Kitchen', ip: '192.168.1.31', mac: '00:11:22:33:44:55' },
config: {
latency: 25,
name: 'Kitchen',
volume: { muted: false, percent: 42 },
},
snapclient: { name: 'Snapclient', version: '0.29.0', protocolVersion: 2 },
}],
}],
streams: [{
id: 'music',
status: 'playing',
uri: { raw: 'pipe:///tmp/snapfifo?name=music', scheme: 'pipe', query: { name: 'music' } },
metadata: { title: 'Example Track', artist: ['Example Artist'], album: 'Example Album' },
properties: { position: 12 },
}],
},
};
tap.test('maps Snapcast clients groups and streams to canonical devices', async () => {
const devices = SnapcastMapper.toDevices(snapshot);
expect(devices.some((deviceArg) => deviceArg.id === 'snapcast.client.client_1')).toBeTrue();
expect(devices.some((deviceArg) => deviceArg.id === 'snapcast.group.group_1')).toBeTrue();
expect(devices.some((deviceArg) => deviceArg.id === 'snapcast.stream.music')).toBeTrue();
});
tap.test('maps Snapcast clients groups and streams to entities', async () => {
const entities = SnapcastMapper.toEntities(snapshot);
const clientEntity = entities.find((entityArg) => entityArg.id === 'media_player.kitchen_snapcast_client');
const groupEntity = entities.find((entityArg) => entityArg.id === 'media_player.kitchen_group_snapcast_group');
const streamEntity = entities.find((entityArg) => entityArg.id === 'sensor.music_snapcast_stream');
expect(clientEntity?.platform).toEqual('media_player');
expect(clientEntity?.state).toEqual('playing');
expect(clientEntity?.attributes?.volumeLevel).toEqual(0.42);
expect(groupEntity?.attributes?.source).toEqual('music');
expect(streamEntity?.state).toEqual('playing');
});
export default tap.start();