Ejemplo n.º 1
0
 def test_to_knx_wrong_month(self):
     """Test parsing from DPTDateTime object from wrong month value."""
     with self.assertRaises(ConversionError):
         DPTDateTime().to_knx({
             'year': 2002,
             'month': 0,
             'day': 20,
             'hours': 12,
             'minutes': 42,
             'seconds': 53
         })
Ejemplo n.º 2
0
 def test_to_knx_date_in_future(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx({
         'year': 2155,
         'month': 12,
         'day': 31,
         'weekday': DPTWeekday.SUNDAY,
         'hours': 23,
         'minutes': 59,
         'seconds': 59
     })
     self.assertEqual(raw, (0xFF, 0x0C, 0x1F, 0xF7, 0x3B, 0x3B, 0x00, 0x00))
Ejemplo n.º 3
0
 def test_to_knx_date_in_past(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx({
         'year': 1900,
         'month': 1,
         'day': 1,
         'weekday': DPTWeekday.MONDAY,
         'hours': 0,
         'minutes': 0,
         'seconds': 0
     })
     self.assertEqual(raw, (0x00, 0x1, 0x1, 0x20, 0x00, 0x00, 0x00, 0x00))
Ejemplo n.º 4
0
 def test_from_knx_date_in_future(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0xFF, 0x0C, 0x1F, 0xF7, 0x3B, 0x3B, 0x00, 0x00)), {
             'year': 2155,
             'month': 12,
             'day': 31,
             'weekday': DPTWeekday.SUNDAY,
             'hours': 23,
             'minutes': 59,
             'seconds': 59
         })
Ejemplo n.º 5
0
 def test_from_knx_date_in_past(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0x00, 0x1, 0x1, 0x20, 0x00, 0x00, 0x00, 0x00)), {
             'year': 1900,
             'month': 1,
             'day': 1,
             'weekday': DPTWeekday.MONDAY,
             'hours': 0,
             'minutes': 0,
             'seconds': 0
         })
Ejemplo n.º 6
0
 def test_to_knx(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx({
         'year': 2017,
         'month': 11,
         'day': 28,
         'weekday': DPTWeekday.NONE,
         'hours': 23,
         'minutes': 7,
         'seconds': 24
     })
     self.assertEqual(raw, (0x75, 0x0B, 0x1C, 0x17, 0x07, 0x18, 0x00, 0x00))
Ejemplo n.º 7
0
 def test_from_knx(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0x75, 0x0B, 0x1C, 0x17, 0x07, 0x18, 0x00, 0x00)), {
             'year': 2017,
             'month': 11,
             'day': 28,
             'weekday': DPTWeekday.NONE,
             'hours': 23,
             'minutes': 7,
             'seconds': 24
         })
Ejemplo n.º 8
0
 def test_from_knx_wrong_size(self):
     """Test parsing DPTDateTime from KNX with wrong binary values (wrong size)."""
     with self.assertRaises(ConversionError):
         DPTDateTime().from_knx((0xF8, 0x23))
Ejemplo n.º 9
0
 def test_to_knx_date_in_future(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx(
         time.strptime("2155-12-31 0 23:59:59", "%Y-%m-%d %w %H:%M:%S")
     )
     self.assertEqual(raw, (0xFF, 0x0C, 0x1F, 0xF7, 0x3B, 0x3B, 0x20, 0x80))
Ejemplo n.º 10
0
 def test_from_knx_date_in_future(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0xFF, 0x0C, 0x1F, 0xF7, 0x3B, 0x3B, 0x20, 0x80)),
         time.strptime("2155-12-31 0 23:59:59", "%Y-%m-%d %w %H:%M:%S"),
     )
Ejemplo n.º 11
0
 def test_to_knx_date_in_past(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx(
         time.strptime("1900-1-1 1 0:0:0", "%Y-%m-%d %w %H:%M:%S")
     )
     self.assertEqual(raw, (0x00, 0x1, 0x1, 0x20, 0x00, 0x00, 0x20, 0x80))
Ejemplo n.º 12
0
 def test_from_knx_date_in_past(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0x00, 0x1, 0x1, 0x20, 0x00, 0x00, 0x00, 0x00)),
         time.strptime("1900 1 1 0 0 0", "%Y %m %d %H %M %S"),
     )
Ejemplo n.º 13
0
 def test_to_knx(self):
     """Testing KNX/Byte representation of DPTDateTime object."""
     raw = DPTDateTime().to_knx(
         time.strptime("2017-11-28 23:7:24", "%Y-%m-%d %H:%M:%S")
     )
     self.assertEqual(raw, (0x75, 0x0B, 0x1C, 0x57, 0x07, 0x18, 0x20, 0x80))
Ejemplo n.º 14
0
 def test_test_range_wrong_weekday(self):
     """Test range testing with wrong weekday (Cant be tested with normal from_/to_knx)."""
     # pylint: disable=protected-access
     self.assertFalse(DPTDateTime._test_range(1900, 1, 1, 8, 0, 0, 0))
Ejemplo n.º 15
0
 def test_from_knx_wrong_bytes(self):
     """Test parsing DPTDateTime from KNX with wrong binary values (wrong bytes)."""
     with self.assertRaises(ConversionError):
         # (second byte exceeds value...)
         DPTDateTime().from_knx((0xFF, 0x0D, 0x1F, 0xF7, 0x3B, 0x3B, 0x00, 0x00))
Ejemplo n.º 16
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing from DPTDateTime object from wrong string value."""
     with self.assertRaises(ConversionError):
         DPTDateTime().to_knx("hello")
Ejemplo n.º 17
0
 def test_from_knx(self):
     """Test parsing of DPTDateTime object from binary values. Example 1."""
     self.assertEqual(
         DPTDateTime().from_knx((0x75, 0x0B, 0x1C, 0x17, 0x07, 0x18, 0x20, 0x80)),
         time.strptime("2017-11-28 23:7:24", "%Y-%m-%d %H:%M:%S"),
     )