Exemple #1
0
    def test_telegram_set(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet with DPTArray/DPTTime as payload."""
        xknx = XKNX(loop=self.loop)
        knxipframe = KNXIPFrame(xknx)
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.src_addr = PhysicalAddress("1.2.2")

        telegram = Telegram()
        telegram.group_address = GroupAddress(337)

        telegram.payload = DPTArray(DPTTime().to_knx({
            'hours': 13,
            'minutes': 23,
            'seconds': 42
        }))

        knxipframe.body.telegram = telegram

        knxipframe.body.set_hops(5)
        knxipframe.normalize()

        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x14, 0x29, 0x00, 0xbc, 0xd0,
                0x12, 0x02, 0x01, 0x51, 0x04, 0x00, 0x80, 13, 23, 42))

        self.assertEqual(knxipframe.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe.to_knx(), list(raw))
Exemple #2
0
    def from_knx(self, payload):
        """Convert current payload to value."""
        # if self.datetime_type == DateTimeType.DATETIME:
        #     datetime_data = DPTDateTime.from_knx(payload.value)
        if self.datetime_type == DateTimeType.DATE:
            datetime_data = DPTDate.from_knx(payload.value)

        elif self.datetime_type == DateTimeType.TIME:
            datetime_data = DPTTime.from_knx(payload.value)

        return datetime_data
Exemple #3
0
    def test_telegram_set(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet with DPTArray/DPTTime as payload."""
        xknx = XKNX(loop=self.loop)
        knxipframe = KNXIPFrame(xknx)
        knxipframe.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe.body.cemi.src_addr = PhysicalAddress("1.2.2")

        telegram = Telegram(
            group_address=GroupAddress(337),
            payload=DPTArray(DPTTime().to_knx(
                time.strptime("13:23:42", "%H:%M:%S"))),
        )

        knxipframe.body.cemi.telegram = telegram

        knxipframe.body.cemi.set_hops(5)
        knxipframe.normalize()

        raw = (
            0x06,
            0x10,
            0x05,
            0x30,
            0x00,
            0x14,
            0x29,
            0x00,
            0xBC,
            0xD0,
            0x12,
            0x02,
            0x01,
            0x51,
            0x04,
            0x00,
            0x80,
            13,
            23,
            42,
        )

        self.assertEqual(knxipframe.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe.to_knx(), list(raw))
Exemple #4
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_to_knx_max(self):
     """Testing KNX/Byte representation of DPTTime object. Maximum values."""
     raw = DPTTime().to_knx(time.strptime("23 59 59 0", "%H %M %S %w"))
     self.assertEqual(raw, (0xF7, 0x3b, 0x3b))
Exemple #6
0
 def test_to_knx_max(self):
     """Testing KNX/Byte representation of DPTTime object. Maximum values."""
     raw = DPTTime.to_knx(time.strptime("23 59 59 0", "%H %M %S %w"))
     assert raw == (0xF7, 0x3B, 0x3B)
Exemple #7
0
 def test_from_knx_wrong_type(self):
     """Test parsing from DPTTime object from wrong binary values (wrong type)."""
     with pytest.raises(ConversionError):
         DPTTime.from_knx((0xF8, "0x23"))
Exemple #8
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing from DPTTime object from wrong string value."""
     with pytest.raises(ConversionError):
         DPTTime.to_knx("fnord")
Exemple #9
0
 def test_to_knx_default(self):
     """Testing default initialization of DPTTime object."""
     assert DPTTime.to_knx(time.strptime("", "")) == (0x0, 0x0, 0x0)
Exemple #10
0
 def test_from_knx_wrong_bytes(self):
     """Test parsing from DPTTime object from wrong binary values (wrong bytes)."""
     with pytest.raises(ConversionError):
         # this parameter exceeds limit
         DPTTime.from_knx((0xF7, 0x3B, 0x3C))
Exemple #11
0
 def test_to_knx_min(self):
     """Testing KNX/Byte representation of DPTTime object. Minimum values."""
     raw = DPTTime.to_knx(time.strptime("0 0 0", "%H %M %S"))
     assert raw == (0x0, 0x0, 0x0)
Exemple #12
0
 def test_from_knx_min(self):
     """Test parsing of DPTTime object from binary values. Example 3."""
     assert DPTTime.from_knx((0x0, 0x0, 0x0)) == time.strptime("0 0 0", "%H %M %S")
Exemple #13
0
 def test_from_knx_max(self):
     """Test parsing of DPTTime object from binary values. Example 2."""
     self.assertEqual(DPTTime().from_knx((0xF7, 0x3b, 0x3b)),
                      time.strptime("23 59 59 0", "%H %M %S %w"))
Exemple #14
0
 def test_from_knx_max(self):
     """Test parsing of DPTTime object from binary values. Example 2."""
     assert DPTTime.from_knx((0xF7, 0x3B, 0x3B)) == time.strptime(
         "23 59 59 0", "%H %M %S %w"
     )
Exemple #15
0
 def test_to_knx(self):
     """Testing KNX/Byte representation of DPTTime object."""
     raw = DPTTime.to_knx(time.strptime("13 23 42 2", "%H %M %S %w"))
     assert raw == (0x4D, 0x17, 0x2A)
Exemple #16
0
 def test_from_knx(self):
     """Test parsing of DPTTime object from binary values. Example 1."""
     assert DPTTime.from_knx((0x4D, 0x17, 0x2A)) == time.strptime(
         "13 23 42 2", "%H %M %S %w"
     )
Exemple #17
0
 def test_from_knx_wrong_bytes(self):
     """Test parsing from DPTTime object from wrong binary values (wrong bytes)."""
     with self.assertRaises(ConversionError):
         # this parameter exceeds limit
         DPTTime().from_knx((0xF7, 0x3b, 0x3c))
Exemple #18
0
 def test_from_knx_wrong_size(self):
     """Test parsing from DPTTime object from wrong binary values (wrong size)."""
     with self.assertRaises(ConversionError):
         DPTTime().from_knx((0xF8, 0x23))
Exemple #19
0
 def test_to_knx_default(self):
     """Testing default initialization of DPTTime object."""
     self.assertEqual(DPTTime().to_knx(time.strptime("", "")),
                      (0x0, 0x0, 0x0))