3Dshock/server/power.py

54 lines
1.3 KiB
Python
Raw Normal View History

2021-03-08 00:22:24 +00:00
import requests
import settings
import time
def np_02B_api(ip, username, password, is_on):
2021-03-11 00:37:01 +00:00
if settings.DEBUG: return
2021-03-08 00:22:24 +00:00
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)
2021-03-08 00:24:46 +00:00
def grid_on():
np_02B_api(settings.GRID_IP, settings.GRID_USER, settings.GRID_PASS, True)
def grid_off():
np_02B_api(settings.GRID_IP, settings.GRID_USER, settings.GRID_PASS, False)
2021-03-08 00:22:24 +00:00
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:
2021-03-08 01:52:38 +00:00
print('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e)))
2021-03-08 00:24:46 +00:00
try:
print('Turning grid on...')
grid_on()
print('Waiting three seconds...')
time.sleep(3)
print('Turning grid off...')
grid_off()
except BaseException as e:
2021-03-08 01:52:38 +00:00
print('Problem with grid: {} - {}'.format(e.__class__.__name__, str(e)))