def post(self): try: zwave.update_options(opt_parse.parse_args(strict=True)) except ZWaveException as e: return Ajax(msg="ZWaveException thrown: {}".format(str(e))) \ .set_state("options", OptionState.failed).render() p = zwave.raw_opts.device try: msg = "Could not open zwave serial device: {} [permissions?]".format( p) if p is None or not os.path.exists(p) or \ (not open(p, "rb").readable()) or \ (not open(p, "wb").writable()): print("bad device path: {}".format(p)) return ret_err(404, msg) except PermissionError as e: return ret_err(404, msg + " Exception: " + str(e)) try: zwave.set_options() except ZWaveException as e: return Ajax(msg="ZWaveException thrown: {}".format(str(e))) \ .set_state("options", OptionState.failed).render() return Ajax(data=dict(zwave.raw_opts.items())) \ .set_state("options", OptionState.locked).render()
def patch(self): msg = None try: zwave.update_options(opt_parse.parse_args(strict=True)) except ZWaveException as e: return Ajax(msg="ZWaveException thrown: {}".format(str(e))) \ .set_state("options", OptionState.failed).render() return Ajax(data=dict(zwave.raw_opts.items())) \ .set_state("options", OptionState.editable).render()
def delete(self): try: zwave.clear_options() except ZWaveException as e: return ret_err(404, msg="ZWaveException thrown: {}".format(str(e))) return Ajax(data=dict(zwave.raw_opts.items())) \ .set_state("options", OptionState.empty).render()
def netaction(action): """exec an 'action', restricted to the listed ones (for now)""" if (zwave.net is None and action != "start") and not hasattr(zwave.net, action): abort(404) ret = zwave.start() if action == "start" else \ get_member(zwave.net, action, request.args) if zwave.net is None: abort(414) return Ajax(data={"returned": ret, "executed": action}, jsonify=True) \ .set_state("net", NetState(zwave.net.state)).render()
def netaction(action): """exec an 'action', restricted to the listed ones (for now)""" if action not in (NET_ACTIONS + NET_ATTRS): return ret_jerr(404, "Requested action: {} not available".format(action)) if (zwave.net is None and action != "start") and not action in NET_ACTIONS: return ret_jerr(404, "Network and/or Controller inactive") ret = action_handler(NET_ATTRS, NET_SUB_ACTIONS, NET_WRAPPED, action, request.args, zwave.net, zwave) if zwave.net is None: return ret_jerr(404, "Network and/or Controller inactive") return Ajax(data={"returned": ret, "executed": action}, jsonify=True) \ .set_state("net", NetState(zwave.net.state)).render()