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

Added support for controlling screen on and off #7

Merged
merged 3 commits into from
Jun 19, 2024
Merged
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
16 changes: 15 additions & 1 deletion src/alga/cli_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from alga import client, config


app = Typer(no_args_is_help=True, help="Turn TV on and off")
app = Typer(no_args_is_help=True, help="Turn TV (or screen) on and off")


@app.command()
Expand All @@ -20,3 +20,17 @@ def on() -> None:

cfg = config.get()
send_magic_packet(cfg["mac"])


@app.command()
def screen_off() -> None:
"""Turn TV screen off"""

client.request("ssap://com.webos.service.tvpower/power/turnOffScreen")


@app.command()
def screen_on() -> None:
"""Turn TV screen on"""

client.request("ssap://com.webos.service.tvpower/power/turnOnScreen")
20 changes: 20 additions & 0 deletions tests/test_cli_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ def test_off(mock_request: mock.MagicMock) -> None:
assert result.stdout == ""


def test_screen_off(mock_request: mock.MagicMock) -> None:
result = runner.invoke(app, ["power", "screen-off"])

mock_request.assert_called_once_with(
"ssap://com.webos.service.tvpower/power/turnOffScreen"
)
assert result.exit_code == 0
assert result.stdout == ""


def test_screen_on(mock_request: mock.MagicMock) -> None:
result = runner.invoke(app, ["power", "screen-on"])

mock_request.assert_called_once_with(
"ssap://com.webos.service.tvpower/power/turnOnScreen"
)
assert result.exit_code == 0
assert result.stdout == ""


@mock.patch("alga.config.get")
@mock.patch("alga.cli_power.send_magic_packet")
def test_on(
Expand Down
34 changes: 32 additions & 2 deletions usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ alga [OPTIONS] COMMAND [ARGS]...
* `channel`: TV channels
* `input`: HDMI and similar inputs
* `media`: Control the playing media
* `power`: Turn TV on and off
* `power`: Turn TV (or screen) on and off
* `setup`: Pair a new TV
* `sound-output`: Audio output device
* `version`: Print Alga version
Expand Down Expand Up @@ -390,7 +390,7 @@ $ alga media stop [OPTIONS]

## `alga power`

Turn TV on and off
Turn TV (or screen) on and off

**Usage**:

Expand All @@ -406,6 +406,8 @@ $ alga power [OPTIONS] COMMAND [ARGS]...

* `off`: Turn TV off
* `on`: Turn TV on via Wake-on-LAN
* `screen-off`: Turn TV screen off
* `screen-on`: Turn TV screen on

### `alga power off`

Expand Down Expand Up @@ -435,6 +437,34 @@ $ alga power on [OPTIONS]

* `--help`: Show this message and exit.

### `alga power screen-off`

Turn TV screen off

**Usage**:

```console
$ alga power screen-off [OPTIONS]
```

**Options**:

* `--help`: Show this message and exit.

### `alga power screen-on`

Turn TV screen on

**Usage**:

```console
$ alga power screen-on [OPTIONS]
```

**Options**:

* `--help`: Show this message and exit.

## `alga setup`

Pair a new TV
Expand Down