53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
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();
|