Skip to content
Permalink
Browse files

improvements to nbclient and cleanup of nbcmd

  • Loading branch information
Slinger360
Slinger360 committed Feb 8, 2020
1 parent 0881947 commit b2c7f1ae57df0a83903933e09da7c2de0e31118e
Showing with 10 additions and 11 deletions.
  1. +10 −4 nbclient.py
  2. +0 −7 nbcmd.py
@@ -9,6 +9,7 @@
from kivy.properties import BooleanProperty, StringProperty, ObjectProperty
from utils import tprint, specialthread
import asyncio
from threading import Event

class Client(EventDispatcher):
state = StringProperty('disconnected')
@@ -100,17 +101,20 @@ def _connect_inner(self, link):
transport = XiaomiTransport(link)

if transport.execute(ReadRegs(BT.ESC, 0x68, "<H"))[0] > 0x081 and self.link is ('ble'):
transport.keys = link.fetch_keys_pro()
transport.keys = link.fetch_keys()
transport.recover_keys()
tprint('Keys recovered')

self._tran = transport
self._link = link

if self._tran is not None and self._link is not None:
if not self._link.connected.is_set():
self._link.connected.wait(self._link.timeout*1.5)

if self._link.connected.is_set():
self.update_state('connected')
else:
self.disconnect
self.disconnect()

return transport

@@ -125,11 +129,13 @@ def update_state(self, state):

def disconnect(self):
self.update_state('disconnecting')
self.address = ''
try:
self._link.close()
self._link = None
self._tran = None
except:
pass
self.address = ''
self.update_state('disconnected')

def on_error(self, *args):
@@ -19,18 +19,13 @@ def tprint(msg):

class Command:
def __init__(self, conn):
self.new_sn = ''
self.device = ''
self.conn = conn

def setdev(self, d):
self.device = d.lower()
tprint(self.device+' selected as device')

def setnewsn(self, p):
self.new_sn = p
tprint(self.new_sn+' input for newsn')

def powerdown(self):
tran = self.conn._tran
tran.execute(WriteRegs(BT.ESC, 0x79, "<H", 0x0001))
@@ -50,5 +45,3 @@ def reboot(self):
tran = self.conn._tran
tran.execute(WriteRegs(BT.ESC, 0x78, "<H", 0x0001))
tprint('Done')


0 comments on commit b2c7f1a

Please sign in to comment.
You can’t perform that action at this time.