Add native camera and media service integrations
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createVolumioDiscoveryDescriptor } from '../../ts/integrations/volumio/index.js';
|
||||
|
||||
tap.test('matches Volumio zeroconf records', async () => {
|
||||
const descriptor = createVolumioDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_Volumio._tcp.local.',
|
||||
name: 'Kitchen._Volumio._tcp.local.',
|
||||
host: 'kitchen-volumio.local',
|
||||
port: 3000,
|
||||
txt: {
|
||||
volumioName: 'Kitchen Volumio',
|
||||
UUID: 'volumio-uuid-123',
|
||||
},
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.confidence).toEqual('certain');
|
||||
expect(result.normalizedDeviceId).toEqual('volumio-uuid-123');
|
||||
expect(result.candidate?.integrationDomain).toEqual('volumio');
|
||||
expect(result.candidate?.host).toEqual('kitchen-volumio.local');
|
||||
expect(result.candidate?.port).toEqual(3000);
|
||||
expect(result.candidate?.name).toEqual('Kitchen Volumio');
|
||||
});
|
||||
|
||||
tap.test('matches manual Volumio host entries and validates candidates', async () => {
|
||||
const descriptor = createVolumioDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[1];
|
||||
const matched = await matcher.matches({
|
||||
host: '192.168.1.81',
|
||||
name: 'Office Volumio',
|
||||
uuid: 'manual-volumio-1',
|
||||
}, {});
|
||||
|
||||
expect(matched.matched).toBeTrue();
|
||||
expect(matched.candidate?.port).toEqual(3000);
|
||||
|
||||
const validator = descriptor.getValidators()[0];
|
||||
const validated = await validator.validate(matched.candidate!, {});
|
||||
expect(validated.matched).toBeTrue();
|
||||
expect(validated.confidence).toEqual('high');
|
||||
});
|
||||
|
||||
tap.test('rejects unrelated mDNS records', async () => {
|
||||
const descriptor = createVolumioDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_http._tcp.local.',
|
||||
name: 'Office Printer',
|
||||
host: 'printer.local',
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeFalse();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,67 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { VolumioMapper, type IVolumioSnapshot } from '../../ts/integrations/volumio/index.js';
|
||||
|
||||
const snapshot: IVolumioSnapshot = {
|
||||
deviceInfo: {
|
||||
uuid: 'volumio-uuid-123',
|
||||
name: 'Kitchen Volumio',
|
||||
host: '192.168.1.81',
|
||||
port: 3000,
|
||||
manufacturer: 'Volumio',
|
||||
hardware: 'Raspberry Pi',
|
||||
systemVersion: '3.661',
|
||||
},
|
||||
systemInfo: {
|
||||
id: 'volumio-uuid-123',
|
||||
name: 'Kitchen Volumio',
|
||||
},
|
||||
systemVersion: {
|
||||
hardware: 'Raspberry Pi',
|
||||
systemversion: '3.661',
|
||||
},
|
||||
state: {
|
||||
status: 'play',
|
||||
title: 'Test Track',
|
||||
artist: 'Test Artist',
|
||||
album: 'Test Album',
|
||||
albumart: 'http://192.168.1.81:3000/albumart?cacheid=1',
|
||||
uri: 'music-library/NAS/test.flac',
|
||||
trackType: 'flac',
|
||||
seek: 123000,
|
||||
duration: 245,
|
||||
volume: 42,
|
||||
mute: false,
|
||||
random: true,
|
||||
repeat: false,
|
||||
service: 'mpd',
|
||||
samplerate: '44100',
|
||||
bitdepth: '16',
|
||||
},
|
||||
playlists: [{ name: 'Morning' }, { name: 'Evening' }],
|
||||
online: true,
|
||||
updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
};
|
||||
|
||||
tap.test('maps Volumio snapshots to media devices', async () => {
|
||||
const devices = VolumioMapper.toDevices(snapshot);
|
||||
expect(devices[0].id).toEqual('volumio.device.volumio_uuid_123');
|
||||
expect(devices[0].protocol).toEqual('http');
|
||||
expect(devices[0].state.some((stateArg) => stateArg.featureId === 'playback' && stateArg.value === 'playing')).toBeTrue();
|
||||
expect(devices[0].state.some((stateArg) => stateArg.featureId === 'volume' && stateArg.value === 42)).toBeTrue();
|
||||
expect(devices[0].state.some((stateArg) => stateArg.featureId === 'current_title' && stateArg.value === 'Test Track')).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('maps Volumio snapshots to media player entities', async () => {
|
||||
const entities = VolumioMapper.toEntities(snapshot);
|
||||
expect(entities[0].id).toEqual('media_player.kitchen_volumio');
|
||||
expect(entities[0].platform).toEqual('media_player');
|
||||
expect(entities[0].state).toEqual('playing');
|
||||
expect(entities[0].attributes?.volumeLevel).toEqual(0.42);
|
||||
expect(entities[0].attributes?.mediaTitle).toEqual('Test Track');
|
||||
expect(entities[0].attributes?.mediaArtist).toEqual('Test Artist');
|
||||
expect(entities[0].attributes?.mediaPosition).toEqual(123);
|
||||
expect(entities[0].attributes?.mediaDuration).toEqual(245);
|
||||
expect(entities[0].attributes?.sourceList).toEqual(['Morning', 'Evening']);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user