Files

60 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2026-05-05 14:57:06 +00:00
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { NanoleafMapper } from '../../ts/integrations/nanoleaf/index.js';
const snapshot = {
controllerInfo: {
name: 'Living Room Shapes',
serialNo: 'NL123ABC',
manufacturer: 'Nanoleaf',
model: 'NL42',
firmwareVersion: '9.6.1',
},
state: {
on: { value: true },
brightness: { value: 80, min: 0, max: 100 },
hue: { value: 220, min: 0, max: 360 },
sat: { value: 65, min: 0, max: 100 },
ct: { value: 4000, min: 1200, max: 6500 },
colorMode: 'effect',
},
effects: {
select: 'Northern Lights',
effectsList: ['Northern Lights', '*Solid*'],
},
panelLayout: {
layout: {
numPanels: 2,
sideLength: 150,
positionData: [
{ panelId: 101, x: 0, y: 0, o: 0, shapeType: 7 },
{ panelId: 102, x: 150, y: 0, o: 60, shapeType: 7 },
],
},
},
rhythm: {
rhythmConnected: true,
rhythmActive: false,
},
};
tap.test('maps Nanoleaf controller and panels to canonical devices', async () => {
const devices = NanoleafMapper.toDevices(snapshot);
expect(devices[0].id).toEqual('nanoleaf.controller.nl123abc');
expect(devices[0].features.some((featureArg) => featureArg.id === 'panel_count')).toBeTrue();
expect(devices.some((deviceArg) => deviceArg.id === 'nanoleaf.panel.nl123abc.101')).toBeTrue();
});
tap.test('maps Nanoleaf light state, sensors, select, and button entities', async () => {
const entities = NanoleafMapper.toEntities(snapshot);
const light = entities.find((entityArg) => entityArg.id === 'light.living_room_shapes');
const effect = entities.find((entityArg) => entityArg.id === 'select.living_room_shapes_effect');
expect(light?.state).toEqual('on');
expect(light?.attributes?.brightness).toEqual(80);
expect(effect?.state).toEqual('Northern Lights');
expect(entities.some((entityArg) => entityArg.id === 'button.living_room_shapes_identify')).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'sensor.living_room_shapes_panel_count')).toBeTrue();
expect(entities.some((entityArg) => entityArg.id === 'sensor.living_room_shapes_panel_101')).toBeTrue();
});
export default tap.start();