Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional length parameter to play_* for chuangmi_ir #1043

Merged
merged 3 commits into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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