Skip to content

Commit

Permalink
Add Xiaomi Door Sensor BLE #19
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 11, 2020
1 parent 61c6038 commit 960c064
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions custom_components/xiaomi_gateway3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_device(zigbee_model: str) -> Optional[dict]:


def get_ble_domain(param: str) -> Optional[str]:
if param in ('motion', 'is_active'):
if param in ('motion', 'is_active', 'contact', 'light'):
return 'binary_sensor'

elif param in ('temperature', 'humidity', 'illuminance', 'moisture',
Expand All @@ -298,7 +298,12 @@ def parse_xiaomi_ble(event: dict) -> Optional[dict]:
raw = event['eid'].to_bytes(length=2, byteorder='little')
data = bytes.fromhex(event['edata'])

if raw[0] == 0x03 and len(data) == 1:
if raw[0] == 0x01 and len(data) == 3: # magic cube
return {
'action': 'right' if data == b'\x00\x00\x00' else 'left'
}

elif raw[0] == 0x03 and len(data) == 1:
return {'motion': bool(data)}

elif raw[0] == 0x04 and len(data) == 2:
Expand Down Expand Up @@ -351,11 +356,20 @@ def parse_xiaomi_ble(event: dict) -> Optional[dict]:
'mosquitto': int.from_bytes(data, byteorder='little')
}

elif raw == b'\x01\x10': # magic cube
elif raw[0] == 0x18 and len(data) == 1:
return {
'action': 'right' if data == b'\x00\x00\x00' else 'left'
'light': int.from_bytes(data, byteorder='little')
}

elif raw[0] == 0x19 and len(data) == 1:
# HA: open == true == 1
if data == b'\x00': # xiaomi open
return {'contact': 1}
elif data == b'\x01': # xiaomi close
return {'contact': 0}
else: # timeout
return {}

# elif raw[0] == 0x17 and len(data) == 4:
# return {
# 'idle_time': int.from_bytes(data, byteorder='little') / 60.0
Expand Down

0 comments on commit 960c064

Please sign in to comment.