Add name change functionality #16

Merged
sqozz merged 3 commits from feature/name_icon into master 2020-05-07 21:13:04 +02:00
Showing only changes of commit b80c640e61 - Show all commits

View file

@ -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])