From b80c640e618efb47b74815c1beddd74819384eec Mon Sep 17 00:00:00 2001 From: sqozz Date: Thu, 7 May 2020 12:17:52 +0200 Subject: [PATCH] Raise exception if name is set without login --- sem6000.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sem6000.py b/sem6000.py index fe7b397..1a3ffc6 100644 --- a/sem6000.py +++ b/sem6000.py @@ -96,13 +96,13 @@ class SEMSocket(): @name.setter def name(self, newName): - newName = newName.encode("UTF-8") + newNameBytes = newName.encode("UTF-8") cmd = bytearray([0x02]) payload = bytearray() payload.append(0x02) for i in range(20): - if i <= (len(newName) - 1): - payload.append(newName[i]) + if i <= (len(newNameBytes) - 1): + payload.append(newNameBytes[i]) else: payload.append(0x00) msg = self.BTLEMessage(self, cmd, payload) @@ -113,6 +113,7 @@ class SEMSocket(): # payload[i+1] = 0x00 #msg = self.BTLEMessage(self, cmd, payload) if not success: raise self.SendMessageFailed + if self.name != newName: raise self.NotLoggedIn @property def connected(self): @@ -174,6 +175,9 @@ class SEMSocket(): class SendMessageFailed(Exception): pass + class NotLoggedIn(Exception): + pass + class BTLEMessage(): MAGIC_START = bytearray([0x0f]) MAGIC_END = bytearray([0xff, 0xff])