Skip to content

Commit b719ff9

Browse files
committed
Include missing hook files
1 parent 9cf0d26 commit b719ff9

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

smuxi_hooks/on-message-received/flash_helios_light.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/python3
2+
3+
# A Smuxi hook script. This hooks flashes the ceiling light when a new message
4+
# on the #dimsumlabs channel was received.
5+
#
6+
# Usage: put this script in
7+
# ~/.local/share/smuxi/hooks/engine/protocol-manager/on-message-received/
8+
# and chmod +x it
9+
10+
from urllib import request
11+
from time import sleep
12+
import os
13+
import sys
14+
import time
15+
16+
dnd_file = open("/home/pi/smuxi_scripting_fun/dnd_expire_epoch.txt", "r")
17+
dnd_on = int(dnd_file.read().strip()) > time.time()
18+
19+
def change_ceiling_color(light_host, red, green, blue):
20+
color_url = 'rgb.lua?r={}&g={}&b={}'.format(red, green, blue)
21+
request_url = light_host + color_url
22+
23+
print('request begin to {}'.format(request_url))
24+
req = request.Request(request_url, method='POST')
25+
# timeout after 1 second as the light might be turned off
26+
res = request.urlopen(req, data=None, timeout=1)
27+
body = res.read()
28+
print('res body: ' + str(body))
29+
30+
if os.environ['SMUXI_MSG_TYPE'] != "Normal" or os.environ['SMUXI_CHAT_ID'] != "#dimsumlabs" or dnd_on:
31+
sys.exit(0)
32+
33+
helios_service = 'http://helios.lan/'
34+
helios2_service = 'http://helios2.lan/'
35+
36+
# color value range 0 to 1024
37+
light_pink = (7, 751, 130)
38+
light_green = (783, 7, 652)
39+
change_ceiling_color(helios_service, *light_green)
40+
change_ceiling_color(helios2_service, *light_green)
41+
42+
# sleep for 1 second to give time for the color transition to complete
43+
sleep(1)
44+
45+
# WTF: 0 is brightest value, lulz
46+
white = (0, 0, 0)
47+
change_ceiling_color(helios_service, *white)
48+
change_ceiling_color(helios2_service, *white)
49+

smuxi_hooks/on-message-received/flash_led.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/python3
2+
3+
from gpiozero import LED
4+
from time import sleep
5+
import os
6+
7+
led = LED(14)
8+
9+
if os.environ['SMUXI_MSG_TYPE'] == "Normal" and os.environ['SMUXI_CHAT_ID'] == "#dimsumlabs":
10+
led.on()
11+
sleep(1)
12+
led.off()
13+

smuxi_scripting_fun/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test:
2+
SMUXI_MSG="dnd lights 100h" SMUXI_SENDER="dsl-wall" SMUXI_CHAT_ID="#dimsumlabs" python3 dnd_until.py
3+
cat ~/smuxi_scripting_fun/dnd_expire_epoch.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1592919705

smuxi_scripting_fun/dnd_until.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python3
2+
3+
from time import sleep
4+
import os
5+
import time
6+
7+
msg = os.environ['SMUXI_MSG'].strip()
8+
chatroom = os.environ['SMUXI_CHAT_ID']
9+
sender = os.environ['SMUXI_SENDER']
10+
11+
if msg.find("dnd lights ") == 0 and chatroom == "#dimsumlabs" and sender == "dsl-wall":
12+
duration = msg.split("dnd lights ")[1].strip()
13+
last_letter = duration[-1:]
14+
if last_letter == "h":
15+
multiplier = 60 * 60
16+
elif last_letter == "m":
17+
multiplier = 60
18+
elif duration == "cancel":
19+
multiplier = 0
20+
elif duration == "off":
21+
multiplier = 0
22+
else:
23+
multiplier = 1
24+
25+
try:
26+
dnd_seconds = int(duration[:-1]) * multiplier
27+
except ValueError:
28+
dnd_seconds = 0
29+
30+
dnd_expire = int(time.time()) + dnd_seconds
31+
32+
os.system("cd ~/smuxi_scripting_fun; echo " + str(dnd_expire) + " > dnd_expire_epoch.txt")
33+
print("Session.Command /echo dnd mode enabled until " + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(dnd_expire)))
34+
35+

0 commit comments

Comments
 (0)