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 source subcommand #26

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -57,6 +57,9 @@ funiculi [FLAGS] COMMAND
- `up`
Turns the volume up one step.

- `source [get | set NAME]`
Selects or queries the audio source.

- `status`
Queries whether the device is on standby.

9 changes: 9 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -22,6 +22,15 @@ funiculi [FLAGS] COMMAND
`up`
: Turns the volume up one step.

`source [get | set NAME]`
: Selects or queries the audio source.
The `get` subcommand returns the current source.
The `set` subcommand accepts a source name according to Denon’s
protocol; the name is case-insensitive.
Acceptable values vary by model. To find out the values for a
specific model, omit this parameter while your device is set to a
known source. Repeat for each source.

`status`
: Queries whether the device is on standby.

29 changes: 28 additions & 1 deletion funiculi/api.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import socket
import subprocess
import tempfile
from typing import Optional, Sequence, TYPE_CHECKING
from typing import Callable, Optional, Sequence, TYPE_CHECKING

from .errors import CliError
from .logging import get_logger
@@ -25,6 +25,29 @@
CompletedProcess = subprocess.CompletedProcess


class SourceApi:
"""Selects or queries the audio source."""

def __init__(self, send: Callable[[str], str]) -> None:
self._send = send

def get(self) -> str:
"""Queries the current audio source."""
return self._send('SI?')[2:]

def set(self, name: str) -> str:
"""Selects an audio source.
:param name:
Source name according to Denon’s protocol.
This parameter is case-insensitive.
Acceptable values vary by model. To find out the values
for a specific model, omit this parameter while your
device is set to a known source. Repeat for each source.
"""
return self._send(f'SI{name.upper()}')


class Api:
"""
:param host:
@@ -46,6 +69,9 @@ class Api:
The remote path to the UPnP XML descriptor.
"""

source: SourceApi
"""Selects or queries the audio source."""

def __init__(self, # pylint: disable=too-many-arguments
host: Optional[str]=None,
ctrlport: int=DEFAULT_AVR_CTRL_PORT,
@@ -61,6 +87,7 @@ def __init__(self, # pylint: disable=too-many-arguments
self._avr_web_port = webport
self._timeout_ms = timeout
self._upnp_descriptor_path = path
self.source = SourceApi(self._send)


def off(self) -> None: