File tree Expand file tree Collapse file tree
custom_components/xiaomi_gateway3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import time
77from telnetlib import Telnet
88from threading import Thread
9- from typing import Optional
9+ from typing import Optional , Union
1010
1111from paho .mqtt .client import Client , MQTTMessage
1212from . 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
Original file line number Diff line number Diff line change 11import logging
22
3+ from homeassistant .components .remote import ATTR_DEVICE
34from homeassistant .helpers .entity import ToggleEntity
45
56from . 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 ])
You can’t perform that action at this time.
0 commit comments