- def response(self, *args):
- if len(args) == 0:
- return None
- assert len(args) == 1 and isinstance(args[0], bytes)
- payload = args[0]
+ @classmethod
+ def make_packet(cls, payload):
+ assert isinstance(payload, bytes)
- return pack("BB", length, self.PROTO) + payload
+ return pack("BB", length, cls.PROTO) + payload
+
+ @classmethod
+ def inline_response(cls, packet):
+ if cls.INLINE:
+ return cls.make_packet(b"")
+ else:
+ return None
def response(self, supnum=0):
# 1: The device automatically answers Pickup effect
# 2: Automatically Answering Two-way Calls
# 3: Ring manually answer the two-way call
def response(self, supnum=0):
# 1: The device automatically answers Pickup effect
# 2: Automatically Answering Two-way Calls
# 3: Ring manually answer the two-way call
- def response(self):
- payload = pack("!HBBBBB", *datetime.utcnow().timetuple()[:6])
- return super().response(payload)
+ @classmethod
+ def inline_response(cls, packet):
+ return pack(
+ "!BBHBBBBB", 7, cls.PROTO, *datetime.utcnow().timetuple()[:6]
+ )
def response(self, status=1): # Server sent, 0-off, 1-on
def response(self, status=1): # Server sent, 0-off, 1-on
def response(self, lat=None, lon=None):
if lat is None or lon is None:
def response(self, lat=None, lon=None):
if lat is None or lon is None:
- def response(self):
- return super().response(pack("!H", self.interval))
+ def response(self, interval=10):
+ return self.make_packet(pack("!H", interval))
- return unpack("B", packet[1:2])
+ return unpack("B", packet[1:2])[0]
+
+
+def inline_response(packet):
+ proto = proto_of_message(packet)
+ if proto in CLASSES:
+ return CLASSES[proto].inline_response(packet)
+ else:
+ return None
def make_response(msg, **kwargs): # DEPRECATED
inframe = msg.response(**kwargs)
return None if inframe is None else b"xx" + inframe + b"\r\n"
def make_response(msg, **kwargs): # DEPRECATED
inframe = msg.response(**kwargs)
return None if inframe is None else b"xx" + inframe + b"\r\n"