File: read_process_data.py

package info (click to toggle)
pykoplenti 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 372 kB
  • sloc: python: 2,215; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 936 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
import asyncio
import sys

from aiohttp import ClientSession

from pykoplenti import ApiClient

"""
Provides a simple example which reads two process data from the plenticore.

Must be called with host and password:
  `python read_process_data.py 192.168.1.100 mysecretpassword`

"""


async def async_main(host, passwd):
    async with ClientSession() as session:
        client = ApiClient(session, host)
        await client.login(passwd)

        data = await client.get_process_data_values(
            "devices:local", ["Inverter:State", "Home_P"]
        )

        device_local = data["devices:local"]
        inverter_state = device_local["Inverter:State"]
        home_p = device_local["Home_P"]

        print(f"Inverter-State: {inverter_state.value}\nHome-P: {home_p.value}\n")


if len(sys.argv) != 3:
    print("Usage: <host> <password>")
    sys.exit(1)

_, host, passwd = sys.argv

asyncio.run(async_main(host, passwd))