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

New Zone 2 commands #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions nad_receiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ def main_volume(self, operator: str, value: Optional[str] =None) -> Optional[flo

Returns float
"""
return self._volume('main', operator, value)

def _volume(self, domain: str, operator: str, value: str) -> Optional[float]:
if value is not None:
volume = self.exec_command('main', 'volume', operator, str(value))
volume = self.exec_command(domain, 'volume', operator, str(value))
else:
volume = self.exec_command('main', 'volume', operator)
volume = self.exec_command(domain, 'volume', operator)

if volume is None:
return None
Expand Down Expand Up @@ -118,10 +121,13 @@ def main_source(self, operator: str, value: Optional[str]=None) -> Optional[Unio

Returns int
"""
return self._source('main', operator, value)

def _source(self, domain: str, operator: str, value: str) -> Optional[Union[int, str]]:
if value is not None:
source = self.exec_command('main', 'source', operator, str(value))
source = self.exec_command(domain, 'source', operator, str(value))
else:
source = self.exec_command('main', 'source', operator)
source = self.exec_command(domain, 'source', operator)

if source is None:
return None
Expand All @@ -133,6 +139,14 @@ def main_source(self, operator: str, value: Optional[str]=None) -> Optional[Unio
return source
return None

def main_codec(self, operator: str, value: Optional[str] =None) -> Optional[str]:
"""Execute Main.Audio.Codec."""
return self.exec_command('main', 'codec', operator, value)

def main_arc(self, operator: str, value: Optional[str] =None) -> Optional[str]:
"""Execute Main.Video.ARC."""
return self.exec_command('main', 'arc', operator, value)

def main_version(self, operator: str, value: Optional[str] =None) -> Optional[str]:
"""Execute Main.Version."""
return self.exec_command('main', 'version', operator, value)
Expand Down Expand Up @@ -165,6 +179,44 @@ def tuner_fm_preset(self, operator: str, value: Optional[str] =None) -> Optional
"""Execute Tuner.FM.Preset."""
return self.exec_command('tuner', 'fm_preset', operator, value)

def _has_zone2(self) -> bool:
back_config = self.exec_command('main', 'back', "?")
if back_config is None or "zone2" not in back_config.lower():
return False
return True

def zone2_source(self, operator: str, value: Optional[str]=None) -> Optional[Union[int, str]]:
"""
Execute Zone2.Source.

Returns int
"""
if not self._has_zone2():
raise ValueError("Zone2 unavilable")
return self._source('zone2', operator, value)

def zone2_power(self, operator: str, value: Optional[str] =None) -> Optional[str]:
"""Execute Zone2.Power."""
if not self._has_zone2():
raise ValueError("Zone2 unavilable")
return self.exec_command('zone2', 'power', operator, value)

def zone2_volume(self, operator: str, value: Optional[str] =None) -> Optional[float]:
"""
Execute Zone2.Volume.

Returns float
"""
if not self._has_zone2():
raise ValueError("Zone2 unavilable")
return self._volume('zone2', operator, value)

def zone2_listeningmode(self, operator: str, value: Optional[str] =None) -> Optional[str]:
"""Execute Zone2.ListeningMode."""
if not self._has_zone2():
raise ValueError("Zone2 unavilable")
return self.exec_command('zone2', 'listeningmode', operator, value)


class NADReceiverTelnet(NADReceiver):
"""
Expand Down
33 changes: 32 additions & 1 deletion nad_receiver/nad_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
'listeningmode':
{'cmd': 'Main.ListeningMode',
'supported_operators': ['+', '-']
'supported_operators': ['+', '-', '=', '?']
},
'sleep':
{'cmd': 'Main.Sleep',
Expand All @@ -41,6 +41,18 @@
{'cmd': 'Main.Source',
'supported_operators': ['+', '-', '=', '?']
},
'codec':
{'cmd': 'Main.Audio.CODEC',
'supported_operators': ['=', '?']
},
'arc':
{'cmd': 'Main.Video.ARC',
'supported_operators': ['=', '?']
},
'back':
{'cmd': 'Main.Amp.Back',
'supported_operators': ['?']
},
'version':
{'cmd': 'Main.Version',
'supported_operators': ['?']
Expand Down Expand Up @@ -88,5 +100,24 @@
{'cmd': 'Tuner.FM.Preset',
'supported_operators': ['+', '-', '=', '?']
}
},
'zone2':
{
'power':
{'cmd': 'Zone2.Power',
'supported_operators': ['+', '-', '=', '?']
},
'source':
{'cmd': 'Zone2.Source',
'supported_operators': ['+', '-', '=', '?']
},
'volume':
{'cmd': 'Zone2.Volume',
'supported_operators': ['+', '-', '=', '?']
},
'listeningmode':
{'cmd': 'Zone2.ListeningMode',
'supported_operators': ['+', '-', '=', '?']
},
}
}