File: example_write_serial_number.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 (34 lines) | stat: -rw-r--r-- 860 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
33
34
"""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."""

    if len(argv) != 3:
        print(
            f"{argv[0]}: required arguments: serial number formatted as f0:18:fa:23:d2:00 and individual address."
        )
        return 1

    serial = bytes.fromhex(argv[1].replace(":", ""))
    address = IndividualAddress(argv[2])

    print(f"Setting address {address} to device with serial {argv[1]}")

    async with XKNX() as xknx:
        await procedures.nm_individual_address_serial_number_write(
            xknx, serial, address
        )

    return 0


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