def test_EndTOEnd_group_write_binary_on(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, switch on light in my kitchen."""
        # Switch on Kitchen-L1
        raw = bytes.fromhex("0610053000112900BCD0FFF90149010081")
        xknx = XKNX()
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        self.assertEqual(
            telegram,
            Telegram(
                destination_address=GroupAddress("329"),
                payload=GroupValueWrite(DPTBinary(1)),
                source_address=IndividualAddress("15.15.249"),
            ),
        )

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("15.15.249"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        self.assertEqual(knxipframe2.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe2.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe2.to_knx(), list(raw))
    def test_EndTOEnd_group_write_2bytes(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, setting value of thermostat."""
        # Incoming Temperature from thermostat
        raw = bytes.fromhex("0610053000132900BCD01402080103008007C1")
        xknx = XKNX()
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        self.assertEqual(
            telegram,
            Telegram(
                destination_address=GroupAddress("2049"),
                payload=GroupValueWrite(
                    DPTArray(DPTTemperature().to_knx(19.85))),
                source_address=IndividualAddress("1.4.2"),
            ),
        )

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("1.4.2"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        self.assertEqual(knxipframe2.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe2.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe2.to_knx(), list(raw))
    def test_EndTOEnd_group_response(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, group response."""
        # Incoming state
        raw = bytes.fromhex("0610053000112900BCD013010188010041")
        xknx = XKNX()
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        self.assertEqual(
            telegram,
            Telegram(
                destination_address=GroupAddress("392"),
                payload=GroupValueResponse(DPTBinary(1)),
                source_address=IndividualAddress("1.3.1"),
            ),
        )

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("1.3.1"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        self.assertEqual(knxipframe2.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe2.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe2.to_knx(), list(raw))
Example #4
0
 def test_routing_indication_str(self):
     """Test string representation of GatewayDescriptor."""
     xknx = XKNX()
     ri = RoutingIndication(xknx)
     self.assertEqual(
         str(ri),
         '<RoutingIndication cemi="<CEMIFrame SourceAddress="PhysicalAddress("0.0.0")" DestinationAddress="GroupAddress("0/0/0")" Flags="               0" Command="APCICommand.GROUP_READ" payload="None" />" />',
     )
Example #5
0
 def test_routing_indication_str(self):
     """Test string representation of GatewayDescriptor."""
     routing_indication = RoutingIndication()
     assert (
         str(routing_indication) ==
         '<RoutingIndication cemi="<CEMIFrame SourceAddress="IndividualAddress("0.0.0")" '
         'DestinationAddress="GroupAddress("0/0/0")" Flags="               0" code="L_DATA_IND" payload="None" />" />'
     )
Example #6
0
 def test_routing_indication_str(self):
     """Test string representation of GatewayDescriptor."""
     routing_indication = RoutingIndication()
     assert (
         str(routing_indication) ==
         '<RoutingIndication cemi="<CEMIFrame code="L_DATA_IND" src_addr="IndividualAddress("0.0.0")" '
         'dst_addr="GroupAddress("0/0/0")" flags="               0" tpci="TDataGroup()" payload="None" />" />'
     )
Example #7
0
 async def send_telegram(self, telegram: "Telegram") -> None:
     """Send Telegram to routing connected device."""
     cemi = CEMIFrame.init_from_telegram(
         telegram=telegram,
         code=CEMIMessageCode.L_DATA_IND,
         src_addr=self.xknx.own_address,
     )
     routing_indication = RoutingIndication(cemi=cemi)
     await self.send_knxipframe(KNXIPFrame.init_from_body(routing_indication))
Example #8
0
    def test_telegram_set(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet with DPTArray/DPTTime as payload."""
        telegram = Telegram(
            destination_address=GroupAddress(337),
            payload=GroupValueWrite(
                DPTArray(DPTTime().to_knx(time.strptime(
                    "13:23:42", "%H:%M:%S")))),
        )
        cemi = CEMIFrame(src_addr=IndividualAddress("1.2.2"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(cemi=cemi)
        knxipframe = KNXIPFrame.init_from_body(routing_indication)

        raw = bytes.fromhex(
            "06 10 05 30 00 14 29 00 bc d0 12 02 01 51 04 00 80 0d 17 2a")

        assert knxipframe.header.to_knx() == raw[0:6]
        assert knxipframe.body.to_knx() == raw[6:]
        assert knxipframe.to_knx() == raw
    def test_maximum_apci(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, testing maximum APCI."""
        telegram = Telegram(
            destination_address=GroupAddress(337),
            payload=GroupValueWrite(DPTBinary(DPTBinary.APCI_MAX_VALUE)),
            source_address=IndividualAddress("1.3.1"),
        )
        xknx = XKNX()

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("1.3.1"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe = KNXIPFrame.init_from_body(routing_indication)

        raw = bytes.fromhex("0610053000112900BCD0130101510100BF")

        self.assertEqual(knxipframe.to_knx(), list(raw))

        knxipframe2 = KNXIPFrame(xknx)
        knxipframe2.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe2.from_knx(knxipframe.to_knx())
        self.assertEqual(knxipframe2.body.cemi.telegram, telegram)
Example #10
0
    def test_end_to_end_group_read(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, group read."""
        # State request
        raw = bytes.fromhex("0610053000112900BCD0FFF901B8010000")
        xknx = XKNX()
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        assert telegram == Telegram(
            destination_address=GroupAddress("440"),
            payload=GroupValueRead(),
            source_address=IndividualAddress("15.15.249"),
        )

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("15.15.249"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        assert knxipframe2.header.to_knx() == list(raw[0:6])
        assert knxipframe2.body.to_knx() == list(raw[6:])
        assert knxipframe2.to_knx() == list(raw)
Example #11
0
    def test_end_to_end_group_write_1byte(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, dimm light in my kitchen."""
        # Dimm Kitchen L1 to 0x65
        raw = bytes.fromhex("0610053000122900BCD0FFF9014B02008065")
        xknx = XKNX()
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        assert telegram == Telegram(
            destination_address=GroupAddress("331"),
            payload=GroupValueWrite(DPTArray(0x65)),
            source_address=IndividualAddress("15.15.249"),
        )

        cemi = CEMIFrame(xknx, src_addr=IndividualAddress("15.15.249"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(xknx, cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        assert knxipframe2.header.to_knx() == list(raw[0:6])
        assert knxipframe2.body.to_knx() == list(raw[6:])
        assert knxipframe2.to_knx() == list(raw)
Example #12
0
    def test_end_to_end_group_write_binary_on(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, switch on light in my kitchen."""
        # Switch on Kitchen-L1
        raw = bytes.fromhex(
            "06 10 05 30 00 11 29 00 bc d0 ff f9 01 49 01 00 81")
        knxipframe = KNXIPFrame()
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        assert telegram == Telegram(
            destination_address=GroupAddress("329"),
            payload=GroupValueWrite(DPTBinary(1)),
            source_address=IndividualAddress("15.15.249"),
        )

        cemi = CEMIFrame(src_addr=IndividualAddress("15.15.249"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        assert knxipframe2.header.to_knx() == raw[0:6]
        assert knxipframe2.body.to_knx() == raw[6:]
        assert knxipframe2.to_knx() == raw
Example #13
0
    def test_end_to_end_group_response(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, group response."""
        # Incoming state
        raw = bytes.fromhex(
            "06 10 05 30 00 11 29 00 bc d0 13 01 01 88 01 00 41")
        knxipframe = KNXIPFrame()
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.cemi.telegram
        assert telegram == Telegram(
            destination_address=GroupAddress("392"),
            payload=GroupValueResponse(DPTBinary(1)),
            source_address=IndividualAddress("1.3.1"),
        )

        cemi = CEMIFrame(src_addr=IndividualAddress("1.3.1"))
        cemi.telegram = telegram
        cemi.set_hops(5)
        routing_indication = RoutingIndication(cemi=cemi)
        knxipframe2 = KNXIPFrame.init_from_body(routing_indication)

        assert knxipframe2.header.to_knx() == raw[0:6]
        assert knxipframe2.body.to_knx() == raw[6:]
        assert knxipframe2.to_knx() == raw
 def test_from_knx_invalid_cemi(self):
     """Test parsing and streaming CEMIFrame KNX/IP packet with unsupported CEMICode."""
     xknx = XKNX()
     ri = RoutingIndication(xknx)
     raw = bytes([43, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0])
     self.assertEqual(11, ri.from_knx(raw))
Example #15
0
 def test_from_knx_invalid_cemi(self):
     """Test parsing and streaming CEMIFrame KNX/IP packet with unsupported CEMICode."""
     routing_indication = RoutingIndication()
     raw = bytes([43, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0])
     assert routing_indication.from_knx(raw) == 11