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 44 45 46 47 48 49 50 51 52 53 54 55
|
"""Unit test for RemoteValueDateTime objects."""
import pytest
from xknx import XKNX
from xknx.dpt import DPTArray
from xknx.dpt.dpt_19 import KNXDateTime, KNXDayOfWeek
from xknx.exceptions import CouldNotParseTelegram
from xknx.remote_value import RemoteValueDateTime
class TestRemoteValueDateTime:
"""Test class for RemoteValueDateTime objects."""
def test_from_knx(self) -> None:
"""Test parsing of RV with datetime object."""
xknx = XKNX()
rv_datetime = RemoteValueDateTime(xknx)
assert rv_datetime.from_knx(
DPTArray((0x75, 0x0B, 0x1C, 0x17, 0x07, 0x18, 0x20, 0x80))
) == KNXDateTime(
2017,
11,
28,
23,
7,
24,
day_of_week=KNXDayOfWeek.ANY_DAY,
external_sync=True,
)
def test_to_knx(self) -> None:
"""Testing date time object."""
xknx = XKNX()
rv_datetime = RemoteValueDateTime(xknx)
array = rv_datetime.to_knx(
KNXDateTime(
2017,
11,
28,
23,
7,
24,
day_of_week=KNXDayOfWeek.ANY_DAY,
external_sync=True,
)
)
assert array.value == (0x75, 0x0B, 0x1C, 0x17, 0x07, 0x18, 0x20, 0x80)
def test_payload_invalid(self) -> None:
"""Testing KNX/Byte representation of DPTDateTime object."""
xknx = XKNX()
rv_datetime = RemoteValueDateTime(xknx)
with pytest.raises(CouldNotParseTelegram):
rv_datetime.from_knx(DPTArray((0x0B, 0x1C, 0x57, 0x07, 0x18, 0x20, 0x80)))
|