Пример #1
0
    def test_time_a_to_bytes(self):
        d = datetime.datetime(2017, 1, 2, 3, 4)
        tiempo = app_asdu.TimeA(d)
        thebytes = tiempo.to_bytes()

        tiempo2 = app_asdu.TimeA()
        tiempo2.from_hex(thebytes)
        self.assertEqual(tiempo2.datetime, d)
Пример #2
0
    def test_empty_time_a_from_hex(self):
        tiempo = app_asdu.TimeA()

        # 2000 0 0 0 0 0
        tiempo.from_hex(bytearray.fromhex("00 00 00 00 00"))
        print(tiempo)
        self.assertEqual(tiempo.datetime,
                         localize(datetime.datetime(2000, 1, 1, 0, 0, 0, 0)))
Пример #3
0
    def test_time_a_from_hex(self):
        tiempo = app_asdu.TimeA()

        #segun el pdf 18/09/09 00:01:00
        tiempo.from_hex(bytearray.fromhex("01 0012 0909"))
        print(tiempo)
        self.assertEqual(tiempo.datetime, datetime.datetime(2009, 9, 18, 0, 1))

        #segun el pdf 7/02/10 11:00
        tiempo.from_hex(bytearray.fromhex("00 0b 07 02 0a"))
        print(tiempo)
        self.assertEqual(tiempo.datetime, datetime.datetime(2010, 2, 7, 11, 0))
Пример #4
0
    def test_time_a_StoW_to_bytes(self):
        d = datetime.datetime(2019, 10, 27, 2, 0, 0)
        ds = TIMEZONE.localize(d, is_dst=True)
        dw = TIMEZONE.localize(d, is_dst=False)

        # Change hour Summer
        tiempo_summer = app_asdu.TimeA(ds)
        self.assertEqual(tiempo_summer.SU, 1)
        thebytes = tiempo_summer.to_bytes()
        print(thebytes)
        t2s = app_asdu.TimeA()
        t2s.from_hex(thebytes)
        self.assertGreater(t2s.datetime.dst().seconds, 0)
        self.assertEqual(t2s.datetime, ds)

        # Change hour Winter
        tiempo_winter = app_asdu.TimeA(dw)
        self.assertEqual(tiempo_winter.SU, 0)
        thebytes = tiempo_winter.to_bytes()
        t2w = app_asdu.TimeA()
        t2w.from_hex(thebytes)
        self.assertEqual(t2w.datetime.dst().seconds, 0)
        self.assertEqual(t2w.datetime, dw)