Verified Commit ac780602 authored by Gigadoc 2's avatar Gigadoc 2
Browse files

simple power command

[submodule "eins"]
path = eins
url =
Subproject commit 56e1b2b22e28a4630499644270c292047b62e7cf
Description=Desktop speakers
ExecStart=echo speaker turned on
ExecStop=echo speaker turned off
#!/usr/bin/env python3
import configparser
import sys
import subprocess
from eins import Eins
actors = configparser.ConfigParser()"power_command.ini")
#XXX: Complain on not present, make name configurable
# Check if all the devices have the required settings
error = False
for actor in actors.sections():
for key in ["ExecStart", "ExecStop"]:
if key not in actors[actor]:
#XXX: Logging
print("Device {} is missing the required setting {}.".format(actor, key))
error = True
if error:
eins = Eins()
def power(target, state):
if target not in actors.sections():
print("Don't know the device {}.".format(target)) #XXX: Logging
if state == "on":[target]['ExecStart'], shell=True, check=True)
#TODO: catch errors, logging
elif state == "off":[target]['ExecStop'], shell=True, check=True)
#TODO: above
print("Unknown power state {}, did you mean \"on\" or \"off\"?".format(target))
#XXX: Logging
#TODO: Replace with standardized discovery
def commands():
print("Known devices:")
for key in actors.sections():
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment