protocol: handle error code 0x7

Deprecated, but still exists on the Slate so let's wrap the connect attempt
so we throw the right error.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
pull/191/head
Peter Hutterer 2019-08-23 09:01:55 +10:00 committed by Benjamin Tissoires
parent 02ca3a7058
commit c466c7d431
1 changed files with 23 additions and 0 deletions

View File

@ -436,6 +436,7 @@ class DeviceError(ProtocolError):
INVALID_STATE = 0x2
READ_ONLY_PARAM = 0x3
COMMAND_NOT_SUPPORTED = 0x4
AUTHORIZATION_ERROR = 0x7
def __init__(self, errorcode, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -611,6 +612,28 @@ class MsgConnectSpark(Msg):
raise e
class MsgConnectSlate(Msg):
interaction = Interactions.CONNECT
opcode = 0xe6
protocol = ProtocolVersion.SLATE
def __init__(self, uuid, *args, **kwargs):
super().__init__(*args, **kwargs)
self.uuid = uuid
self.args = [int(i) for i in binascii.unhexlify(uuid)]
if len(self.args) != 6:
raise ValueError('UUID must be 6 bytes long')
def _handle_reply(self, reply):
try:
super()._handle_reply(reply)
except DeviceError as e:
# Same as spark but we get 0x7 as error code
if e.errorcode == DeviceError.ErrorCode.AUTHORIZATION_ERROR:
raise AuthorizationError()
raise e
class MsgGetName(Msg):
'''
.. attribute:: name