From 9c3e560900c516af55a1116b0bb2dfa3157292c8 Mon Sep 17 00:00:00 2001 From: Kai Wansart Date: Fri, 2 Feb 2018 00:21:59 +0100 Subject: [PATCH] . --- .DS_Store | Bin 0 -> 8196 bytes app/.DS_Store | Bin 0 -> 6148 bytes app/__pycache__/config.cpython-36.pyc | Bin 0 -> 2145 bytes app/__pycache__/denon.cpython-36.pyc | Bin 0 -> 801 bytes app/__pycache__/linux.cpython-36.pyc | Bin 0 -> 1521 bytes app/__pycache__/webserver.cpython-36.pyc | Bin 0 -> 2507 bytes app/__pycache__/yeelight.cpython-36.pyc | Bin 0 -> 4822 bytes app/config.py | 80 +++++ app/devices/.DS_Store | Bin 0 -> 6148 bytes app/devices/__pycache__/ssh.cpython-36.pyc | Bin 0 -> 1160 bytes .../__pycache__/yeelight.cpython-36.pyc | Bin 0 -> 6814 bytes app/devices/denon.py | 25 ++ app/devices/ssh.py | 44 +++ app/devices/wol.py | 19 + app/devices/yeelight.py | 328 ++++++++++++++++++ app/webserver.py | 91 +++++ config/.DS_Store | Bin 0 -> 6148 bytes config/devices.json | 51 +++ config/devices.json.example | 36 ++ config/settings.json | 9 + config/settings.json.example | 9 + readme.md | 8 + remote.py | 54 +++ server.py | 10 + server_old.py | 180 ++++++++++ test/yeelight.json | 12 + test/yeelightG.json | 9 + www/.DS_Store | Bin 0 -> 8196 bytes www/css/main.css | 0 www/html/.DS_Store | Bin 0 -> 6148 bytes www/html/devices.html | 33 ++ www/html/settings.html | 18 + www/img/.DS_Store | Bin 0 -> 6148 bytes www/index.html | 36 ++ www/js/.DS_Store | Bin 0 -> 6148 bytes www/js/cm.js | 62 ++++ 36 files changed, 1114 insertions(+) create mode 100644 .DS_Store create mode 100644 app/.DS_Store create mode 100644 app/__pycache__/config.cpython-36.pyc create mode 100644 app/__pycache__/denon.cpython-36.pyc create mode 100644 app/__pycache__/linux.cpython-36.pyc create mode 100644 app/__pycache__/webserver.cpython-36.pyc create mode 100644 app/__pycache__/yeelight.cpython-36.pyc create mode 100644 app/config.py create mode 100644 app/devices/.DS_Store create mode 100644 app/devices/__pycache__/ssh.cpython-36.pyc create mode 100644 app/devices/__pycache__/yeelight.cpython-36.pyc create mode 100644 app/devices/denon.py create mode 100644 app/devices/ssh.py create mode 100644 app/devices/wol.py create mode 100644 app/devices/yeelight.py create mode 100644 app/webserver.py create mode 100644 config/.DS_Store create mode 100644 config/devices.json create mode 100644 config/devices.json.example create mode 100644 config/settings.json create mode 100644 config/settings.json.example create mode 100644 readme.md create mode 100644 remote.py create mode 100644 server.py create mode 100644 server_old.py create mode 100644 test/yeelight.json create mode 100644 test/yeelightG.json create mode 100644 www/.DS_Store create mode 100644 www/css/main.css create mode 100644 www/html/.DS_Store create mode 100644 www/html/devices.html create mode 100644 www/html/settings.html create mode 100644 www/img/.DS_Store create mode 100644 www/index.html create mode 100644 www/js/.DS_Store create mode 100644 www/js/cm.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c285bcb57360c02732abacc181b42b64a74dd7ec GIT binary patch literal 8196 zcmeHMON-M`6h3!a#|9}=M3^E70TEnO>BG(lB9vMevlAk^@X=|S+7{B>(xg+ySn0;S z%Z|Dh{0X{oB`7Z3jXz+1fU&&f3ePaD&M$5RB@-|C>r{kwg~qLVruJC@7GF@%Co)Xbgr{Y&La zv0BitR!Y-??r(1w3;LDH)^w_6HZPQ}@9YltANxYuKb?(J8VXUOJ|R$%@nhlAU<4f)V8}eg%lQ24M}tP5 z#e$}RisWTNFkyBxf!qZvo{l5(bR04G!w}m#nlhi7#F;?sLHXl9 S1pHQ}q2B*ISgKkX27Uk*2+|n< literal 0 HcmV?d00001 diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f30855f52f6b89c9d4ae7e09c17a330ee0e3c31d GIT binary patch literal 6148 zcmeHK%}&BV5dIcPgy4aj9DDR+!r222sRz$I07{Es0+xtqy!GNk_z1p`ui#_oH@hQR zih47|%p^14cK4h8`L^kH0l5Au>jG^64Z2{h$*{$wUA$s7t&v9O`$%zt6jO{btgx+O z7Zs4bYjL-RSm1$s_ql(=vss>wX8DK=c|A_(M{nL(0-9v!xW*-}Fu}3pmowbqM#ere zz8QDqr^IEMjpv`)vq^W5=JSONt+vtMJWrBrb(;b&Po39ZkE{wK`-QQXRz^9%J!d<@ zlJSPKm$+@Uj~wr-J|D9*GzClnQ(*TL;F&GfXa%%r3YY?>z*+(MK16iESg{D`KOGGI z3P7y0+8fLAvnV-{VysvMWDCuORANYVdc|-do%NCOV#Ok0NQcwQhtrXr-cXz$o&86i z4i^WsXbPADWd-)aV_VMu)9>&9DgLYoSd~0{hTf)ydvN_ jg#~{UlPgDYhwhE_krarrViAxvH2V?oGFUJL{#1c?iC$q% literal 0 HcmV?d00001 diff --git a/app/__pycache__/config.cpython-36.pyc b/app/__pycache__/config.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae72d761c4c2a54826f22ca691f1c17695b01e3e GIT binary patch literal 2145 zcma)7&2QsG6rUM?#QA7iy4|i=afsm1Mq-;(yA%!xRobFO93s&Qb@9bAnQ8098Hbq( zRjrgu_P}Me960h1@GtqwX~lnlgv5KclTEr2s;znR;rH>I_kJ^ey0KCFcdY%tHwgKQ zEIl@ikD=*LL2$xpOnjR6%x8IT`PK`<8Mj^$ZV7v4`3|RNq;0?X zP2-0Da3Xq3r;mgvkLhvq7CBYhFYBD0gRkeQ8J&m05?3JNl#YCx^5eyt*dcM9BMstzk{ zyF7d5W-M}2`&B%K0Xn9El*vYC$kc_$0=0BM5$)gmLjj;m;)}Sk9@OCkn$Y5eR>93NJ&2_Z`kOGSag= z$J_KO-pBcR+XeXg02!^CsGM)qg##-3I&+gB2cmCs&2_Fb@5=(}bl(upP#ASf)PmCw78ocPve*SXW3+$Ar= zD{V`aSD=BJH9-f;NHZSK?>961;_NK_@OoW*jRAhZ1Hyl}Kz2`1C{V0{0xm&u741Mp znr)+kEA|Ppc#jdVs7M|tLgfP4Jwu_PUJ))dn}+H#q3n^0`x`m)zyxKW5;4RJG6U5Wy@U@`KH-=B`)ga0^i${KLbE073( z+%zA7q_ycbyU#{}Wuy&YV1!3k~Hl-F8HpGtY%s!c=sOv-PY zvKc*gibd=>33>?+deK!Z4Q#0e?aED1h)5*qX|Ul6={@>Md$rP4A8f}8c=2*<{)#RT H5R2$HjtQ$3 literal 0 HcmV?d00001 diff --git a/app/__pycache__/linux.cpython-36.pyc b/app/__pycache__/linux.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..550d7e295ec4b6b7511ed6c8d0b9882850ac13d9 GIT binary patch literal 1521 zcmbVMOK%e~5Vm(W8z)U)&>{{9RUjelp$Vu+1*t-ocIfznDHikh#pWa`Lky|9)JF3)*JKl?e@+f{N5tu7rD_qm~TTjTL6+s znvj%+l;Ye;oYW0nO7@9#rFTiBr@RX{Y=GU6KG?psec3!90s9RRNI)xhlqWE>4h}x- zCb7!O2p49}fyp*>vjU(b`v2-P;TtjeEjnqcX`;aU4gy5Ya%Dfm3-#B}bK; zis&cNO>q0O-urBnHobv}d;4+O)4~*oO6zei%Cl1ENlz3-FNw3^S+^Kh?GdotQ{Uo9 z%_A#I)j40eBHz7s=)!AyZmj&sWxTx3=1jnlf zuEyKxMT8{;%*gfqQM@>dOU@s`cY~4;htW3m>G@*Kx;yiTD6T@o5p~;zZXN>wZ6FQ^ zbWdGLe>hm@wt50;j}1JH#Z@&Sb+=H zzE+2MUfv|7AHoTDbJ44~1pS)E{8XGe&b>&SKM_T_HY}tl)!K^}YqfQ(g;ZXTT)H^;kD%#K!3ZK~N(MBf11EGSc}j#M*clN_vQrjv!FNg1{RbjR(=qOoG}ed4 zSMtSB>Y|I?)5`(p5j4F9Mv{;U5;}qk=Zu6*Fu~!@g$p>(%srQTTB>8Iy7(Gic*ph_ zn$4_$%uXpKC$tZcQ+h%o$NJ3rOb|fvPPsf|Z6sMzBypPPM5@9BS{6l;^|bMYJWje& zH@R_-RFV~jD;W#r!nc$M28P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gn4B9yDB>LN9X+FK^Vlb zpG5xGPO}DimS#m0K1LWC+pNccd+LO`NX08;F2Us9v}g>nx=e+uWY)+K$!eVpt?C(i zzkyosnC7xC5PYKG6k_Z76?LW;i)GsX8Sz`IhyJL5)&f*HD~cUo*(d_O}5 z!dFBUJTnnZSV;DfCJhnAhna&N7!+hyDZb8FeBC+mb>vv)9&lK>&e}S0gADTi}i@A;m zQi^K~#02IzCeY$4JxC~p$<=MGo?7{|n7)9Hjw)jS)z--HyJU8@zS1s#wj?$kQbX0< z(R3}+gsmIUBP!7QIafLF=6pv>VP2u=^e%1fHt=m)lyGm;*DW-(i-q{u{$r#z*_kh)2Aza|U(mM9!0{0LKxpsf+C$SHz&cYmclyz@m!PuVy!2oytPjero9FIRR5|m&q#khA(q6_* zM+KeeDMCroE=BvV4q&HSe$zt`s*=_&UYptEFU{!FwDm^40KKB$A&+t=2&K-P)6eec zV1{CsdqpFU>UdL1Gn)spJIgrvR%r_Lf>ASD_s!d0h-(}A9B!#aR`0R}cP z1%E+`37ujaUQ|jt0ZnvL=lE!~ob83)#rAe%lK3{9p`UZq>tx<24YZPNH&E=+&jw-p zFle=Muhlw?BUC^uZUkoA21UdYsB^G4r0S77>Efs z*Kj@Wy7#)b;ay|gyP>EQKaaS_t81dU876a-e8Lz_UJjz z>)&+!hI8%rNNfuYI(#tpfa68+bDUUzXIXD}$Ja$!*T`0`DH%uxl7VF478u~2t{&GtOX#>=r*CPy@ckJz#2F>a)u(FO7v8T7DGIp{t|ID zaB%c=NHiZ3Z~kpw#NN*O#lj)gF?BMK42&7j-j~wq{r}8QX0pk*kW|S)GH|O5$ZWY< zF1Wk6TmS4+@7lt#=1|eNK@AG+(N6#$^c;DxNuMujGp+^>j#@?imQKtc0V5<;GVl)! F`~cAFOW6Pb literal 0 HcmV?d00001 diff --git a/app/devices/__pycache__/ssh.cpython-36.pyc b/app/devices/__pycache__/ssh.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..28778b6d15a34742a943695245a967602b17e977 GIT binary patch literal 1160 zcmbVLy>8nu5GEyAW^AWjTA(O87##v=NHnx#Q3UXiOkRvGS_nnQ)N&+ICFLeIyg6&1 zpbt>=mAH25D|G6eWH$+rp$LKdk&gH2yC1zfJRI2XHu(`U_KV#+0s5yXc8m%b@Pd^* z;hdc@@W8)i;45$ICq4u-7WIDPEf#TiFq@rEidGs7JT7t8D|^x zrN8k|2fz@5PotipBo}5a#pGq7Q;>FL8&%4=wvD_}E9<E=>WJaL*a~yxdJ2t*b^Y|=p;&WZ9iLM%>i#V<87}VE1Q#Q7Cep0WTkTS3GM#?@W zTS8!--~%4=^$1Hl*@rVuAv|Ph3~i0C(81cUI@DOx!Uz7%<2V|u%$r8Mr4|K-GF(5? zRi(1#jx=7N@3zc4bwH0pRL@Z?^@VxsAu-t{KOpk2*?S^wi`!-c-{M~Eh$N!c*UIS2 z%gArhJ3=FMqcWN4vP>&@oQo57zHC5WS1*VV)jt?*HA#K$7=xE$MeKskm@$u?EdAa_w?ou9bYe%+=Od~;i zMtduz8%SAdSQg}ur2Mi>i!NdYh|o>vkUT2b&>GxZ4_Z*u?g;&BG!08x!WTmHL?}W- l@263K6HiTA=2v?6bLoo(tsaFR!*k+8$Lb?3c)NHb|1T7C-h2Q6 literal 0 HcmV?d00001 diff --git a/app/devices/__pycache__/yeelight.cpython-36.pyc b/app/devices/__pycache__/yeelight.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..922862fa58c684dc1890a57c90a9675ccd020321 GIT binary patch literal 6814 zcmdT}&u<)89e;0r?d*8HaU91^(lnW*p{=3BQCpyjLaCCHA`qrZOp}hNw(EUkd+qhi z`ps-=uV$sH&H*7R^@PH$LcJiN9;%)Yr<_rR#BEe0BrcdgfCEUt=lkZzj)U8nsE0Dn zd;8}7p7%bV@2@;JIqCfKmy!3UZ!q>3R(TARUqXs5AQMdR9$TVct;aq73KP08?lNKc z+OF>DLc7W4%{}yF^E~BWUF=Y?cq|lNLW=Gn^O?s5^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d|N}X0~GZcd!l^dFr_$1M!lz~q?kyCn0849->$0om%1Yy5EUa>p|0}_Lb~AUZl^A3|fQR`hNh- Cmzkmf literal 0 HcmV?d00001 diff --git a/app/devices/denon.py b/app/devices/denon.py new file mode 100644 index 0000000..1a99f29 --- /dev/null +++ b/app/devices/denon.py @@ -0,0 +1,25 @@ +import denonavr + +##---------------------------------------------------------------------------------------## +class Denon(object): +##---------------------------------------------------------------------------------------## + ##-----------------------------------------------------------------------------------## + def __init__(self, device): + ##-----------------------------------------------------------------------------------## + self.device = denonavr.DenonAVR(device['ip']) + + ##-----------------------------------------------------------------------------------## + def power(self, state=None): + ##-----------------------------------------------------------------------------------## + if(state==None): + return -1 + + if(state=="on"): + self.device.power_on() + else: + self.device.power_off() + + ##-----------------------------------------------------------------------------------## + def setInput(self, input): + ##-----------------------------------------------------------------------------------## + self.device.input_func = input \ No newline at end of file diff --git a/app/devices/ssh.py b/app/devices/ssh.py new file mode 100644 index 0000000..4d6fdcf --- /dev/null +++ b/app/devices/ssh.py @@ -0,0 +1,44 @@ +from paramiko import SSHClient + +##---------------------------------------------------------------------------------------## +class SSH(object): +##---------------------------------------------------------------------------------------## + ##-----------------------------------------------------------------------------------## + def __init__(self, devices): + ##-----------------------------------------------------------------------------------## + for device in devices: + self.devices[device] = {} + self.devices[device]['user'] = devices[device]['user'] + self.devices[device]['ip'] = devices[device]['ip'] + + ##-----------------------------------------------------------------------------------## + def command(self, device, command): + ##-----------------------------------------------------------------------------------## + self.client = SSHClient() + self.client.load_system_host_keys() + self.client.connect(self.devices[device]['ip'], self.devices[device]['user']) + + if(command=="shutdown"): + self.shutdown(device) + if(command=="reboot"): + self.reboot(device) + if(command=="upgrade"): + self.upgrade(device) + + ##-----------------------------------------------------------------------------------## + def shutdown(self, device): + ##-----------------------------------------------------------------------------------## + self.connect() + self.client.exec_command('poweroff') + + ##-----------------------------------------------------------------------------------## + def reboot(self, device): + ##-----------------------------------------------------------------------------------## + self.connect() + self.client.exec_command('reboot') + + ##-----------------------------------------------------------------------------------## + def upgrade(self, device): + ##-----------------------------------------------------------------------------------## + self.connect() + self.client.exec_command('apt update && apt upgrade -y') \ No newline at end of file diff --git a/app/devices/wol.py b/app/devices/wol.py new file mode 100644 index 0000000..c146c16 --- /dev/null +++ b/app/devices/wol.py @@ -0,0 +1,19 @@ +from wakeonlan import wol + +##---------------------------------------------------------------------------------------## +class WOL(object): +##---------------------------------------------------------------------------------------## + ##-----------------------------------------------------------------------------------## + def __init__(self, devices): + ##-----------------------------------------------------------------------------------## + count = 0 + for device in devices: + self.devices[device] = devices[device]['mac'] + + ##-----------------------------------------------------------------------------------## + def wakeDevice(self, device): + ##-----------------------------------------------------------------------------------## + if(device in self.devices): + wol.send_magic_packet(self.devices[device]) + + diff --git a/app/devices/yeelight.py b/app/devices/yeelight.py new file mode 100644 index 0000000..d814fdb --- /dev/null +++ b/app/devices/yeelight.py @@ -0,0 +1,328 @@ +from yeelight import * +import time + +##---------------------------------------------------------------------------------------## +class Yeelight(object): +##---------------------------------------------------------------------------------------## + ##-----------------------------------------------------------------------------------## + def __init__(self, bulbs): + ##-----------------------------------------------------------------------------------## + self.bulbs = {} + self.groups = {} + for bulb in bulbs: + try: + self.bulbs.update({bulb : Bulb(bulbs[bulb]['ip'],auto_on=True)}) + except: + print("ERROR: Config not saved for " + bulb) + + try: + for group in bulbs[bulb]['groups']: + groupName = bulbs[bulb]['groups'][group] + if(groupName not in self.groups): + print("Create new Group " + groupName) + self.groups[groupName] = {} + + self.groups[groupName][bulb] = bulb + except: + print(bulb + " ist in keiner Gruppe") + + ##-----------------------------------------------------------------------------------## + def command(self, data): + ##-----------------------------------------------------------------------------------## + for device in data: + group = 0 + if device in self.groups: + group = True + if(device in self.bulbs or device in self.groups): + if 'power' in data[device]: + self.power(device, group, data[device]['power']) + if(data[device]['power'] == "off"): + return 0 + if 'brightness' in data[device]: + self.brightness(device, group, data[device]['brightness']) + if 'r' in data[device] or 'g' in data[device] or 'b' in data[device]: + if 'r' in data[device]: + r = data[device]['r'] + else: + r = "0" + if 'g' in data[device]: + g = data[device]['g'] + else: + g = "0" + if 'b' in data[device]: + b = data[device]['b'] + else: + b = "0" + self.color(device, group, r, g, b) + if 'temperature' in data[device]: + self.temperature(device, group, data[device]['temperature']) + + ##-----------------------------------------------------------------------------------## + def power(self, device, group=None, state=None): + ##-----------------------------------------------------------------------------------## + if(state==None): + return -1 + + if(device==None): + for bulb in self.bulbs: + self.powerBulb(device, state) + if(group == True): + for bulb in self.groups[device]: + self.powerBulb(bulb, state) + else: + if(device in self.bulbs): + self.powerBulb(device, state) + + ##-----------------------------------------------------------------------------------## + def powerBulb(self, device, state): + ##-----------------------------------------------------------------------------------## + if(device in self.bulbs): + error = False + try: + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + error = True + finally: + if(str(oldState['power']) != str(state)): + if(state=="on"): + self.bulbs[device].turn_on() + print(device + " turned on") + else: + self.bulbs[device].turn_off() + print(device + " turned off") + if(error == True): + for count in range(0,10): + try: + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + finally: + if(str(oldState['power']) != str(state)): + if(state=="on"): + self.bulbs[device].turn_on() + print(device + " turned on") + else: + self.bulbs[device].turn_off() + print(device + " turned off") + try: + oldState = self.bulbs[device].get_properties() + if(oldState['power'] == str(state)): + break + except: + print(device + " keine Veraenderung") + + ##-----------------------------------------------------------------------------------## + def brightness(self, device, group, state=None): + ##-----------------------------------------------------------------------------------## + if(state==None): + return -1 + + if(device==None): + for bulb in self.bulbs: + self.brightnessBulb(device, state) + if(group == True): + for bulb in self.groups[device]: + self.brightnessBulb(bulb, state) + else: + if(device in self.bulbs): + self.brightnessBulb(device, state) + + ##-----------------------------------------------------------------------------------## + def brightnessBulb(self, device, state): + ##-----------------------------------------------------------------------------------## + if(device in self.bulbs): + error = False + try: + oldState = self.bulbs[device].get_properties() + print(oldState) + except: + print(device + ": Konnte nicht angesteuert werden") + error = True + finally: + if(str(oldState['bright']) != str(state)): + self.bulbs[device].set_brightness(int(state)) + print(device + " turned brightness to " + str(state)) + if(error == True): + for count in range(0,10): + try: + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + finally: + if(str(oldState['brigh']) != str(state)): + self.bulbs[device].set_brightness(int(state)) + print(device + " turned brightness to " + str(state)) + try: + oldState = self.bulbs[device].get_properties() + if(oldState['bright'] == str(state)): + break + except: + print(device + " keine Veraenderung") + + ##-----------------------------------------------------------------------------------## + def temperature(self, device, group, state=None): + ##-----------------------------------------------------------------------------------## + if(state==None): + return -1 + + if(device==None): + for bulb in self.bulbs: + self.temperatureBulb(device, state) + if(group == True): + for bulb in self.groups[device]: + self.temperatureBulb(bulb, state) + else: + if(device in self.bulbs): + self.temperatureBulb(device, state) + + ##-----------------------------------------------------------------------------------## + def temperatureBulb(self, device, state): + ##-----------------------------------------------------------------------------------## + if(device in self.bulbs): + error = False + try: + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + error = True + finally: + if(str(oldState['ct']) != str(state)): + self.bulbs[device].set_color_temp(int(state)) + print(device + " turned temperature to " + str(state)) + if(error == True): + for count in range(0,10): + try: + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + finally: + if(str(oldState['ct']) != str(state)): + self.bulbs[device].set_color_temp(int(state)) + print(device + " turned temperature to " + str(state)) + try: + oldState = self.bulbs[device].get_properties() + if(oldState['ct'] == str(state)): + break + except: + print(device + " keine Veraenderung") + + ##-----------------------------------------------------------------------------------## + def color(self, device, group, r, g, b): + ##-----------------------------------------------------------------------------------## + if(device==None): + for bulb in self.bulbs: + self.colorBulb(device, r, g, b) + if(group == True): + for bulb in self.groups[device]: + self.colorBulb(bulb, r, g, b) + else: + if(device in self.bulbs): + self.colorBulb(device, r, g, b) + + ##-----------------------------------------------------------------------------------## + def colorBulb(self, device, r, g, b): + ##-----------------------------------------------------------------------------------## + bulbCount = 0 + bulbCheck = 0 + if(device in self.bulbs): + error = False + try: + bulbCount = bulbCount + 1 + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + error = True + finally: + self.bulbs[device].set_rgb(int(r), int(g), int(b)) + print(device + " color r:" + str(r) + " g:" + str(g) + " b:" + str(b)) + bulbCheck = bulbCheck + 1 + if(bulbCount != bulbCheck): + for count in range(0,10): + bulbCount = 0 + bulbCheck = 0 + try: + bulbCount = bulbCount + 1 + oldState = self.bulbs[device].get_properties() + except: + print(device + ": Konnte nicht angesteuert werden") + error = True + finally: + self.bulbs[device].set_rgb(int(r), int(g), int(b)) + print(device + " color r:" + str(r) + " g:" + str(g) + " b:" + str(b)) + bulbCheck = bulbCheck + 1 + if(bulbCheck==bulbCount): + return 0 + + ##-----------------------------------------------------------------------------------## + def temperatureTransition(self, startTemp=1700, endTemp=6500, startBrightness=100, + endBrightness=100, seconds=0, count=None): + ##-----------------------------------------------------------------------------------## + if(count==None): + count=10 + + duration = seconds*1000 + transitions = [ + TemperatureTransition(startTemp, duration, startBrightness), + SleepTransition(duration), + TemperatureTransition(endTemp, duration, endBrightness) + ] + flow = Flow( + count=1, + action=Flow.actions.recover, + transitions=transitions + ) + self.temperature(startBrightness) + self.brightness(startBrightness) + + bulbCount = 0 + bulbCheck = 0 + for bulb in self.bulbs: + bulbCount = bulbCount + 1 + try: + oldState = self.bulbs[bulb].get_properties() + except: + print(bulb + ": Konnte nicht angesteuert werden") + finally: + self.bulbs[bulb].start_flow(flow) + print(bulb + " Flow") + bulbCheck = bulbCheck + 1 + + if(bulbCount == bulbCheck): + return 0 + else: + if(count!=0): + time.sleep(.250) + temperatureTransition(startTemp, endTemp, startBrightness, endBrightness,seconds,count-1) + else: + print("Zu viele Versuche. Fehlgeschlagen!") + return -1 + return 0 + + ##-----------------------------------------------------------------------------------## + def stopTransition(self, count=None): + ##-----------------------------------------------------------------------------------## + if(count==None): + count=10 + bulbCount = 0 + bulbCheck = 0 + for bulb in self.bulbs: + bulbCount = bulbCount + 1 + try: + oldState = self.bulbs[bulb].get_properties() + except: + print(bulb + ": Konnte nicht angesteuert werden") + finally: + self.bulbs[bulb].stop_flow() + bulbCheck = bulbCheck + 1 + + if(bulbCount == bulbCheck): + return 0 + else: + if(count!=0): + time.sleep(.250) + stopTransition(count-1) + else: + print("Zu viele Versuche. Fehlgeschlagen!") + return -1 + return 0 \ No newline at end of file diff --git a/app/webserver.py b/app/webserver.py new file mode 100644 index 0000000..6297782 --- /dev/null +++ b/app/webserver.py @@ -0,0 +1,91 @@ +from flask import Flask, request + + +##---------------------------------------------------------------------------------------## +class Webserver(object): +##---------------------------------------------------------------------------------------## + ##-----------------------------------------------------------------------------------## + def __init__(self, config): + ##-----------------------------------------------------------------------------------## + print("Webserver initialisiert") + self.settings = config.read("settings") + self.devices = config.read("devices") + + ##-----------------------------------------------------------------------------------## + def run(self): + ##-----------------------------------------------------------------------------------## + app = Flask(__name__) + + if(self.devices['yeelight'] != None): + print("Enabled Yeelight") + from app.devices import yeelight + self.yeelight = yeelight.Yeelight(self.devices['yeelight']) + + @app.route('/yeelight', methods=['POST']) + def yeelight(): + app.logger.debug("JSON received...") + app.logger.debug(request.json) + if request.json: + data = request.get_json(force=True) + self.yeelight.command(data) + return '200' + else: + return '500' + else: + print("Disabled Yeelight") + + if(self.devices['ssh'] != None): + print("Enabled SSH") + from app.devices import ssh + self.ssh = ssh.SSH(self.devices['ssh']) + + @app.route('/ssh', methods=['POST']) + def ssh(): + app.logger.debug("JSON received...") + app.logger.debug(request.json) + if request.json: + data = request.get_json(force=True) + self.ssh.command(data) + return '200' + else: + return '500' + else: + print("Disabled SSH") + + if(self.devices['wol'] != None): + print("Enabled WOL") + from app.devices import wol + self.wol = wol.WOL(self.devices['wol']) + + @app.route('/wol', methods=['POST']) + def wol(): + app.logger.debug("JSON received...") + app.logger.debug(request.json) + if request.json: + data = request.get_json(force=True) + self.wol.command(data) + return '200' + else: + return '500' + else: + print("Disabled SSH") + + if(self.devices['denon'] != None): + print("Enabled Denon") + from app.devices import denon + self.denon = wol.WOL(self.devices['denon']) + + @app.route('/denon', methods=['POST']) + def denon(): + app.logger.debug("JSON received...") + app.logger.debug(request.json) + if request.json: + data = request.get_json(force=True) + self.denon.command(data) + return '200' + else: + return '500' + else: + print("Disabled Denon") + + app.run(debug=False, host='0.0.0.0') \ No newline at end of file diff --git a/config/.DS_Store b/config/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0bcec6c7da9391dc3ca8fe30e40df55ad7845d84 GIT binary patch literal 6148 zcmeHKJxc>Y5PhR50yZfWEVr~0{0B#fg|&Y`lN=Jcc!DNaUgMAPSL%B^Yw+~INs4tp!F>l&AV?@{s%gJjNTEG!kUE`78im^94Cce#N&z~~obfJQQ zU?3O>27-YfVSs10WPIQlIv5BBf`J_a+8+{&uqxO&=Bh^Z%T` z%-|!x9}=}-AQ<>(4A^LPIh%4(o?cODT740L(+3EfyoBgVS Voujg-J% 0: + out = str(ser.readline()) + + if out != '': + l = list(out) + try: + del(l[0]) + del(l[0]) + del(l[2]) + del(l[2]) + del(l[2]) + del(l[2]) + del(l[2]) + out = "".join(l) + #print("try") + except: + print("Fehlerhafter Wert") + finally: + print(out) + # Taste 3 + if(out == "31"): # Abend + yeelight.color(0,0,255) + if(out == "30"): # Nacht + yeelight.temperature(1700) + yeelight.brightness(1) + + # Taste 4 + if(out == "41"): # Hell + yeelight.brightness(100) + if(out == "40"): # Dunkel + yeelight.brightness(1) + + # Taste 5 + if(out == "51"): # An + yeelight.power("on") + if(out == "50"): # Aus + yeelight.power("off") + time.sleep(.250) \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..f1d1a34 --- /dev/null +++ b/server.py @@ -0,0 +1,10 @@ +from app import config, webserver + +##---------------------------------------------------------------------------------------## +## Main Program +##---------------------------------------------------------------------------------------## +if __name__ == '__main__': + config = config.Config() + webserver = webserver.Webserver(config) + + webserver.run() \ No newline at end of file diff --git a/server_old.py b/server_old.py new file mode 100644 index 0000000..97b1836 --- /dev/null +++ b/server_old.py @@ -0,0 +1,180 @@ +#!flask/bin/python +from flask import Flask, request +from app import yeelight, linux, denon + +import pprint, json + +class LoggingMiddleware(object): + def __init__(self, app): + self._app = app + + def __call__(self, environ, resp): + errorlog = environ['wsgi.errors'] + pprint.pprint(('REQUEST', environ), stream=errorlog) + + def log_response(status, headers, *args): + pprint.pprint(('RESPONSE', status, headers), stream=errorlog) + return resp(status, headers, *args) + + return self._app(environ, log_response) + +global devices +devices = None + +def loadConfig(): + with open('devices.json', encoding='utf-8') as data_file: + devices = json.loads(data_file.read()) +##---------------------------------------------------------------------------------------## +## Config +##---------------------------------------------------------------------------------------## +#bulbs = { +# "fernseher" : { "ip" : "192.168.178.127" }, +# "regal" : { "ip" : "192.168.178.128" }, +# "monitor" : { "ip" : "192.168.178.126" }, +# "bett" : { "ip" : "192.168.178.122" } +# } +brightnessDark = 1 +brightnessBright = 100 +temperatureWarm = 1700 +temperatureNormal = 3000 +temperatureCold = 6500 + +#sshIp = "192.168.178.81" +#sshUser = "root" + +#wakeonlanMac = "38.EA.A7.A1.09.D7" +# +#denonIp = "192.168.178.69" + +##---------------------------------------------------------------------------------------## +## Init +##---------------------------------------------------------------------------------------## +def init(): + app = Flask(__name__) + yeelight = yeelight.Yeelight(devices['yeelight']['rgb']) + wakeonlan = linux.WakeOnLan() + sshcmd = linux.SSHCmd(devices['ssh']['nas']['ip'], devices['ssh']['nas']['user']) # fuer mehrere Verbindungen, mehrere Instanzen erzeugen! + denon = denon.Denon(devices['denon']['ip']) + +##---------------------------------------------------------------------------------------## +## HTTP REQUESTS +##---------------------------------------------------------------------------------------## + +##-----------------------------------------------------------------------------------## +## Yeelight +##-----------------------------------------------------------------------------------## +@app.route('/bulb/on', methods=['PUT', 'POST']) +def httpBulbOn(): + yeelight.power("on") + return 'OK' +@app.route('/bulb/off', methods=['PUT', 'POST']) +def httpBulbOff(): + yeelight.power("off") + return 'OK' +#@app.route('/bulb/brightness', methods=['PUT', 'POST']) +#def httpBrightness(): +# data = str(request.data) +# brightness = int(data["brightness"]) +# if brightness <= 100 and brightness >= 0: +# yeelight.brightness(brightness) +# return 'OK' +@app.route('/bulb/dark', methods=['PUT', 'POST']) +def httpBulbBrightnessDark(): + yeelight.brightness(brightnessDark) + return 'OK' +@app.route('/bulb/bright', methods=['PUT', 'POST']) +def httpBulbBrightnessBright(): + yeelight.brightness(brightnessBright) + return 'OK' +@app.route('/bulb/blue', methods=['PUT', 'POST']) +def httpBulbColorBlue(): + yeelight.color(0,0,255) + return 'OK' +@app.route('/bulb/red', methods=['PUT', 'POST']) +def httpBulbColorRed(): + yeelight.color(255,0,0) + return 'OK' +@app.route('/bulb/warm', methods=['PUT', 'POST']) +def httpBulbTempWarm(): + yeelight.temperature(temperatureWarm) + return 'OK' +@app.route('/bulb/cold', methods=['PUT', 'POST']) +def httpBulbTempCold(): + yeelight.temperature(temperatureCold) + return 'OK' +@app.route('/bulb/normal', methods=['PUT', 'POST']) +def httpBulbNormal(): + yeelight.temperature(temperatureNormal) + return 'OK' +@app.route('/bulb/abend', methods=['PUT', 'POST']) +def httpBulbEvening(): + yeelight.color(0,0,255) + return 'OK' +@app.route('/bulb/nacht', methods=['PUT', 'POST']) +def httpBulbNight(): + yeelight.temperature(temperatureWarm) + yeelight.brightness(brightnessDark) + return 'OK' +@app.route('/bulb/flowMorgen', methods=['PUT', 'POST']) +def httpBulbFlowMorning(): + yeelight.temperatureTransition(startTemp=1700, endTemp=6500, startBrightness=0, + endBrightness=100, seconds=60*15) + return 'OK' +@app.route('/bulb/flowNacht', methods=['PUT', 'POST']) +def httpBulbFlowNight(): + yeelight.temperatureTransition(startTemp=1700, endTemp=1700, startBrightness=100, + endBrightness=1, seconds=60*15) + return 'OK' +@app.route('/bulb/flowStopp', methods=['PUT', 'POST']) +def httpBulbFlowStop(): + yeelight.stopTransition() + return 'OK' + +##-----------------------------------------------------------------------------------## +## Denon +##-----------------------------------------------------------------------------------## +@app.route('/denon/on', methods=['PUT', 'POST']) +def httpReceiverOn(): + denon.power("on") + return 'OK' +@app.route('/denon/off', methods=['PUT', 'POST']) +def httpReceiverOff(): + denon.power("off") + return 'OK' +@app.route('/denon/inet', methods=['PUT', 'POST']) +def httpReceiverInet(): + denon.setInput("Internet Radio") + return 'OK' +@app.route('/denon/tv', methods=['PUT', 'POST']) +def httpReceiverTv(): + denon.setInput("TV Audio") + return 'OK' + +##-----------------------------------------------------------------------------------## +## SSH +##-----------------------------------------------------------------------------------## +@app.route('/wol/nas', methods=['PUT', 'POST']) +def httpNasOn(): + wakeonlan.wakeDevice(devices['wol']['nas']['mac']) + return 'OK' +@app.route('/nas/poweroff', methods=['PUT', 'POST']) +def httpNasOff(): + sshcmd.shutdown + return 'OK' +@app.route('/nas/reboot', methods=['PUT', 'POST']) +def httpNasReboot(): + sshcmd.reboot() + return 'OK' +@app.route('/nas/update', methods=['PUT', 'POST']) +def httpNasUpdate(): + sshcmd.upgrade() + return 'OK' + +##---------------------------------------------------------------------------------------## +## Main Program +##---------------------------------------------------------------------------------------## +if __name__ == '__main__': + #app.wsgi_app = LoggingMiddleware(app.wsgi_app) + loadConfig() + init() + app.run(debug=True, host='0.0.0.0') \ No newline at end of file diff --git a/test/yeelight.json b/test/yeelight.json new file mode 100644 index 0000000..fa20f34 --- /dev/null +++ b/test/yeelight.json @@ -0,0 +1,12 @@ +{ + "fernseher" : { + "power" : "on", + "brightness" : "50", + "r" : "100", + "g" : "0", + "b" : "100" + }, + "bett" : { + "power" : "off" + } +} \ No newline at end of file diff --git a/test/yeelightG.json b/test/yeelightG.json new file mode 100644 index 0000000..f698a77 --- /dev/null +++ b/test/yeelightG.json @@ -0,0 +1,9 @@ +{ + "zimmer" : { + "power" : "on", + "brightness" : "50", + "r" : "100", + "g" : "0", + "b" : "50" + } +} \ No newline at end of file diff --git a/www/.DS_Store b/www/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a98d8040b1bb1da3394f85bf53b465e3e976e3eb GIT binary patch literal 8196 zcmeHM&5P4O6o1oJO%$;QVGAPUB6uj$u6Fkz3!zqFZ$d;5y6h%RX(MT-H0f5Ym0ZM| zXZ1hu=*9oRtBBscdenO z;J-wG?GFYvrcJ41q50N<9WMb;SJ2D_$Nc3VwZROiO{rs{(SkxmDr%8RWQjp!?Lb62 z`b`-h3oX)t@H^u?^3Ft7C`6VX#NgpTOrce;5Kss#Bfx6+GISw?aMxd`->;(Q;!iF- zO-4D>a3rhzch1Q7!l=>sL`vn#vEwH+UDx!}`kpnQQ!BEgN!Yf>ciGiVI~q80e2Y>) z8QacnuQ%PVp1nqc$o7KXm?wK~4@2(V@dB4l+jJ7RA)m(*4t}HkYHc>#Y_;mfW@~F+ zH)h-0jk_LMH% z!t5WP5g2LDY+xCC0aZLcM-)z@m8nNo2q*;p6aiA{Se-UT z|9(HtC$d`Gz;=L*35$z`<|)|mavU`;$5AJL7~^yQY28j^}LRYMToumCaIOy?R*GGzKe73s;vBbOvc8*-3iBpMAmAGPv(-|+3R|7jo zr$ekV_le39Hx#kzj2BCXRL2}sfmEQcz@<+c?f(z-6Zii +

