From c466c7d431d7422d7a2a161becc050e6f7e7850e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 23 Aug 2019 09:01:55 +1000 Subject: [PATCH] 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 --- tuhi/protocol.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tuhi/protocol.py b/tuhi/protocol.py index 24f0e52..72b3c3f 100644 --- a/tuhi/protocol.py +++ b/tuhi/protocol.py @@ -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