File: example_construct.py

package info (click to toggle)
python-mypermobil 0.1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: python: 1,172; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Example of how to construct a MyPermobil instance"""

import asyncio
from datetime import datetime, timedelta
import mypermobil


async def main():
    """Example of how to construct a MyPermobil instance"""

    # Create a session
    # mypermobil uses aiohttp.ClientSession for the requests
    session = await mypermobil.create_session()
    email = "example@email.com"
    token = "a" * 256
    expiration = (datetime.now() + timedelta(days=365)).strftime("%Y-%m-%d")
    region = "https://region.com/api/v1"
    application = "example-application"
    p_api = mypermobil.MyPermobil(
        application=application,
        session=session,
        email=email,
        token=token,
        expiration_date=expiration,
        region=region,
    )
    # mark as authenticated
    p_api.self_authenticate()

    #################
    #               #
    # Do stuff here #
    #               #
    #################
    # p_api.request_item(mypermobil.BATTERY_STATE_OF_CHARGE)

    # close session

    await p_api.close_session()


if __name__ == "__main__":
    asyncio.run(main())