File: timer_notify_test.py

package info (click to toggle)
python-xknx 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,012 kB
  • sloc: python: 39,710; javascript: 8,556; makefile: 27; sh: 12
file content (43 lines) | stat: -rw-r--r-- 1,595 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
"""Unit test for KNX/IP TimerNotify objects."""

from xknx.knxip import KNXIPFrame, TimerNotify


class TestKNXIPTimerNotify:
    """Test class for KNX/IP TimerNotify objects."""

    def test_timer_notify(self) -> None:
        """Test parsing and streaming TimerNotify KNX/IP packet."""
        message_authentication_code = bytes.fromhex(
            "72 12 a0 3a aa e4 9d a8 56 89 77 4c 1d 2b 4d a4"
        )
        raw = (
            bytes.fromhex(
                "06 10 09 55 00 24"  # KNXnet/IP header - length 36 octets
                "c0 c1 c2 c3 c4 c5"  # timer value
                "00 fa 12 34 56 78"  # KNX serial number
                "af fe"  # message tag
            )
            + message_authentication_code
        )
        knxipframe, _ = KNXIPFrame.from_knx(raw)

        assert isinstance(knxipframe.body, TimerNotify)
        assert knxipframe.body.timer_value == 211938428830917
        assert knxipframe.body.serial_number == bytes.fromhex("00 fa 12 34 56 78")
        assert knxipframe.body.message_tag == bytes.fromhex("af fe")
        assert (
            knxipframe.body.message_authentication_code == message_authentication_code
        )

        assert knxipframe.to_knx() == raw

        timer_notify = TimerNotify(
            timer_value=211938428830917,
            serial_number=bytes.fromhex("00 fa 12 34 56 78"),
            message_tag=bytes.fromhex("af fe"),
            message_authentication_code=message_authentication_code,
        )
        knxipframe2 = KNXIPFrame.init_from_body(timer_notify)

        assert knxipframe2.to_knx() == raw