Add native Z-Wave JS integration
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createZwaveJsDiscoveryDescriptor } from '../../ts/integrations/zwave_js/index.js';
|
||||
|
||||
tap.test('matches Z-Wave JS Server mDNS records', async () => {
|
||||
const descriptor = createZwaveJsDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_zwave-js-server._tcp.local.',
|
||||
name: 'Z-Wave JS._zwave-js-server._tcp.local.',
|
||||
host: 'zwave.local',
|
||||
port: 3000,
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('zwave.local');
|
||||
expect(result.candidate?.metadata?.url).toEqual('ws://zwave.local:3000');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,44 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { ZwaveJsMapper } from '../../ts/integrations/zwave_js/index.js';
|
||||
|
||||
const snapshot = ZwaveJsMapper.toSnapshot({
|
||||
version: { serverVersion: '1.39.0', driverVersion: '15.0.0', homeId: 123456 },
|
||||
controller: { homeId: 123456, ownNodeId: 1 },
|
||||
nodes: [{
|
||||
nodeId: 2,
|
||||
name: 'Living Room Switch',
|
||||
manufacturer: 'Zooz',
|
||||
productLabel: 'ZEN71',
|
||||
status: 'alive',
|
||||
ready: true,
|
||||
values: {
|
||||
'37-0-currentValue': {
|
||||
commandClass: 37,
|
||||
commandClassName: 'Binary Switch',
|
||||
endpoint: 0,
|
||||
property: 'currentValue',
|
||||
metadata: { label: 'Switch', type: 'boolean', readable: true, writeable: true },
|
||||
value: true,
|
||||
},
|
||||
'50-0-value': {
|
||||
commandClass: 50,
|
||||
commandClassName: 'Meter',
|
||||
endpoint: 0,
|
||||
property: 'value',
|
||||
propertyKey: 'Electric_kWh_Consumed',
|
||||
metadata: { label: 'Electric consumption', type: 'number', readable: true, writeable: false, unit: 'kWh' },
|
||||
value: 12.4,
|
||||
},
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
tap.test('maps Z-Wave JS nodes and values to devices and entities', async () => {
|
||||
const devices = ZwaveJsMapper.toDevices(snapshot);
|
||||
const entities = ZwaveJsMapper.toEntities(snapshot);
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'zwave_js.node.2')).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'switch' && entityArg.state === 'on')).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'sensor' && entityArg.state === 12.4)).toBeTrue();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user