Add driver for lights
This commit is contained in:
parent
7cc29f6b9f
commit
c3d83be3c4
34
server/power.py
Normal file
34
server/power.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import requests
|
||||||
|
import settings
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
def np_02B_api(ip, username, password, is_on):
|
||||||
|
if is_on:
|
||||||
|
endpoint = '/cmd.cgi?grp=0'
|
||||||
|
else:
|
||||||
|
endpoint = '/cmd.cgi?grp=30'
|
||||||
|
|
||||||
|
url = 'http://' + ip + endpoint
|
||||||
|
r = requests.get(url, auth=(username, password), timeout=4)
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
|
def lights_on():
|
||||||
|
np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, True)
|
||||||
|
|
||||||
|
def lights_off():
|
||||||
|
np_02B_api(settings.LIGHT_IP, settings.LIGHT_USER, settings.LIGHT_PASS, False)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
print('Turning lights on...')
|
||||||
|
lights_on()
|
||||||
|
|
||||||
|
print('Waiting three seconds...')
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
print('Turning lights off...')
|
||||||
|
lights_off()
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e)))
|
7
server/settings.py
Normal file
7
server/settings.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
LIGHT_IP = '192.168.99.25'
|
||||||
|
LIGHT_USER = 'admin'
|
||||||
|
LIGHT_PASS = 'admin'
|
||||||
|
|
||||||
|
GRID_IP = '192.168.99.20'
|
||||||
|
GRID_USER = 'admin'
|
||||||
|
GRID_PASS = 'admin'
|
Loading…
Reference in New Issue
Block a user