From 854f39030c7d41bec01fa3748e8a1a85c69973ff Mon Sep 17 00:00:00 2001 From: Jeff Laflamme Date: Mon, 17 Jun 2024 10:56:00 +0700 Subject: [PATCH 1/3] Added support for controlling screen on and off --- src/alga/__main__.py | 2 ++ src/alga/cli_screen.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/alga/cli_screen.py diff --git a/src/alga/__main__.py b/src/alga/__main__.py index fb9ff64..4a23439 100644 --- a/src/alga/__main__.py +++ b/src/alga/__main__.py @@ -9,6 +9,7 @@ cli_input, cli_media, cli_power, + cli_screen, cli_setup, cli_sound_output, cli_volume, @@ -21,6 +22,7 @@ app.add_typer(cli_input.app, name="input") app.add_typer(cli_media.app, name="media") app.add_typer(cli_power.app, name="power") +app.add_typer(cli_screen.app, name="screen") app.add_typer(cli_sound_output.app, name="sound-output") app.add_typer(cli_volume.app, name="volume") diff --git a/src/alga/cli_screen.py b/src/alga/cli_screen.py new file mode 100644 index 0000000..149ce37 --- /dev/null +++ b/src/alga/cli_screen.py @@ -0,0 +1,21 @@ +from typer import Typer +from wakeonlan import send_magic_packet + +from alga import client, config + + +app = Typer(no_args_is_help=True, help="Turn TV screen on and off") + + +@app.command() +def off() -> None: + """Turn TV screen off""" + + client.request("ssap://com.webos.service.tvpower/power/turnOffScreen") + +@app.command() +def on() -> None: + """Turn TV screen on""" + + client.request("ssap://com.webos.service.tvpower/power/turnOnScreen") + From 003e9e8abe2574006456dd7572665e6349a299fe Mon Sep 17 00:00:00 2001 From: Jeff Laflamme Date: Tue, 18 Jun 2024 16:25:53 +0700 Subject: [PATCH 2/3] Change to power menu instead of screen, test coverage fixes --- src/alga/__main__.py | 2 -- src/alga/cli_power.py | 15 ++++++++++++++- src/alga/cli_screen.py | 21 --------------------- tests/test_cli_power.py | 14 ++++++++++++++ usage.md | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 60 insertions(+), 26 deletions(-) delete mode 100644 src/alga/cli_screen.py diff --git a/src/alga/__main__.py b/src/alga/__main__.py index 4a23439..fb9ff64 100644 --- a/src/alga/__main__.py +++ b/src/alga/__main__.py @@ -9,7 +9,6 @@ cli_input, cli_media, cli_power, - cli_screen, cli_setup, cli_sound_output, cli_volume, @@ -22,7 +21,6 @@ app.add_typer(cli_input.app, name="input") app.add_typer(cli_media.app, name="media") app.add_typer(cli_power.app, name="power") -app.add_typer(cli_screen.app, name="screen") app.add_typer(cli_sound_output.app, name="sound-output") app.add_typer(cli_volume.app, name="volume") diff --git a/src/alga/cli_power.py b/src/alga/cli_power.py index 0646fe1..a524b4f 100644 --- a/src/alga/cli_power.py +++ b/src/alga/cli_power.py @@ -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() @@ -20,3 +20,16 @@ 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") + diff --git a/src/alga/cli_screen.py b/src/alga/cli_screen.py deleted file mode 100644 index 149ce37..0000000 --- a/src/alga/cli_screen.py +++ /dev/null @@ -1,21 +0,0 @@ -from typer import Typer -from wakeonlan import send_magic_packet - -from alga import client, config - - -app = Typer(no_args_is_help=True, help="Turn TV screen on and off") - - -@app.command() -def off() -> None: - """Turn TV screen off""" - - client.request("ssap://com.webos.service.tvpower/power/turnOffScreen") - -@app.command() -def on() -> None: - """Turn TV screen on""" - - client.request("ssap://com.webos.service.tvpower/power/turnOnScreen") - diff --git a/tests/test_cli_power.py b/tests/test_cli_power.py index 75c2a4d..8c563ae 100644 --- a/tests/test_cli_power.py +++ b/tests/test_cli_power.py @@ -17,6 +17,20 @@ 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( diff --git a/usage.md b/usage.md index ca621a9..80c89dd 100644 --- a/usage.md +++ b/usage.md @@ -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 @@ -390,7 +390,7 @@ $ alga media stop [OPTIONS] ## `alga power` -Turn TV on and off +Turn TV (or screen) on and off **Usage**: @@ -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` @@ -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 From 94f86424b6943125528b795134bafcff942b7b49 Mon Sep 17 00:00:00 2001 From: Jeppe Fihl-Pearson Date: Wed, 19 Jun 2024 20:38:43 +0100 Subject: [PATCH 3/3] Format files using Ruff --- src/alga/cli_power.py | 3 ++- tests/test_cli_power.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/alga/cli_power.py b/src/alga/cli_power.py index a524b4f..ffff49b 100644 --- a/src/alga/cli_power.py +++ b/src/alga/cli_power.py @@ -21,15 +21,16 @@ 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") - diff --git a/tests/test_cli_power.py b/tests/test_cli_power.py index 8c563ae..74d2017 100644 --- a/tests/test_cli_power.py +++ b/tests/test_cli_power.py @@ -20,17 +20,23 @@ def test_off(mock_request: mock.MagicMock) -> None: 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") + 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") + 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(