Skip to content

Commit

Permalink
Add optional length parameter to play_* for chuangmi_ir (#1043)
Browse files Browse the repository at this point in the history
* Add optional length parameter to play_raw in chuangmi_ir.py

* Added Length to Play_pronto

Co-authored-by: ChiaHung Lee <chlee@bocco.com.tw>
  • Loading branch information
Dozku and ChiaHung Lee authored May 12, 2021
1 parent e29b933 commit 34f3370
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions miio/chuangmi_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,29 @@ def read(self, key: int = 1):
raise ChuangmiIrException("Invalid storage slot.")
return self.send("miIO.ir_read", {"key": str(key)})

def play_raw(self, command: str, frequency: int = 38400):
def play_raw(self, command: str, frequency: int = 38400, length: int = -1):
"""Play a captured command.
:param str command: Command to execute
:param int frequency: Execution frequency
:param int length: Length of the command. -1 means not sending the length parameter.
"""
return self.send("miIO.ir_play", {"freq": frequency, "code": command})
if length < 0:
return self.send("miIO.ir_play", {"freq": frequency, "code": command})
else:
return self.send(
"miIO.ir_play", {"freq": frequency, "code": command, "length": length}
)

def play_pronto(self, pronto: str, repeats: int = 1):
def play_pronto(self, pronto: str, repeats: int = 1, length: int = -1):
"""Play a Pronto Hex encoded IR command. Supports only raw Pronto format,
starting with 0000.
:param str pronto: Pronto Hex string.
:param int repeats: Number of extra signal repeats.
:param int length: Length of the command. -1 means not sending the length parameter.
"""
return self.play_raw(*self.pronto_to_raw(pronto, repeats))
return self.play_raw(*self.pronto_to_raw(pronto, repeats), length)

@classmethod
def pronto_to_raw(cls, pronto: str, repeats: int = 1):
Expand Down

0 comments on commit 34f3370

Please sign in to comment.