1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +01:00

Add support for additional Xiaomi BLE sensors (#1027) (#1027)

This commit is contained in:
Alexander Pohl
2020-05-27 00:33:28 +02:00
committed by GitHub
parent e64246f642
commit 3fba3a5e2e
48 changed files with 1875 additions and 276 deletions

View File

@@ -566,6 +566,23 @@ def mac_address(value):
return core.MACAddress(*parts_int)
def bind_key(value):
value = string_strict(value)
parts = [value[i:i+2] for i in range(0, len(value), 2)]
if len(parts) != 16:
raise Invalid("Bind key must consist of 16 hexadecimal numbers")
parts_int = []
if any(len(part) != 2 for part in parts):
raise Invalid("Bind key must be format XX")
for part in parts:
try:
parts_int.append(int(part, 16))
except ValueError:
raise Invalid("Bind key must be hex values from 00 to FF")
return ''.join(f'{part:02X}' for part in parts_int)
def uuid(value):
return Coerce(uuid_.UUID)(value)