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

New API Endpoints: Basics working. Thoughts & Help needed #242

Merged
merged 152 commits into from
Dec 22, 2023

Conversation

GitOldGrumpy
Copy link
Collaborator

Status

This is the initial work on interfacing with the new API/Endpoints/application. It is very much a WIP(work in progress) but it does work to pull the basic information. No statistics, trips or HVAC all of which are possible and currently nothing can be sent back to the car(e.g. turn on your de-foggers) but again is possible when I work out the endpoint. However I've pushed it up for discussion as I want to propose a change and am after peoples thoughts.

Proposed Change

It currently seems that getting details about a car is split between interfaces Vehicle and MyT. For example, if I want to know what the fuel level I call get_vehicle_status with the VIN and inspect the returned Vehicle object BUT if I want trip details I call get_trip on MyT with the VIN and a trip_id. I think a better approach is that all functionality for a Vehicle is called on a Vehicle object. This would mean that MyT only has two methods login and get_vehicles. The new get_vehicles method returns a list of Vehicle objects. For example,

client = MyT("username", "password")
client.login()
vehicles = client.get_vehicles()
vehicle = vehicles[0]

# Get Fuel Level
vehicle.dashboard.fuel_level  # Or just vehicle.fuel_level

# Get trips
vehicle.trips(from=yesterday, to=tomorrow) # Or some such arguments

Why make this change:

  • Better encapsulates a Vehicle. For example, unless the user wants to know the VIN then they never have to use it.
  • Vehicle becomes responsive. Currently once you've got the vehicle status it does not change but with this change a call to vehicle.evRange could update as it could make another call to the API to check. (I've noticed the new API is more responsive then the old)
  • It solves a problem with the new endpoints(and possibly the old) that the vehicle can check if the vehicle supports a given endpoint before its called. For example get_vehicle_electric_status_endpoint does not exist on cars that are not electic/hybrid so the call fails, so why call it? All the capabilities are returned with the initial vehicle information in the extendedCapabilities field this will be easy to manage when everything is handled in the one Vehicle class.
    • There are 76 of these capabilites BUT NOT all relate to an endpoint.

Help needed

In the merge request there is a new file simple_client_test.py it would be helpful if people run it and tell me if it works.

  1. just to know it works on more than two cars ;-)
  2. to check if other cars return less/more information
  3. to see what other cars have what capabilities

Finally

Thanks to wide wings and his work on another project that helped nail the authorisation(which is only slightly different). Unfortunately many of the endpoints are totally different.

No statistics. Possible but needs changing. Will cause exceptions.
No trips. Possible but needs changing. Will cause exceptions.
No "setting" of data. Is possible need to work out endpoints.
No HVAC. Is possible need to work out endpoint.
Tests will fail.
Doesn't deal with regresh token.
Depracated endpoints still there but fail.

May other things are still missing.
@CM000n CM000n marked this pull request as draft November 18, 2023 10:31
@CM000n CM000n changed the title Basics working. Thoughts & Help needed News API Endpoints: Basics working. Thoughts & Help needed Nov 18, 2023
@CM000n CM000n changed the title News API Endpoints: Basics working. Thoughts & Help needed New API Endpoints: Basics working. Thoughts & Help needed Nov 18, 2023
@CM000n
Copy link
Collaborator

CM000n commented Nov 18, 2023

Hello @GitOldGrumpy, thank you very much for your efforts!
I like your idea of standardizing the different interfaces into a single Vehicle object.
I'll see if I can find time during the week to look at your POC and also check what data my Corolla returns using your test file.
Greetings

@CM000n CM000n self-requested a review November 18, 2023 11:57
@GitOldGrumpy
Copy link
Collaborator Author

I started implementing the proposal today and need to make a change. If I implement it as I suggested you get a strange Vehicle class that has a mixture of synchronous and asynchronous calls(as you never know if you are going to have to update an endpoint). This makes the class complicated for the user to call so I will make all calls synchronous and add a single asynchronous update function.

Trips, Statistics & HVAC still missing.
All "getter" functions are synchronous.
All "setter" functions are asynchronous. HOWEVER none of them work, something is missing.
Re-worked they way endpoints are retrieved and added capability checking.
@GitOldGrumpy
Copy link
Collaborator Author

I've done what I suggested and pushed for people to take a look. Still endpoints missing(they are there just need to do the work) but am currently stuck on "setting" values am missing something in the headers which upsets the endpoint. Needs more investigation.

Can retrieve all notifications. Seems no way to limit how little/many are returned. Added flag for only unread notifications.
@CM000n
Copy link
Collaborator

CM000n commented Nov 20, 2023

Hello @GitOldGrumpy. I am currently still getting the following error message when trying to run your simple_client_test.py file:

Forget it. I found out that PyJWT must be installed as a module instead of jwt 😉.
Afterwards the login works and I get the following output:

➜  python simple_client_test.py
Logging in...
Retrieving cars...
Alias: Corolla
Mileage : 18828.1685
Fuel    : 12
Battery : None
Latitude : 49.xxxx
Notifications:
    2023-11-08 09:58:38.687000+00:00 : 2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.
    2023-11-07 13:37:40.899000+00:00 : 2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.
    2023-11-07 13:22:25.985000+00:00 : 2019 Corolla HB/TS Fahrertür offen.
    2023-11-07 13:13:34.968000+00:00 : 2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.
    2023-11-07 12:24:16.203000+00:00 : 2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.

@GitOldGrumpy
Copy link
Collaborator Author

GitOldGrumpy commented Nov 20, 2023

Ok. Hopefully I've updated that correctly. You'll have to forgive me with these things hacking away at python I'm use too, doing it all properly not so much.

I assume its possible to run all the checks locally before I push, could someone point me at the documentation on how to do this.

@CM000n
Copy link
Collaborator

CM000n commented Nov 20, 2023

Ok. Hopefully I've updated that correctly. You'll have to forgive me with these things hacking away at python I'm use too, doing it all properly not so much.

I assume its possible to run all the checks locally before I push, could someone point me at the documentation on how to do this.

I don't know how much you know about poetry? My workflow is usually as follows.

Install poetry with your default Python3 Version:

curl -sSL https://install.python-poetry.org | python3 -

Afterwards you can generate a Python 3.11 venv manually and can use poetry:
If you are using a Debian Linux or corresponding derivative (like Ubuntu), the easiest way for additional Python versions is via deadsnakes ppa: https://ubuntuhandbook.org/index.php/2022/10/python-3-11-released-how-install-ubuntu/

Afterwards you can generate a Python 3.11 venv manually and can use poetry with it:

python3.11 -m venv /path/to/new/virtual/environment
source /path/to/new/virtual/environment/bin/activate
cd /path/to/your/local/mytoyota/repository
poetry install

Pre-commit itself is already installed into the venv via the dev dependencies in this way
To run the test locally you have to first initiate the pre-commit hooks and can run pre-commit afterwards :

pre-commit install
pre-commit run --all-files

pre-commit now also runs automatically for every changed file with every commit.

@CM000n
Copy link
Collaborator

CM000n commented Nov 20, 2023

By the wasy: The car.details now look like this for me 😉 🥳

