power: restrict lines to 80 chars, remove trailing whitespace

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-07-29 17:46:27 -04:00
parent 31bebdd59c
commit 92d7d7c2b7
2 changed files with 34 additions and 19 deletions

View File

@ -49,7 +49,8 @@ class PrinterPower:
result[dev] = "device_not_found"
continue
GPIO.verify_pin(self.devices[dev]["pin"], self.devices[dev]["active_low"])
GPIO.verify_pin(self.devices[dev]["pin"],
self.devices[dev]["active_low"])
if path == "/printer/power/on":
GPIO.set_pin_value(self.devices[dev]["pin"], 1)
elif path == "/printer/power/off":
@ -57,7 +58,8 @@ class PrinterPower:
elif path != "/printer/power/status":
raise self.server.error("Unsupported power request")
self.devices[dev]["status"] = GPIO.is_pin_on(self.devices[dev]["pin"])
self.devices[dev]["status"] = GPIO.is_pin_on(
self.devices[dev]["pin"])
result[dev] = self.devices[dev]["status"]
return result
@ -72,22 +74,33 @@ class PrinterPower:
for dev in devices:
dev = dev.strip()
if dev + "_pin" not in config.keys():
logging.info("Power plugin: ERR " + dev + " does not have a pin defined")
logging.info(
"Power plugin: ERR " + dev + " does not have a pin defined")
continue
name = config[dev + "_name"] if dev + "_name" in config.keys() \
else dev
active_low = 1 if dev+"_active_low" in config.keys() and \
config[dev+"_active_low"] == "True" else 0
self.devices[dev] = {
"name": config[dev + "_name"] if dev + "_name" in config.keys() else dev,
"name": name,
"pin": int(config[dev + "_pin"]),
"active_low": 1 if dev+"_active_low" in config.keys() and config[dev+"_active_low"] == "True" else 0,
"active_low": active_low,
"status": None
}
try:
logging.debug("Attempting to configure pin GPIO" + str(self.devices[dev]["pin"]))
GPIO.setup_pin(self.devices[dev]["pin"], self.devices[dev]["active_low"])
self.devices[dev]["status"] = GPIO.is_pin_on(self.devices[dev]["pin"])
except:
logging.info("Power plugin: ERR Problem configuring the output pin for device " + dev + ". Removing device")
logging.debug(
"Attempting to configure pin GPIO%d"
% (self.devices[dev]["pin"]))
GPIO.setup_pin(
self.devices[dev]["pin"], self.devices[dev]["active_low"])
self.devices[dev]["status"] = GPIO.is_pin_on(
self.devices[dev]["pin"])
except Exception:
logging.info(
"Power plugin: ERR Problem configuring the output pin for"
" device %s. Removing device" % (dev))
self.devices.pop(dev, None)
continue
@ -97,13 +110,14 @@ class GPIO:
@staticmethod
def _set_gpio_option(gpio, option, value):
GPIO._write(
os.path.join(GPIO.gpio_root, "gpio"+str(gpio), option),
os.path.join(GPIO.gpio_root, "gpio%d" % (gpio), option),
value
)
@staticmethod
def _get_gpio_option(pin, option):
return GPIO._read(
os.path.join(GPIO.gpio_root, "gpio"+str(pin), option)
os.path.join(GPIO.gpio_root, "gpio%d" % (pin), option)
)
@staticmethod
@ -120,9 +134,9 @@ class GPIO:
@staticmethod
def verify_pin(pin, active_low=1):
gpiopath = os.path.join(GPIO.gpio_root, "gpio"+str(pin))
gpiopath = os.path.join(GPIO.gpio_root, "gpio%d" % (pin))
if not os.path.exists(gpiopath):
logging.info("Re-intializing GPIO"+str(pin))
logging.info("Re-intializing GPIO%d" % (pin))
GPIO.setup_pin(pin, active_low)
return
@ -137,13 +151,14 @@ class GPIO:
pin = int(pin)
active_low = 1 if active_low == 1 else 0
gpiopath = os.path.join(GPIO.gpio_root, "gpio"+str(pin))
gpiopath = os.path.join(GPIO.gpio_root, "gpio%d" % (pin))
if not os.path.exists(gpiopath):
GPIO._write(
os.path.join(GPIO.gpio_root, "export"),
pin)
logging.info("Waiting for GPIO"+str(pin)+" to initialize")
while os.stat(os.path.join(GPIO.gpio_root, "gpio"+str(pin),"active_low")).st_gid == 0:
logging.info("Waiting for GPIO%d to initialize" % (pin))
while os.stat(os.path.join(
GPIO.gpio_root, "gpio%dactive_low") % (pin)).st_gid == 0:
time.sleep(.1)
if GPIO._get_gpio_option(pin, "active_low").strip() != str(active_low):