generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented manufacturer data parsing
As the data format is different for each manufacturer, its decoding need to be implemented per vendor. Currently supported one is Shelly as the majority of BTHome devices on the market are made by Shelly.
- Loading branch information
Showing
7 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ManufacturerData } from './types'; | ||
|
||
function decodeModelName(identifier: number) : (string | undefined) { | ||
switch (identifier) { | ||
case 0x0001: | ||
return 'Shelly BLU Button1'; | ||
case 0x0002: | ||
return 'Shelly BLU DoorWindow'; | ||
case 0x0003: | ||
return 'Shelly BLU HT'; | ||
case 0x0005: | ||
return 'Shelly BLU Motion'; | ||
case 0x0006: | ||
return 'Shelly BLU Wall Switch 4'; | ||
case 0x0007: | ||
return 'Shelly BLU RC Button 4'; | ||
case 0x0008: | ||
return 'Shelly BLU TRV'; | ||
} | ||
} | ||
|
||
export function decodeShellyManufacturerData(data: Buffer) : ManufacturerData { | ||
const result : ManufacturerData = { manufacturer: 'Shelly' }; | ||
|
||
let offset = 2; | ||
while (offset < data.length) { | ||
const blockType = data[offset]; | ||
|
||
switch (blockType) { | ||
case 0x01: | ||
offset += 3; | ||
break; | ||
case 0x0A: | ||
offset += 7; | ||
break; | ||
case 0x0B: | ||
result.model = decodeModelName(data.readUInt16LE(offset + 1)); | ||
offset += 3; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
export type BluetoothDevice = { | ||
name: string, | ||
mac: string, | ||
serviceData: Buffer | ||
serviceData: Buffer, | ||
manufacturerData: ManufacturerData | ||
}; | ||
|
||
export type ManufacturerData = { | ||
manufacturer?: string, | ||
model? : string, | ||
serialNumber? : string | ||
}; | ||
|
||
export class BluetoothError extends Error {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters