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.UploadDiagnostics.DiagnosticsState"})
if ret.status_code != 200:
    print("Erro ao fazer o refresh do objeto: ", str(ret.status_code))

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

#Seta o tamanho do upload
parameter_values = ["Device.IP.Diagnostics.UploadDiagnostics.TestFileLength","304557665", "xsd:unsignedInt"]
ret = acs.send_request({"name": "setParameterValues", "parameterValues": [parameter_values]})
if ret.status_code != 200:
    print("Erro ao alterar o tamanho do arquivo de upload:", str(ret.status_code))

#Seta a quantidade de conexões simultâneas com o server http
parameter_values = ["Device.IP.Diagnostics.UploadDiagnostics.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 o upload:", str(ret.status_code))

time.sleep(5)

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