From 4685b18998802d8664c9155b757c7961b6dabacc Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Thu, 26 Nov 2020 00:38:03 +0100 Subject: [PATCH] Add tests for address CEMI frame flags --- test/knxip_tests/cemi_frame_test.py | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/knxip_tests/cemi_frame_test.py b/test/knxip_tests/cemi_frame_test.py index b911f8fb15..ed25d409f1 100644 --- a/test/knxip_tests/cemi_frame_test.py +++ b/test/knxip_tests/cemi_frame_test.py @@ -6,8 +6,8 @@ from xknx.dpt import DPTBinary, DPTComparator from xknx.exceptions import ConversionError, CouldNotParseKNXIP, UnsupportedCEMIMessage from xknx.knxip.cemi_frame import CEMIFrame -from xknx.knxip.knxip_enum import APCICommand, CEMIMessageCode -from xknx.telegram import PhysicalAddress, Telegram +from xknx.knxip.knxip_enum import APCICommand, CEMIMessageCode, CEMIFlags +from xknx.telegram import PhysicalAddress, Telegram, GroupAddress def get_data(code, adil, flags, src, dst, mpdu_len, tpci_apci, payload): @@ -153,3 +153,33 @@ def test_invalid_invalid_len(frame): """Test for invalid cemi len""" with raises(UnsupportedCEMIMessage, match=r".*CEMI too small.*"): frame.from_knx_data_link_layer(get_data(0x29, 0, 0, 0, 0, 2, 0, [])[:5]) + + +def test_from_knx_group_address(frame): + """Test conversion for a cemi with a group address as destination""" + frame.from_knx(get_data(0x29, 0, 0x80, 0, 0, 1, 0, [])) + + assert frame.dst_addr == GroupAddress(0) + + +def test_from_knx_physical_address(frame): + """Test conversion for a cemi with a physical address as destination""" + frame.from_knx(get_data(0x29, 0, 0x00, 0, 0, 1, 0, [])) + + assert frame.dst_addr == PhysicalAddress(0) + + +def test_telegram_group_address(frame): + """Test telegram conversion flags with a group address""" + frame.telegram = Telegram(address=GroupAddress(0)) + + assert (frame.flags & CEMIFlags.DESTINATION_GROUP_ADDRESS) == \ + CEMIFlags.DESTINATION_GROUP_ADDRESS + + +def test_telegram_physical_address(frame): + """Test telegram conversion flags with a physical address""" + frame.telegram = Telegram(address=PhysicalAddress(0)) + + assert (frame.flags & CEMIFlags.DESTINATION_INDIVIDUAL_ADDRESS) == \ + CEMIFlags.DESTINATION_INDIVIDUAL_ADDRESS