33 lines
826 B
Python
33 lines
826 B
Python
import queue
|
|
|
|
from metawatch import protocol
|
|
|
|
class Watch:
|
|
def __init__(self, fd):
|
|
self._fd = fd
|
|
self._extra_packets = queue.Queue()
|
|
|
|
def _read_packet(self, expected):
|
|
while True:
|
|
ib = protocol.InboundPacket(self._fd)
|
|
p = ib.read()
|
|
if isinstance(p, expected):
|
|
return p
|
|
self._extra_packets.put(p)
|
|
|
|
def get_device_type(self):
|
|
o = protocol.GetDeviceType()
|
|
o.emit(self._fd)
|
|
i = self._read_packet(protocol.GetDeviceTypeResponse)
|
|
return i.device_type
|
|
|
|
def get_rtc(self):
|
|
o = protocol.GetRTC()
|
|
o.emit(self._fd)
|
|
i = self._read_packet(protocol.GetRTCResponse)
|
|
return i.datetime
|
|
|
|
def set_rtc(self, dt):
|
|
o = protocol.SetRTC(dt)
|
|
o.emit(self._fd)
|