46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from abc import ABCMeta
|
|
|
|
from commands.command_base import AbstractCommand
|
|
|
|
from json import loads
|
|
from urllib.parse import urlencode
|
|
import requests
|
|
|
|
class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
|
"""
|
|
this is the test command.
|
|
"""
|
|
command = "!lights"
|
|
|
|
def __init__(self):
|
|
super().__init__(Command_lights_v2.command, n_args=1, command_type=AbstractCommand.CommandType.Ver2)
|
|
self.help = ["This command allows you to modify the lights via the Lights_Module.",
|
|
"\nExample:","lights \"SCENE\"","lights \"COLOR\"","lights \"R\" \"G\" \"B\"","lights \"1\" \"0.5\" \"0\""]
|
|
self.isCommandEnabled = True
|
|
|
|
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None):
|
|
returnString = ""
|
|
|
|
returnString = self.dothething(user, 16, "!lights hydration", "")
|
|
|
|
return returnString
|
|
|
|
def dothething(self, username, light_group, command, rest):
|
|
# todo need to url-escape command and rest
|
|
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
|
#standalone_lights
|
|
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
|
resp = requests.get(url)
|
|
if resp.status_code == 200:
|
|
print("Got the following message: %s" % resp.text)
|
|
data = loads(resp.text)
|
|
msg = data['message']
|
|
if msg is not None:
|
|
return msg
|
|
# todo send to logger and other relevent services
|
|
else:
|
|
# todo handle failed requests
|
|
pass
|
|
|
|
def get_help(self):
|
|
return self.help |