CJNE / pyporscheconnectapi

Python client library for Porsche Connect API
MIT License
44 stars 9 forks source link

porschecli: error: argument command: invalid choice - not working #20

Closed TimoD87 closed 1 year ago

TimoD87 commented 1 year ago

I'm trying to bring the cli working,

I try: python porschecli -e my@mail.me -p 6passs! -v WP0ZZZY16PS111118 services

and get:

porschecli: error: argument command: invalid choice: 'WP0ZZZY1611111198' (choose from 'list', 'services', 'overview', 'maintenance', 'summary', 'capabilities', 'permissions', 'emobility', 'position', 'triplongterm', 'tripshortterm', 'speedalerts', 'theftalerts', 'tokens', 'lock', 'unlock', 'climate-on', 'climate-off', 'directcharge-on', 'directcharge-off', 'honk', 'flash', 'chargingprofile')

I also tried "python porschecli -v WP0ZZZY16111118 services" and I get the same error - hopefully you can help me :-)

What I'm doing wrong?

Thank you

What is working python porschecli services but a soon a vin is needed I get the error

CJNE commented 1 year ago

Hi!

services need to go before -v, so: python porschecli -e my@mail.me -p 6passs! services -v WP0ZZZY16PSA69498

You can view all options using python porschecli services --help

One last tip, you should be able to skip the python part if you have installed the module. Hope this helps!

TimoD87 commented 1 year ago

Thanks for the fast support, I don't want to open a new ticket, because it is not an issue, I would like to add to your cli a MQTT broker sending the Information to an MQTT server, so I can read the values in my Smarthome.

I tested the following:


import asyncio
from pyporscheconnectapi.connection import Connection
from pyporscheconnectapi.client import Client
from sys import argv
import logging
import paho.mqtt.client as mqtt
import time
#logging.basicConfig()

# By default the root logger is set to WARNING and all loggers you define
# inherit that value. Here we set the root logger to NOTSET. This logging
# level is automatically inherited by all existing and new sub-loggers
# that do not set a less verbose level.
#logging.root.setLevel(logging.INFO)

email = 'maile'
password = 'passs!'

async def vehicles() -> None:
    clientMQTT = mqtt.Client()
    clientMQTT.connect("192.168.178.3", 1883, 60)

    conn = Connection(email, password)
    client = Client(conn)

    vehicles = await client.getVehicles()
    for vehicle in vehicles:
        print(f"VIN: {vehicle['vin']} Model: {vehicle['modelDescription']} Year: {vehicle['modelYear']}") 

    clientMQTT.publish("MQTT2_CLIENT/AA_Model_Year", vehicle['modelYear'])
    time.sleep(3)
    clientMQTT.publish("MQTT2_CLIENT/AA_Model_VIN", vehicle['vin'])
    time.sleep(3)
    clientMQTT.publish("MQTT2_CLIENT/AA_Model_Description", vehicle['modelDescription'])
    time.sleep(3)

    clientMQTT.disconnect()
    await conn.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(vehicles())

In General it is working. But I missing the skills to implement it in your cli or to make a separate "example" getting vehicle data and pushing them to the Matt. Can you help me a little bit? (I would love to use the API)

Do you have a example getting the VIN / getting User and Passwort from Config and then pushing the Car Data to MQTT?

I'm for example struggling with:

import asyncio
from pyporscheconnectapi.connection import Connection
from pyporscheconnectapi.client import Client
from sys import argv
import logging
import paho.mqtt.client as mqtt
import time

# logging.basicConfig()
# logging.root.setLevel(logging.DEBUG)

email = argv[1]
password = argv[2]

async def vehicles() -> None:
    clientMQTT = mqtt.Client()
    clientMQTT.connect("192.168.178.3", 1883, 60)

    conn = Connection(email, password)
    client = Client(conn)

    vehicles = await client.getVehicles()
    for vehicle in vehicles:
        print(f"VIN: {vehicle['vin']} Model: {vehicle['modelDescription']} Year: {vehicle['modelYear']}")
        data = await conn.get(f"https://api.porsche.com/service-vehicle/se/sv_SE/vehicle-data/{vehicle['vin']}/stored")
        #if data['batteryLevel'] is not None:
        print(f"Battery at {data['batteryLevel']['value']}%")
        print(f"Locked or open? {data['overallOpenStatus']}")
        clientMQTT.publish("MQTT2_CLIENT/AA_Battery", {data['batteryLevel']['value']}) 

    await conn.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(vehicles())

Getting the Error that {data['batteryLevel']['value']} is not payload must be a string, bytearray, int, float or None.

:-(

Thanks a lot in advance