Skip to content
Open
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
2 changes: 0 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ log_level: INFO # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL

nut:
ups: "ups@localhost" # Format: <ups-name>@<host>
username: "upsmon" # Optional: omit if NUT server doesn't require auth
password: "password"

poll_interval: 15 # Poll interval in seconds — should be shorter than the NUT shutdown delay on any client
status_file: "/config/wolnut_state.json" # Path to status file, recommended you change this to be outside container if using Docker
Expand Down
6 changes: 1 addition & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ The file path where `wolnut` will store its state. This allows the service to re
Configuration for connecting to your NUT (Network UPS Tools) server.

- `ups`: **(Required)** The name and address of the UPS to monitor.
- **Format**: `<ups-name>`, supports deprecated `<ups-name>@<hostname>` for backward compatibilty.
- `hostname`: The hostname of the NUT server. Defaults to `localhost`.
- `port`: The port of the NUT server. Defaults to `3493`.
- `username`: The username for authenticating with the NUT server (optional).
- `password`: The password for authenticating with the NUT server (optional).
- **Format**: `<ups-name>@<hostname>` (for example: `ups@localhost`).

---

Expand Down
7 changes: 3 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ Open `~/wolnut/config.yaml` in your favorite text editor and add the following m

nut:
# The name of your UPS as defined in your NUT server configuration.
# Format: <ups-name>
ups: "ups"
hostname: "127.0.0.1" # not needed if running localhost/127.0.0.1
# Format: <ups-name>@<hostname>
ups: "ups@localhost"

# The directory for the status file should be writable. It will be created if it doesn't exist.
status_file: "/config/wolnut_state.json"
status_file: "/config/wolnut_state.json"

clients:
- name: "my-pc"
Expand Down
4 changes: 0 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def full_config_dict():
"status_file": "/data/status.json",
"nut": {
"ups": "myups@nut-server",
"port": 1234,
"username": "monuser",
"password": "monpassword",
},
"wake_on": {
"restore_delay_sec": 60,
Expand Down Expand Up @@ -82,7 +79,6 @@ def test_load_config_full(mocker, full_config_dict):
assert cfg.poll_interval == 5
assert cfg.status_file == "/data/status.json"
assert cfg.nut.ups == "myups@nut-server"
assert cfg.nut.username == "monuser"
assert cfg.wake_on.restore_delay_sec == 60
assert cfg.wake_on.min_battery_percent == 50
assert len(cfg.clients) == 2
Expand Down
4 changes: 0 additions & 4 deletions wolnut/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
@dataclass
class NutConfig:
ups: str
port: int = 3493
timeout: int = 5
username: str | None = None
password: str | None = None


@dataclass
Expand Down
11 changes: 1 addition & 10 deletions wolnut/monitor.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import subprocess
import logging
import platform
from typing import Optional

logger = logging.getLogger("wolnut")


def get_ups_status(
ups_name: str, username: Optional[str] = None, password: Optional[str] = None
) -> dict:
env = None

if username and password:
env = {**subprocess.os.environ, "USERNAME": username, "PASSWORD": password}

def get_ups_status(ups_name: str) -> dict:
try:
result = subprocess.run(
["upsc", ups_name],
capture_output=True,
text=True,
env=env,
timeout=5,
check=False,
)
Expand Down