Skip to content

Commit

Permalink
add new cmds, support more than 1 arg
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveicedgreentea committed Jul 2, 2023
1 parent c199068 commit 46eb066
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
34 changes: 14 additions & 20 deletions madvr/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class DisplayAlert(Enum):
class Information(Enum):
pass

class Profiles(Enum):
pass

class SettingsPages(Enum):
pass

Expand All @@ -85,29 +82,33 @@ class IsInformational(Enum):
true = True
false = False

class Menus(Enum):
Info = b"Info"
Settings = b"Settings"
Configuration = b"Configuration"
Profiles = b"Profiles"
TestPatterns = b"TestPatterns"

class Profiles(Enum):
SOURCE = b"SOURCE"
DISPLAY = b"DISPLAY"

class Commands(Enum):
# Power stuff
PowerOff = b"PowerOff", SingleCmd, IsInformational.false
Standby = b"Standby", SingleCmd, IsInformational.false
Restart = b"Restart", SingleCmd, IsInformational.false
ReloadSoftware = b"ReloadSoftware", SingleCmd, IsInformational.false
Bye = b"Bye", SingleCmd, IsInformational.false
ResetTemporary = b"ResetTemporary", SingleCmd, IsInformational.false

# vb'KeyPress MENU\r\n'
# b'CloseMenu\r\n'
# b'OK\r\nIncomingSignalInfo 3840x2160 59.940p 2D 420 10bit SDR 709 TV 16:9\r\nReloadSoftware\r\nOutgoingSignalInfo 4096x2160 59.940p 2D RGB 8bit SDR 709 TV\r\nIncomingSignalInfo 3840x2160 59.940p 2D 420 10bit SDR 709 TV 16:9\r\nAspectRatio 3840:2160 1.778 178 "16:9"\r\nMaskingRatio 3044:1712 1.778 178\r\nKeyPress MENU\r\nOpenMenu Configuration\r\n'
# playing fast n furous
# b'OK\r\nAspectRatio 3816:2146 1.778 178 "16:9"\r\nResetTemporary\r\nNoSignal\r\nOutgoingSignalInfo 4096x2160 59.940p 2D RGB 8bit SDR 709 TV\r\nIncomingSignalInfo 1280x720 59.940p 2D 422 12bit SDR 709 TV 16:9\r\nAspectRatio 1280:0720 1.778 178 "16:9"\r\nAspectRatio 1272:0525 2.423 240 "Panavision"\r\nMaskingRatio 4092:1689 2.423 240\r\n'
ActivateProfile = b"ActivateProfile", Profiles, IsInformational.false

# Menu
OpenMenu = b"OpenMenu", SingleCmd, IsInformational.false
OpenMenu = b"OpenMenu", Menus, IsInformational.false
CloseMenu = b"CloseMenu", SingleCmd, IsInformational.false
KeyPress = b"KeyPress", KeyPress, IsInformational.false
KeyHold = b"KeyHold", KeyPress, IsInformational.false

# display_alert = b"DisplayAlertWindow", ACKs.reply
# close_alert = b"CloseAlertWindow", ACKs.reply
# display_message = b"DisplayMessage", ACKs.reply

GetIncomingSignalInfo = b"GetIncomingSignalInfo", SignalInfo, IsInformational.true
GetOutgoingSignalInfo = b"GetOutgoingSignalInfo", OutgoingSignalInfo, IsInformational.true
Expand All @@ -116,13 +117,6 @@ class Commands(Enum):
GetTemperatures = b"GetTemperatures", Temperatures, IsInformational.true
GetMacAddress = b"GetMacAddress", SingleCmd, IsInformational.true

# enum_settings = b"EnumSettingsPages"
# enum_configs = b"EnumConfigPages"
# enum_options = b"EnumOptions"
# query_option = b"QueryOption"
# change_option = b"ChangeOption"
# reset_temp = b"ResetTemporary"

# toggle = b"Toggle"
ToneMapOn = b"ToneMapOn", SingleCmd, IsInformational.false
ToneMapOff = b"ToneMapOff", SingleCmd, IsInformational.false
Expand Down
40 changes: 28 additions & 12 deletions madvr/madvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,34 @@ async def _construct_command(self, raw_command: list[str]) -> tuple[bytes, str]:
# HA seems to always send commands as a list even if you set them as a str

# This lets you use single cmds or something with val like KEYPRESS
# If len is 1 like ["keypress,val"], then try to split, otherwise its just one word

if len(raw_command) == 1:
# If len is 1 like ["keypress,val"], then try to split, otherwise its just one word
# sent directly from HA send_command
if len(raw_command) == 1: # if its a list
try:
# ['key_press, menu']
command, raw_value = raw_command[0].split(",")
# ['key_press, menu'] -> 'key_press', ['menu']
# ['activate_profile, SOURCE, 1'] -> 'activate_profile', ['SOURCE', '1']
command, *raw_value = raw_command[0].split(",")
# remove space
value = raw_value.strip()
self.logger.debug("using command %s and value %s", command, value)
values = [val.strip() for val in raw_value]
self.logger.debug("using command %s and values %s", command, values)
# if valuerror it means theres just one command like PowerOff, so use that directly
except ValueError as err:
self.logger.debug(err)
self.logger.debug("Using raw_command directly")
command = raw_command[0]
skip_val = True
# if there are more than two values, this is incorrect, error
elif len(raw_command) > 2:
# if there are more than three values, this is incorrect, error
elif len(raw_command) > 3:
self.logger.error(
"More than two command values provided. Envy does not have more than 2 command values e.g KeyPress MENU"
"More than three command values provided."
)
raise NotImplementedError(f"Too many values provided {raw_command}")
else:
self.logger.debug("command is a list")
# else a command was provided as a proper list ['keypress', 'menu']
# raw command will be a list of 2
command, value = raw_command
# raw command will be a list of 2+
command, *values = raw_command

self.logger.debug("checking command %s", command)

Expand All @@ -261,9 +264,22 @@ async def _construct_command(self, raw_command: list[str]) -> tuple[bytes, str]:
# if there is a value to process
if not skip_val:
try:
command_base: bytes = command_name + b" " + val[value.lstrip(" ")].value
# add the base command
command_base: bytes = command_name

# append each value with a space
for value in values:
# if value is a number, use it directly
# TODO: check this?
if value.isnumeric(): # encode 1 for ActivateProfile
command_base += b" " + value.encode("utf-8")
else:
# else use the enum
command_base += b" " + val[value.lstrip(" ")].value

# Construct command based on required values
cmd: bytes = command_base + Footer.footer.value

except KeyError as exc:
raise NotImplementedError(
"Incorrect parameter given for command"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="py_madvr",
version="1.4.5",
version="1.4.6",
author="iloveicedgreentea",
description="A package to control MadVR Envy over IP",
long_description=long_description,
Expand Down

0 comments on commit 46eb066

Please sign in to comment.