mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-07-11 03:17:28 -04:00
Tidy up broadcast in python client
This commit is contained in:
@@ -10,7 +10,7 @@ from typing import Optional
|
||||
from struct import pack, unpack
|
||||
from platform import platform
|
||||
|
||||
from .types import XAPSecureStatus, XAPFlags, XAPRequest, XAPResponse
|
||||
from .types import XAPSecureStatus, XAPFlags, XAPRequest, XAPResponse, XAPBroadcast
|
||||
from .routes import XAPRoutes, XAPRouteError
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ class XAPDeviceBase:
|
||||
while not hasattr(event, '_ret'):
|
||||
event.wait(timeout=0.25)
|
||||
|
||||
r = XAPResponse.from_bytes(event._ret)
|
||||
return (r.flags, r.data[:r.length])
|
||||
r = XAPBroadcast.from_bytes(event._ret)
|
||||
return (r.event, r.data[:r.length])
|
||||
|
||||
|
||||
class XAPDevice(XAPDeviceBase):
|
||||
|
||||
@@ -59,6 +59,20 @@ class XAPResponse(namedtuple('XAPResponse', 'token flags length data')):
|
||||
return self.fmt.pack(*list(self))
|
||||
|
||||
|
||||
class XAPBroadcast(namedtuple('XAPBroadcast', 'token event length data')):
|
||||
fmt = Struct('<HBB60s')
|
||||
|
||||
def __new__(cls, *args):
|
||||
return super().__new__(cls, *args)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data):
|
||||
return cls._make(cls.fmt.unpack(data))
|
||||
|
||||
def to_bytes(self):
|
||||
return self.fmt.pack(*list(self))
|
||||
|
||||
|
||||
class XAPConfigBacklight(namedtuple('XAPConfigBacklight', 'enable mode val')):
|
||||
fmt = Struct('<BBB')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user