def send_command_to_ampel(conn, token, i2c_command, data=None):
    """ send the new command to the ampel """
    cmd = Command("i3c.call\n%s\n1 device\n0x20\n1 command\n%s" %(token, hex(i2c_command)))
    if data:
        cmd.params["data"] = data
    cmd = xmpp.Message(ampel_xmpp_account, cmd.toString())
    conn.send(cmd)
def send_command_to_ampel(conn, token, i2c_command, data=None):
    """ send the new command to the ampel """
    cmd = Command("i3c.call\n%s\n1 device\n0x20\n1 command\n%s" %
                  (token, hex(i2c_command)))
    if data:
        cmd.params["data"] = data
    cmd = xmpp.Message(ampel_xmpp_account, cmd.toString())
    conn.send(cmd)
def translate_response(cmd):
    """docstring for translate_response"""
    response = Command()
    response.command = "ampel.response"
    response.setToken(cmd.getToken())
    try:
        response.params["color"] = color_from_i2c_byte(
            cmd.params["i2c.response"])
        response.params["modus"] = modus_from_i2c_byte(
            cmd.params["i2c.response"])
    except KeyError, k:
        print k
        response.params["error"] = "i2c.response missing"
def translate_response(cmd):
    """docstring for translate_response"""
    response = Command()
    response.command = "ampel.response"
    response.setToken(cmd.getToken())
    try:
        response.params["color"] = color_from_i2c_byte(cmd.params["i2c.response"])
        response.params["modus"] = modus_from_i2c_byte(cmd.params["i2c.response"])
    except KeyError, k:
        print k
        response.params["error"] = "i2c.response missing"
def messageCB(conn, msg):
    reply = None
    user = xmpp.protocol.JID(msg.getFrom())
    print "%s:\n%s\n" %(user, msg.getBody())
    # answer with same Thread ID ...
    try:
        cmd = Command(msg.getBody())
        print cmd.getToken()
        print messageCB.tokens
        if str(cmd.getToken()) in messageCB.tokens:
            to = messageCB.tokens[str(cmd.getToken())]
            to_cmd = Command(to.getBody())
            cmd = ampel.translate_response(cmd)
            print cmd.toString()
            cmd.setToken(to_cmd.getToken())
            reply = to.buildReply(text = cmd.toString())
            reply.setType("chat")
            print reply.getBody()
            conn.send(reply)
            return None

        messageCB.tokens[str(messageCB.token)] = msg
        if cmd.getPrefix() == "ampel":
            ampel.process(cmd, conn, messageCB.token)
    except ValueError, e:
        print e
Example #6
0
 def testAdd(self):
     parsed = self.parser.parse()
     self.assertEqual(parsed[0], Command("1"))
Example #7
0
def messageCB(conn, msg):
    reply = None
    user = xmpp.protocol.JID(msg.getFrom())
    print "%s:\n%s\n" % (user, msg.getBody())
    # answer with same Thread ID ...
    try:
        cmd = Command(msg.getBody())
        print cmd.getToken()
        print messageCB.tokens
        if str(cmd.getToken()) in messageCB.tokens:
            to = messageCB.tokens[str(cmd.getToken())]
            to_cmd = Command(to.getBody())
            cmd = ampel.translate_response(cmd)
            print cmd.toString()
            cmd.setToken(to_cmd.getToken())
            reply = to.buildReply(text=cmd.toString())
            reply.setType("chat")
            print reply.getBody()
            conn.send(reply)
            return None

        messageCB.tokens[str(messageCB.token)] = msg
        if cmd.getPrefix() == "ampel":
            ampel.process(cmd, conn, messageCB.token)
    except ValueError, e:
        print e