feat(shelly): auto-start script after successful upload in upload.py
This commit is contained in:
parent
f64540a8f5
commit
4082a155a4
|
|
@ -58,6 +58,23 @@ def upload(ip, script_id, code_file):
|
|||
|
||||
print("Script upload complete!")
|
||||
|
||||
# Start the script after upload
|
||||
print(f"Starting script {script_id}...")
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=json.dumps({"id": 1, "method": "Script.Start", "params": {"id": int(script_id)}}).encode('utf-8'),
|
||||
headers={'Content-Type': 'application/json'}
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
res = json.loads(resp.read().decode('utf-8'))
|
||||
if "error" in res:
|
||||
print(f"Start request returned error: {res['error']}")
|
||||
else:
|
||||
print("Script started successfully.")
|
||||
except Exception as e:
|
||||
print(f"Start request failed: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: python3 upload.py <ip> <script_id> <code_file>")
|
||||
|
|
|
|||
Loading…
Reference in New Issue