import time
from tr069_request import AcsRequest

#Instancia a classe AcsRequest
acs = AcsRequest()

#Faz o refresh do objeto para forçar a cpe a atualizar
ret = acs.send_request({"name": "refreshObject", "objectName": "Device.IP.Diagnostics.DownloadDiagnostics.DiagnosticsState"})
if ret.status_code != 200:
    print("Erro ao fazer o refresh do objeto: ", str(ret.status_code))

#Seta a URL de download
parameter_values = ["Device.IP.Diagnostics.DownloadDiagnostics.DownloadURL","http://tr143.venko.local/download/speed_test", "xsd:string"]
ret = acs.send_request({"name": "setParameterValues", "parameterValues": [parameter_values]})
if ret.status_code != 200:
    print("Erro ao alterar a URL de download:", str(ret.status_code))

#Seta a quantidade de conexões simultâneas com o server http
parameter_values = ["Device.IP.Diagnostics.DownloadDiagnostics.NumberOfConnections","1", "xsd:unsignedInt"]
ret = acs.send_request({"name": "setParameterValues", "parameterValues": [parameter_values]})
if ret.status_code != 200:
    print("Erro ao alterar a quantidade de conexões simultâneas para download:", str(ret.status_code))

time.sleep(5)

#Solicita o download
parameter_values = ["Device.IP.Diagnostics.DownloadDiagnostics.DiagnosticsState", "Requested", "xsd:string"]
ret = acs.send_request({"name": "setParameterValues", "parameterValues": [parameter_values]})
if ret.status_code != 200:
    print("Erro ao solicitar o download:", str(ret.status_code))