UNPKG

matterbridge-bthome

Version:
71 lines (70 loc) 2.36 kB
const SHELLY_MODEL_LONG_NAMES = { 0x0001: 'Shelly BLU Button1', 0x0002: 'Shelly BLU DoorWindow', 0x0003: 'Shelly BLU HT', 0x0005: 'Shelly BLU Motion', 0x0006: 'Shelly BLU Wall Switch 4', 0x0007: 'Shelly BLU RC Button 4', 0x0008: 'Shelly BLU TRV', }; const SHELLY_MODEL_SHORT_NAMES = { 0x0001: 'SBBT-002C', 0x0002: 'SBDW-002C', 0x0003: 'SBHT-003C', 0x0005: 'SBMO-003Z', 0x0006: 'SBBT-004CEU', 0x0007: 'SBBT-004CUS', 0x0008: 'SBTR-001AEU', }; export function getShellyBluLongName(id) { return SHELLY_MODEL_LONG_NAMES[id]; } export function getShellyBluShortName(id) { return SHELLY_MODEL_SHORT_NAMES[id]; } export function decodeShellyManufacturerData(input) { if (input.length < 10) return null; const buf = Buffer.isBuffer(input) ? input : Buffer.from(input.replace(/\s+/g, ''), 'hex'); let offset = 0; const companyId = buf.readUInt16LE(offset); if (companyId !== 0x0ba9) return null; offset += 2; const result = { companyId }; while (offset < buf.length) { const blockType = buf.readUInt8(offset++); switch (blockType) { case 0x01: { const flagsRaw = buf.readUInt16LE(offset); offset += 2; result.flags = { discoverable: Boolean(flagsRaw & (1 << 0)), authEnabled: Boolean(flagsRaw & (1 << 1)), rpcEnabled: Boolean(flagsRaw & (1 << 2)), buzzerEnabled: Boolean(flagsRaw & (1 << 3)), inPairingMode: Boolean(flagsRaw & (1 << 4)), }; break; } case 0x0b: { const modelId = buf.readUInt16LE(offset); offset += 2; result.modelId = modelId; result.modelIdShortName = getShellyBluShortName(modelId); result.modelIdLongName = getShellyBluLongName(modelId); break; } case 0x0a: { const macBytes = buf.slice(offset, offset + 6); offset += 6; result.mac = macBytes.toString('hex').match(/.{2}/g)?.join(':'); break; } default: offset = buf.length; break; } } return result; }