homebridge-bthome
Advanced tools
Comparing version 1.1.0 to 1.2.0-beta.0
@@ -13,2 +13,3 @@ import { BluetoothDevice } from './types.js'; | ||
private generateDeviceName; | ||
private decodeManufacturerData; | ||
} |
import { EventEmitter } from 'events'; | ||
import { BluetoothError } from './types.js'; | ||
import { wrapError } from '../util/errors.js'; | ||
import { decodeShellyManufacturerData } from './shelly.js'; | ||
export class BluetoothScanner { | ||
@@ -56,3 +57,7 @@ static DISCOVER_EVENT = 'discover'; | ||
const serviceData = service.data; | ||
const device = { name, mac, serviceData }; | ||
const manufacturerData = this.decodeManufacturerData(advertisementData.manufacturerData); | ||
if (!manufacturerData.serialNumber) { | ||
manufacturerData.serialNumber = mac; | ||
} | ||
const device = { name, mac, serviceData, manufacturerData }; | ||
this.events.emit(BluetoothScanner.DISCOVER_EVENT, device); | ||
@@ -63,3 +68,15 @@ } | ||
} | ||
decodeManufacturerData(data) { | ||
if (!data) { | ||
return {}; | ||
} | ||
const companyIdentifier = data.readUInt16LE(0); | ||
switch (companyIdentifier) { | ||
case 0x0BA9: | ||
return decodeShellyManufacturerData(data); | ||
default: | ||
return {}; | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -5,4 +5,10 @@ export type BluetoothDevice = { | ||
serviceData: Buffer; | ||
manufacturerData: ManufacturerData; | ||
}; | ||
export type ManufacturerData = { | ||
manufacturer?: string; | ||
model?: string; | ||
serialNumber?: string; | ||
}; | ||
export declare class BluetoothError extends Error { | ||
} |
import { BTHomeSensorData } from './types.js'; | ||
import { ManufacturerData } from '../bluetooth/types.js'; | ||
export declare class BTHomeDevice { | ||
@@ -8,6 +9,7 @@ static readonly UUID = "FCD2"; | ||
private readonly mac; | ||
private readonly manufacturerData; | ||
private readonly encryptionKey?; | ||
private readonly events; | ||
private lastSensorData?; | ||
constructor(mac: string, encryptionKey?: string, initialPayload?: Buffer); | ||
constructor(mac: string, manufacturerData: ManufacturerData, encryptionKey?: string, initialPayload?: Buffer); | ||
update(payload: Buffer): void; | ||
@@ -17,2 +19,3 @@ onUpdate(callback: (data: BTHomeSensorData) => void): void; | ||
getMACAddress(): string; | ||
getManufacturerData(): ManufacturerData; | ||
private decodePayload; | ||
@@ -19,0 +22,0 @@ private decryptPayload; |
@@ -11,7 +11,9 @@ import crypto from 'crypto'; | ||
mac; | ||
manufacturerData; | ||
encryptionKey; | ||
events = new EventEmitter(); | ||
lastSensorData; | ||
constructor(mac, encryptionKey, initialPayload) { | ||
constructor(mac, manufacturerData, encryptionKey, initialPayload) { | ||
this.mac = Buffer.from(mac.replaceAll(':', ''), 'hex'); | ||
this.manufacturerData = manufacturerData; | ||
this.encryptionKey = encryptionKey?.length ? Buffer.from(encryptionKey, 'hex') : undefined; | ||
@@ -43,2 +45,5 @@ if (initialPayload) { | ||
} | ||
getManufacturerData() { | ||
return Object.assign({}, this.manufacturerData); | ||
} | ||
decodePayload(payload) { | ||
@@ -97,2 +102,11 @@ const flags = payload.readUInt8(0); | ||
break; | ||
// Firmware version | ||
case 0xF1: | ||
result.firmwareVersion = `${data[offset + 4]}.${data[offset + 3]}.${data[offset + 2]}.${data[offset + 1]}`; | ||
offset += 5; | ||
break; | ||
case 0xF2: | ||
result.firmwareVersion = `${data[offset + 3]}.${data[offset + 2]}.${data[offset + 1]}`; | ||
offset += 4; | ||
break; | ||
// Battery | ||
@@ -208,3 +222,2 @@ case 0x01: | ||
case 0x3C: | ||
case 0xF2: | ||
offset += 4; | ||
@@ -221,3 +234,2 @@ break; | ||
case 0x55: | ||
case 0xF1: | ||
offset += 5; | ||
@@ -224,0 +236,0 @@ break; |
export type BTHomeSensorData = { | ||
id?: number; | ||
firmwareVersion?: string; | ||
counter?: number; | ||
@@ -4,0 +5,0 @@ temperature?: number; |
@@ -57,3 +57,3 @@ import { BTHomeAccessory } from './platformAccessory.js'; | ||
this.log.info('Restoring existing accessory from cache:', accessory.displayName); | ||
accessory.context.device = new BTHomeDevice(mac, config.encryptionKey, device.serviceData); | ||
accessory.context.device = new BTHomeDevice(mac, device.manufacturerData, config.encryptionKey, device.serviceData); | ||
this.handles.set(uuid, new BTHomeAccessory(this, accessory)); | ||
@@ -65,3 +65,3 @@ } | ||
accessory = new this.api.platformAccessory(name, uuid); | ||
accessory.context.device = new BTHomeDevice(mac, config.encryptionKey, device.serviceData); | ||
accessory.context.device = new BTHomeDevice(mac, device.manufacturerData, config.encryptionKey, device.serviceData); | ||
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); | ||
@@ -68,0 +68,0 @@ this.discoveredCacheUUIDs.push(uuid); |
@@ -23,2 +23,3 @@ import type { PlatformAccessory } from 'homebridge'; | ||
private handleButtonEvent; | ||
private updateFirmwareVersion; | ||
} |
@@ -11,7 +11,8 @@ import { ButtonEvent } from './bthome/types.js'; | ||
this.accessory = accessory; | ||
const device = this.getDevice(); | ||
const manufacturerData = device.getManufacturerData(); | ||
this.accessory.getService(this.platform.Service.AccessoryInformation) | ||
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Default-Manufacturer') | ||
.setCharacteristic(this.platform.Characteristic.Model, 'Default-Model') | ||
.setCharacteristic(this.platform.Characteristic.SerialNumber, 'Default-Serial'); | ||
const device = this.getDevice(); | ||
.setCharacteristic(this.platform.Characteristic.Manufacturer, manufacturerData.manufacturer || 'Unknown') | ||
.setCharacteristic(this.platform.Characteristic.Model, manufacturerData.model || 'Unknown') | ||
.setCharacteristic(this.platform.Characteristic.SerialNumber, manufacturerData.serialNumber || 'Unknown'); | ||
this.setupServices(); | ||
@@ -51,3 +52,3 @@ device.onUpdate(this.onDeviceUpdate.bind(this)); | ||
} | ||
/* Sensor specific characteristic and events begin here */ | ||
/* Characteristics related code begin here */ | ||
setupServices() { | ||
@@ -134,2 +135,5 @@ const device = this.getDevice(); | ||
} | ||
if (sensorData?.firmwareVersion) { | ||
this.updateFirmwareVersion(sensorData.firmwareVersion); | ||
} | ||
} | ||
@@ -181,3 +185,10 @@ getDevice() { | ||
} | ||
updateFirmwareVersion(version) { | ||
const service = this.accessory.getService(this.platform.Service.AccessoryInformation); | ||
if (!service) { | ||
return; | ||
} | ||
service.setCharacteristic(this.platform.Characteristic.FirmwareRevision, version); | ||
} | ||
} | ||
//# sourceMappingURL=platformAccessory.js.map |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.1.0", | ||
"version": "1.2.0-beta.0", | ||
"description": "A homebridge plugin that adds support for bluetooth devices that use BTHome protocol.", | ||
@@ -8,0 +8,0 @@ "author": "Boris Yonchev", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
71756
34
899
1