From dfbead69464ac2d53ffba6f62668fc0762966c34 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Thu, 17 Nov 2016 19:50:06 +0100 Subject: [PATCH 1/2] added command for controlling the fensterbogenbeleuchtung in the lounge (lamp_lounge) --- plugins/chch_worker.py | 48 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/plugins/chch_worker.py b/plugins/chch_worker.py index bd55b27..a134861 100644 --- a/plugins/chch_worker.py +++ b/plugins/chch_worker.py @@ -6,6 +6,8 @@ import requests import urllib from subprocess import check_output import json +import socket +import struct def run_ecmd(cmd): # baseuri = "http://netio.chch.lan.ffc/ecmd?" @@ -15,6 +17,49 @@ def run_ecmd(cmd): req = requests.get("%s%s" % (baseuri, cmds)) return req.text.strip() +def run_udp(cmd): + ip="172.23.92.247" + port=49152 + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + # 10 ms timeout + s.settimeout(0.1) + s.sendto(cmd, (ip, port)) + try: + rec = s.recvfrom(1024)[0] + except: + rec = "" + s.close() + print(rec) + return rec + +# lamp_lounge handling +@hook.command("lamp_lounge", autohelp=True) +def cmd_lamp_lounge(inp, reply=None): + """lamp_lounge color - set the lamp color""" + args = inp.split(" ") + if len(args) < 1: + reply("lamp_lounge color - set the lamp color") + return + + if len(args[0]) != 6: + reply("lamp_lounge color - set the lamp color") + return + + c = "a\x00\x03" + struct.pack('BBB', int(args[0][2:4], 16), int(args[0][0:2], 16), int(args[0][4:6], 16)) + + rep = run_udp(c) + + if len(rep) < 3: + reply("Error: no reply") + return + + if rep[0] == 'a': + reply("OK") + elif rep[0] == 'e': + reply("error: " + rep[3:]) + else: + reply("fatal error") + # Lamp handling @hook.command("lamp", autohelp=True) def cmd_lamp(inp, reply=None): @@ -187,12 +232,13 @@ def topic_update(info, conn=None, chan=None): if newtopic != info[-1]: conn.send("TOPIC %s :%s" % (chan, newtopic)) +""" @hook.event("332") def e332_update(info, conn=None, chan=None): - """e332_update -- run after current topic was requested, runs worker tasks too""" chan = info[1] topic_update(info, conn=conn, chan=chan) print_wiki_changes(info, conn=conn, chan=chan) +""" @hook.singlethread @hook.event("353") From 296de07e1498ef24bd4ae7da997508b4f7803d79 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Thu, 17 Nov 2016 19:53:00 +0100 Subject: [PATCH 2/2] uncommented event 332 --- plugins/chch_worker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/chch_worker.py b/plugins/chch_worker.py index a134861..3edb0b2 100644 --- a/plugins/chch_worker.py +++ b/plugins/chch_worker.py @@ -232,13 +232,12 @@ def topic_update(info, conn=None, chan=None): if newtopic != info[-1]: conn.send("TOPIC %s :%s" % (chan, newtopic)) -""" @hook.event("332") def e332_update(info, conn=None, chan=None): + """e332_update -- run after current topic was requested, runs worker tasks too""" chan = info[1] topic_update(info, conn=conn, chan=chan) print_wiki_changes(info, conn=conn, chan=chan) -""" @hook.singlethread @hook.event("353")