thomasgermain / pymultiMATIC

Python interface with Vaillant multiMATIC
MIT License
56 stars 11 forks source link

Module usage #43

Closed Arendtsen closed 3 years ago

Arendtsen commented 3 years ago

Hi

love the module in the earlier versions. Now I have an issue when trying to use the example provided in the README.

When trying this:

get the complete system

system = await manager.get_system()

I get this: system = await manager.get_system() ^ SyntaxError: 'await' outside function

What am I missing?

thomasgermain commented 3 years ago

Hello,

ah yeah sorry 😞 I forgot to update the documentation, you can check this script have a more concrete example.

Basically, you need to run the code inside the event loop, here is the an example (this will probably be the new example in the doc 😛)

#!/usr/bin/env python3
import asyncio
import sys

import aiohttp

from pymultimatic.systemmanager import SystemManager
from pymultimatic.model import System

async def main(user, passw):
    print('Trying to connect with user ' + user)

    async with aiohttp.ClientSession() as session:
        manager = SystemManager(user, passw, session)
        system =  await manager.get_system()
        print(system)

if __name__ == "__main__":
    if not len(sys.argv) == 3:
        print('Usage: python3 xxx.py user pass')
        sys.exit(0)
    user = sys.argv[1]
    passw = sys.argv[2]

    asyncio.get_event_loop().run_until_complete(main(user, passw))

Then you have to run the script like this: python3 your-script.py user password

Arendtsen commented 3 years ago

Ah that makes sense - I wasn't too far away. :-D

Thanks!