Add option for multi-step commands
This option allows to send multi-step commands. These commands have no 'cmd' URL parameter.
This commit is contained in:
@@ -72,17 +72,23 @@ class APIHandler:
|
|||||||
print("Error Login\n", e)
|
print("Error Login\n", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _execute_command(self, command, data):
|
def _execute_command(self, command, data, multi=False):
|
||||||
"""
|
"""
|
||||||
Send a POST request to the IP camera with given JSON body and
|
Send a POST request to the IP camera with given data.
|
||||||
:param command: name of the command to send
|
:param command: name of the command to send
|
||||||
:param data: object to send to the camera
|
:param data: object to send to the camera (send as json)
|
||||||
:return: response as python object
|
:param multi: whether the given command name should be added to the
|
||||||
|
url parameters of the request. Defaults to False. (Some multi-step
|
||||||
|
commands seem to not have a single command name)
|
||||||
|
:return: response JSON as python object
|
||||||
"""
|
"""
|
||||||
|
params = {"token": self.token, 'cmd': command}
|
||||||
|
if multi:
|
||||||
|
del params['cmd']
|
||||||
try:
|
try:
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
raise ValueError("Login first")
|
raise ValueError("Login first")
|
||||||
response = Request.post(self.url, data=data, params={"cmd": command, "token": self.token})
|
response = Request.post(self.url, data=data, params=params)
|
||||||
return json.loads(response.text)
|
return json.loads(response.text)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Command {command} failed: {e}")
|
print(f"Command {command} failed: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user