Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thank you for your great project ! #5

Open
realfire23 opened this issue Dec 19, 2020 · 5 comments
Open

Thank you for your great project ! #5

realfire23 opened this issue Dec 19, 2020 · 5 comments

Comments

@realfire23
Copy link

Hi,

do you see any chance to get that awesome integration running for KIA Europa / Germany ?

If you need any assistance Iam happy to assist.

Kind regards

chris

@realfire23
Copy link
Author

Thanks to https://openwb.de/forum/viewtopic.php?f=5&t=1215&start=10

Here are endpoints and handling

import sys
import requests
import uuid
import json
import urllib.parse as urlparse
from urllib.parse import parse_qs

email = str(sys.argv[1])
password = str(sys.argv[2])
pin = str(sys.argv[3])
vin = str(sys.argv[4])

def main():
#diviceID
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/spa/notifications/register'
headers = {
'ccsp-service-id': 'fdc85c00-0a2f-4c64-bcb4-2cfb1500730a',
'Content-type': 'application/json;charset=UTF-8',
'Content-Length': '80',
'Host': 'prd.eu-ccapi.kia.com:8080',
'Connection': 'close',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'okhttp/3.10.0'}
data = {"pushRegId":"1","pushType":"GCM","uuid": str(uuid.uuid1())}
response = requests.post(url, json = data, headers = headers)
if response.status_code == 200:
response = json.loads(response.text)
deviceId = response['resMsg']['deviceId']
print(deviceId)
else:
print('NOK diviceID')
return

#cookie für login
session = requests.Session()
response = session.get('https://prd.eu-ccapi.kia.com:8080/api/v1/user/oauth2/authorize?response_type=code&state=test&client_id=fdc85c00-0a2f-4c64-bcb4-2cfb1500730a&redirect_uri=https://prd.eu-ccapi.kia.com:8080/api/v1/user/oauth2/redirect')
if response.status_code == 200:
    cookies = session.cookies.get_dict()
    #print(cookies)
else:
    print('NOK cookie für login')
    return

url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/user/language' 
headers = {'Content-type': 'application/json'}
data = {"lang": "en"}
response = requests.post(url, json = data, headers = headers, cookies = cookies)

#login
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/user/signin' 
headers = {'Content-type': 'application/json'}
data = {"email": email,"password": password}
response = requests.post(url, json = data, headers = headers, cookies = cookies)
if response.status_code == 200:
    response = json.loads(response.text)
    response = response['redirectUrl']
    parsed = urlparse.urlparse(response)
    authCode = ''.join(parse_qs(parsed.query)['code'])
    #print(authCode)

else:
    print('NOK login')
    return

#token
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/user/oauth2/token'
headers = {
    'Authorization': 'Basic ZmRjODVjMDAtMGEyZi00YzY0LWJjYjQtMmNmYjE1MDA3MzBhOnNlY3JldA==',
    'Content-type': 'application/x-www-form-urlencoded',
    'Content-Length': '150',
    'Host': 'prd.eu-ccapi.kia.com:8080',
    'Connection': 'close',
    'Accept-Encoding': 'gzip, deflate',
    'User-Agent': 'okhttp/3.10.0'}
data = 'grant_type=authorization_code&redirect_uri=https%3A%2F%2Fprd.eu-ccapi.kia.com%3A8080%2Fapi%2Fv1%2Fuser%2Foauth2%2Fredirect&code=' + authCode
response = requests.post(url, data = data, headers = headers)
if response.status_code == 200:
    response = json.loads(response.text)
    access_token = response['token_type'] + ' ' + response['access_token']
    #print(access_token)
else:
    print('NOK token')
    return

#vehicles
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/spa/vehicles'
headers = {
    'Authorization': access_token,
    'ccsp-device-id': deviceId,
    'ccsp-application-id': '693a33fa-c117-43f2-ae3b-61a02d24f417',
    'offset': '1',
    'Host': 'prd.eu-ccapi.kia.com:8080',
    'Connection': 'close',
    'Accept-Encoding': 'gzip, deflate',
    'User-Agent': 'okhttp/3.10.0'}
response = requests.get(url, headers = headers)
if response.status_code == 200:
    response = json.loads(response.text)
    vehicleId = response['resMsg']['vehicles'][0]['vehicleId']
    #print(vehicleId)
else:
    print('NOK vehicles')
    return

#vehicles/profile

#prewakeup
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/spa/vehicles/' + vehicleId + '/control/engine'
headers = {
    'Authorization': access_token,
    'ccsp-device-id': deviceId,
    'ccsp-application-id': '693a33fa-c117-43f2-ae3b-61a02d24f417',
    'offset': '1',
    'Content-Type': 'application/json;charset=UTF-8',
    'Content-Length': '72',
    'Host': 'prd.eu-ccapi.kia.com:8080',
    'Connection': 'close',
    'Accept-Encoding': 'gzip, deflate',
    'User-Agent': 'okhttp/3.10.0'}
data = {"action":"prewakeup","deviceId": deviceId}
response = requests.post(url, json = data, headers = headers)
if response.status_code == 200:
    #print(response.text)
    response = ''
else:
    print('NOK prewakeup')
    return

#pin
url = 'https://prd.eu-ccapi.kia.com:8080/api/v1/user/pin'
headers = {
    'Authorization': access_token,
    'Content-type': 'application/json;charset=UTF-8',
    'Content-Length': '64',
    'Host': 'prd.eu-ccapi.kia.com:8080',
    'Connection': 'close',
    'Accept-Encoding': 'gzip, deflate',
    'User-Agent': 'okhttp/3.10.0'}
data = {"deviceId": deviceId,"pin": pin}
response = requests.put(url, json = data, headers = headers)
if response.status_code == 200:
    response = json.loads(response.text)
    controlToken = 'Bearer ' + response['controlToken']
    #print(controlToken)
else:
    print('NOK pin')
    return

#status
url = 'https://prd.eu-ccapi.kia.com:8080/api/v2/spa/vehicles/' + vehicleId + '/status'
headers = {
    'Authorization': controlToken,
    'ccsp-device-id': deviceId,
    'Content-Type': 'application/json'}
response = requests.get(url, headers = headers)
if response.status_code == 200:
   statusresponse = json.loads(response.text)
   #log (statusresponse)
   soc = statusresponse['resMsg']['evStatus']['batteryStatus']
   print('soc: ',soc)
   charging = statusresponse['resMsg']['evStatus']['batteryCharge']
   print('charging: ', charging)

   f = open('/var/www/html/openWB/ramdisk/soc', 'w')
   f.write(str(soc))
   f.close()   
else:
     print('NOK status')
     return

if name == 'main':
main()

@holdestmade
Copy link

I have been using the above python in a script in eventghost ( modified a bit) and using MQTT to setup sensors, device_tracker and switches in HA. Its OK, reasonably reliable, but sometimes doesn't update due to throttling (I'm using 10 minute interval when not_home and 1 hour when home)

@realfire23
Copy link
Author

@holdestmade that sounds great. Iam quiet new to programming.
Any chance you could provide that eventghost script ?

@fuatakgun
Copy link

fuatakgun commented Apr 10, 2021

Hi all,

I have baked a custom integration for EU Kia Uvo, this will be working for new account types. Thanks for your hard work @wcomartin

Warning ahead; this is pre-alpha phase, please do not expect something fully functional, I will improve the integration by time.

https://github.com/fuatakgun/kia_uvo

You can install this either manually copying files or using HACS. Configuration can be done on UI, you need to enter your username and password, (I know, translations are missing!).

  • it will only fetch values for the first car, I am not sure if there are people outside using Kia Uvo with multiple cars :slight_smile:
  • update - It will fetch the cached information every 30 minutes from Kia Servers.
  • force update - It will ask your car for the latest data every 2 hours.
  • It will not force update between 10PM to 6AM. I am trying to be cautious here.

I have posted an example screenshot from my own car.

@realfire23
Copy link
Author

realfire23 commented Apr 10, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants