Add native local bus integrations
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createVelbusDiscoveryDescriptor } from '../../ts/integrations/velbus/index.js';
|
||||
|
||||
tap.test('matches manual Velbus serial entries', async () => {
|
||||
const descriptor = createVelbusDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'velbus-manual-match');
|
||||
const result = await matcher!.matches({
|
||||
connection: 'serial',
|
||||
serialPath: '/dev/ttyACM0',
|
||||
manufacturer: 'Velleman',
|
||||
model: 'Velbus USB interface',
|
||||
serialNumber: 'VBUS123',
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.normalizedDeviceId).toEqual('VBUS123');
|
||||
expect(result.candidate?.integrationDomain).toEqual('velbus');
|
||||
expect(result.candidate?.metadata?.connection).toEqual('serial');
|
||||
expect(result.candidate?.metadata?.serialPath).toEqual('/dev/ttyACM0');
|
||||
});
|
||||
|
||||
tap.test('matches manual Velbus TCP entries', async () => {
|
||||
const descriptor = createVelbusDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'velbus-manual-match');
|
||||
const result = await matcher!.matches({
|
||||
connection: 'tcp',
|
||||
host: '192.168.1.60',
|
||||
tls: true,
|
||||
password: 'secret',
|
||||
name: 'Velbus Signum',
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.normalizedDeviceId).toEqual('tcp:192.168.1.60:27015');
|
||||
expect(result.candidate?.port).toEqual(27015);
|
||||
expect(result.candidate?.metadata?.dsn).toEqual('tls://secret@192.168.1.60:27015');
|
||||
});
|
||||
|
||||
tap.test('matches manual Velbus TCP DSN entries', async () => {
|
||||
const descriptor = createVelbusDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'velbus-manual-match');
|
||||
const result = await matcher!.matches({
|
||||
connection: 'tcp',
|
||||
dsn: 'tls://secret@192.168.1.61:27015',
|
||||
model: 'Velbus TCP/IP interface',
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.host).toEqual('192.168.1.61');
|
||||
expect(result.candidate?.metadata?.password).toEqual('secret');
|
||||
});
|
||||
|
||||
tap.test('validates Velbus candidates', async () => {
|
||||
const descriptor = createVelbusDiscoveryDescriptor();
|
||||
const validator = descriptor.getValidators()[0];
|
||||
const result = await validator.validate({
|
||||
source: 'manual',
|
||||
integrationDomain: 'velbus',
|
||||
host: 'velbus.local',
|
||||
manufacturer: 'Velleman',
|
||||
metadata: { connection: 'tcp' },
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.manufacturer).toEqual('Velleman');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,92 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { VelbusMapper, type IVelbusSnapshot } from '../../ts/integrations/velbus/index.js';
|
||||
|
||||
const snapshot: IVelbusSnapshot = {
|
||||
gateway: {
|
||||
id: 'velbus-gateway',
|
||||
name: 'Velbus Gateway',
|
||||
connection: 'tcp',
|
||||
host: '192.168.1.60',
|
||||
port: 27015,
|
||||
tls: true,
|
||||
},
|
||||
connected: true,
|
||||
updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
modules: [{
|
||||
address: 1,
|
||||
name: 'Cabinet Module',
|
||||
type: 0x26,
|
||||
typeName: 'VMB4RYLD-20',
|
||||
swVersion: '1.0',
|
||||
serialNumber: 'MOD001',
|
||||
channels: [
|
||||
{ id: 'relay-1', channelNumber: 1, kind: 'relay', name: 'Kitchen Relay', state: true },
|
||||
{ id: 'dimmer-1', channelNumber: 2, kind: 'dimmer', name: 'Living Dimmer', state: true, brightness: 75 },
|
||||
{ id: 'input-1', channelNumber: 3, kind: 'button', name: 'Door Contact', state: 'closed', deviceClass: 'door' },
|
||||
{ id: 'blind-1', channelNumber: 4, kind: 'blind', name: 'Kitchen Blind', state: 'open', position: 60 },
|
||||
{ id: 'temp-1', channelNumber: 5, kind: 'temperature', name: 'Hall Temperature', currentTemperature: 21.5, unit: 'C' },
|
||||
{ id: 'thermostat-1', channelNumber: 6, kind: 'climate', name: 'Hall Thermostat', currentTemperature: 21.5, targetTemperature: 22, hvacMode: 'heat', presetMode: 'home', unit: 'C' },
|
||||
],
|
||||
}],
|
||||
};
|
||||
|
||||
tap.test('maps Velbus modules and channels to canonical devices and entities', async () => {
|
||||
const devices = VelbusMapper.toDevices(snapshot);
|
||||
const entities = VelbusMapper.toEntities(snapshot);
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'velbus.gateway.velbus_gateway')).toBeTrue();
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'velbus.module.mod001')).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'light' && entityArg.id === 'light.living_dimmer' && entityArg.attributes?.brightness === 75)).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'switch' && entityArg.id === 'switch.kitchen_relay' && entityArg.state === 'on')).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'binary_sensor' && entityArg.id === 'binary_sensor.door_contact' && entityArg.state === 'on')).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'sensor' && entityArg.id === 'sensor.hall_temperature' && entityArg.state === 21.5)).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'cover' && entityArg.id === 'cover.kitchen_blind' && entityArg.attributes?.currentPosition === 60)).toBeTrue();
|
||||
expect(entities.some((entityArg) => entityArg.platform === 'climate' && entityArg.id === 'climate.hall_thermostat' && entityArg.attributes?.targetTemperature === 22)).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('maps supported Velbus services to commands', async () => {
|
||||
const lightCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'light',
|
||||
service: 'turn_on',
|
||||
target: { entityId: 'light.living_dimmer' },
|
||||
data: { brightness: 128 },
|
||||
});
|
||||
expect(lightCommand).toEqual({ type: 'turn_on', moduleAddress: 1, channelId: 'dimmer-1', channelNumber: 2, platform: 'light', entityId: 'light.living_dimmer', value: 50 });
|
||||
|
||||
const switchCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'switch',
|
||||
service: 'turn_off',
|
||||
target: { entityId: 'switch.kitchen_relay' },
|
||||
});
|
||||
expect(switchCommand).toEqual({ type: 'turn_off', moduleAddress: 1, channelId: 'relay-1', channelNumber: 1, platform: 'switch', entityId: 'switch.kitchen_relay' });
|
||||
|
||||
const velbusTurnOffCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'velbus',
|
||||
service: 'turn_off',
|
||||
target: { entityId: 'light.living_dimmer' },
|
||||
});
|
||||
expect(velbusTurnOffCommand?.type).toEqual('turn_off');
|
||||
|
||||
const setValueCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'velbus',
|
||||
service: 'set_value',
|
||||
target: { entityId: 'cover.kitchen_blind' },
|
||||
data: { value: 30 },
|
||||
});
|
||||
expect(setValueCommand).toEqual({ type: 'set_value', moduleAddress: 1, channelId: 'blind-1', channelNumber: 4, platform: 'cover', entityId: 'cover.kitchen_blind', value: 30 });
|
||||
|
||||
const openCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'cover',
|
||||
service: 'open_cover',
|
||||
target: { entityId: 'cover.kitchen_blind' },
|
||||
});
|
||||
expect(openCommand?.type).toEqual('open');
|
||||
|
||||
const closeCommand = VelbusMapper.commandForService(snapshot, {
|
||||
domain: 'cover',
|
||||
service: 'close_cover',
|
||||
target: { entityId: 'cover.kitchen_blind' },
|
||||
});
|
||||
expect(closeCommand?.type).toEqual('close');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user