File: example_value_reader.py

package info (click to toggle)
python-xknx 3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,044 kB
  • sloc: python: 40,087; javascript: 8,556; makefile: 32; sh: 12
file content (23 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Example on how to read a value from KNX bus."""

import asyncio

from xknx import XKNX
from xknx.core import ValueReader
from xknx.telegram import GroupAddress
from xknx.tools import read_group_value


async def main() -> None:
    """Connect and read value from KNX bus."""
    async with XKNX() as xknx:
        # get the value only (can be decoded when passing `value_type`)
        result = await read_group_value(xknx, "5/1/20")
        print(f"Value: {result}")

        # get the whole telegram
        telegram = await ValueReader(xknx, GroupAddress("5/1/20")).read()
        print(f"Telegram: {telegram}")


asyncio.run(main())