lib.syspower

Host power actions (power off, reboot) via the operating system’s own commands.

No privilege handling is done here: the commands run as the user SmartHomeNG runs as, so the operating system’s configuration (polkit, sudoers, …) decides whether they are permitted.

lib.syspower.is_supported(platform_name=None)[Quellcode]

Tells whether power actions are available on a platform.

Parameter:

platform_name (str | None) – lower-case platform.system() name, defaults to the running platform

Rückgabetyp:

bool

lib.syspower.run_power_action(action, platform_name=None, timeout=15)[Quellcode]

Runs the platform’s command for a power action and waits for it to return.

The command normally returns as soon as the operating system has accepted the request; the host then terminates SmartHomeNG itself.

Parameter:
  • action (Literal['poweroff', 'reboot']) – ‚poweroff‘ or ‚reboot‘

  • platform_name (str | None) – lower-case platform.system() name, defaults to the running platform

  • timeout (float) – seconds to wait for the command to return

Rückgabetyp:

tuple[bool, str]

Rückgabe:

(True, ‚‘) on success, otherwise (False, error text from the command or its failure)

Verursacht:

ValueError – if action is not a known power action