def update(opts): cfg = model.load(filename) cfg[opts['device']] = { 'pin': opts['pin'], 'default': opts['default'] } model.save(filename, cfg)
def set(req, res): yield from req.read_form_data() cfg = model.load() for key, value in req.form.items(): cfg[key] = value model.save(cfg) yield from get(req, res)
def boot(): from util import exists if not exists(filename): factory() cfg = model.load(filename) interface.config(dhcp_hostname=cfg['dhcp_hostname']) if 'ssid' in cfg: interface.connect(cfg['ssid'], cfg['passwd']) logger.info(ujson.dumps(get()))
def list(): cfg = model.load(filename) for name in cfg: pin = cfg[name]['pin'] cfg[name] = { 'pin': pin, 'default': cfg[name]['default'], 'value': device(pin).duty() } return cfg
def boot(): from util import exists if not exists(filename): factory() cfg = model.load(filename) for name in cfg: pin = cfg[name]['pin'] default = cfg[name]['default'] dev = device(pin) dev.freq(1024) dev.duty(default) logger.info(ujson.dumps(cfg))
def set(opts): cfg = model.load(filename) if 'name' in opts: name = opts['name'][0] interface.config(dhcp_hostname=name) cfg['dhcp_hostname'] = name if 'ssid' in opts and 'passwd' in opts: ssid = opts['ssid'][0] passwd = opts['passwd'][0] interface.connect(ssid, passwd) cfg['ssid'] = ssid cfg['passwd'] = passwd model.save(filename, cfg)
def duty(opts): cfg = model.load(filename)[opts['device']] device(cfg['pin']).duty(opts['value'])
def read(opts): cfg = model.load(filename) name = opts['device'] pin = cfg[name]['pin'] cfg[name]['value'] = device(pin).duty() return cfg[name]
def get(req, res): req.parse_qs() yield from ok(res, model.load(req.form['name'][0]))