Skip to content

Commit 4c77810

Browse files
committed
Add BLE emulation for dev purposes
1 parent fa3c899 commit 4c77810

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

custom_components/xiaomi_gateway3/gateway3.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from telnetlib import Telnet
88
from threading import Thread
9-
from typing import Optional
9+
from typing import Optional, Union
1010

1111
from paho.mqtt.client import Client, MQTTMessage
1212
from . import utils
@@ -240,6 +240,8 @@ def _get_devices_v3(self):
240240
continue
241241

242242
retain = json.loads(data[did + '.prop'])['props']
243+
_LOGGER.debug(f"{self.host} | {model} retain: {retain}")
244+
243245
params = {
244246
p[2]: retain.get(p[1])
245247
for p in desc['params']
@@ -422,8 +424,9 @@ def process_message(self, data: dict):
422424
device['mac'] = '0x' + device['mac']
423425
self.setup_devices([device])
424426

425-
def process_ble_event(self, raw: bytes):
426-
data = json.loads(raw[10:])['params']
427+
def process_ble_event(self, raw: Union[bytes, str]):
428+
data = json.loads(raw[10:])['params'] \
429+
if isinstance(raw, bytes) else json.loads(raw)
427430

428431
_LOGGER.debug(f"{self.host} | Process BLE {data}")
429432

custom_components/xiaomi_gateway3/remote.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from homeassistant.components.remote import ATTR_DEVICE
34
from homeassistant.helpers.entity import ToggleEntity
45

56
from . import DOMAIN, Gateway3Device
@@ -40,3 +41,9 @@ def turn_on(self):
4041

4142
def turn_off(self):
4243
self.gw.send(self.device, {'pairing_stop': 0})
44+
45+
async def async_send_command(self, command, **kwargs):
46+
for cmd in command:
47+
# for testing purposes
48+
if cmd == 'ble':
49+
self.gw.process_ble_event(kwargs[ATTR_DEVICE])

0 commit comments

Comments
 (0)