Lampen

+
+
+

Regal

+
+ + +
+
+
+

Monitor

+
+ + +
+
+
+

Fernseher

+
+ + +
+
+
+

Bett

+
+ + +
+
+
+ \ No newline at end of file diff --git a/www/html/settings.html b/www/html/settings.html new file mode 100644 index 0000000..cc33490 --- /dev/null +++ b/www/html/settings.html @@ -0,0 +1,18 @@ +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
\ No newline at end of file diff --git a/www/img/.DS_Store b/www/img/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + HomeControl + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + diff --git a/www/js/.DS_Store b/www/js/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c83695f5c89ee21f530fbf00ba1cea0fe1e224f1 GIT binary patch literal 6148 zcmeHKF-`+P474Fgk!Vt;+>#23nr0P+f|?IRNh%bS0?}W^yZ9N**cQ_1bOi-XG?why z^?7!4Q=DTn^UcTc!E9w_OE}R!8K%bP^odQYz&xqIq$A)36Q-LbPLG iv}0`8j@MC?b&YF0?}bBR(2);1P=5xfi%bgqw*o($WEz?P literal 0 HcmV?d00001 diff --git a/www/js/cm.js b/www/js/cm.js new file mode 100644 index 0000000..651edf0 --- /dev/null +++ b/www/js/cm.js @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// CM - Hauptfunktion +//------------------------------------------------------------------------------ + +class CM +{ + constructor () + { + this.BodyDataAction(); + + console.log("CM LOADED"); + } + + BodyDataAction () + { + var menuButtons = document.getElementById("navbarBtn"). + getElementsByTagName("button"); + for (var i = 0; i < menuButtons.length; i++) { + menuButtons[i].onclick = function(evt) { + var res = evt.target.id; + CM_o.Menu(res); + }; + } + } + + Menu (message) + { + var selectedId = $(".selected").attr('id'); + switch (message) + { + case 'pageDevices': + console.log( "pageDevices") + this.LoadContent('html/devices.html'); + document.getElementById('pageDevices').className = "btn btn-outline-light text-dark active"; + document.getElementById('pageSettings').className = "btn btn-outline-light text-dark"; + break; + case 'pageSettings': + console.log( "pageDevices") + this.LoadContent('html/settings.html'); + document.getElementById('pageDevices').className = "btn btn-outline-light text-dark"; + document.getElementById('pageSettings').className = "btn btn-outline-light text-dark active"; + break; + default: + alert ('[CM] Unbekannte Anfrage: ' + message); + } + } + + LoadContent ( path ) + { + $.get( path, function( data ) { + $( ".content" ).html( data ); + console.log( "Load was performed." ); + }); + } +} + + +$(function() { + console.log("ONLOAD"); + CM_o = new CM(); + CM_o.Menu("pageDevices"); +}); \ No newline at end of file