Skip to content

Commit

Permalink
Added support for controlling screen on and off (#7)
Browse files Browse the repository at this point in the history
* Added support for controlling screen on and off

* Change to power menu instead of screen, test coverage fixes

* Format files using Ruff

---------

Co-authored-by: Jeppe Fihl-Pearson <[email protected]>
  • Loading branch information
jflaflamme and Tenzer authored Jun 19, 2024
1 parent 51e8dff commit 3b5c444
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
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

0 comments on commit 3b5c444

Please sign in to comment.