Add native hub protocol integrations
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { createYeelightDiscoveryDescriptor } from '../../ts/integrations/yeelight/index.js';
|
||||
|
||||
tap.test('matches Yeelight SSDP wifi_bulb responses', async () => {
|
||||
const descriptor = createYeelightDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[0];
|
||||
const result = await matcher.matches({
|
||||
location: 'yeelight://192.168.1.25:55443',
|
||||
id: '0x0000000002eb9f61',
|
||||
model: 'color',
|
||||
support: 'get_prop set_power set_bright set_rgb set_ct_abx',
|
||||
st: 'wifi_bulb',
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.normalizedDeviceId).toEqual('0x0000000002eb9f61');
|
||||
expect(result.candidate?.host).toEqual('192.168.1.25');
|
||||
expect(result.candidate?.port).toEqual(55443);
|
||||
});
|
||||
|
||||
tap.test('matches Yeelight mDNS records', async () => {
|
||||
const descriptor = createYeelightDiscoveryDescriptor();
|
||||
const matcher = descriptor.getMatchers()[1];
|
||||
const result = await matcher.matches({
|
||||
name: 'yeelink-light-color1_mibt1234',
|
||||
type: '_miio._udp.local.',
|
||||
host: 'yeelight-kitchen.local',
|
||||
txt: {
|
||||
id: '0x0000000002eb9f62',
|
||||
model: 'YLDP02YL',
|
||||
},
|
||||
}, {});
|
||||
expect(result.matched).toBeTrue();
|
||||
expect(result.candidate?.manufacturer).toEqual('Yeelight');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
@@ -0,0 +1,40 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { YeelightMapper } from '../../ts/integrations/yeelight/index.js';
|
||||
|
||||
const snapshot = {
|
||||
connected: true,
|
||||
bulbs: [
|
||||
{
|
||||
id: '0x0000000002eb9f61',
|
||||
host: '192.168.1.25',
|
||||
port: 55443,
|
||||
name: 'Kitchen Bulb',
|
||||
model: 'color',
|
||||
support: ['get_prop', 'set_power', 'set_bright', 'set_rgb', 'set_ct_abx'],
|
||||
available: true,
|
||||
properties: {
|
||||
power: 'on',
|
||||
bright: '80',
|
||||
ct: '3700',
|
||||
rgb: '16711680',
|
||||
hue: '0',
|
||||
sat: '100',
|
||||
color_mode: '1',
|
||||
flowing: '0',
|
||||
nl_br: '0',
|
||||
},
|
||||
},
|
||||
],
|
||||
events: [],
|
||||
};
|
||||
|
||||
tap.test('maps Yeelight bulbs to canonical devices and light/sensor entities', async () => {
|
||||
const devices = YeelightMapper.toDevices(snapshot);
|
||||
const entities = YeelightMapper.toEntities(snapshot);
|
||||
expect(devices[0].id).toEqual('yeelight.bulb.0x0000000002eb9f61');
|
||||
expect(devices[0].features.some((featureArg) => featureArg.id === 'color_temperature')).toBeTrue();
|
||||
expect(entities[0].id).toEqual('light.kitchen_bulb');
|
||||
expect(entities.some((entityArg) => entityArg.id === 'sensor.kitchen_bulb_color_temperature')).toBeTrue();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user