mirror of
https://github.com/mjg59/python-broadlink.git
synced 2024-11-22 23:17:47 +01:00
Expose retry_intvl option
This commit is contained in:
parent
0d80cf99b8
commit
6af6cff36d
@ -262,7 +262,7 @@ class device:
|
|||||||
"""Return device type."""
|
"""Return device type."""
|
||||||
return self.type
|
return self.type
|
||||||
|
|
||||||
def send_packet(self, command: int, payload: bytes) -> bytes:
|
def send_packet(self, command: int, payload: bytes, retry_intvl: float = 1.0) -> bytes:
|
||||||
"""Send a packet to the device."""
|
"""Send a packet to the device."""
|
||||||
self.count = ((self.count + 1) | 0x8000) & 0xFFFF
|
self.count = ((self.count + 1) | 0x8000) & 0xFFFF
|
||||||
packet = bytearray(0x38)
|
packet = bytearray(0x38)
|
||||||
@ -315,11 +315,11 @@ class device:
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
time_left = timeout - (time.time() - start_time)
|
time_left = timeout - (time.time() - start_time)
|
||||||
conn.settimeout(min(5, time_left))
|
conn.settimeout(min(retry_intvl, time_left))
|
||||||
conn.sendto(packet, self.host)
|
conn.sendto(packet, self.host)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp, _ = conn.recvfrom(2048)
|
resp = conn.recvfrom(2048)[0]
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
if (time.time() - start_time) > timeout:
|
if (time.time() - start_time) > timeout:
|
||||||
|
@ -13,10 +13,10 @@ class rm(device):
|
|||||||
device.__init__(self, *args, **kwargs)
|
device.__init__(self, *args, **kwargs)
|
||||||
self.type = "RM2"
|
self.type = "RM2"
|
||||||
|
|
||||||
def _send(self, command: int, data: bytes = b'') -> bytes:
|
def _send(self, command: int, data: bytes = b'', retry_intvl: float = 1.0) -> bytes:
|
||||||
"""Send a packet to the device."""
|
"""Send a packet to the device."""
|
||||||
packet = struct.pack("<I", command) + data
|
packet = struct.pack("<I", command) + data
|
||||||
resp = self.send_packet(0x6A, packet)
|
resp = self.send_packet(0x6A, packet, retry_intvl=retry_intvl)
|
||||||
check_error(resp[0x22:0x24])
|
check_error(resp[0x22:0x24])
|
||||||
payload = self.decrypt(resp[0x38:])
|
payload = self.decrypt(resp[0x38:])
|
||||||
return payload[0x4:]
|
return payload[0x4:]
|
||||||
@ -27,7 +27,7 @@ class rm(device):
|
|||||||
|
|
||||||
def send_data(self, data: bytes) -> None:
|
def send_data(self, data: bytes) -> None:
|
||||||
"""Send a code to the device."""
|
"""Send a code to the device."""
|
||||||
self._send(0x2, data)
|
self._send(0x2, data=data, retry_intvl=5)
|
||||||
|
|
||||||
def enter_learning(self) -> None:
|
def enter_learning(self) -> None:
|
||||||
"""Enter infrared learning mode."""
|
"""Enter infrared learning mode."""
|
||||||
@ -71,10 +71,10 @@ class rm4(rm):
|
|||||||
device.__init__(self, *args, **kwargs)
|
device.__init__(self, *args, **kwargs)
|
||||||
self.type = "RM4"
|
self.type = "RM4"
|
||||||
|
|
||||||
def _send(self, command: int, data: bytes = b'') -> bytes:
|
def _send(self, command: int, data: bytes = b'', retry_intvl: float = 1.0) -> bytes:
|
||||||
"""Send a packet to the device."""
|
"""Send a packet to the device."""
|
||||||
packet = struct.pack("<HI", len(data) + 4, command) + data
|
packet = struct.pack("<HI", len(data) + 4, command) + data
|
||||||
resp = self.send_packet(0x6A, packet)
|
resp = self.send_packet(0x6A, packet, retry_intvl=retry_intvl)
|
||||||
check_error(resp[0x22:0x24])
|
check_error(resp[0x22:0x24])
|
||||||
payload = self.decrypt(resp[0x38:])
|
payload = self.decrypt(resp[0x38:])
|
||||||
p_len = struct.unpack("<H", payload[:0x2])[0]
|
p_len = struct.unpack("<H", payload[:0x2])[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user