Add native media and network integrations
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createSamsungtvDiscoveryDescriptor } from '../../ts/integrations/samsungtv/index.js';
|
||||
|
||||
tap.test('matches Samsung TV SSDP MainTVAgent records', async () => {
|
||||
const descriptor = createSamsungtvDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
st: 'urn:samsung.com:service:MainTVAgent2:1',
|
||||
usn: 'uuid:tv-udn-123::urn:samsung.com:service:MainTVAgent2:1',
|
||||
location: 'http://192.168.1.55:8001/api/v2/',
|
||||
headers: {
|
||||
manufacturer: 'Samsung Electronics',
|
||||
modelName: 'QN90A',
|
||||
},
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('192.168.1.55');
|
||||
expect(result.normalizedDeviceId).toEqual('tv-udn-123');
|
||||
expect(result.candidate?.metadata?.ssdpMainTvAgentLocation).toEqual('http://192.168.1.55:8001/api/v2/');
|
||||
});
|
||||
|
||||
tap.test('matches Samsung TV mDNS AirPlay records', async () => {
|
||||
const descriptor = createSamsungtvDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[1];
|
||||
const result = await matcher.matches({
|
||||
type: '_airplay._tcp.local.',
|
||||
name: 'Living Room TV',
|
||||
host: 'living-room-tv.local',
|
||||
port: 7000,
|
||||
properties: {
|
||||
manufacturer: 'Samsung Electronics',
|
||||
deviceid: 'AA:BB:CC:DD:EE:FF',
|
||||
model: 'Tizen TV',
|
||||
},
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('living-room-tv.local');
|
||||
expect(result.candidate?.port).toEqual(8001);
|
||||
expect(result.normalizedDeviceId).toEqual('AA:BB:CC:DD:EE:FF');
|
||||
});
|
||||
|
||||
tap.test('validates Samsung TV candidates', async () => {
|
||||
const descriptor = createSamsungtvDiscoveryDescriptor();
|
||||
const validator = descriptor.getValidators()[0];
|
||||
const result = await validator.validate({
|
||||
source: 'manual',
|
||||
integrationDomain: 'samsungtv',
|
||||
host: '192.168.1.55',
|
||||
manufacturer: 'Samsung',
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.confidence).toEqual('high');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,39 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { SamsungtvMapper } from '../../ts/integrations/samsungtv/index.js';
|
||||
|
||||
const snapshot = {
|
||||
deviceInfo: {
|
||||
id: 'tv-udn-123',
|
||||
device: {
|
||||
type: 'Samsung SmartTV',
|
||||
name: '[TV] Living Room',
|
||||
modelName: 'QN90A',
|
||||
wifiMac: 'AA:BB:CC:DD:EE:FF',
|
||||
PowerState: 'on',
|
||||
},
|
||||
},
|
||||
state: {
|
||||
playback: 'playing' as const,
|
||||
volumeLevel: 35,
|
||||
muted: false,
|
||||
},
|
||||
apps: [
|
||||
{ id: '11101200001', name: 'Netflix' },
|
||||
{ id: '3201512006785', name: 'Prime Video' },
|
||||
],
|
||||
activeApp: { id: '11101200001', name: 'Netflix' },
|
||||
};
|
||||
|
||||
tap.test('maps Samsung TV snapshots to media devices and entities', async () => {
|
||||
const devices = SamsungtvMapper.toDevices(snapshot);
|
||||
const entities = SamsungtvMapper.toEntities(snapshot);
|
||||
|
||||
expect(devices[0].id).toEqual('samsungtv.device.tv_udn_123');
|
||||
expect(devices[0].state.some((stateArg) => stateArg.featureId === 'source' && stateArg.value === 'Netflix')).toBeTrue();
|
||||
expect(entities[0].id).toEqual('media_player.living_room');
|
||||
expect(entities[0].platform).toEqual('media_player');
|
||||
expect(entities[0].state).toEqual('playing');
|
||||
expect((entities[0].attributes?.sourceList as string[]).includes('Netflix')).toBeTrue();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user