예제 #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
         })
예제 #2
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))
예제 #3
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))
예제 #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
         })
예제 #5
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))
예제 #6
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
         })
예제 #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
         })
예제 #8
0
 async def broadcast_time(self, response):
     """Broadcast time to KNX bus."""
     if self.broadcast_type == DateTimeBroadcastType.DATETIME:
         broadcast_data = DPTDateTime.current_datetime_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
     elif self.broadcast_type == DateTimeBroadcastType.DATE:
         broadcast_data = DPTDate.current_date_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
     elif self.broadcast_type == DateTimeBroadcastType.TIME:
         broadcast_data = DPTTime.current_time_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
예제 #9
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")
예제 #10
0
 def test_from_knx_wrong_parameter(self):
     """Test parsing from DPTDateTime object from wrong binary values."""
     with self.assertRaises(ConversionError):
         DPTDateTime().from_knx((0xF8, 0x23))
예제 #11
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))
예제 #12
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))
예제 #13
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))