Add native local bus integrations

This commit is contained in:
2026-05-05 18:06:03 +00:00
parent e7441844c9
commit accfa82f36
64 changed files with 10778 additions and 185 deletions
@@ -0,0 +1,42 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createHomematicDiscoveryDescriptor } from '../../ts/integrations/homematic/index.js';
tap.test('matches manual Homematic CCU entries', async () => {
const descriptor = createHomematicDiscoveryDescriptor();
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'homematic-manual-match');
const result = await matcher!.matches({
host: '192.168.1.20',
model: 'Homematic CCU3',
manufacturer: 'eQ-3',
interfaceName: 'rf',
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('homematic');
expect(result.candidate?.port).toEqual(2001);
expect(result.candidate?.metadata?.interfaceName).toEqual('rf');
});
tap.test('matches Homematic metadata records and validates candidates', async () => {
const descriptor = createHomematicDiscoveryDescriptor();
const metadataMatcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'homematic-metadata-match');
const metadataResult = await metadataMatcher!.matches({
domain: 'homematic',
name: 'Homematic',
metadata: { upstreamDomain: 'homematic' },
}, {});
expect(metadataResult.matched).toBeTrue();
expect(metadataResult.candidate?.manufacturer).toEqual('eQ-3');
const validator = descriptor.getValidators()[0];
const validation = await validator.validate({
source: 'manual',
integrationDomain: 'homematic',
host: 'ccu3.local',
manufacturer: 'eQ-3',
model: 'CCU3',
}, {});
expect(validation.matched).toBeTrue();
expect(validation.candidate?.port).toEqual(2001);
});
export default tap.start();
@@ -0,0 +1,120 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { HomematicMapper, type IHomematicSnapshot } from '../../ts/integrations/homematic/index.js';
const snapshot: IHomematicSnapshot = {
ccu: {
id: 'ccu3-1234',
name: 'Main CCU',
host: '192.168.1.20',
model: 'CCU3',
online: true,
serviceMessages: [],
},
interfaces: [{ id: 'rf', name: 'rf', host: '192.168.1.20', port: 2001, family: 'bidcos-rf', online: true }],
devices: [
{
address: 'SWITCH001',
name: 'Kitchen Plug',
type: 'SwitchPowermeter',
interfaceName: 'rf',
available: true,
channels: [
{ address: 'SWITCH001:1', index: 1, parentAddress: 'SWITCH001', datapoints: [{ name: 'STATE', value: true, kind: 'write', writable: true, readable: true }] },
{ address: 'SWITCH001:2', index: 2, parentAddress: 'SWITCH001', datapoints: [{ name: 'POWER', value: 42.5, kind: 'sensor', readable: true }, { name: 'ENERGY_COUNTER', value: 1234, kind: 'sensor', readable: true }] },
],
},
{
address: 'DIMMER001',
name: 'Dining Light',
type: 'Dimmer',
interfaceName: 'rf',
available: true,
channels: [{ address: 'DIMMER001:1', index: 1, parentAddress: 'DIMMER001', datapoints: [{ name: 'LEVEL', value: 0.5, kind: 'write', writable: true, readable: true }] }],
},
{
address: 'MOTION001',
name: 'Hall Motion',
type: 'Motion',
interfaceName: 'rf',
available: true,
channels: [{ address: 'MOTION001:1', index: 1, parentAddress: 'MOTION001', datapoints: [{ name: 'MOTION', value: false, kind: 'binary', readable: true }, { name: 'BRIGHTNESS', value: 80, kind: 'sensor', readable: true }] }],
},
{
address: 'BLIND001',
name: 'Office Blind',
type: 'Blind',
interfaceName: 'rf',
available: true,
channels: [{ address: 'BLIND001:1', index: 1, parentAddress: 'BLIND001', datapoints: [{ name: 'LEVEL', value: 0.75, kind: 'write', writable: true, readable: true }] }],
},
{
address: 'THERMO001',
name: 'Bedroom Thermostat',
type: 'Thermostat',
interfaceName: 'rf',
available: true,
channels: [{ address: 'THERMO001:4', index: 4, parentAddress: 'THERMO001', datapoints: [{ name: 'SET_TEMPERATURE', value: 21, kind: 'write', writable: true, readable: true }, { name: 'ACTUAL_TEMPERATURE', value: 20.5, kind: 'sensor', readable: true }, { name: 'CONTROL_MODE', value: 1, kind: 'attribute', readable: true }] }],
},
{
address: 'LOCK001',
name: 'Front Door',
type: 'KeyMatic',
interfaceName: 'rf',
available: true,
channels: [{ address: 'LOCK001:1', index: 1, parentAddress: 'LOCK001', datapoints: [{ name: 'STATE', value: false, kind: 'write', writable: true, readable: true }, { name: 'OPEN', value: false, kind: 'action', writable: true, readable: false }] }],
},
],
events: [],
connected: true,
updatedAt: '2026-01-01T00:00:00.000Z',
source: 'manual',
};
tap.test('maps Homematic devices, channels, and datapoints to canonical devices and entities', async () => {
const devices = HomematicMapper.toDevices(snapshot);
const entities = HomematicMapper.toEntities(snapshot);
expect(devices.some((deviceArg) => deviceArg.id === 'homematic.ccu.ccu3_1234')).toBeTrue();
expect(devices.some((deviceArg) => deviceArg.id === 'homematic.device.ccu3_1234.switch001')).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'switch.kitchen_plug' && entityArg.state === 'on')).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'sensor.kitchen_plug_2_power' && entityArg.state === 42.5)).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'light.dining_light' && entityArg.attributes?.brightness === 128)).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'binary_sensor.hall_motion_motion' && entityArg.state === 'off')).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'cover.office_blind' && entityArg.attributes?.position === 75)).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'climate.bedroom_thermostat' && entityArg.attributes?.currentTemperature === 20.5)).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'lock.front_door' && entityArg.state === 'locked')).toBeTrue();
});
tap.test('maps Homematic services to XML-RPC command models', async () => {
const setCommand = HomematicMapper.commandForService(snapshot, {
domain: 'homematic',
service: 'set_value',
target: {},
data: { address: 'SWITCH001', channel: 1, datapoint: 'STATE', value: false },
});
expect(setCommand).toEqual({ type: 'set_value', address: 'SWITCH001', channel: 1, datapoint: 'STATE', value: false, interfaceName: undefined, entityId: undefined, deviceId: undefined });
const turnOffCommand = HomematicMapper.commandForService(snapshot, {
domain: 'switch',
service: 'turn_off',
target: { entityId: 'switch.kitchen_plug' },
});
expect(turnOffCommand).toEqual({ type: 'turn_off', address: 'SWITCH001', channel: 1, datapoint: 'STATE', value: false, interfaceName: 'rf', entityId: 'switch.kitchen_plug', deviceId: undefined });
const openCommand = HomematicMapper.commandForService(snapshot, {
domain: 'cover',
service: 'open',
target: { entityId: 'cover.office_blind' },
});
expect(openCommand).toEqual({ type: 'open', address: 'BLIND001', channel: 1, datapoint: 'LEVEL', value: 1, interfaceName: 'rf', entityId: 'cover.office_blind', deviceId: undefined });
const pressCommand = HomematicMapper.commandForService(snapshot, {
domain: 'homematic',
service: 'press',
target: {},
data: { address: 'SWITCH001', channel: 1, param: 'PRESS_SHORT' },
});
expect(pressCommand).toEqual({ type: 'press', address: 'SWITCH001', channel: 1, datapoint: 'PRESS_SHORT', value: undefined, interfaceName: undefined, entityId: undefined, deviceId: undefined });
});
export default tap.start();
+34
View File
@@ -0,0 +1,34 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createKnxDiscoveryDescriptor } from '../../ts/integrations/knx/index.js';
tap.test('matches KNXnet/IP gateway descriptors', async () => {
const descriptor = createKnxDiscoveryDescriptor();
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'knx-gateway-descriptor-match');
const result = await matcher!.matches({
ip_addr: '192.168.1.50',
port: 3671,
name: 'MDT SCN-IP000.03',
individual_address: '1.1.1',
supports_tunnelling: true,
supports_tunnelling_tcp: true,
supports_routing: true,
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('knx');
expect(result.candidate?.metadata?.connectionType).toEqual('tunneling_tcp');
});
tap.test('matches manual KNX/IP entries', async () => {
const descriptor = createKnxDiscoveryDescriptor();
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'knx-manual-match');
const result = await matcher!.matches({
host: '192.168.1.51',
connectionType: 'tunneling',
individualAddress: '0.0.240',
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.host).toEqual('192.168.1.51');
expect(result.candidate?.port).toEqual(3671);
});
export default tap.start();
+87
View File
@@ -0,0 +1,87 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { KnxMapper } from '../../ts/integrations/knx/index.js';
const snapshot = KnxMapper.toSnapshot({
connectionType: 'tunneling_tcp',
host: '192.168.1.50',
port: 3671,
gateway: {
ip_addr: '192.168.1.50',
port: 3671,
name: 'KNX IP Interface',
supports_tunnelling_tcp: true,
},
entities: [
{
platform: 'light',
name: 'Kitchen light',
entityId: 'light.kitchen_light',
uniqueId: 'knx_light_kitchen',
address: '1/1/1',
brightnessAddress: '1/1/2',
state: true,
},
{
platform: 'switch',
name: 'Kitchen outlet',
address: '1/2/1',
state: false,
},
{
platform: 'sensor',
name: 'Kitchen temperature',
stateAddress: '2/1/1',
type: 'temperature',
state: 21.4,
unit: 'degC',
},
{
platform: 'cover',
name: 'Living blind',
moveLongAddress: '3/1/1',
positionAddress: '3/1/2',
currentCoverPosition: 75,
},
{
platform: 'climate',
name: 'Hall thermostat',
temperatureAddress: '4/1/1',
targetTemperatureAddress: '4/1/2',
hvacMode: 'heat',
targetTemperature: 22,
},
],
});
tap.test('maps KNX group address entities to canonical entities', async () => {
const entities = KnxMapper.toEntities(snapshot);
expect(entities.some((entityArg) => entityArg.id === 'light.kitchen_light' && entityArg.state === 'on')).toBeTrue();
expect(entities.some((entityArg) => entityArg.platform === 'switch' && entityArg.state === 'off')).toBeTrue();
expect(entities.some((entityArg) => entityArg.platform === 'sensor' && entityArg.state === 21.4)).toBeTrue();
expect(entities.some((entityArg) => entityArg.platform === 'cover' && entityArg.state === 75)).toBeTrue();
expect(entities.some((entityArg) => entityArg.platform === 'climate' && entityArg.state === 'heat')).toBeTrue();
});
tap.test('maps KNX devices and entity commands', async () => {
const devices = KnxMapper.toDevices(snapshot);
const command = KnxMapper.commandForService(snapshot, {
domain: 'light',
service: 'turn_on',
target: { entityId: 'light.kitchen_light' },
data: { brightness: 128 },
});
expect(devices.some((deviceArg) => deviceArg.id.startsWith('knx.interface.'))).toBeTrue();
expect(command?.telegrams[0].address).toEqual('1/1/2');
expect(command?.telegrams[0].payload).toEqual(128);
});
tap.test('maps KNX group write and read commands', async () => {
const writeCommand = KnxMapper.groupWriteCommand(['1/0/1'], true, '1.001');
const readCommand = KnxMapper.groupReadCommand(['1/0/2']);
expect(writeCommand?.type).toEqual('group.write');
expect(writeCommand?.telegrams[0].action).toEqual('write');
expect(readCommand?.type).toEqual('group.read');
expect(readCommand?.telegrams[0].action).toEqual('read');
});
export default tap.start();
+44
View File
@@ -0,0 +1,44 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createModbusDiscoveryDescriptor } from '../../ts/integrations/modbus/index.js';
tap.test('matches manual Modbus TCP entries', async () => {
const descriptor = createModbusDiscoveryDescriptor();
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'modbus-manual-tcp-match');
const result = await matcher!.matches({
host: '192.168.1.50',
port: 502,
type: 'tcp',
name: 'Heat pump Modbus',
unitId: 2,
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('modbus');
expect(result.candidate?.port).toEqual(502);
expect(result.candidate?.metadata?.unitId).toEqual(2);
});
tap.test('does not guess serial RTU ports', async () => {
const descriptor = createModbusDiscoveryDescriptor();
const matcher = descriptor.getMatchers().find((matcherArg) => matcherArg.id === 'modbus-manual-tcp-match');
const result = await matcher!.matches({
type: 'serial',
host: '/dev/ttyUSB0',
name: 'RS485 adapter',
}, {});
expect(result.matched).toBeFalse();
expect(result.reason).toContain('Serial RTU');
});
tap.test('validates Modbus TCP candidates', async () => {
const descriptor = createModbusDiscoveryDescriptor();
const validator = descriptor.getValidators()[0];
const result = await validator.validate({
source: 'manual',
integrationDomain: 'modbus',
host: 'plc.local',
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.port).toEqual(502);
});
export default tap.start();
+102
View File
@@ -0,0 +1,102 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { ModbusClient, ModbusMapper, type IModbusConfig } from '../../ts/integrations/modbus/index.js';
const config: IModbusConfig = {
hubs: [{
name: 'plant_hub',
type: 'tcp',
host: '192.168.1.50',
port: 502,
registers: [{
name: 'Supply Temp',
address: 100,
slave: 2,
dataType: 'int16',
registers: [215],
scale: 0.1,
precision: 1,
unitOfMeasurement: 'C',
}],
numbers: [{
name: 'Setpoint',
address: 101,
slave: 2,
dataType: 'uint16',
value: 22,
min: 10,
max: 30,
step: 0.5,
writable: true,
}],
coils: [{
name: 'Pump Running',
address: 5,
slave: 2,
value: true,
}],
switches: [{
name: 'Pump Enable',
address: 6,
slave: 2,
writeType: 'coil',
value: false,
commandOn: 1,
commandOff: 0,
}],
}],
};
tap.test('maps configured Modbus registers and coils to devices and entities', async () => {
const snapshot = await new ModbusClient(config).getSnapshot();
const devices = ModbusMapper.toDevices(snapshot);
const entities = ModbusMapper.toEntities(snapshot);
expect(devices.some((deviceArg) => deviceArg.id === 'modbus.hub.plant_hub')).toBeTrue();
expect(devices.some((deviceArg) => deviceArg.id === 'modbus.slave.plant_hub.2')).toBeTrue();
expect(entities.find((entityArg) => entityArg.id === 'sensor.supply_temp')?.state).toEqual(21.5);
expect(entities.find((entityArg) => entityArg.id === 'binary_sensor.pump_running')?.state).toEqual('on');
expect(entities.find((entityArg) => entityArg.id === 'switch.pump_enable')?.state).toEqual('off');
expect(entities.find((entityArg) => entityArg.id === 'number.setpoint')?.state).toEqual(22);
});
tap.test('maps Modbus services to coil and register commands', async () => {
const snapshot = await new ModbusClient(config).getSnapshot();
const switchCommand = ModbusMapper.commandForService(snapshot, {
domain: 'switch',
service: 'turn_on',
target: { entityId: 'switch.pump_enable' },
});
expect(switchCommand).toEqual({
type: 'write_coil',
hub: 'plant_hub',
hubId: 'plant_hub',
unitId: 2,
entityId: 'switch.pump_enable',
deviceId: undefined,
uniqueId: 'modbus_plant_hub_slave_2_switch_6',
address: 6,
value: 1,
});
const readCommand = ModbusMapper.commandForService(snapshot, {
domain: 'modbus',
service: 'read_register',
target: {},
data: { hub: 'plant_hub', slave: 2, address: 100, count: 1, inputType: 'holding' },
});
expect(readCommand).toEqual({
type: 'read_register',
hub: 'plant_hub',
hubId: 'plant_hub',
unitId: 2,
entityId: undefined,
deviceId: undefined,
uniqueId: undefined,
address: 100,
count: 1,
inputType: 'holding',
dataType: undefined,
});
});
export default tap.start();
@@ -0,0 +1,31 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createOpenthermGwDiscoveryDescriptor } from '../../ts/integrations/opentherm_gw/index.js';
tap.test('matches manual OpenTherm Gateway TCP entries', async () => {
const descriptor = createOpenthermGwDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({ host: 'otgw.local', port: 25238, name: 'Boiler OTGW' }, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('opentherm_gw');
expect(result.candidate?.host).toEqual('otgw.local');
expect(result.candidate?.port).toEqual(25238);
});
tap.test('validates manual OpenTherm Gateway candidates', async () => {
const descriptor = createOpenthermGwDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({ host: '192.168.1.40', metadata: { otgw: true } }, {});
const validator = descriptor.getValidators()[0];
const validation = await validator.validate(result.candidate!, {});
expect(validation.matched).toBeTrue();
expect(validation.normalizedDeviceId).toEqual('192.168.1.40:23');
});
tap.test('rejects unrelated manual entries', async () => {
const descriptor = createOpenthermGwDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({ name: 'Kitchen Speaker', model: 'MPD' }, {});
expect(result.matched).toBeFalse();
});
export default tap.start();
@@ -0,0 +1,74 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { OpenthermGwMapper, type IOpenthermGwSnapshot } from '../../ts/integrations/opentherm_gw/index.js';
const snapshot: IOpenthermGwSnapshot = {
gateway: {
id: 'otgw-living-room',
name: 'Living Room OTGW',
host: '192.168.1.40',
port: 25238,
firmwareVersion: 'OpenTherm Gateway 5.1',
},
status: {
gateway: {
otgw_about: 'OpenTherm Gateway 5.1',
otgw_mode: 'G',
otgw_dhw_ovrd: 'A',
otgw_gpio_a: 6,
otgw_gpio_a_state: 0,
central_heating_1_override: 1,
},
boiler: {
slave_ch_active: 1,
slave_dhw_active: 1,
slave_flame_on: 1,
slave_cooling_active: 0,
slave_fault_indication: 0,
control_setpoint: 55.5,
ch_water_temp: 46.2,
dhw_temp: 51.3,
dhw_setpoint: 60,
relative_mod_level: 34,
ch_water_pressure: 1.7,
master_ch_enabled: 1,
},
thermostat: {
master_ch_enabled: 1,
master_dhw_enabled: 1,
room_temp: 20.4,
room_setpoint: 21,
outside_temp: 5.5,
},
},
online: true,
source: 'manual',
updatedAt: '2026-01-01T00:00:00.000Z',
};
tap.test('maps OpenTherm Gateway devices', async () => {
const devices = OpenthermGwMapper.toDevices(snapshot);
expect(devices.map((deviceArg) => deviceArg.id)).toContain('opentherm_gw.gateway.otgw_living_room');
expect(devices.map((deviceArg) => deviceArg.id)).toContain('opentherm_gw.boiler.otgw_living_room');
expect(devices.map((deviceArg) => deviceArg.id)).toContain('opentherm_gw.thermostat.otgw_living_room');
});
tap.test('maps climate sensors binary sensors and switches', async () => {
const entities = OpenthermGwMapper.toEntities(snapshot);
const climate = entities.find((entityArg) => entityArg.id === 'climate.living_room_otgw_thermostat');
const waterTemp = entities.find((entityArg) => entityArg.id === 'sensor.living_room_otgw_boiler_central_heating_1_water_temperature');
const flame = entities.find((entityArg) => entityArg.id === 'binary_sensor.living_room_otgw_boiler_flame');
const switchEntity = entities.find((entityArg) => entityArg.id === 'switch.living_room_otgw_central_heating_1_override');
expect(climate?.platform).toEqual('climate');
expect(climate?.state).toEqual('heat');
expect(climate?.attributes?.hvacAction).toEqual('heating');
expect(climate?.attributes?.currentTemperature).toEqual(20.4);
expect(waterTemp?.state).toEqual(46.2);
expect(waterTemp?.attributes?.unitOfMeasurement).toEqual('C');
expect(flame?.platform).toEqual('binary_sensor');
expect(flame?.state).toEqual('on');
expect(switchEntity?.platform).toEqual('switch');
expect(switchEntity?.state).toEqual('on');
});
export default tap.start();
+49
View File
@@ -0,0 +1,49 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createRflinkDiscoveryDescriptor } from '../../ts/integrations/rflink/index.js';
tap.test('matches manual RFLink serial gateway entries', async () => {
const descriptor = createRflinkDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({
connectionType: 'serial',
port: '/dev/serial/by-id/usb-Nodo_RFLink_Gateway',
baudRate: 57600,
name: 'RFLink Gateway',
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.integrationDomain).toEqual('rflink');
expect(result.candidate?.metadata?.connectionType).toEqual('serial');
expect(result.candidate?.metadata?.serialPort).toEqual('/dev/serial/by-id/usb-Nodo_RFLink_Gateway');
});
tap.test('matches manual RFLink TCP bridge entries', async () => {
const descriptor = createRflinkDiscoveryDescriptor();
const matcher = descriptor.getMatchers()[0];
const result = await matcher.matches({
connectionType: 'tcp',
host: '192.168.1.34',
port: 1234,
metadata: { rflink: true },
}, {});
expect(result.matched).toBeTrue();
expect(result.candidate?.host).toEqual('192.168.1.34');
expect(result.candidate?.port).toEqual(1234);
expect(result.candidate?.metadata?.connectionType).toEqual('tcp');
});
tap.test('validates RFLink gateway candidates', async () => {
const descriptor = createRflinkDiscoveryDescriptor();
const validator = descriptor.getValidators()[0];
const result = await validator.validate({
source: 'manual',
integrationDomain: 'rflink',
name: 'RFLink over TCP',
host: '192.168.1.35',
port: 1234,
metadata: { connectionType: 'tcp' },
}, {});
expect(result.matched).toBeTrue();
expect(result.normalizedDeviceId).toEqual('192.168.1.35');
});
export default tap.start();
+76
View File
@@ -0,0 +1,76 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { RflinkClient, RflinkMapper } from '../../ts/integrations/rflink/index.js';
import type { IRflinkSnapshot } from '../../ts/integrations/rflink/index.js';
const snapshot: IRflinkSnapshot = {
gateway: {
id: 'rflink-gateway',
name: 'Nodo RFLink',
connectionType: 'tcp',
host: '192.168.1.34',
port: 1234,
firmware: 'RFLink Gateway',
version: '1.1',
revision: '46',
online: true,
},
connected: true,
updatedAt: '2026-05-05T00:00:00.000Z',
devices: [],
events: [],
entities: [
{ id: 'newkaku_0000c6c2_1', platform: 'light', name: 'Kitchen Lamp', type: 'hybrid', state: 'on', brightness: 170, aliases: ['kaku_000001_a'] },
{ id: 'conrad_00785c_0a', platform: 'switch', name: 'Ceiling Fan', state: 'off' },
{ id: 'alectov1_0334_temp', platform: 'sensor', name: 'Outdoor Temperature', sensorType: 'temperature', value: 7.4, unitOfMeasurement: '°C' },
{ id: 'pt2262_00174754_0', platform: 'binary_sensor', name: 'PIR Entrance', deviceClass: 'motion', state: 'on' },
{ id: 'newkaku_0a8720_0', platform: 'cover', name: 'Office Blind', type: 'inverted', state: 'closed' },
],
};
tap.test('maps RFLink snapshots to gateway and RF device definitions', async () => {
const devices = RflinkMapper.toDevices(snapshot);
expect(devices.length).toEqual(6);
expect(devices[0].id).toEqual('rflink.gateway.rflink_gateway');
expect(devices.find((deviceArg) => deviceArg.id === 'rflink.light.newkaku_0000c6c2_1')?.features.some((featureArg) => featureArg.id === 'brightness')).toBeTrue();
expect(devices.find((deviceArg) => deviceArg.id === 'rflink.sensor.alectov1_0334_temp')?.state[0].value).toEqual(7.4);
});
tap.test('maps RFLink entities to Home Assistant-style platforms', async () => {
const entities = RflinkMapper.toEntities(snapshot);
expect(entities.map((entityArg) => entityArg.platform)).toContain('light');
expect(entities.map((entityArg) => entityArg.platform)).toContain('switch');
expect(entities.map((entityArg) => entityArg.platform)).toContain('sensor');
expect(entities.map((entityArg) => entityArg.platform)).toContain('binary_sensor');
expect(entities.map((entityArg) => entityArg.platform)).toContain('cover');
expect(entities.find((entityArg) => entityArg.id === 'sensor.outdoor_temperature')?.attributes?.unitOfMeasurement).toEqual('°C');
expect(entities.find((entityArg) => entityArg.id === 'cover.office_blind')?.state).toEqual('closed');
});
tap.test('maps RFLink services to line protocol commands', async () => {
const closeCommand = RflinkMapper.commandForService(snapshot, {
domain: 'cover',
service: 'close_cover',
target: { entityId: 'cover.office_blind' },
data: {},
});
expect(closeCommand?.rflinkCommand).toEqual('UP');
expect(RflinkClient.commandShape(closeCommand?.deviceId || '', closeCommand?.rflinkCommand || '').line).toEqual('10;newkaku;0a8720;0;UP;');
const dimCommand = RflinkMapper.commandForService(snapshot, {
domain: 'light',
service: 'turn_on',
target: { entityId: 'light.kitchen_lamp' },
data: { brightness: 128 },
});
expect(dimCommand?.type).toEqual('set_value');
expect(dimCommand?.rflinkCommand).toEqual('7');
});
tap.test('decodes RFLink sensor line packets into events', async () => {
const packet = RflinkClient.decodeLine('20;00;Alecto V1;ID=0334;TEMP=004a;HUM=26;BAT=OK;');
const events = packet ? RflinkClient.eventsFromPacket(packet) : [];
expect(events.find((eventArg) => eventArg.id === 'alectov1_0334_temp')?.value).toEqual(7.4);
expect(events.find((eventArg) => eventArg.id === 'alectov1_0334_hum')?.value).toEqual(26);
});
export default tap.start();
+64
View File
@@ -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();
+92
View File
@@ -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();