nordicopen / pyeasee

Easee EV charger API python library
MIT License
39 stars 12 forks source link

Providing a more complete code example #43

Closed TipsTricksMore closed 2 years ago

TipsTricksMore commented 3 years ago

Hi there, at first a huge THANK YOU to all who helped to develope this library! It saved me a lot of time so far :)

I opened this 'issue' to ask some of you, if one could give a more complete, more complex python example using this library.

I'm currently struggeling to get this all running... I'm not that experienced in python yet but always trying to learn :)

Maybe an example that includes: - getting the authentication token by given login data and charger information - the execution of a basic command like 'stopping'/starting' a charge - and one more complex command like settting the 'dynamicCircuitCurrentPx' on all three phase.

That would be a giant help for me!

Have a great day! Leo

olalid commented 3 years ago

Yes, documentation is limited, we are developing this lib mostly for use in the Home Assistant component, so using it directly is an added bonus more or less. Have you looked att the included __main__.py file? It contains a lot of utility code for calling and testing the lib. Setting dynamic circuit current per phase is already supported, look at circuit method set_dynamic_current(self, currentP1: int, currentP2: int = None, currentP3: int = None), it has 3 parameters, one for each phase (if you call it with only 1 input parameter it defaults to setting all phases to same value.

yanschneider commented 2 years ago

I find it always helps to have code that just runs for an example. With just a few more lines, you can achieve just that:

from pyeasee import Easee, Charger, Site
import asyncio

async def check_easee():

    easee = Easee('<YOUR_EMAIL>', '<YOUR_PASSWORD>')
    chargers = await easee.get_chargers()

    for charger in chargers:
        state = await charger.get_state()
        print(charger.name,state["chargerOpMode"])

    sites =  await easee.get_sites()
    for site in sites:
        charger = site.get_circuits()[0].get_chargers()[0]
        state =  await charger.get_state()
    await easee.close()

async def main():
    await check_easee()

asyncio.run(main())