File: example_write_individual_address.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 (32 lines) | stat: -rw-r--r-- 818 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
24
25
26
27
28
29
30
31
32
"""Example for writing an individual address to a KNX device."""

import asyncio
import sys

from xknx import XKNX
from xknx.management import procedures
from xknx.telegram import IndividualAddress


async def main(argv: list[str]) -> int:
    """
    Write the individual address to a device in programming mode.

    This fails if multiple devices are in programming mode and/or when there is no device found in programming mode.
    """

    if len(argv) != 2:
        print(f"{argv[0]}: missing target address.")
        return 1

    address = IndividualAddress(argv[1])

    async with XKNX() as xknx:
        individual_address = IndividualAddress(address)
        await procedures.nm_individual_address_write(xknx, individual_address)

    return 0


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