Add native media and network integrations
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createKodiDiscoveryDescriptor } from '../../ts/integrations/kodi/index.js';
|
||||
|
||||
tap.test('matches Kodi JSON-RPC mDNS records', async () => {
|
||||
const descriptor = createKodiDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_xbmc-jsonrpc-h._tcp.local.',
|
||||
name: 'Living Room Kodi._xbmc-jsonrpc-h._tcp.local.',
|
||||
host: 'living-room-kodi.local',
|
||||
port: 8080,
|
||||
txt: {
|
||||
uuid: 'kodi-uuid-123',
|
||||
version: '21.0',
|
||||
},
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('living-room-kodi.local');
|
||||
expect(result.candidate?.port).toEqual(8080);
|
||||
expect(result.normalizedDeviceId).toEqual('kodi-uuid-123');
|
||||
});
|
||||
|
||||
tap.test('matches manual Kodi host entries', async () => {
|
||||
const descriptor = createKodiDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[1];
|
||||
const result = await matcher.matches({
|
||||
host: '192.168.1.70',
|
||||
name: 'Living Room Kodi',
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('192.168.1.70');
|
||||
expect(result.candidate?.port).toEqual(8080);
|
||||
});
|
||||
|
||||
tap.test('validates Kodi candidates', async () => {
|
||||
const descriptor = createKodiDiscoveryDescriptor();
|
||||
const validator = descriptor.getValidators()[0];
|
||||
const result = await validator.validate({
|
||||
source: 'mdns',
|
||||
integrationDomain: 'kodi',
|
||||
host: '192.168.1.71',
|
||||
port: 8080,
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.confidence).toEqual('high');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,58 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { KodiMapper, type IKodiSnapshot } from '../../ts/integrations/kodi/index.js';
|
||||
|
||||
const snapshot: IKodiSnapshot = {
|
||||
deviceInfo: {
|
||||
uuid: 'kodi-uuid-123',
|
||||
name: 'Living Room Kodi',
|
||||
host: '192.168.1.70',
|
||||
port: 8080,
|
||||
manufacturer: 'Kodi',
|
||||
version: '21.0',
|
||||
},
|
||||
application: {
|
||||
name: 'Kodi',
|
||||
volume: 42,
|
||||
muted: false,
|
||||
version: { major: 21, minor: 0 },
|
||||
},
|
||||
players: [{ playerid: 1, type: 'video', playertype: 'internal' }],
|
||||
player: { playerid: 1, type: 'video', playertype: 'internal' },
|
||||
playerProperties: {
|
||||
speed: 1,
|
||||
time: { hours: 0, minutes: 3, seconds: 4 },
|
||||
totaltime: { hours: 1, minutes: 2, seconds: 3 },
|
||||
live: false,
|
||||
},
|
||||
item: {
|
||||
id: 77,
|
||||
type: 'movie',
|
||||
title: 'The Test Movie',
|
||||
file: 'smb://media/test.mkv',
|
||||
thumbnail: 'image://poster.jpg/',
|
||||
streamdetails: { video: [{ hdrtype: 'hdr10' }] },
|
||||
},
|
||||
online: true,
|
||||
};
|
||||
|
||||
tap.test('maps Kodi JSON-RPC snapshots to media devices', async () => {
|
||||
const devices = KodiMapper.toDevices(snapshot);
|
||||
expect(devices[0].id).toEqual('kodi.device.kodi_uuid_123');
|
||||
expect(devices[0].protocol).toEqual('http');
|
||||
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 === 'The Test Movie')).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('maps Kodi JSON-RPC snapshots to media player entities', async () => {
|
||||
const entities = KodiMapper.toEntities(snapshot);
|
||||
expect(entities[0].id).toEqual('media_player.living_room_kodi');
|
||||
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?.mediaContentType).toEqual('movie');
|
||||
expect(entities[0].attributes?.mediaDuration).toEqual(3723);
|
||||
expect(entities[0].attributes?.mediaPosition).toEqual(184);
|
||||
expect(entities[0].attributes?.dynamicRange).toEqual('hdr10');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user