Add TypeScript integrations package
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user