Click me
{
    "alerts": [],
    "asiCode": "FC",
    "brand": "T",
    "capabilities": [
        {
            "name": "alexaStandardCapable",
            "description": None,
            "value": True,
            "translation": {"english": None, "french": None, "spanish": None},
            "display": True,
            "displayName": None,
        },
        {
            "name": "androidAutoCapable",
            "description": None,
            "value": True,
            "translation": {"english": None, "french": None, "spanish": None},
            "display": True,
            "displayName": None,
        },
        {
            "name": "carplayStandardCapable",
            "description": None,
            "value": True,
            "translation": {"english": None, "french": None, "spanish": None},
            "display": True,
            "displayName": None,
        },
    ],
    "carlineName": "Corolla HB/TS",
    "color": "Emotional Red 2",
    "commercialRental": False,
    "contractId": "xxxMyContractIdxxx>",
    "ctsLinks": {
        "name": "Connected Services Support",
        "link": "https://qa.toyotaaudioandconnectedservicessupport.com/toyota/home?source=OneApp&vin=xxxMyVinxxx>",
        "imageUrl": None,
        "body": None,
        "buttonText": None,
    },
    "dataConsent": {
        "serviceConnect": "False",
        "can300": "False",
        "dealerContact": "False",
        "ubi": "false",
    },
    "dateOfFirstUse": None,
    "dcm": {
        "dcmModelYear": "19",
        "dcmDestination": "10",
        "countryCode": None,
        "dcmSupplier": "65",
        "dcmSupplierName": "Continental",
        "dcmGrade": "1",
        "euiccid": "xxxMyeuiccidxxx>",
        "hardwareType": None,
        "vehicleUnitTerminalNumber": None,
    },
    "dcmActive": False,
    "dcms": None,
    "displayModelDescription": "2019 Toyota Corolla HB/TS - NG '19",
    "displaySubscriptions": [
        {"productName": "STANDARD SERVICES", "displayStatus": "Expires On OCT 23, 2033"}
    ],
    "electricalPlatformCode": "15",
    "emergencyContact": None,
    "extendedCapabilities": {
        "remoteEngineStartStop": False,
        "remoteEConnectCapable": False,
        "doorLockUnlockCapable": False,
        "frontDriverDoorLockStatus": True,
        "frontPassengerDoorLockStatus": True,
        "rearDriverDoorLockStatus": True,
        "rearPassengerDoorLockStatus": True,
        "frontDriverDoorOpenStatus": True,
        "frontPassengerDoorOpenStatus": True,
        "rearDriverDoorOpenStatus": True,
        "rearPassengerDoorOpenStatus": True,
        "frontDriverDoorWindowStatus": True,
        "frontPassengerDoorWindowStatus": True,
        "rearDriverDoorWindowStatus": True,
        "rearPassengerDoorWindowStatus": True,
        "rearHatchRearWindow": False,
        "moonroof": False,
        "powerWindowsCapable": False,
        "hazardCapable": False,
        "hornCapable": False,
        "lightsCapable": False,
        "climateCapable": False,
        "climateTemperatureControlFull": False,
        "climateTemperatureControlLimited": False,
        "frontDriverSeatHeater": False,
        "frontPassengerSeatHeater": False,
        "rearDriverSeatHeater": False,
        "rearPassengerSeatHeater": False,
        "frontDriverSeatVentilation": False,
        "frontPassengerSeatVentilation": False,
        "rearDriverSeatVentilation": False,
        "rearPassengerSeatVentilation": False,
        "steeringHeater": False,
        "mirrorHeater": False,
        "frontDefogger": False,
        "rearDefogger": False,
        "vehicleFinder": False,
        "guestDriver": False,
        "buzzerCapable": False,
        "trunkLockUnlockCapable": False,
        "evChargeStationsCapable": False,
        "fcvStationsCapable": False,
        "lastParkedCapable": False,
        "acScheduling": False,
        "chargeManagement": False,
        "nextCharge": False,
        "weeklyCharge": False,
        "powerTailgateCapable": False,
        "batteryStatus": False,
        "evBattery": False,
        "drivePulse": False,
        "electricPulse": False,
        "hydrogenPulse": False,
        "hybridPulse": True,
        "emergencyAssist": False,
        "bumpCollisions": False,
        "fuelLevelAvailable": True,
        "fuelRangeAvailable": True,
        "equippedWithAlarm": False,
        "manualRearWindows": False,
        "lightStatus": True,
        "bonnetStatus": True,
        "sunroof": False,
        "smartKeyStatus": True,
        "ecare": False,
        "tryAndPlay": False,
        "dashboardWarningLights": False,
        "weHybridCapable": False,
        "enhancedSecuritySystemCapable": False,
        "vehicleStatus": True,
        "stellantisVehicleStatusCapable": False,
        "stellantisClimateCapable": False,
        "vehicleDiagnosticCapable": True,
        "telemetryCapable": True,
        "econnectVehicleStatusCapable": False,
        "econnectClimateCapable": False,
    },
    "externalSubscriptions": None,
    "familySharing": False,
    "faqUrl": "http://toyota.com/FAQ",
    "features": {
        "achPayment": 0,
        "addServiceRecord": 0,
        "autoDrive": 0,
        "cerence": 0,
        "chargingStation": 0,
        "climateStartEngine": 0,
        "collisionAssistance": 0,
        "connectedCard": 0,
        "connectedInsurance": 0,
        "connectedSupport": 0,
        "crashNotification": 0,
        "criticalAlert": 0,
        "dashboardLights": 0,
        "dealerAppointment": 1,
        "digitalKey": 0,
        "doorLockCapable": 0,
        "drivePulse": 0,
        "driverCompanion": 0,
        "driverScore": 0,
        "dtcAccess": 0,
        "dynamicNavi": 0,
        "ecoHistory": 0,
        "ecoRanking": 0,
        "electricPulse": 0,
        "emergencyAssist": 0,
        "enhancedSecuritySystem": 0,
        "evChargeStation": 0,
        "evRemoteServices": 0,
        "evVehicleStatus": 0,
        "financialServices": 0,
        "flexRental": 0,
        "h2FuelStation": 0,
        "homeCharge": 0,
        "howToVideos": 0,
        "hybridPulse": 1,
        "hydrogenPulse": 0,
        "importantMessage": 0,
        "insurance": 0,
        "lastParked": 1,
        "lcfs": 0,
        "linkedAccounts": 0,
        "maintenanceTimeline": 0,
        "marketingCard": 0,
        "marketingConsent": 0,
        "masterConsentEditable": 0,
        "myDestination": 0,
        "ownersManual": 0,
        "paidProduct": 0,
        "parkedVehicleLocator": 0,
        "parking": 0,
        "parkingNotes": 0,
        "personalizedSettings": 0,
        "privacy": 1,
        "recentTrip": 0,
        "remoteDtc": 0,
        "remoteParking": 0,
        "remoteService": 0,
        "roadsideAssistance": 0,
        "safetyRecall": 0,
        "scheduleMaintenance": 0,
        "serviceHistory": 1,
        "shopGenuineParts": 0,
        "smartCharging": 0,
        "ssaDownload": 0,
        "sxmRadio": 0,
        "telemetry": 1,
        "tff": 0,
        "tirePressure": 0,
        "v1g": 0,
        "vaSetting": 0,
        "vehicleDiagnostic": 1,
        "vehicleHealthReport": 0,
        "vehicleSpecifications": 0,
        "vehicleStatus": 1,
        "weHybrid": 0,
        "wifi": 0,
        "xcapp": 0,
    },
    "fleetInd": None,
    "fuelType": "B",
    "generation": "17CYPLUS",
    "headUnit": {
        "mobilePlatformCode": None,
        "huDescription": None,
        "huGeneration": None,
        "huVersion": None,
        "multimediaType": None,
    },
    "hwType": None,
    "image": "https://dj3z27z47basa.cloudfront.net/a2fcaccc-8307-41d8-b1fe-ee4833fb9cde",
    "katashikiCode": "xxxMyKatashikiCodexxx>",
    "manufacturedDate": "2020-10-26",
    "manufacturerCode": "TOY",
    "modelCode": "CR",
    "modelDescription": "Corolla HB/TS - NG '19",
    "modelName": "Corolla HB/TS - NG '19",
    "modelYear": "2019",
    "nickName": "Corolla",
    "nonCvtVehicle": False,
    "oldImei": None,
    "owner": True,
    "personalizedSettings": {
        "name": None,
        "link": None,
        "imageUrl": None,
        "body": None,
        "buttonText": None,
    },
    "preferred": 1,
    "primarySubscriber": True,
    "region": "EU",
    "registrationNumber": None,
    "remoteDisplay": "9",
    "remoteServiceCapabilities": {
        "guestDriverCapable": False,
        "vehicleFinderCapable": False,
        "estartStopCapable": False,
        "estartEnabled": False,
        "estopEnabled": False,
        "acsettingEnabled": False,
        "hazardCapable": False,
        "dlockUnlockCapable": False,
        "headLightCapable": False,
        "trunkCapable": False,
        "powerWindowCapable": False,
        "ventilatorCapable": False,
        "steeringWheelHeaterCapable": False,
        "allowHvacOverrideCapable": False,
        "moonRoofCapable": False,
    },
    "remoteServicesExceptions": [],
    "remoteSubscriptionExists": False,
    "remoteSubscriptionStatus": "INACTIVE",
    "remoteUser": True,
    "remoteUserGuid": "",
    "serviceConnectStatus": None,
    "services": [],
    "shopGenuinePartsUrl": "https://parts.toyota.com/accessories/Toyota_2019_Corolla.html?partner=ONEAPP2019Corolla",
    "status": "ACTIVE",
    "stockPicReference": "https://dj3z27z47basa.cloudfront.net/a2fcaccc-8307-41d8-b1fe-ee4833fb9cde",
    "subscriberGuid": "xxxMySubscriberGuidxxx>",
    "subscriptionExpirationStatus": False,
    "subscriptionStatus": "SUBSCRIBED",
    "subscriptions": [
        {
            "subscriptionID": "xxxMySubscriptionIdxxx>",
            "productName": "STANDARD SERVICES",
            "productDescription": "Standard Services",
            "displayProductName": "STANDARD SERVICES",
            "subscriptionEndDate": "2033-10-23",
            "subscriptionNextBillingDate": None,
            "subscriptionStartDate": "2023-10-23",
            "status": "ACTIVE",
            "type": "Trial",
            "subscriptionRemainingDays": 3626,
            "subscriptionRemainingTerm": None,
            "productCode": "PROD_STANDARDSERVICES",
            "productLine": "PROD_STANDARDSERVICES",
            "productType": None,
            "term": 120,
            "termUnit": "MTH",
            "goodwillIssuedFor": None,
            "renewable": False,
            "displayTerm": "Expires On OCT 23, 2033",
            "subscriptionTerm": "YRLY",
            "autoRenew": False,
            "futureCancel": False,
            "consolidatedProductIds": [],
            "consolidatedGoodwillIds": [],
            "components": None,
            "category": "STANDALONE",
        }
    ],
    "suffixCode": None,
    "svlStatus": False,
    "tffLinks": {
        "name": None,
        "link": None,
        "imageUrl": None,
        "body": None,
        "buttonText": None,
    },
    "transmissionType": "A",
    "vehicleCapabilities": [],
    "vehicleDataConsents": None,
}

