Raise exception if name is set without login
This commit is contained in:
parent
271e1bc5bf
commit
b80c640e61
10
sem6000.py
10
sem6000.py
|
@ -96,13 +96,13 @@ class SEMSocket():
|
||||||
|
|
||||||
@name.setter
|
@name.setter
|
||||||
def name(self, newName):
|
def name(self, newName):
|
||||||
newName = newName.encode("UTF-8")
|
newNameBytes = newName.encode("UTF-8")
|
||||||
cmd = bytearray([0x02])
|
cmd = bytearray([0x02])
|
||||||
payload = bytearray()
|
payload = bytearray()
|
||||||
payload.append(0x02)
|
payload.append(0x02)
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
if i <= (len(newName) - 1):
|
if i <= (len(newNameBytes) - 1):
|
||||||
payload.append(newName[i])
|
payload.append(newNameBytes[i])
|
||||||
else:
|
else:
|
||||||
payload.append(0x00)
|
payload.append(0x00)
|
||||||
msg = self.BTLEMessage(self, cmd, payload)
|
msg = self.BTLEMessage(self, cmd, payload)
|
||||||
|
@ -113,6 +113,7 @@ class SEMSocket():
|
||||||
# payload[i+1] = 0x00
|
# payload[i+1] = 0x00
|
||||||
#msg = self.BTLEMessage(self, cmd, payload)
|
#msg = self.BTLEMessage(self, cmd, payload)
|
||||||
if not success: raise self.SendMessageFailed
|
if not success: raise self.SendMessageFailed
|
||||||
|
if self.name != newName: raise self.NotLoggedIn
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def connected(self):
|
def connected(self):
|
||||||
|
@ -174,6 +175,9 @@ class SEMSocket():
|
||||||
class SendMessageFailed(Exception):
|
class SendMessageFailed(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class NotLoggedIn(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class BTLEMessage():
|
class BTLEMessage():
|
||||||
MAGIC_START = bytearray([0x0f])
|
MAGIC_START = bytearray([0x0f])
|
||||||
MAGIC_END = bytearray([0xff, 0xff])
|
MAGIC_END = bytearray([0xff, 0xff])
|
||||||
|
|
Loading…
Reference in a new issue