Skip to content

Commit

Permalink
Fix gateway CPU 90% fulltime
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 19, 2020
1 parent 6081b37 commit eb4654c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions custom_components/xiaomi_gateway3/gateway3.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,20 @@ def _enable_mqtt(self):
telnet = Telnet(self.host)
telnet.read_until(b"login: ")
telnet.write(b"admin\r\n")
telnet.read_very_eager() # skip response
telnet.read_until(b"\r\n# ") # skip greeting

# enable public mqtt
telnet.write(b"killall mosquitto\r\n")
telnet.read_very_eager() # skip response
time.sleep(.5)
telnet.read_until(b"\r\n") # skip command
time.sleep(.5) # it's important to wait
telnet.write(b"mosquitto -d\r\n")
telnet.read_very_eager() # skip response
time.sleep(1)
telnet.read_until(b"\r\n") # skip command
time.sleep(.5) # it's important to wait

# fix CPU 90% full time bug
telnet.write(b"killall zigbee_gw\r\n")
telnet.read_until(b"\r\n") # skip command
time.sleep(.5) # it's important to wait

telnet.close()
return True
Expand Down Expand Up @@ -519,22 +524,22 @@ def run(self):
telnet = Telnet(self.gw.host, timeout=5)
telnet.read_until(b"login: ")
telnet.write(b"admin\r\n")
telnet.read_until(b'\r\n# ') # skip greeting
telnet.read_until(b"\r\n# ") # skip greeting

telnet.write(b"killall silabs_ncp_bt; "
b"silabs_ncp_bt /dev/ttyS1 1\r\n")
telnet.read_until(b'\r\n') # skip command
telnet.read_until(b"\r\n") # skip command

while True:
raw = telnet.read_until(b'\r\n')
raw = telnet.read_until(b"\r\n")

if 'bluetooth' in self.gw.debug:
_LOGGER.debug(f"[BT] {raw}")

if b'_async.ble_event' in raw:
self.gw.process_ble_event(raw)

except (ConnectionRefusedError, ConnectionResetError,
except (ConnectionRefusedError, ConnectionResetError, EOFError,
socket.timeout):
pass
except Exception as e:
Expand Down

0 comments on commit eb4654c

Please sign in to comment.