示例#1
0
 def test_from_knx(self):
     """Test parsing of DPTDate object from binary values. Example 1."""
     self.assertEqual(DPTDate().from_knx((0x04, 0x01, 0x02)), {
         'year': 2002,
         'month': 1,
         'day': 4
     })
示例#2
0
 def test_from_knx_future_date(self):
     """Test parsing of DPTDate object from binary values. Example 3."""
     self.assertEqual(DPTDate().from_knx((0x04, 0x0C, 0x59)), {
         'year': 2089,
         'month': 12,
         'day': 4
     })
示例#3
0
 def test_from_knx_old_date(self):
     """Test parsing of DPTDate object from binary values. Example 2."""
     self.assertEqual(DPTDate().from_knx((0x1F, 0x01, 0x5A)), {
         'year': 1990,
         'month': 1,
         'day': 31
     })
示例#4
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
示例#5
0
 def test_from_knx_future_date(self):
     """Test parsing of DPTDate object from binary values. Example 3."""
     self.assertEqual(DPTDate().from_knx((0x04, 0x0C, 0x59)),
                      time.strptime("2089-12-4", "%Y-%m-%d"))
示例#6
0
 def test_from_knx_wrong_range_month(self):
     """Test Exception when parsing DPTDAte from KNX with wrong month."""
     with self.assertRaises(ConversionError):
         DPTDate().from_knx((0x04, 0x00, 0x59))
示例#7
0
 def test_from_knx_wrong_range_year(self):
     """Test Exception when parsing DPTDate from KNX with wrong year."""
     with self.assertRaises(ConversionError):
         DPTDate().from_knx((0x04, 0x01, 0x64))
示例#8
0
 def test_from_knx_wrong_parameter(self):
     """Test parsing from DPTDate object from wrong binary values."""
     with self.assertRaises(ConversionError):
         DPTDate().from_knx((0xF8, 0x23))
示例#9
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing from DPTDate object from wrong string value."""
     with self.assertRaises(ConversionError):
         DPTDate().to_knx("hello")
示例#10
0
 def test_to_knx_old_date(self):
     """Testing KNX/Byte representation of DPTDate object. Example 2."""
     raw = DPTDate().to_knx(time.strptime("1990-01-31", "%Y-%m-%d"))
     self.assertEqual(raw, (0x1F, 0x01, 0x5A))
示例#11
0
 def test_to_knx_future_date(self):
     """Testing KNX/Byte representation of DPTDate object. Example 3."""
     raw = DPTDate().to_knx(time.strptime("2089-12-04", "%Y-%m-%d"))
     self.assertEqual(raw, (0x04, 0x0C, 0x59))
示例#12
0
 def test_to_knx(self):
     """Testing KNX/Byte representation of DPTDate object. Example 1."""
     raw = DPTDate().to_knx({'year': 2002, 'month': 1, 'day': 4})
     self.assertEqual(raw, (0x04, 0x01, 0x02))
示例#13
0
 def test_to_knx(self):
     """Testing KNX/Byte representation of DPTDate object. Example 1."""
     raw = DPTDate().to_knx(time.strptime("2002-1-04", "%Y-%m-%d"))
     self.assertEqual(raw, (0x04, 0x01, 0x02))
示例#14
0
 def test_from_knx_old_date(self):
     """Test parsing of DPTDate object from binary values. Example 2."""
     self.assertEqual(DPTDate().from_knx((0x1F, 0x01, 0x5A)),
                      time.strptime("1990-01-31", "%Y-%m-%d"))
示例#15
0
 def test_from_knx(self):
     """Test parsing of DPTDate object from binary values. Example 1."""
     self.assertEqual(DPTDate().from_knx((0x04, 0x01, 0x02)),
                      time.strptime("2002-01-04", "%Y-%m-%d"))
示例#16
0
 def test_to_knx_old_date(self):
     """Testing KNX/Byte representation of DPTDate object. Example 2."""
     raw = DPTDate().to_knx({'year': 1990, 'month': 1, 'day': 31})
     self.assertEqual(raw, (0x1F, 0x01, 0x5A))
示例#17
0
 def test_to_knx_wrong_month(self):
     """Test parsing from DPTDate object from wrong month value."""
     with self.assertRaises(ConversionError):
         DPTDate().to_knx({'year': 2002, 'month': 0, 'day': 20})
示例#18
0
 def test_to_knx_future_date(self):
     """Testing KNX/Byte representation of DPTDate object. Example 3."""
     raw = DPTDate().to_knx({'year': 2089, 'month': 12, 'day': 4})
     self.assertEqual(raw, (0x04, 0x0C, 0x59))