Beispiel #1
0
def node_action(node_id, action):
    if node_id not in zwave:
        return ret_jerr(404, msg="node-id: {} does not exist".format(node_id))

    # @TOOD: add list of possible node-actions

    node = zwave[node_id]
    ret = getattr(node, action)
    if callable(ret):
        ret = ret()
    return ret_jmsg(msg="Action: {} sent for node-id: {} returned: {}". \
                    format(action, node_id, str(ret)))
Beispiel #2
0
def node_action(node_id, action):
    if node_id not in zwave:
        return ret_jerr(404, "node-id: {} does not exist".format(node_id))

    if action not in (NODE_ACTIONS + NODE_ATTRS):
        return ret_jerr(404,
                        "Requested action: {} not available".format(action))

    ret = action_handler(NODE_ATTRS, NODE_SUB_ACTIONS, NODE_WRAPPED, action,
                         request.args, zwave.get_node(node_id), zwave)

    return ret_jmsg(msg="Action: {} sent for node-id: {} returned: {}". \
                    format(action, node_id, str(ret)))
Beispiel #3
0
def run_mqtt():

    if not cfg.mqtt.active:
        return ret_jerr("MQTT not active")

    if cfg.mqtt.topics.raw:
        for node_id in zwave.net.nodes:
            node = zwave.get_node(node_id)
            topic = f"{cfg.mqtt.topics.raw}/node/{node.node_id}"
            mqtt.publish(topic, node.to_dict())

    if cfg.mqtt.topics.ha:
        for node_id in zwave.net.nodes:
            node = zwave.get_node(node_id)

            dev_dct = {
                "identifiers": [10000 + int(node_id)],
                "manufacturer": node.manufacturer_name,
                "model": node.product_name,
                "name": node.name or ("node_id " + str(node_id))
            }

            for value_id, value in node.values.items():
                comp = None
                cmd_cls = value.command_class
                if cmd_cls == 37:
                    comp = "switch"
                elif cmd_cls in [49, 50]:
                    comp = "sensor"
                else:
                    print(f"unhandled COMMAND CLS: {cmd_cls}")
                    continue

                _t = f"{cfg.mqtt.topics.ha}/{comp}/{node.node_id}/{value_id}/"

                # HA auto-discover stuff
                cfg_topic = _t + "config"
                myname = node.name or ("node_" + str(node.node_id))
                payload = {
                    "unique_id":
                    md5(
                        bytes(
                            str(node.node_id) + "___" + str(value_id),
                            "ascii")).hexdigest(),
                    "name":
                    value.label,
                    "device":
                    dev_dct
                }

                state_topic = _t + "state"
                command_topic = _t + "set"
                if comp == "switch":
                    payload["command_topic"] = command_topic
                elif comp in ["sensor", "switch"]:
                    payload["state_topic"] = state_topic
                mqtt.publish(cfg_topic, json.dumps(payload))

                if comp == "switch":
                    mqtt.subscribe(command_topic)

                # state publish (
                state_topic = _t + "state"
                mqtt.publish(state_topic, value.data)

    return ret_jmsg("MQTT topics populated")