ianjwhite99 / connected-car-python-sdk

Open-source Python SDK for Ford vehicles connected with Sync Connect (Ford Pass)
MIT License
73 stars 12 forks source link

request_update()-Send request to refresh data from the cars module #38

Closed HKLM closed 2 years ago

HKLM commented 2 years ago

The request_update() has the vehicle send it's current data to the Ford API. This can be used even after the vehicle is parked and the alarm is armed.

ianjwhite99 commented 2 years ago

@HKLM This looks good. However can you detail the differences between the

def refresh_status()

and

def request_update()

they both seem to return the same result.

ianjwhite99 commented 2 years ago

@HKLM This looks good. However can you detail the differences between the

def refresh_status()

and

def request_update()

they both seem to return the same result.

I did some testing and it seems that both the refresh_status() and request_update() not only return the same result but also refresh the vehicle status in both cases. Could you test for yourself just to confirm with the following code?

import syncconnect

client = syncconnect.AuthClient(
    '9fb503e0-715b-47e8-adfd-ad4b7770f73b',
    None,
    None)

access = client.get_user_access_token(
    '<username>', '<password>')

currentVehicle = syncconnect.Vehicle(
    '<vin>', access['access_token'])

currentVehicle.unlock()
print(currentVehicle.lock_status())
currentVehicle.refresh_status()
print(currentVehicle.lock_status())
HKLM commented 2 years ago

@HKLM This looks good. However can you detail the differences between the

def refresh_status()

and

def request_update()

they both seem to return the same result.

I did some testing and it seems that both the refresh_status() and request_update() not only return the same result but also refresh the vehicle status in both cases. Could you test for yourself just to confirm with the following code?

import syncconnect

client = syncconnect.AuthClient(
    '9fb503e0-715b-47e8-adfd-ad4b7770f73b',
    None,
    None)

access = client.get_user_access_token(
    '<username>', '<password>')

currentVehicle = syncconnect.Vehicle(
    '<vin>', access['access_token'])

currentVehicle.unlock()
print(currentVehicle.lock_status())
currentVehicle.refresh_status()
print(currentVehicle.lock_status())

I get two different results between the two. Basically, my test did the following, issue a status() command to get a starting point for the test. Then issue the refresh_status() (for the refresh_status.log) or request_update() (for the request_update.log) the command is followed by json print dumps of the results. and then a few status() commands to get the changes. shorted view of the code used, and the attached log file (I removed my VIN from the log files)

refresh_status.log

refresh_status.log

   def do_refreshstatus(self, widget, **kwargs):
               myvehicle = syncconnect.Vehicle(_VIN, _TOKEN['access_token'])
                    st1 = myvehicle.status()
                    print(">>>>>>>>>> 1 status() <<<<<<<<<<<< \n")
                    zy = json.dumps(st1, indent=1)
                    print(zy)
                    print(">>>>>>>>>> 1 end status() <<<<<<<<<<<< \n")
                    status = myvehicle.refresh_status()
                    print(">>>>>>>>>>  refresh_status() <<<<<<<<<<<< \n")
                    z = json.dumps(status, indent=1)
                    print(z)
                    print(">>>>>>>>>> end refresh_status() <<<<<<<<<<<< \n")
                    time.sleep(10)
                    st2 = myvehicle.status()
                    print(">>>>>>>>>> 2 status() <<<<<<<<<<<< \n")
                    zyx = json.dumps(st2, indent=1)
                    print(zyx)
                    print(">>>>>>>>>> 2 end status() <<<<<<<<<<<< \n")

request_update.log

request_update.log

   def do_requestupdate(self, widget, **kwargs):
               myvehicle = syncconnect.Vehicle(_VIN, _TOKEN['access_token'])
                    st1 = myvehicle.status()
                    print(">>>>>>>>>> 1 status() <<<<<<<<<<<< \n")
                    zy = json.dumps(st1, indent=1)
                    print(zy)
                    print(">>>>>>>>>> 1 end status() <<<<<<<<<<<< \n")
                    status = myvehicle.request_update()
                    print(">>>>>>>>>>  request_update() <<<<<<<<<<<< \n")
                    z = json.dumps(status, indent=1)
                    print(z)
                    print(">>>>>>>>>> end request_update() <<<<<<<<<<<< \n")
                    time.sleep(5)
                    st2 = myvehicle.status()
                    print(">>>>>>>>>> 2 status() <<<<<<<<<<<< \n")
                    zyx = json.dumps(st2, indent=1)
                    print(zyx)
                    print(">>>>>>>>>> 2 end status() <<<<<<<<<<<< \n")

and both used the following

    def get_status(self):
               myvehicle = syncconnect.Vehicle(_VIN, _TOKEN['access_token'])
                    status = myvehicle.status()
                    print(">>>>>>>>>>  status() <<<<<<<<<<<< \n")
                    z = json.dumps(status, indent=1)
                    print(z)
                    print(">>>>>>>>>> end status() <<<<<<<<<<<< \n")

refresh_status() - the server responds with a HTTP 401 - (unauthorized) status yet it says in the json that I am "authorization": "AUTHORIZED".
It did correctly show that the locks are locked and alarm armed, but all other values are null or default values, prob due to the 401. And status() commands after that, show no changes. Even after 40 min, all values are the same except the servertime.

{
 "$id": "1",
 "vehiclestatus": {
  "$id": "2",
  "vin": null,
  "lockStatus": {
   "$id": "3",
   "value": "LOCKED",
   "status": "LAST_KNOWN",
   "timestamp": "01-01-0001 00:00:00"
  },
  "alarm": {
   "$id": "4",
   "value": "SET",
   "status": "LAST_KNOWN",
   "timestamp": "01-01-0001 00:00:00"
  },
  "PrmtAlarmEvent": {
   "$id": "5",
   "value": null,
   "status": "LAST_KNOWN",
   "timestamp": "01-01-0001 00:00:00"
  },
  "odometer": {
   "$id": "6",
   "value": 0.0,
   "status": "LAST_KNOWN",
   "timestamp": "01-01-0001 00:00:00"
  },
  "fuel": {
   "$id": "7",
   "fuelLevel": 0.0,
   "distanceToEmpty": null,
   "status": "LAST_KNOWN",
   "timestamp": "01-01-0001 00:00:00"
...
  "authorization": "AUTHORIZED",
...
 },
 "version": "3.0.0",
 "status": 401
}

request_update() - server responds as expected with HTTP 200 - (OK) status as shown below in its entire response.

{
 "$id": "1",
 "commandId": "221b0ca4-dfa6-4364-98a1-8f147b6c1ac8",
 "status": 200,
 "version": "1.0.0"
}

and after about 2 min, the updated status with the lockstatus and alarm being set is shown