tux-armory 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. tux_armory-0.2.0/.github/workflows/ci.yml +47 -0
  2. tux_armory-0.2.0/.gitignore +7 -0
  3. tux_armory-0.2.0/PKG-INFO +77 -0
  4. tux_armory-0.2.0/README.md +67 -0
  5. tux_armory-0.2.0/assets/screenshot.png +0 -0
  6. tux_armory-0.2.0/data/install-desktop-entry +17 -0
  7. tux_armory-0.2.0/data/install-polkit-helper +10 -0
  8. tux_armory-0.2.0/data/org.tuxarmory.policy +15 -0
  9. tux_armory-0.2.0/data/tux-armory-sysfs-helper +54 -0
  10. tux_armory-0.2.0/data/tux-armory.desktop +10 -0
  11. tux_armory-0.2.0/data/tux-armory.svg +12 -0
  12. tux_armory-0.2.0/docs/ARCHITECTURE.md +54 -0
  13. tux_armory-0.2.0/install-helper.sh +7 -0
  14. tux_armory-0.2.0/pyproject.toml +29 -0
  15. tux_armory-0.2.0/tests/test_battery_validation.py +75 -0
  16. tux_armory-0.2.0/tests/test_multivendor.py +114 -0
  17. tux_armory-0.2.0/tests/test_phase2.py +50 -0
  18. tux_armory-0.2.0/tests/test_phase3.py +96 -0
  19. tux_armory-0.2.0/tests/test_phase4.py +48 -0
  20. tux_armory-0.2.0/tests/test_ui.py +16 -0
  21. tux_armory-0.2.0/tests/test_ui_enhancements.py +113 -0
  22. tux_armory-0.2.0/tux_armory/__init__.py +3 -0
  23. tux_armory-0.2.0/tux_armory/__main__.py +4 -0
  24. tux_armory-0.2.0/tux_armory/backend/__init__.py +11 -0
  25. tux_armory-0.2.0/tux_armory/backend/aura.py +199 -0
  26. tux_armory-0.2.0/tux_armory/backend/base.py +33 -0
  27. tux_armory-0.2.0/tux_armory/backend/battery.py +176 -0
  28. tux_armory-0.2.0/tux_armory/backend/command.py +21 -0
  29. tux_armory-0.2.0/tux_armory/backend/fan.py +27 -0
  30. tux_armory-0.2.0/tux_armory/backend/gpu.py +123 -0
  31. tux_armory-0.2.0/tux_armory/backend/nvidia_telemetry.py +41 -0
  32. tux_armory-0.2.0/tux_armory/backend/power.py +111 -0
  33. tux_armory-0.2.0/tux_armory/backend/presets.py +108 -0
  34. tux_armory-0.2.0/tux_armory/cli.py +133 -0
  35. tux_armory-0.2.0/tux_armory/ui/__init__.py +18 -0
  36. tux_armory-0.2.0/tux_armory/ui/__main__.py +3 -0
  37. tux_armory-0.2.0/tux_armory/ui/app.py +891 -0
  38. tux_armory-0.2.0/tux_armory/ui/launch.py +94 -0
  39. tux_armory-0.2.0/tux_armory/utils/__init__.py +1 -0
  40. tux_armory-0.2.0/tux_armory/utils/config.py +67 -0
  41. tux_armory-0.2.0/tux_armory/utils/privileged.py +23 -0
