def status(): '''Tells whether the door is in the up or down position''' debug = lib.debugging.printmsg errors = ErrCls() up_pin = config.conf['DOOR_REED_UP_PIN'] dn_pin = config.conf['DOOR_REED_DN_PIN'] up_btn = Button(up_pin) dn_btn = Button(dn_pin) up = up_btn.value dn = dn_btn.value # FIXME With nothing plugged in they default to down. Not sure why. status = 'between' if dn and not up: status = 'dn' elif not dn and up: status = 'up' elif up and dn: errors.err('Door reed switch malfunction.') debug("status: '" + str(status) + "'", level=1) return status
import lib.ntp import lib.debugging from lib.leds import leds from lib.err import ErrCls from lib.cloud import cloud from time import time, sleep from lib.config import config from lib.system import SystemCls # TODO ScheduleCls for consistency from lib.schedule import Schedule from lib.update_sys import get_sys_updates from lib.update_data import get_data_updates leds.LED('good', default=True) errors = ErrCls() system = SystemCls() debug = lib.debugging.printmsg def updates(): try: debug("main.py get_sys_updates()", level=1) get_sys_updates() # FIXME Receive this on the server debug("main.py cloud.send version", level=1) cloud.send('version', system.version) # FIXME Also send the attached device status # FIXME Receive this on the server debug("main.py cloud.send attached_devices", level=1) cloud.send('attached_devices', system.attached_devices)
# Import files from the parent directory from sys import path path.append('..') import cgi # FIXME Log to the server and change the line below this to this. #cgitb.enable(display=0, logdir="/path/to/logdir") import cgitb cgitb.enable() import lib.debugging from lib.err import ErrCls from lib.config import config from re import search as re_search from urllib.parse import urlparse, parse_qs err = ErrCls() form = cgi.FieldStorage() params = cgi.FieldStorage() debug = lib.debugging.printmsg def get_template(): '''Returns our template as a string''' #try: with open(config.conf['WEB_ADMIN_TEMPLATE_FILE']) as f: template = f.read() #except OSError: # warning = ("Could not load the web admin template.", # " ('web_admin/__init__.py', '_daemon')") # err.warning(warning)
from lib.err import ErrCls def find_msg(msg_type, test_msg): '''Search for exactly our type and message in errors.log''' found = False if len(errors.log) > 0: for entry in errors.log: if len(entry) > 0: if entry[1] == msg_type: if 'message' in entry[2]: if entry[2]['message'] == test_msg: found = True return found # TODO Ensure I use a consistent name everywhere. Should be errors, not err. errors = ErrCls() good = test_suite.good test_msg = "Test message" errors.warn(test_msg) assert find_msg('warning', test_msg) == True, "errors.warn()" good("errors.warn()") errors.err(test_msg) assert find_msg('error', test_msg) == True, "errors.warn()" good("errors.err()") try: raise RuntimeError("errors.exc()")