Add TypeScript integrations package
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { DiscoveryDescriptor } from '../../ts/core/index.js';
|
||||
|
||||
tap.test('keeps probes, matchers, and validators inspectable', async () => {
|
||||
const descriptor = new DiscoveryDescriptor({ integrationDomain: 'test', displayName: 'Test' });
|
||||
expect(descriptor.getProbes()).toEqual([]);
|
||||
expect(descriptor.getMatchers()).toEqual([]);
|
||||
expect(descriptor.getValidators()).toEqual([]);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,10 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createDefaultIntegrationRegistry, DiscoveryEngine } from '../../ts/index.js';
|
||||
|
||||
tap.test('runs active discovery across default integrations', async () => {
|
||||
const engine = new DiscoveryEngine(createDefaultIntegrationRegistry());
|
||||
const candidates = await engine.runActiveDiscovery();
|
||||
expect(candidates.some((candidateArg) => candidateArg.integrationDomain === 'hue')).toBeTrue();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,13 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { generatedHomeAssistantPortCount, handwrittenHomeAssistantPortDomains } from '../../ts/integrations/generated/index.js';
|
||||
import { createDefaultIntegrationRegistry } from '../../ts/index.js';
|
||||
|
||||
tap.test('registers generated native Home Assistant port skeletons', async () => {
|
||||
expect(generatedHomeAssistantPortCount).toBeGreaterThan(1000);
|
||||
expect(handwrittenHomeAssistantPortDomains).toContain('hue');
|
||||
const registry = createDefaultIntegrationRegistry();
|
||||
expect(registry.get('3_day_blinds')).toBeTruthy();
|
||||
expect(registry.get('hue')?.status).toEqual('control-runtime');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createHueDiscoveryDescriptor } from '../../ts/integrations/hue/index.js';
|
||||
|
||||
tap.test('matches Hue mDNS records', async () => {
|
||||
const descriptor = createHueDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
host: 'hue.local',
|
||||
port: 443,
|
||||
txt: {
|
||||
bridgeid: '001788fffe123456',
|
||||
},
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.normalizedDeviceId).toEqual('001788fffe123456');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,20 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { HueMapper } from '../../ts/integrations/hue/index.js';
|
||||
|
||||
tap.test('maps Hue lights to canonical devices and entities', async () => {
|
||||
const resources = {
|
||||
devices: [],
|
||||
lights: [
|
||||
{
|
||||
id: 'light-1',
|
||||
metadata: { name: 'Kitchen Ceiling' },
|
||||
on: { on: true },
|
||||
dimming: { brightness: 80 },
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(HueMapper.toDevices(resources).length).toEqual(1);
|
||||
expect(HueMapper.toEntities(resources)[0].id).toEqual('light.kitchen_ceiling');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,21 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createShellyDiscoveryDescriptor } from '../../ts/integrations/shelly/index.js';
|
||||
|
||||
tap.test('matches Shelly zeroconf records', async () => {
|
||||
const descriptor = createShellyDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
name: 'shellyplus1pm-a8032abe54dc',
|
||||
type: '_http._tcp.local.',
|
||||
host: 'shellyplus1pm-a8032abe54dc.local',
|
||||
port: 80,
|
||||
txt: {
|
||||
id: 'shellyplus1pm-a8032abe54dc',
|
||||
model: 'SNSW-001P16EU',
|
||||
},
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.normalizedDeviceId).toEqual('shellyplus1pm-a8032abe54dc');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,52 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { ShellyMapper } from '../../ts/integrations/shelly/index.js';
|
||||
|
||||
const snapshot = {
|
||||
deviceInfo: {
|
||||
id: 'shellyplus1pm-a8032abe54dc',
|
||||
mac: 'A8032ABE54DC',
|
||||
model: 'SNSW-001P16EU',
|
||||
gen: 2,
|
||||
ver: '1.0.0',
|
||||
},
|
||||
status: {
|
||||
sys: {
|
||||
mac: 'A8032ABE54DC',
|
||||
uptime: 120,
|
||||
},
|
||||
'switch:0': {
|
||||
id: 0,
|
||||
source: 'init',
|
||||
output: true,
|
||||
apower: 8.9,
|
||||
voltage: 237.5,
|
||||
aenergy: {
|
||||
total: 6.532,
|
||||
},
|
||||
temperature: {
|
||||
tC: 23.5,
|
||||
},
|
||||
},
|
||||
},
|
||||
deviceConfig: {
|
||||
sys: {
|
||||
device: {
|
||||
name: 'Kitchen Plug',
|
||||
},
|
||||
},
|
||||
'switch:0': {
|
||||
name: 'Counter Outlet',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
tap.test('maps Shelly switch status to canonical device features and entities', async () => {
|
||||
const devices = ShellyMapper.toDevices(snapshot);
|
||||
const entities = ShellyMapper.toEntities(snapshot);
|
||||
expect(devices[0].id).toEqual('shelly.device.shellyplus1pm_a8032abe54dc');
|
||||
expect(devices[0].features.some((featureArg) => featureArg.id === 'switch_0_power')).toBeTrue();
|
||||
expect(entities[0].id).toEqual('switch.kitchen_plug_0');
|
||||
expect(entities.some((entityArg) => entityArg.id === 'sensor.kitchen_plug_0_energy')).toBeTrue();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,12 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createWolfSmartsetDiscoveryDescriptor } from '../../ts/integrations/wolf_smartset/index.js';
|
||||
|
||||
tap.test('matches manual Wolf Smartset setup hints', async () => {
|
||||
const descriptor = createWolfSmartsetDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({ host: 'wolf.local' }, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.integrationDomain).toEqual('wolf_smartset');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user