@@ -0,0 +1,47 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ name: Test (Python ${{ matrix.python-version }})
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version: ["3.11", "3.12", "3.13"]
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+ cache: "pip"
27
+
28
+ - name: Install system dependencies for Qt
29
+ run: |
30
+ sudo apt-get update
31
+ sudo apt-get install -y libegl1 libgl1 libxkbcommon-x11-0 libdbus-1-3 libxcb-cursor0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-xfixes0 libxcb-xinerama0 xvfb
32
+
33
+ - name: Install package and test dependencies
34
+ run: |
35
+ python -m pip install --upgrade pip
36
+ python -m pip install hatchling pytest
37
+ python -m pip install ".[gui]"
38
+
39
+ - name: Run test suite
40
+ env:
41
+ QT_QPA_PLATFORM: offscreen
42
+ run: |
43
+ xvfb-run -a pytest tests/
44
+
45
+ - name: Build package distribution
46
+ run: |
47
+ python -m pip wheel --no-deps -w dist .
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.5
2
+ Name: tux-armory
3
+ Version: 0.2.0
4
+ Summary: Cross-distro Linux power profiles, GPU switching, and hardware controls for gaming laptops
5
+ License: MIT
6
+ Requires-Python: >=3.11
7
+ Provides-Extra: gui
8
+ Requires-Dist: pyside6>=6.7; extra == 'gui'
9
+ Description-Content-Type: text/markdown
10
+
11
+ # TuxArmory
12
+
13
+ [![CI](https://github.com/rhn-ryan/TuxArmory/actions/workflows/ci.yml/badge.svg)](https://github.com/rhn-ryan/TuxArmory/actions/workflows/ci.yml)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
15
+
16
+ TuxArmory is a lightweight, cross-distribution Linux hardware and performance control center designed for gaming laptops and workstations. It provides both an intuitive PySide6 desktop interface and a scriptable command-line utility for managing power profiles, GPU switching, battery health thresholds, keyboard backlighting, and live hardware telemetry.
17
+
18
+ ![TuxArmory Preview](assets/screenshot.png)
19
+
20
+ ## Features
21
+
22
+ - **Power Profiles**: Seamless switching across Quiet, Balanced, and Performance modes using Linux kernel ACPI (`platform_profile`) and `power-profiles-daemon`.
23
+ - **GPU Switching & PRIME Offload**: Hybrid and Integrated GPU management via `supergfxctl`, `envycontrol`, or `system76-power`, plus on-demand dGPU application execution via NVIDIA PRIME render offload.
24
+ - **Battery Health Preservation**: Configurable charging limits (60%, 80%, 100%) via standard sysfs battery thresholds, Lenovo IdeaPad conservation mode, and ThinkPad charge stop controls.
25
+ - **Keyboard Lighting**: Multi-mode RGB lighting and brightness controls with support for ASUS Aura, OpenRGB, and generic Linux kernel sysfs LED backlights.
26
+ - **Hardware Telemetry**: Real-time monitoring of CPU governors, thermal sensors, fan speeds, and NVIDIA GPU statistics (temperatures, power draw, and VRAM utilization).
27
+ - **Desktop Integration**: Polkit-authenticated sysfs helper for secure unprivileged tuning, tray menu with background polling, and responsive Qt interface.
28
+
29
+ ## Installation
30
+
31
+ ```sh
32
+ # Install base package and CLI
33
+ python -m pip install .
34
+
35
+ # Install with GUI dependencies
36
+ python -m pip install '.[gui]'
37
+ ```
38
+
39
+ ## Desktop & Launcher Setup
40
+
41
+ Install the desktop entry and system icons:
42
+
43
+ ```sh
44
+ data/install-desktop-entry
45
+ ```
46
+
47
+ To enable unprivileged battery limit and platform profile updates via PolicyKit:
48
+
49
+ ```sh
50
+ sudo ./install-helper.sh
51
+ ```
52
+
53
+ ## CLI Usage
54
+
55
+ ```sh
56
+ # View system hardware status
57
+ tux-armory status
58
+
59
+ # View and set power profile
60
+ tux-armory profiles
61
+ tux-armory set-profile balanced
62
+
63
+ # GPU control
64
+ tux-armory gpu
65
+ tux-armory set-gpu Hybrid
66
+
67
+ # Set battery charge limit
68
+ tux-armory set-charge-limit 80
69
+
70
+ # Keyboard lighting
71
+ tux-armory aura mode "Colour Cycle"
72
+ tux-armory aura brightness 3
73
+ ```
74
+
75
+ ## Architecture
76
+
77
+ For an overview of the modular backend drivers, sysfs integration, and extension points, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
@@ -0,0 +1,67 @@
1
+ # TuxArmory
2
+
3
+ [![CI](https://github.com/rhn-ryan/TuxArmory/actions/workflows/ci.yml/badge.svg)](https://github.com/rhn-ryan/TuxArmory/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ TuxArmory is a lightweight, cross-distribution Linux hardware and performance control center designed for gaming laptops and workstations. It provides both an intuitive PySide6 desktop interface and a scriptable command-line utility for managing power profiles, GPU switching, battery health thresholds, keyboard backlighting, and live hardware telemetry.
7
+
8
+ ![TuxArmory Preview](assets/screenshot.png)
9
+
10
+ ## Features
11
+
12
+ - **Power Profiles**: Seamless switching across Quiet, Balanced, and Performance modes using Linux kernel ACPI (`platform_profile`) and `power-profiles-daemon`.
13
+ - **GPU Switching & PRIME Offload**: Hybrid and Integrated GPU management via `supergfxctl`, `envycontrol`, or `system76-power`, plus on-demand dGPU application execution via NVIDIA PRIME render offload.
14
+ - **Battery Health Preservation**: Configurable charging limits (60%, 80%, 100%) via standard sysfs battery thresholds, Lenovo IdeaPad conservation mode, and ThinkPad charge stop controls.
15
+ - **Keyboard Lighting**: Multi-mode RGB lighting and brightness controls with support for ASUS Aura, OpenRGB, and generic Linux kernel sysfs LED backlights.
16
+ - **Hardware Telemetry**: Real-time monitoring of CPU governors, thermal sensors, fan speeds, and NVIDIA GPU statistics (temperatures, power draw, and VRAM utilization).
17
+ - **Desktop Integration**: Polkit-authenticated sysfs helper for secure unprivileged tuning, tray menu with background polling, and responsive Qt interface.
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ # Install base package and CLI
23
+ python -m pip install .
24
+
25
+ # Install with GUI dependencies
26
+ python -m pip install '.[gui]'
27
+ ```
28
+
29
+ ## Desktop & Launcher Setup
30
+
31
+ Install the desktop entry and system icons:
32
+
33
+ ```sh
34
+ data/install-desktop-entry
35
+ ```
36
+
37
+ To enable unprivileged battery limit and platform profile updates via PolicyKit:
38
+
39
+ ```sh
40
+ sudo ./install-helper.sh
41
+ ```
42
+
43
+ ## CLI Usage
44
+
45
+ ```sh
46
+ # View system hardware status
47
+ tux-armory status
48
+
49
+ # View and set power profile
50
+ tux-armory profiles
51
+ tux-armory set-profile balanced
52
+
53
+ # GPU control
54
+ tux-armory gpu
55
+ tux-armory set-gpu Hybrid
56
+
57
+ # Set battery charge limit
58
+ tux-armory set-charge-limit 80
59
+
60
+ # Keyboard lighting
61
+ tux-armory aura mode "Colour Cycle"
62
+ tux-armory aura brightness 3
63
+ ```
64
+
65
+ ## Architecture
66
+
67
+ For an overview of the modular backend drivers, sysfs integration, and extension points, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
Binary file
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ set -eu
3
+
4
+ source_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
5
+ applications_dir=${XDG_DATA_HOME:-"$HOME/.local/share"}/applications
6
+ mkdir -p "$applications_dir"
7
+ if [ -f "$source_dir/tux-armory.desktop" ]; then
8
+ install -m 0644 "$source_dir/tux-armory.desktop" "$applications_dir/tux-armory.desktop"
9
+ fi
10
+
11
+ if [ "${1:-}" = "--autostart" ]; then
12
+ autostart_dir=${XDG_CONFIG_HOME:-"$HOME/.config"}/autostart
13
+ mkdir -p "$autostart_dir"
14
+ if [ -f "$source_dir/tux-armory.desktop" ]; then
15
+ install -m 0644 "$source_dir/tux-armory.desktop" "$autostart_dir/tux-armory.desktop"
16
+ fi
17
+ fi
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+ set -eu
3
+
4
+ if [ "$(id -u)" -ne 0 ]; then
5
+ echo "Run this installer as root (for example, with sudo)." >&2
6
+ exit 1
7
+ fi
8
+ source_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
9
+ install -D -m 0755 "$source_dir/tux-armory-sysfs-helper" /usr/libexec/tux-armory-sysfs-helper
10
+ install -D -m 0644 "$source_dir/org.tuxarmory.policy" /usr/share/polkit-1/actions/org.tuxarmory.policy
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
3
+ "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
4
+ <policyconfig>
5
+ <action id="org.tuxarmory.write-sysfs">
6
+ <description>Change TuxArmory hardware settings</description>
7
+ <message>Authentication is required to change hardware settings</message>
8
+ <defaults>
9
+ <allow_any>auth_admin</allow_any>
10
+ <allow_inactive>auth_admin</allow_inactive>
11
+ <allow_active>auth_admin_keep</allow_active>
12
+ </defaults>
13
+ <annotate key="org.freedesktop.policykit.exec.path">/usr/libexec/tux-armory-sysfs-helper</annotate>
14
+ </action>
15
+ </policyconfig>
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env python3
2
+ """Narrowly scoped root helper for supported TuxArmory sysfs writes across laptop vendors."""
3
+ import re
4
+ import sys
5
+ from pathlib import Path
6
+
7
+
8
+ def main() -> int:
9
+ if len(sys.argv) != 3:
10
+ print("usage: tux-armory-sysfs-helper SETTING VALUE", file=sys.stderr)
11
+ return 2
12
+ setting, value = sys.argv[1:]
13
+ if setting == "platform_profile":
14
+ path = Path("/sys/firmware/acpi/platform_profile")
15
+ choices = Path("/sys/firmware/acpi/platform_profile_choices")
16
+ if not re.fullmatch(r"[a-zA-Z0-9_-]+", value) or value not in choices.read_text().split():
17
+ print("unsupported platform profile", file=sys.stderr)
18
+ return 2
19
+ elif setting in ("charge_control_end_threshold", "charge_control_start_threshold", "charge_stop_threshold", "charge_start_threshold"):
20
+ path = next((p / setting for p in sorted(Path("/sys/class/power_supply").glob("BAT*"))
21
+ if (p / setting).is_file()), None)
22
+ if path is None or not value.isdecimal() or not 1 <= int(value) <= 100:
23
+ print("invalid battery charge limit", file=sys.stderr)
24
+ return 2
25
+ elif setting == "conservation_mode":
26
+ candidates = (
27
+ Path("/sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode"),
28
+ Path("/sys/bus/platform/drivers/ideapad_laptop/VPC2004:00/conservation_mode"),
29
+ Path("/sys/bus/platform/devices/VPC2004:00/conservation_mode"),
30
+ )
31
+ path = next((c for c in candidates if c.is_file()), None)
32
+ if path is None or value not in ("0", "1"):
33
+ print("invalid Lenovo conservation mode value", file=sys.stderr)
34
+ return 2
35
+ elif setting == "kbd_brightness":
36
+ candidates = sorted(Path("/sys/class/leds").glob("*kbd*")) + sorted(Path("/sys/class/leds").glob("*::kbd_backlight"))
37
+ led = next((c for c in candidates if (c / "brightness").is_file()), None)
38
+ path = (led / "brightness") if led else None
39
+ if path is None or not value.isdecimal():
40
+ print("invalid keyboard brightness", file=sys.stderr)
41
+ return 2
42
+ else:
43
+ print("unsupported sysfs setting", file=sys.stderr)
44
+ return 2
45
+ try:
46
+ path.write_text(value, encoding="utf-8")
47
+ except OSError as exc:
48
+ print(f"cannot write sysfs setting: {exc}", file=sys.stderr)
49
+ return 1
50
+ return 0
51
+
52
+
53
+ if __name__ == "__main__":
54
+ raise SystemExit(main())
@@ -0,0 +1,10 @@
1
+ [Desktop Entry]
2
+ Name=TuxArmory
3
+ Comment=Linux power profile, GPU switching, and hardware controls
4
+ Exec=tux-armory-gui
5
+ Icon=tux-armory
6
+ Terminal=false
7
+ Type=Application
8
+ Categories=System;Settings;HardwareSettings;
9
+ StartupWMClass=tux-armory
10
+ StartupNotify=true
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128">
2
+ <defs>
3
+ <linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" stop-color="#3182ce"/>
5
+ <stop offset="100%" stop-color="#805ad5"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect width="128" height="128" rx="28" fill="#1b222c"/>
9
+ <rect x="6" y="6" width="116" height="116" rx="24" fill="none" stroke="#3c4a5b" stroke-width="4"/>
10
+ <path d="M64 20 L86 54 L68 54 L80 96 L46 62 L60 62 Z" fill="url(#grad)" stroke="#63b3ed" stroke-width="2" stroke-linejoin="round"/>
11
+ <circle cx="64" cy="108" r="6" fill="#63b3ed"/>
12
+ </svg>
@@ -0,0 +1,54 @@
1
+ # TuxArmory Architecture & Extension Guide
2
+
3
+ TuxArmory is built around decoupled backend abstractions. Hardware interactions are isolated into independent driver classes that interface directly with Linux kernel sysfs nodes, D-Bus interfaces, or system command utilities.
4
+
5
+ ## Core Architecture
6
+
7
+ ```
8
+ ┌────────────────────────────────────────────────────────┐
9
+ │ TuxArmory │
10
+ │ PySide6 Desktop GUI / CLI Interface │
11
+ └──────────────────────────┬─────────────────────────────┘
12
+ │
13
+ ┌─────────────┼─────────────┐
14
+ ▼ ▼ ▼
15
+ PowerManager GpuManager BatteryManager
16
+ │ │ │
17
+ ┌────────┴────────┐ │ ├─ sysfs (Standard Linux)
18
+ │ platform_profile│ │ ├─ ideapad (Lenovo Conservation)
19
+ │ powerprofilesctl│ │ ├─ thinkpad (Legacy stop/start)
20
+ └─────────────────┘ │ └─ asusctl (ASUS fallback)
21
+ │
22
+ ┌────────┴────────┐
23
+ │ supergfxctl │
24
+ │ envycontrol │
25
+ │ system76-power │
26
+ │ prime-offload │
27
+ └─────────────────┘
28
+ ```
29
+
30
+ ## Backend Modules
31
+
32
+ ### 1. Power Profiles (`tux_armory/backend/power.py`)
33
+ - **`PlatformProfileDriver`**: Standard ACPI platform profile `/sys/firmware/acpi/platform_profile` (supported by ASUS, Lenovo ThinkPad/IdeaPad, Dell, HP, Framework).
34
+ - **`PowerProfilesDaemonDriver`**: D-Bus daemon backend accessible via `powerprofilesctl` on standard desktop installations.
35
+
36
+ ### 2. GPU Switching & Acceleration (`tux_armory/backend/gpu.py`)
37
+ - **`SupergfxctlDriver`**: Communicates with the `supergfxd` D-Bus daemon.
38
+ - **`EnvycontrolDriver`**: Cross-distro GPU switcher for NVIDIA Optimus laptops.
39
+ - **`System76PowerGpuDriver`**: Graphics switcher for System76 / Pop!_OS systems.
40
+ - **PRIME Offload**: Execution of individual applications on dedicated GPUs via `__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia`.
41
+
42
+ ### 3. Battery Health & Charging Limits (`tux_armory/backend/battery.py`)
43
+ - **Standard Linux sysfs**: Reads and writes to `/sys/class/power_supply/BAT*/charge_control_end_threshold`.
44
+ - **Lenovo IdeaPad**: Interfaces with `conservation_mode` across `ideapad_acpi` and `ideapad_laptop` platform drivers.
45
+ - **ThinkPad Legacy**: Supports `/sys/class/power_supply/BAT*/charge_stop_threshold`.
46
+ - **ASUS fallback**: Uses `asusctl battery limit`.
47
+
48
+ ### 4. Keyboard Lighting & LEDs (`tux_armory/backend/aura.py`)
49
+ - **ASUS Aura D-Bus & CLI**: Hardware-tailored effect maps for single-zone and multi-zone ASUS gaming laptops.
50
+ - **OpenRGB**: Universal multi-vendor RGB peripheral control.
51
+ - **Generic Linux LED class**: Standard `/sys/class/leds/*kbd_backlight/brightness` brightness control for any backlit keyboard.
52
+
53
+ ### 5. PolicyKit Root Helper (`data/tux-armory-sysfs-helper`)
54
+ - Privileged sysfs writes (platform profile, battery thresholds, conservation mode) are narrowly validated and executed via `pkexec` without running entire applications as root.
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -e
3
+ echo "Installing TuxArmory sysfs helper and Polkit policy..."
4
+ sudo mkdir -p /usr/libexec
5
+ sudo install -m 755 data/tux-armory-sysfs-helper /usr/libexec/tux-armory-sysfs-helper
6
+ sudo install -m 644 data/org.tuxarmory.policy /usr/share/polkit-1/actions/org.tuxarmory.policy
7
+ echo "Installation complete."
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tux-armory"
7
+ version = "0.2.0"
8
+ description = "Cross-distro Linux power profiles, GPU switching, and hardware controls for gaming laptops"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+ dependencies = []
13
+
14
+ [project.optional-dependencies]
15
+ gui = ["PySide6>=6.7"]
16
+
17
+ [project.scripts]
18
+ tux-armory = "tux_armory.cli:main"
19
+ tux-armory-gui = "tux_armory.ui:main"
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ packages = ["tux_armory"]
23
+
24
+ [tool.hatch.build.targets.wheel.force-include]
25
+ "data/org.tuxarmory.policy" = "share/tux-armory/org.tuxarmory.policy"
26
+ "data/tux-armory-sysfs-helper" = "libexec/tux-armory-sysfs-helper"
27
+ "data/tux-armory.desktop" = "share/applications/tux-armory.desktop"
28
+ "data/tux-armory.svg" = "share/icons/hicolor/scalable/apps/tux-armory.svg"
29
+ "data/install-desktop-entry" = "share/tux-armory/install-desktop-entry"
@@ -0,0 +1,75 @@
1
+ import pytest
2
+ from tux_armory.backend.battery import BatteryManager
3
+ from tux_armory.backend.base import BackendError
4
+ from tux_armory.backend.presets import Preset
5
+
6
+
7
+ def test_battery_validation_valid_values():
8
+ assert BatteryManager.validate_limit(20) == 20
9
+ assert BatteryManager.validate_limit(100) == 100
10
+ assert BatteryManager.validate_limit(80) == 80
11
+ assert BatteryManager.validate_limit(75) == 75
12
+ assert BatteryManager.validate_limit("80") == 80
13
+ assert BatteryManager.validate_limit(" 85% ") == 85
14
+ assert BatteryManager.validate_limit(90.0) == 90
15
+
16
+
17
+ @pytest.mark.parametrize("invalid_limit", [
18
+ -1, -50, "-10", "-80%", "0", 0, 1, 10, 19, "19%", 101, 150, "150%",
19
+ "abc", "", " ", True, False, None, float("nan"), float("inf"), 80.5,
20
+ ])
21
+ def test_battery_validation_edgecases(invalid_limit):
22
+ with pytest.raises(BackendError):
23
+ BatteryManager.validate_limit(invalid_limit)
24
+
25
+
26
+ def test_preset_validation_with_charge_limit():
27
+ preset = Preset("TestPreset", "Balanced", "Hybrid", 75)
28
+ preset.validate()
29
+ assert preset.charge_limit == 75
30
+
31
+ with pytest.raises(BackendError):
32
+ bad_preset = Preset("Bad", "Balanced", "Hybrid", -5)
33
+ bad_preset.validate()
34
+
35
+ with pytest.raises(BackendError):
36
+ bad_preset2 = Preset("Bad2", "Balanced", "Hybrid", 105)
37
+ bad_preset2.validate()
38
+
39
+
40
+ def test_ui_custom_battery_sync():
41
+ from PySide6.QtWidgets import QApplication
42
+ from tux_armory.ui.app import MainWindow
43
+
44
+ app = QApplication.instance() or QApplication([])
45
+ window = MainWindow()
46
+
47
+ # Verify custom limit updates and formats UI
48
+ window._sync_charge_limit_ui(75)
49
+ assert window.charge_limit.currentText() == "75% (Custom)"
50
+ assert window.charge_limit.currentData() == 75
51
+
52
+ # Setting a standard limit resets selection
53
+ window.set_charge_limit(80)
54
+ assert window.charge_limit.currentText() == "80%"
55
+ assert window.charge_limit.currentData() == 80
56
+
57
+
58
+ def test_cli_set_charge_limit_validation(capsys):
59
+ from tux_armory.cli import main
60
+
61
+ with pytest.raises(SystemExit):
62
+ main(["set-charge-limit", "-10"])
63
+ err = capsys.readouterr().err
64
+ assert "Charge limit cannot be negative" in err
65
+
66
+ with pytest.raises(SystemExit):
67
+ main(["set-charge-limit", "150"])
68
+ err = capsys.readouterr().err
69
+ assert "cannot exceed 100%" in err
70
+
71
+ with pytest.raises(SystemExit):
72
+ main(["set-charge-limit", "10"])
73
+ err = capsys.readouterr().err
74
+ assert "below 20%" in err
75
+
@@ -0,0 +1,114 @@
1
+ from pathlib import Path
2
+ import pytest
3
+
4
+ from tux_armory.backend.base import BackendError
5
+ from tux_armory.backend.battery import BatteryManager
6
+ from tux_armory.backend.gpu import EnvycontrolDriver, System76PowerGpuDriver, GpuManager
7
+ from tux_armory.backend.aura import AuraManager
8
+
9
+
10
+ def test_battery_lenovo_ideapad_conservation_mode(tmp_path):
11
+ ideapad_dir = tmp_path / "ideapad"
12
+ ideapad_dir.mkdir()
13
+ conservation_file = ideapad_dir / "conservation_mode"
14
+ conservation_file.write_text("1\n")
15
+
16
+ manager = BatteryManager(sysfs_root=tmp_path / "missing", conservation_path=conservation_file)
17
+ assert manager.status().available
18
+ assert manager.status().name == "ideapad"
19
+ assert manager.get_limits() == {"end": 60}
20
+
21
+ manager.set_limit(100)
22
+ assert conservation_file.read_text().strip() == "0"
23
+ manager.set_limit(60)
24
+ assert conservation_file.read_text().strip() == "1"
25
+
26
+
27
+ def test_battery_thinkpad_legacy_thresholds(tmp_path):
28
+ bat = tmp_path / "BAT0"
29
+ bat.mkdir()
30
+ (bat / "charge_start_threshold").write_text("45\n")
31
+ (bat / "charge_stop_threshold").write_text("85\n")
32
+
33
+ manager = BatteryManager(sysfs_root=tmp_path)
34
+ assert manager.status().available
35
+ assert manager.get_limits() == {"start": 45, "end": 85}
36
+ manager.set_limit(80)
37
+ assert (bat / "charge_stop_threshold").read_text().strip() == "80"
38
+
39
+
40
+ def test_envycontrol_gpu_driver(monkeypatch):
41
+ calls = []
42
+
43
+ def fake_run(cmd):
44
+ calls.append(cmd)
45
+ if "--query" in cmd:
46
+ return "hybrid\n"
47
+ return "switching to integrated"
48
+
49
+ monkeypatch.setattr("tux_armory.backend.gpu.has_command", lambda cmd: cmd == "envycontrol")
50
+ monkeypatch.setattr("tux_armory.backend.gpu.run_command", fake_run)
51
+
52
+ driver = EnvycontrolDriver()
53
+ assert driver.available()
54
+ assert driver.get_mode() == "hybrid"
55
+ assert driver.get_modes() == ["hybrid", "integrated", "nvidia"]
56
+ driver.set_mode("integrated")
57
+ assert ["envycontrol", "-s", "integrated"] in calls
58
+
59
+
60
+ def test_system76_power_gpu_driver(monkeypatch):
61
+ calls = []
62
+
63
+ def fake_run(cmd):
64
+ calls.append(cmd)
65
+ if len(cmd) == 2 and cmd[1] == "graphics":
66
+ return "integrated\n"
67
+ return ""
68
+
69
+ monkeypatch.setattr("tux_armory.backend.gpu.has_command", lambda cmd: cmd == "system76-power")
70
+ monkeypatch.setattr("tux_armory.backend.gpu.run_command", fake_run)
71
+
72
+ driver = System76PowerGpuDriver()
73
+ assert driver.available()
74
+ assert driver.get_mode() == "integrated"
75
+ assert "nvidia" in driver.get_modes()
76
+ driver.set_mode("hybrid")
77
+ assert ["system76-power", "graphics", "hybrid"] in calls
78
+
79
+
80
+ def test_gpu_manager_selects_available_driver(monkeypatch):
81
+ monkeypatch.setattr("tux_armory.backend.gpu.has_command", lambda cmd: cmd == "envycontrol")
82
+ monkeypatch.setattr("tux_armory.backend.gpu.run_command", lambda cmd: "integrated\n")
83
+
84
+ manager = GpuManager()
85
+ assert manager.backend_name == "envycontrol"
86
+ assert manager.get_mode() == "integrated"
87
+
88
+
89
+ def test_keyboard_lighting_sysfs_fallback(monkeypatch, tmp_path):
90
+ monkeypatch.setattr("tux_armory.backend.aura._dbus_check", lambda: False)
91
+ monkeypatch.setattr("tux_armory.backend.aura.has_command", lambda _: False)
92
+ led_dir = tmp_path / "tpacpi::kbd_backlight"
93
+ led_dir.mkdir()
94
+ (led_dir / "brightness").write_text("1\n")
95
+ (led_dir / "max_brightness").write_text("2\n")
96
+
97
+ manager = AuraManager(leds_root=tmp_path)
98
+ assert manager.status().available
99
+ assert manager.status().name == "sysfs_leds"
100
+ manager.set_brightness(3)
101
+ assert (led_dir / "brightness").read_text().strip() == "2"
102
+
103
+
104
+ def test_aura_colour_cycle_and_pulse_cli(monkeypatch):
105
+ from tux_armory.backend import aura
106
+ calls = []
107
+ monkeypatch.setattr(aura, "_dbus_check", lambda: False)
108
+ monkeypatch.setattr(aura, "has_command", lambda name: name == "asusctl")
109
+ monkeypatch.setattr(aura, "run_command", lambda args: calls.append(args) or "")
110
+ manager = AuraManager()
111
+ manager.set_mode("Colour Cycle")
112
+ assert ["asusctl", "aura", "effect", "rainbow-cycle", "--speed", "med"] in calls
113
+ manager.set_mode("Pulse")
114
+ assert ["asusctl", "aura", "effect", "pulse", "-c", "ffffff"] in calls
@@ -0,0 +1,50 @@
1
+ import pytest
2
+
3
+ from tux_armory.backend.battery import BatteryManager
4
+ from tux_armory.backend.nvidia_telemetry import NvidiaTelemetry
5
+ from tux_armory.backend.fan import FanManager
6
+
7
+
8
+ def test_battery_reads_and_writes_sysfs_threshold(tmp_path):
9
+ bat = tmp_path / "BAT0"
10
+ bat.mkdir()
11
+ (bat / "charge_control_start_threshold").write_text("40\n")
12
+ (bat / "charge_control_end_threshold").write_text("80\n")
13
+ manager = BatteryManager(tmp_path)
14
+ assert manager.status().available
15
+ assert manager.get_limits() == {"start": 40, "end": 80}
16
+ manager.set_limit(75)
17
+ assert (bat / "charge_control_end_threshold").read_text() == "75"
18
+
19
+
20
+ def test_battery_asusctl_fallback(monkeypatch, tmp_path):
21
+ from tux_armory.backend import battery
22
+ calls = []
23
+ monkeypatch.setattr(battery, "has_command", lambda _: True)
24
+ monkeypatch.setattr(battery, "run_command", lambda args: calls.append(args) or "80")
25
+ manager = BatteryManager(tmp_path)
26
+ assert manager.get_limits()["end"] == 80
27
+
28
+
29
+ def test_nvidia_csv_parse_and_offline_fallback(monkeypatch):
30
+ from tux_armory.backend import nvidia_telemetry as module
31
+ csv = '52, 34, 4096, 8192, 120.5, 1234, "python, 123, 4 MiB"'
32
+ monkeypatch.setattr(module, "has_command", lambda _: True)
33
+ monkeypatch.setattr(module, "run_command", lambda args: csv)
34
+ result = NvidiaTelemetry().read()
35
+ assert result.temperature_c == 52
36
+ assert result.utilization_percent == 34
37
+ assert result.memory_used_mib == 4096 and result.memory_total_mib == 8192
38
+ assert result.power_w == 120.5 and len(result.processes) == 1
39
+ monkeypatch.setattr(module, "run_command", lambda args: (_ for _ in ()).throw(module.BackendError("offline")))
40
+ assert NvidiaTelemetry().read() is None
41
+
42
+
43
+ def test_fan_detection_and_unsupported(tmp_path):
44
+ hwmon = tmp_path / "hwmon0"
45
+ hwmon.mkdir()
46
+ (hwmon / "fan1_input").write_text("2100\n")
47
+ (hwmon / "fan1_label").write_text("CPU Fan\n")
48
+ manager = FanManager(tmp_path)
49
+ assert manager.get_fans()[0].rpm == 2100
50
+ assert FanManager(tmp_path / "missing").get_fans() == []