Add native local infrastructure integrations
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { HomeAssistantDevoloHomeNetworkIntegration, type IDevoloCommand, type IDevoloConfig } from '../../ts/integrations/devolo_home_network/index.js';
|
||||
|
||||
const config: IDevoloConfig = {
|
||||
host: '192.168.1.20',
|
||||
name: 'Office Adapter',
|
||||
serialNumber: 'S12345',
|
||||
features: ['led'],
|
||||
switches: { leds: true },
|
||||
};
|
||||
|
||||
tap.test('does not fake devolo command success without an injected executor', async () => {
|
||||
const runtime = await new HomeAssistantDevoloHomeNetworkIntegration().setup(config, {});
|
||||
const result = await runtime.callService!({
|
||||
domain: 'switch',
|
||||
service: 'turn_off',
|
||||
target: { entityId: 'switch.office_adapter_enable_leds' },
|
||||
});
|
||||
|
||||
expect(result.success).toBeFalse();
|
||||
expect(result.error || '').toInclude('not faked');
|
||||
await runtime.destroy();
|
||||
});
|
||||
|
||||
tap.test('executes devolo commands through an injected executor', async () => {
|
||||
let command: IDevoloCommand | undefined;
|
||||
const runtime = await new HomeAssistantDevoloHomeNetworkIntegration().setup({
|
||||
...config,
|
||||
commandExecutor: async (commandArg) => {
|
||||
command = commandArg;
|
||||
return { success: true, data: { accepted: true } };
|
||||
},
|
||||
}, {});
|
||||
const result = await runtime.callService!({
|
||||
domain: 'switch',
|
||||
service: 'turn_off',
|
||||
target: { entityId: 'switch.office_adapter_enable_leds' },
|
||||
});
|
||||
|
||||
expect(result.success).toBeTrue();
|
||||
expect(command?.type).toEqual('device.set_leds');
|
||||
expect(command?.enabled).toEqual(false);
|
||||
await runtime.destroy();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,36 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { DevoloHomeNetworkConfigFlow } from '../../ts/integrations/devolo_home_network/index.js';
|
||||
|
||||
tap.test('creates devolo config from local discovery candidate', async () => {
|
||||
const flow = new DevoloHomeNetworkConfigFlow();
|
||||
const step = await flow.start({
|
||||
source: 'mdns',
|
||||
integrationDomain: 'devolo_home_network',
|
||||
id: 'S12345',
|
||||
host: '192.168.1.20',
|
||||
name: 'Office Adapter',
|
||||
model: 'Magic 2 WiFi 6',
|
||||
metadata: { MT: '8528', SN: 'S12345' },
|
||||
}, {});
|
||||
const done = await step.submit!({ password: 'local-secret' });
|
||||
|
||||
expect(step.kind).toEqual('form');
|
||||
expect(done.kind).toEqual('done');
|
||||
expect(done.config?.host).toEqual('192.168.1.20');
|
||||
expect(done.config?.serialNumber).toEqual('S12345');
|
||||
expect(done.config?.metadata?.liveHttpImplemented).toEqual(false);
|
||||
});
|
||||
|
||||
tap.test('rejects unsupported Home Control candidates in config flow', async () => {
|
||||
const flow = new DevoloHomeNetworkConfigFlow();
|
||||
const step = await flow.start({
|
||||
source: 'mdns',
|
||||
integrationDomain: 'devolo_home_network',
|
||||
host: '192.168.1.21',
|
||||
metadata: { homeControl: true },
|
||||
}, {});
|
||||
|
||||
expect(step.kind).toEqual('error');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,66 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createDevoloHomeNetworkDiscoveryDescriptor } from '../../ts/integrations/devolo_home_network/index.js';
|
||||
|
||||
tap.test('matches devolo device API mDNS records', async () => {
|
||||
const descriptor = createDevoloHomeNetworkDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_dvl-deviceapi._tcp.local.',
|
||||
name: 'devolo-office._dvl-deviceapi._tcp.local.',
|
||||
host: '192.168.1.20',
|
||||
port: 80,
|
||||
txt: {
|
||||
Product: 'Magic 2 WiFi 6',
|
||||
SN: 'S12345',
|
||||
MT: '8528',
|
||||
},
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.integrationDomain).toEqual('devolo_home_network');
|
||||
expect(result.normalizedDeviceId).toEqual('S12345');
|
||||
expect(result.candidate?.metadata?.MT).toEqual('8528');
|
||||
});
|
||||
|
||||
tap.test('rejects devolo Home Control central units', async () => {
|
||||
const descriptor = createDevoloHomeNetworkDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
type: '_dvl-deviceapi._tcp.local.',
|
||||
host: '192.168.1.21',
|
||||
txt: { Product: 'Home Control Central Unit', SN: 'HC1', MT: '2600' },
|
||||
}, {});
|
||||
|
||||
expect(result.matched).toBeFalse();
|
||||
expect(result.metadata?.homeControl).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('matches and validates manual snapshot candidates', async () => {
|
||||
const descriptor = createDevoloHomeNetworkDiscoveryDescriptor();
|
||||
const manualMatcher = descriptor.getMatchers()[1];
|
||||
const validator = descriptor.getValidators()[0];
|
||||
const manual = await manualMatcher.matches({
|
||||
host: '192.168.1.22',
|
||||
product: 'devolo Magic 2 LAN',
|
||||
serialNumber: 'S67890',
|
||||
snapshot: {
|
||||
connected: true,
|
||||
device: { host: '192.168.1.22', name: 'Basement Adapter', serialNumber: 'S67890' },
|
||||
plcDevices: [],
|
||||
plcLinks: [],
|
||||
wifiStations: [],
|
||||
neighboringWifiNetworks: [],
|
||||
sensors: {},
|
||||
switches: {},
|
||||
actions: [],
|
||||
events: [],
|
||||
},
|
||||
}, {});
|
||||
const validated = await validator.validate(manual.candidate!, {});
|
||||
|
||||
expect(manual.matched).toBeTrue();
|
||||
expect(validated.matched).toBeTrue();
|
||||
expect(validated.metadata?.liveHttpImplemented).toEqual(false);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,107 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { DevoloHomeNetworkMapper, type IDevoloConfig } from '../../ts/integrations/devolo_home_network/index.js';
|
||||
|
||||
const config: IDevoloConfig = {
|
||||
host: '192.168.1.20',
|
||||
name: 'Office Adapter',
|
||||
product: 'Magic 2 WiFi 6',
|
||||
serialNumber: 'S12345',
|
||||
macAddress: 'AA-AA-AA-AA-AA-AA',
|
||||
firmwareVersion: '5.10.0',
|
||||
features: ['led', 'restart', 'update', 'wifi1'],
|
||||
plcDevices: [
|
||||
{
|
||||
macAddress: 'AA:AA:AA:AA:AA:AA',
|
||||
userDeviceName: 'Office Adapter',
|
||||
topology: 'LOCAL',
|
||||
attachedToRouter: true,
|
||||
},
|
||||
{
|
||||
macAddress: 'BB:BB:BB:BB:BB:BB',
|
||||
userDeviceName: 'Garage Adapter',
|
||||
topology: 'REMOTE',
|
||||
attachedToRouter: true,
|
||||
},
|
||||
],
|
||||
plcLinks: [
|
||||
{
|
||||
macAddressFrom: 'AA:AA:AA:AA:AA:AA',
|
||||
macAddressTo: 'BB:BB:BB:BB:BB:BB',
|
||||
rxRate: 410,
|
||||
txRate: 395,
|
||||
},
|
||||
],
|
||||
wifiStations: [
|
||||
{
|
||||
macAddress: 'CC:CC:CC:CC:CC:CC',
|
||||
hostname: 'Kitchen Tablet',
|
||||
ipAddress: '192.168.1.44',
|
||||
band: 1,
|
||||
vapType: 0,
|
||||
rssi: -55,
|
||||
},
|
||||
],
|
||||
neighboringWifiNetworks: [
|
||||
{ ssid: 'Neighbor', bssid: 'DD:DD:DD:DD:DD:DD', band: 1, channel: 44, rssi: -70 },
|
||||
],
|
||||
switches: {
|
||||
leds: true,
|
||||
guestWifi: { enabled: false, ssid: 'Guest', key: 'secret' },
|
||||
},
|
||||
firmware: {
|
||||
installedVersion: '5.10.0',
|
||||
latestVersion: '5.11.0',
|
||||
},
|
||||
};
|
||||
|
||||
tap.test('maps devolo PLC/Wi-Fi snapshot to devices and HA-style entities', async () => {
|
||||
const snapshot = DevoloHomeNetworkMapper.toSnapshot(config);
|
||||
const devices = DevoloHomeNetworkMapper.toDevices(snapshot);
|
||||
const entities = DevoloHomeNetworkMapper.toEntities(snapshot);
|
||||
|
||||
expect(snapshot.connected).toBeTrue();
|
||||
expect(snapshot.sensors.connected_plc_devices).toEqual(1);
|
||||
expect(snapshot.sensors.connected_wifi_clients).toEqual(1);
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'devolo_home_network.device.s12345')).toBeTrue();
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'devolo_home_network.plc.bb_bb_bb_bb_bb_bb')).toBeTrue();
|
||||
expect(devices.some((deviceArg) => deviceArg.id === 'devolo_home_network.station.cc_cc_cc_cc_cc_cc')).toBeTrue();
|
||||
expect(entities.find((entityArg) => entityArg.id === 'sensor.office_adapter_connected_wifi_clients')?.state).toEqual(1);
|
||||
expect(entities.find((entityArg) => entityArg.id === 'sensor.office_adapter_plc_downlink_phy_rate_garage_adapter')?.state).toEqual(410);
|
||||
expect(entities.find((entityArg) => entityArg.id === 'sensor.office_adapter_plc_uplink_phy_rate_garage_adapter')?.state).toEqual(395);
|
||||
expect(entities.find((entityArg) => entityArg.id === 'switch.office_adapter_enable_leds')?.state).toEqual('on');
|
||||
expect(entities.find((entityArg) => entityArg.id === 'switch.office_adapter_enable_guest_wi_fi')?.state).toEqual('off');
|
||||
expect(entities.find((entityArg) => entityArg.id === 'update.office_adapter_regular_firmware')?.attributes?.latestVersion).toEqual('5.11.0');
|
||||
expect(entities.find((entityArg) => entityArg.id === 'sensor.kitchen_tablet_wi_fi_band')?.state).toEqual('5');
|
||||
});
|
||||
|
||||
tap.test('maps only represented devolo service actions to safe commands', async () => {
|
||||
const snapshot = DevoloHomeNetworkMapper.toSnapshot(config);
|
||||
const ledCommand = DevoloHomeNetworkMapper.commandForService(snapshot, {
|
||||
domain: 'switch',
|
||||
service: 'turn_off',
|
||||
target: { entityId: 'switch.office_adapter_enable_leds' },
|
||||
});
|
||||
const restartCommand = DevoloHomeNetworkMapper.commandForService(snapshot, {
|
||||
domain: 'button',
|
||||
service: 'press',
|
||||
target: { entityId: 'button.office_adapter_restart_device' },
|
||||
});
|
||||
const updateCommand = DevoloHomeNetworkMapper.commandForService(snapshot, {
|
||||
domain: 'update',
|
||||
service: 'install',
|
||||
target: { entityId: 'update.office_adapter_regular_firmware' },
|
||||
});
|
||||
const unsupported = DevoloHomeNetworkMapper.commandForService(DevoloHomeNetworkMapper.toSnapshot({ ...config, features: ['wifi1'], actions: [] }), {
|
||||
domain: 'button',
|
||||
service: 'press',
|
||||
target: { entityId: 'button.office_adapter_restart_device' },
|
||||
});
|
||||
|
||||
expect(ledCommand?.type).toEqual('device.set_leds');
|
||||
expect(ledCommand?.enabled).toEqual(false);
|
||||
expect(restartCommand?.type).toEqual('device.restart');
|
||||
expect(updateCommand?.type).toEqual('firmware.install');
|
||||
expect(unsupported).toBeUndefined();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user