@GitOldGrumpy
Copy link
Collaborator Author

GitOldGrumpy commented Nov 20, 2023

@CM000n thanks for that. It would be interesting if you could run <vehicle_object>._dump_all() as shown in the simple_client_test.py currently in the repository. It may fail with an exception as I dont yet know if all cars support all the endpoints implemented and what capability ties too what endpoints.

As you noticed the output is not yet censored so you might want to check that. I will look at re-using the orginal cens_dict function this evening(if I have the time) that will automatically censor our sensitive information.

As for poetry I'd never heard of it until I started looking at this project. I will have to take a look and come up to speed.

@CM000n
Copy link
Collaborator

CM000n commented Nov 20, 2023

Hi @GitOldGrumpy. A <vehicle_object>._dump_all() returns this, without any exception:

Click me
{
    "vehicle_info": {
        "registrationNumber": None,
        "vin": "xxxx",
        "modelYear": "2019",
        "modelName": "Corolla HB/TS - NG '19",
        "modelDescription": "Corolla HB/TS - NG '19",
        "modelCode": "CR",
        "region": "EU",
        "status": "ACTIVE",
        "generation": "17CYPLUS",
        "image": "https://dj3z27z47basa.cloudfront.net/a2fcaccc-8307-41d8-b1fe-ee4833fb9cde",
        "nickName": "Corolla",
        "brand": "T",
        "hwType": None,
        "asiCode": "FC",
        "subscriptionStatus": "SUBSCRIBED",
        "primarySubscriber": True,
        "remoteUser": True,
        "evVehicle": False,
        "remoteSubscriptionStatus": "INACTIVE",
        "remoteUserGuid": "",
        "subscriberGuid": "xxxx",
        "remoteDisplay": "9",
        "emergencyContact": None,
        "remoteServiceCapabilities": {
            "powerWindowCapable": False,
            "ventilatorCapable": False,
            "moonRoofCapable": False,
            "steeringWheelHeaterCapable": False,
            "allowHvacOverrideCapable": False,
            "estartStopCapable": False,
            "estartEnabled": False,
            "hazardCapable": False,
            "dlockUnlockCapable": False,
            "estopEnabled": False,
            "acsettingEnabled": False,
            "guestDriverCapable": False,
            "vehicleFinderCapable": False,
            "headLightCapable": False,
            "trunkCapable": False,
        },
        "nonCvtVehicle": False,
        "remoteServicesExceptions": [],
        "extendedCapabilities": {
            "remoteEngineStartStop": False,
            "remoteEConnectCapable": False,
            "doorLockUnlockCapable": False,
            "frontDriverDoorLockStatus": True,
            "frontPassengerDoorLockStatus": True,
            "rearDriverDoorLockStatus": True,
            "rearPassengerDoorLockStatus": True,
            "frontDriverDoorOpenStatus": True,
            "frontPassengerDoorOpenStatus": True,
            "rearDriverDoorOpenStatus": True,
            "rearPassengerDoorOpenStatus": True,
            "frontDriverDoorWindowStatus": True,
            "frontPassengerDoorWindowStatus": True,
            "rearDriverDoorWindowStatus": True,
            "rearPassengerDoorWindowStatus": True,
            "rearHatchRearWindow": False,
            "moonroof": False,
            "powerWindowsCapable": False,
            "hazardCapable": False,
            "hornCapable": False,
            "lightsCapable": False,
            "climateCapable": False,
            "climateTemperatureControlFull": False,
            "climateTemperatureControlLimited": False,
            "frontDriverSeatHeater": False,
            "frontPassengerSeatHeater": False,
            "rearDriverSeatHeater": False,
            "rearPassengerSeatHeater": False,
            "frontDriverSeatVentilation": False,
            "frontPassengerSeatVentilation": False,
            "rearDriverSeatVentilation": False,
            "rearPassengerSeatVentilation": False,
            "steeringHeater": False,
            "mirrorHeater": False,
            "frontDefogger": False,
            "rearDefogger": False,
            "vehicleFinder": False,
            "guestDriver": False,
            "buzzerCapable": False,
            "trunkLockUnlockCapable": False,
            "evChargeStationsCapable": False,
            "fcvStationsCapable": False,
            "lastParkedCapable": False,
            "acScheduling": False,
            "chargeManagement": False,
            "nextCharge": False,
            "weeklyCharge": False,
            "powerTailgateCapable": False,
            "batteryStatus": False,
            "evBattery": False,
            "drivePulse": False,
            "electricPulse": False,
            "hydrogenPulse": False,
            "hybridPulse": True,
            "emergencyAssist": False,
            "bumpCollisions": False,
            "fuelLevelAvailable": True,
            "fuelRangeAvailable": True,
            "equippedWithAlarm": False,
            "manualRearWindows": False,
            "lightStatus": True,
            "bonnetStatus": True,
            "sunroof": False,
            "smartKeyStatus": True,
            "ecare": False,
            "tryAndPlay": False,
            "dashboardWarningLights": False,
            "weHybridCapable": False,
            "enhancedSecuritySystemCapable": False,
            "vehicleStatus": True,
            "stellantisVehicleStatusCapable": False,
            "stellantisClimateCapable": False,
            "vehicleDiagnosticCapable": True,
            "telemetryCapable": True,
            "econnectClimateCapable": False,
            "econnectVehicleStatusCapable": False,
        },
        "electricalPlatformCode": "15",
        "personalizedSettings": {
            "name": None,
            "link": None,
            "imageUrl": None,
            "body": None,
            "buttonText": None,
        },
        "fuelType": "B",
        "fleetInd": None,
        "svlStatus": False,
        "displayModelDescription": "2019 Toyota Corolla HB/TS - NG '19",
        "manufacturerCode": "TOY",
        "suffixCode": None,
        "imei": "xxxx",
        "color": "Emotional Red 2",
        "vehicleDataConsents": None,
        "dataConsent": {
            "serviceConnect": "False",
            "can300": "False",
            "dealerContact": "False",
            "ubi": "false",
        },
        "vehicleCapabilities": [],
        "capabilities": [
            {
                "name": "alexaStandardCapable",
                "description": None,
                "value": True,
                "translation": {"english": None, "french": None, "spanish": None},
                "display": True,
                "displayName": None,
            },
            {
                "name": "androidAutoCapable",
                "description": None,
                "value": True,
                "translation": {"english": None, "french": None, "spanish": None},
                "display": True,
                "displayName": None,
            },
            {
                "name": "carplayStandardCapable",
                "description": None,
                "value": True,
                "translation": {"english": None, "french": None, "spanish": None},
                "display": True,
                "displayName": None,
            },
        ],
        "subscriptions": [
            {
                "subscriptionID": "xxxx",
                "productName": "STANDARD SERVICES",
                "productDescription": "Standard Services",
                "displayProductName": "STANDARD SERVICES",
                "subscriptionEndDate": "2033-10-23",
                "subscriptionNextBillingDate": None,
                "subscriptionStartDate": "2023-10-23",
                "status": "ACTIVE",
                "type": "Trial",
                "subscriptionRemainingDays": 3626,
                "subscriptionRemainingTerm": None,
                "productCode": "PROD_STANDARDSERVICES",
                "productLine": "PROD_STANDARDSERVICES",
                "productType": None,
                "term": 120,
                "termUnit": "MTH",
                "goodwillIssuedFor": None,
                "renewable": False,
                "displayTerm": "Expires On OCT 23, 2033",
                "subscriptionTerm": "YRLY",
                "autoRenew": False,
                "futureCancel": False,
                "consolidatedProductIds": [],
                "consolidatedGoodwillIds": [],
                "components": None,
                "category": "STANDALONE",
            }
        ],
        "services": [],
        "displaySubscriptions": [
            {
                "productName": "STANDARD SERVICES",
                "displayStatus": "Expires On OCT 23, 2033",
            }
        ],
        "alerts": [],
        "features": {
            "achPayment": 0,
            "addServiceRecord": 0,
            "autoDrive": 0,
            "cerence": 0,
            "chargingStation": 0,
            "climateStartEngine": 0,
            "collisionAssistance": 0,
            "connectedCard": 0,
            "connectedInsurance": 0,
            "connectedSupport": 0,
            "crashNotification": 0,
            "criticalAlert": 0,
            "dashboardLights": 0,
            "dealerAppointment": 1,
            "digitalKey": 0,
            "doorLockCapable": 0,
            "drivePulse": 0,
            "driverCompanion": 0,
            "driverScore": 0,
            "dtcAccess": 0,
            "dynamicNavi": 0,
            "ecoHistory": 0,
            "ecoRanking": 0,
            "electricPulse": 0,
            "emergencyAssist": 0,
            "enhancedSecuritySystem": 0,
            "evChargeStation": 0,
            "evRemoteServices": 0,
            "evVehicleStatus": 0,
            "financialServices": 0,
            "flexRental": 0,
            "h2FuelStation": 0,
            "homeCharge": 0,
            "howToVideos": 0,
            "hybridPulse": 1,
            "hydrogenPulse": 0,
            "importantMessage": 0,
            "insurance": 0,
            "lastParked": 1,
            "lcfs": 0,
            "linkedAccounts": 0,
            "maintenanceTimeline": 0,
            "marketingCard": 0,
            "marketingConsent": 0,
            "masterConsentEditable": 0,
            "myDestination": 0,
            "ownersManual": 0,
            "paidProduct": 0,
            "parkedVehicleLocator": 0,
            "parking": 0,
            "parkingNotes": 0,
            "personalizedSettings": 0,
            "privacy": 1,
            "recentTrip": 0,
            "remoteDtc": 0,
            "remoteParking": 0,
            "remoteService": 0,
            "roadsideAssistance": 0,
            "safetyRecall": 0,
            "scheduleMaintenance": 0,
            "serviceHistory": 1,
            "shopGenuineParts": 0,
            "smartCharging": 0,
            "ssaDownload": 0,
            "sxmRadio": 0,
            "telemetry": 1,
            "tff": 0,
            "tirePressure": 0,
            "v1g": 0,
            "vaSetting": 0,
            "vehicleDiagnostic": 1,
            "vehicleHealthReport": 0,
            "vehicleSpecifications": 0,
            "vehicleStatus": 1,
            "weHybrid": 0,
            "wifi": 0,
            "xcapp": 0,
        },
        "subscriptionExpirationStatus": False,
        "faqUrl": "http://toyota.com/FAQ",
        "shopGenuinePartsUrl": "https://parts.toyota.com/accessories/Toyota_2019_Corolla.html?partner=ONEAPP2019Corolla",
        "familySharing": False,
        "ctsLinks": {
            "name": "Connected Services Support",
            "link": "https://qa.toyotaaudioandconnectedservicessupport.com/toyota/home?source=OneApp&vin=xxxx",
            "imageUrl": None,
            "body": None,
            "buttonText": None,
        },
        "tffLinks": {
            "name": None,
            "link": None,
            "imageUrl": None,
            "body": None,
            "buttonText": None,
        },
        "headUnit": {
            "mobilePlatformCode": None,
            "huDescription": None,
            "huGeneration": None,
            "huVersion": None,
            "multimediaType": None,
        },
        "katashikiCode": "xxxx",
        "oldImei": None,
        "stockPicReference": "https://dj3z27z47basa.cloudfront.net/a2fcaccc-8307-41d8-b1fe-ee4833fb9cde",
        "transmissionType": "A",
        "dateOfFirstUse": None,
        "dcm": {
            "dcmModelYear": "19",
            "dcmDestination": "10",
            "countryCode": None,
            "dcmSupplier": "65",
            "dcmSupplierName": "Continental",
            "dcmGrade": "1",
            "euiccid": "xxxx",
            "hardwareType": None,
            "vehicleUnitTerminalNumber": None,
        },
        "dcms": None,
        "manufacturedDate": "2020-10-26",
        "contractId": "xxxx",
        "carlineName": "Corolla HB/TS",
        "externalSubscriptions": None,
        "serviceConnectStatus": None,
        "owner": True,
        "remoteSubscriptionExists": False,
        "dcmActive": False,
        "commercialRental": False,
        "preferred": 1,
    },
    "location": {
        "vin": "xxx",
        "lastTimestamp": "2023-11-19T18:30:06Z",
        "vehicleLocation": {
            "displayName": "Last Parked",
            "latitude": 49.0000,
            "longitude": 8.0000,
            "locationAcquisitionDatetime": "2023-11-19T18:30:06Z",
        },
    },
    "status": {
        "quantityOfEngOilIcon": [],
        "warning": [],
        "vin": "xxxx",
        "wnglastUpdTime": "2023-11-20T11:31:12.229Z",
    },
    "telemetry": {
        "fuelType": "B",
        "odometer": {"value": 30301, "unit": "km"},
        "fuelLevel": 12,
        "distanceToEmpty": {"value": 82, "unit": "km"},
        "timestamp": "2023-11-19T18:30:06Z",
    },
    "notifications": [
        {
            "messageId": "654b5bce89146fe1dcde1c4f",
            "vin": "xxxx",
            "notificationDate": "2023-11-08T09:58:38.687Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "654a3da42b1dfee3530570dc",
            "vin": "xxxx",
            "notificationDate": "2023-11-07T13:37:40.899Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "654a3a116992523ebe9a9594",
            "vin": "xxxx",
            "notificationDate": "2023-11-07T13:22:25.985Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS Fahrertür offen.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "654a37fee4770b7ca1b54704",
            "vin": "xxxx",
            "notificationDate": "2023-11-07T13:13:34.968Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "654a2c7005dbda98a304e580",
            "vin": "xxxx",
            "notificationDate": "2023-11-07T12:24:16.203Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "65492ec33f510e170fe5146d",
            "vin": "xxxx",
            "notificationDate": "2023-11-06T18:21:55.165Z",
            "isRead": True,
            "readTimestamp": "2023-11-09T07:56:20.011Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "6547ce408ad4f16916836695",
            "vin": "xxxx",
            "notificationDate": "2023-11-05T17:17:52.406Z",
            "isRead": True,
            "readTimestamp": "2023-11-06T05:20:47.985Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "6547a1fbfc25822d4c52c47c",
            "vin": "xxxx",
            "notificationDate": "2023-11-05T14:08:59.748Z",
            "isRead": True,
            "readTimestamp": "2023-11-06T05:20:47.985Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "65451782581159f1eddc2b31",
            "vin": "xxxx",
            "notificationDate": "2023-11-03T15:53:38.575Z",
            "isRead": True,
            "readTimestamp": "2023-11-06T05:20:47.985Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS Hintere Tür auf der Fahrerseite offen.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "6540e84142e4d41d6443222f",
            "vin": "xxxx",
            "notificationDate": "2023-10-31T11:42:57.690Z",
            "isRead": True,
            "readTimestamp": "2023-10-31T17:04:37.990Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "6540dd4d8ff01b76f1875e14",
            "vin": "xxxx",
            "notificationDate": "2023-10-31T10:56:13.484Z",
            "isRead": True,
            "readTimestamp": "2023-10-31T11:11:20.049Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653fb6a3d3feeb0008e44f12",
            "vin": "xxxx",
            "notificationDate": "2023-10-30T13:58:59.004Z",
            "isRead": True,
            "readTimestamp": "2023-10-31T11:11:20.049Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653e8ee2a7a3a90008856e61",
            "vin": "xxxx",
            "notificationDate": "2023-10-29T16:57:06.311Z",
            "isRead": True,
            "readTimestamp": "2023-10-31T11:11:20.049Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653cfc040a144c0008bba0ef",
            "vin": "xxxx",
            "notificationDate": "2023-10-28T12:18:12.849Z",
            "isRead": True,
            "readTimestamp": "2023-10-31T11:11:20.049Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653ccfcc2e44c10008df8985",
            "vin": "xxxx",
            "notificationDate": "2023-10-28T09:09:32.825Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653cc7e2a8a7cb0008df88ba",
            "vin": "xxxx",
            "notificationDate": "2023-10-28T08:35:46.870Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS Hintere Tür auf der Fahrerseite offen.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653cc2a2a8a7cb0008df86f2",
            "vin": "xxxx",
            "notificationDate": "2023-10-28T08:13:22.199Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS Hintere Tür auf der Fahrerseite offen.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653a3478a573a50008a84dea",
            "vin": "xxxx",
            "notificationDate": "2023-10-26T09:42:16.514Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653a2d76a573a50008a84c04",
            "vin": "xxxx",
            "notificationDate": "2023-10-26T09:12:22.223Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653690bc7724c70007d2a672",
            "vin": "xxxx",
            "notificationDate": "2023-10-23T15:26:52.381Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "65368896e25ecd00088ad3ed",
            "vin": "xxxx",
            "notificationDate": "2023-10-23T14:52:06.679Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
        {
            "messageId": "653637c8d323d2000817abac",
            "vin": "xxxx",
            "notificationDate": "2023-10-23T09:07:20.076Z",
            "isRead": True,
            "readTimestamp": "2023-10-28T09:50:13.749Z",
            "iconUrl": "https://assets.preprod.ctdevops.com/assets/notification/icons/critical_alert.png",
            "message": "2019 Corolla HB/TS mehrere Türen entriegelt, bitte prüfen Sie die App für weitere Details.",
            "status": 0,
            "type": "alert",
            "category": "VehicleStatusAlert",
            "displayCategory": "Vehicle Alerts",
        },
    ],
}

@DurgNomis-drol
Copy link
Owner

Awesome work, and some good points.

My vision for this lib is that it is wrapper for the API and returns simple dataclasses where we don't process data in any way, as this most be the users problem. This was not possible with old API. It seems that with new APP and API, this will be possible, and you (and @CM000n) have done a lot of work towards making that a reality. This will also make it easier to create unit tests and make sure that it keeps working in the future.

Regarding calling endpoints, we should limit the number of calls the API needs to do get all the data. We don't want to overload their servers, and possibly get to much attention from them 😉 When we fetch data we should extract as much info we can, as to not waste API calls, if this makes sense.

I don't have much time at the moment, and I don't have a car that supports much, but I will help review and find solutions to get this over the line.

@CM000n If this it is possible, should this be split into multiple PR to make it easier to review?

mytoyota/controller.py Outdated Show resolved Hide resolved
mytoyota/controller.py Outdated Show resolved Hide resolved
mytoyota/controller.py Outdated Show resolved Hide resolved
mytoyota/controller.py Outdated Show resolved Hide resolved
mytoyota/controller.py Outdated Show resolved Hide resolved
mytoyota/api.py Outdated Show resolved Hide resolved
mytoyota/api.py Show resolved Hide resolved
mytoyota/client.py Outdated Show resolved Hide resolved
@CM000n
Copy link
Collaborator

CM000n commented Nov 20, 2023

Perhaps a general question for you two @DurgNomis-drol & @GitOldGrumpy .
I don't like the current approach with the classes for the models. The redundant returing of the data via self.xyz seems somehow confusing.
I myself am a big fan of pydantic models for data validation and use it both privately and professionally:
https://docs.pydantic.dev/latest/

What is your opinion on this? Maybe we should refactor this as well, if we are already working on a new big bang version of the mytoyota lib which will probably bring some braking changes?

@GitOldGrumpy
Copy link
Collaborator Author

GitOldGrumpy commented Nov 20, 2023

@CM000n I'm not opposed to anything and that looks like it would automatically parse the JSON and check for correctness. A copule of quick questions(I can have a proper look later):

  1. Do you have to fully model(if that's the correct term) the JSON? There is a lot of information in vehicle_info that we will never want/need to expose.
  2. If you have to fully model it I assume every time it changes the parser will start to fail? The only thing that is pulled out of vehicle_info are the capabilities and the vin(off the top of my head)
  3. Can you extend this classes with further python functionality? The functions for getting trip data will actually need to call to the server on the request same with any of the setting functions and they will all need to be async functions.

EDIT: Do you mean just for modelling the endpoint data or for the client API's? For example the "Vehicle" class is a combination of several endpoints?

I will take a further look at the documentation later.

@GitOldGrumpy
Copy link
Collaborator Author

GitOldGrumpy commented Nov 20, 2023

@CM000n Out of interest does the application show the status of the locks your car supports? I can see in the notifications you get warnings if there open, but cant see an obvious endpoint it uses to get a list of them.

@skgsergio
Copy link
Contributor

skgsergio commented Dec 18, 2023

The correct notation would then be
preferred: bool = False
Optional only means that the value can be set to None.

Ok, so it works with normal default values, good to know.

The question here is more about what you prefer to do if the response lacks of it. If missing in the response set it to None, or assume that is not preferred and set it to False.

@CM000n
Copy link
Collaborator

CM000n commented Dec 18, 2023

The correct notation would then be
preferred: bool = False
Optional only means that the value can be set to None.

Ok, so it works with normal default values, good to know.

The question here is more about what you prefer to do if the response lacks of it. If missing in the response set it to None, or assume that is not preferred and set it to False.

As we have no official API documentation, it is also difficult to make assumptions about default values. The only thing we can say for sure in this case is that we do not receive a value for preferred. I think we should reflect this in the code and make the field Optional.

@Simon-Naylor
Copy link

Hi All, I'd like to help with the testing.
Having never got involved in anything like this before, could do with a pointer to get a test system up and running.

@HuffYk
Copy link

HuffYk commented Dec 18, 2023

Hi @HuffYk, the error output already tells you that the preferred field is missing 😉

@HuffYk the issue is not with registrationNumber, is that the response for your second car doesn't have the property preferred. The appropriate change in the VehicleGuidModel model would be something along the lines of:

-    preferred: bool
+    preferred: Optional[bool]

I don't know much about pydantic but maybe if absent can be defaulted to False.

The correct notation would then be preferred: bool = False Optional only means that the value can be set to None.

Thanks, this worked. Didn't decode "payload.1.preferred" as missing field :)

Checked output and everything looks ok except it shows "miles" rather than "km" for all relevant fields (fuel_range, odo etc.)

@skgsergio
Copy link
Contributor

Hi All, I'd like to help with the testing. Having never got involved in anything like this before, could do with a pointer to get a test system up and running.

As a quick test you can use the included simple_client_example.py:

python -m venv mytoyota
source mytoyota/bin/activate
python -m pip install "mytoyota @ git+https://github.com/DurgNomis-drol/mytoyota@refs/pull/242/head"
curl -LO https://raw.githubusercontent.com/GitOldGrumpy/mytoyota/master/simple_client_example.py
# Create a credentials.json file with {"username":"your@mail.tld","password":"yourpassword"}
python simple_client_example.py

@CM000n
Copy link
Collaborator

CM000n commented Dec 18, 2023

Checked output and everything looks ok except it shows "miles" rather than "km" for all relevant fields (fuel_range, odo etc.)

@HuffYk: You have to run the client.get_vehicles(metric=False) function in the example file with metric set to True if you want "km" instead of "miles".

@Simon-Naylor
Copy link

Thanks skgsergio for your help.
Other than having to "mkdir /root/.cache" it all worked OK for me. Fantastic work. How can I now help?

@clews
Copy link

clews commented Dec 18, 2023

Just tested with my account, got the following error (PHEV):

Logging in...
Retrieving cars...
Traceback (most recent call last):
  File "/home/cch/Devel/Clemens/mytoyota/simple_client_example.py", line 69, in <module>
    loop.run_until_complete(get_information())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/cch/Devel/Clemens/mytoyota/simple_client_example.py", line 47, in get_information
    await car.update()
  File "/home/cch/Devel/Clemens/mytoyota/lib/python3.11/site-packages/mytoyota/models/vehicle.py", line 103, in update
    for name, data in await responses:
                      ^^^^^^^^^^^^^^^
  File "/home/cch/Devel/Clemens/mytoyota/lib/python3.11/site-packages/mytoyota/models/vehicle.py", line 99, in parallel_wrapper
    r = await function()
        ^^^^^^^^^^^^^^^^
  File "/home/cch/Devel/Clemens/mytoyota/lib/python3.11/site-packages/mytoyota/api.py", line 113, in get_vehicle_electric_status_endpoint
    return await self._request_and_parse(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cch/Devel/Clemens/mytoyota/lib/python3.11/site-packages/mytoyota/api.py", line 45, in _request_and_parse
    return model(**response)
           ^^^^^^^^^^^^^^^^^
  File "/home/cch/Devel/Clemens/mytoyota/lib/python3.11/site-packages/pydantic/main.py", line 164, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 1 validation error for ElectricResponseModel
payload.canSetNextChargingEvent
  Field required [type=missing, input_value={'fuelLevel': 54, 'batter... '2023-12-18T15:09:07Z'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.5/v/missing

@CM000n
Copy link
Collaborator

CM000n commented Dec 18, 2023

What car and motor type do you own @clews ?
..::edit::.. ah, I see. A plugin hybrid car.

@clews
Copy link

clews commented Dec 18, 2023

What car and motor type do you own @clews ? ..::edit::.. ah, I see. A plugin hybrid car.

Exactly - Prius 2023 PHEV

@GitOldGrumpy
Copy link
Collaborator Author

This is kind of what I expected the more people use it the more we need to refine the pydantic models.

@clews was the car parked up at the time? Or does your car not support scheduled charging. Anyway the fix is to change line electric.py:27 to the following.

    can_set_next_charging_event: Optional[bool] = Field(alias="canSetNextChargingEvent", default=None)

@clews
Copy link

clews commented Dec 19, 2023

@clews was the car parked up at the time? Or does your car not support scheduled charging.

@GitOldGrumpy the car was parked at this time, it supports charging schedule but the schedule is empty (even unused) right now (don't have a fixed charging installation yet).

Setting the default worked, got all data that the App is showing me the last trips.

Will do a test in the next 2 days while the car is charging.

Copy link
Owner

@DurgNomis-drol DurgNomis-drol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job you guys have done 🚀

I can see you have add a lot of extra things. Would this be possible to add later instead? It is nearly impossible to review probably because of so much code. Can we keep this PR to only the changes that is need to get it working?. This will also make it much faster for me, and the others to get it merged 😄

.github/workflows/build.yml Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
mytoyota/api.py Show resolved Hide resolved
@CM000n
Copy link
Collaborator

CM000n commented Dec 19, 2023

Awesome job you guys have done 🚀

I can see you have add a lot of extra things. Would this be possible to add later instead? It is nearly impossible to review probably because of so much code. Can we keep this PR to only the changes that is need to get it working?. This will also make it much faster for me, and the others to get it merged 😄

Hi @DurgNomis-drol, thx for reviewing! As already written somewhere here in the discussion:
Yes, there are certainly a few extra things that are not necessary. But most of the changes are related to each other, which is why splitting up the MR, especially in its current state, is time-consuming and makes little sense.

CM000n
CM000n previously approved these changes Dec 19, 2023
@DurgNomis-drol
Copy link
Owner

Workflows, gitignore, pre-commit-config.yaml, setup.cfg, pyprojekt.toml changes that are not related to this PR need to be removed before this can be merged.

I value all you guy's works, but someone needs to be the strict about how we go about it so we make sure this code is as good as it can be 🚀

@CM000n
Copy link
Collaborator

CM000n commented Dec 20, 2023

Workflows, gitignore, pre-commit-config.yaml, setup.cfg, pyprojekt.toml changes that are not related to this PR need to be removed before this can be merged.

I value all you guy's works, but someone needs to be the strict about how we go about it so we make sure this code is as good as it can be 🚀

The changes to the workflows are linked to the formatting of the code. So that will also mean work to roll it back again.
But I may take a look at it during the week and move it to a separate MR.

@DurgNomis-drol
Copy link
Owner

@CM000n Thanks! Much appreciated ⭐

Related changes can still be part of this PR, and most of them are related.

@CM000n CM000n dismissed DurgNomis-drol’s stale review December 22, 2023 19:32

workflow changes afe now reverted

@CM000n CM000n merged commit d3c6b60 into DurgNomis-drol:master Dec 22, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants