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,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();