Beispiel #1
0
 def test_wakeup(self):
     self.mock_connection_handler = self.wakeup_handler
     self.wakeup_handler_packets = []
     self.wakeup_handler_called = 0
     this_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(this_loop)
     this_loop.call_later(2, lambda: this_loop.stop())
     service = nabclockd.NabClockd()
     config = models.Config.load()
     now = datetime.datetime.now()
     config.wakeup_hour = now.hour
     config.wakeup_min = 0
     if now.hour == 23:
         config.sleep_hour = 0
     else:
         config.sleep_hour = now.hour + 1
     config.sleep_min = 0
     config.save()
     this_loop.create_task(service.reload_config())
     this_loop.call_later(
         1, lambda: this_loop.create_task(service.reload_config()))
     service.run()
     self.assertEqual(self.wakeup_handler_called, 1)
     self.assertEqual(len(self.wakeup_handler_packets), 2)
     # NLU packet
     self.assertTrue("type" in self.wakeup_handler_packets[0])
     self.assertEqual(self.wakeup_handler_packets[0]["type"], "mode")
     self.assertTrue("type" in self.wakeup_handler_packets[1])
     self.assertEqual(self.wakeup_handler_packets[1]["type"], "wakeup")
Beispiel #2
0
 def test_wakeup(self):
     self.mock_connection_handler = self.wakeup_handler
     self.wakeup_handler_packets = []
     self.wakeup_handler_called = 0
     this_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(this_loop)
     config = models.Config.load()
     now = datetime.datetime.now()
     config.wakeup_hour = now.hour + 2
     if config.wakeup_hour >= 24:
         config.wakeup_hour -= 24
     config.wakeup_min = 0
     config.sleep_hour = now.hour - 2
     if config.sleep_hour < 0:
         config.sleep_hour += 24
     config.sleep_min = 0
     config.save()
     service = nabclockd.NabClockd()
     this_loop.call_later(1, lambda: self._update_wakeup_hours(service))
     service.run()
     self.assertEqual(self.wakeup_handler_called, 1)
     self.assertEqual(len(self.wakeup_handler_packets), 2)
     # NLU packet
     self.assertTrue("type" in self.wakeup_handler_packets[0])
     self.assertEqual(self.wakeup_handler_packets[0]["type"], "mode")
     self.assertTrue("type" in self.wakeup_handler_packets[1])
     self.assertEqual(self.wakeup_handler_packets[1]["type"], "wakeup")
Beispiel #3
0
 def test_wakeup(self):
     self.mock_connection_handler = self.wakeup_handler
     self.wakeup_handler_packet = None
     self.wakeup_handler_called = 0
     this_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(this_loop)
     this_loop.call_later(2, lambda: this_loop.stop())
     service = nabclockd.NabClockd()
     config = models.Config.load()
     now = datetime.datetime.now()
     config.wakeup_hour = now.hour
     config.wakeup_min = 0
     if now.hour == 23:
         config.sleep_hour = 0
     else:
         config.sleep_hour = now.hour + 1
     config.sleep_min = 0
     config.save()
     this_loop.create_task(service.reload_config())
     this_loop.call_later(
         1, lambda: this_loop.create_task(service.reload_config()))
     service.run()
     self.assertEqual(self.wakeup_handler_called, 1)
     self.assertIsNot(self.wakeup_handler_packet, None)
     self.assertTrue('type' in self.wakeup_handler_packet)
     self.assertEqual(self.wakeup_handler_packet['type'], 'wakeup')
Beispiel #4
0
 def test_connect(self):
     self.mock_connection_handler = self.connect_handler
     self.connect_handler_called = 0
     this_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(this_loop)
     this_loop.call_later(1, lambda: this_loop.stop())
     service = nabclockd.NabClockd()
     service.run()
     self.assertEqual(self.connect_handler_called, 1)
Beispiel #5
0
 def test_clock_response(self):
     service = nabclockd.NabClockd()
     config = models.Config.load()
     config.wakeup_hour = 7
     config.wakeup_min = 0
     config.sleep_hour = 22
     config.sleep_min = 0
     config.chime_hour = True
     config.save()
     this_loop = asyncio.new_event_loop()
     asyncio.set_event_loop(this_loop)
     reload_task = this_loop.create_task(service.reload_config())
     this_loop.run_until_complete(reload_task)
     self.assertEqual(
         service.clock_response(
             datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(1970, 1, 1, 8, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     service.asleep = True
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 0, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 7, 0, 0, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 0, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 30, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 1, 0, tzinfo=tz.gettz())),
         ["wakeup"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 6, 0, tzinfo=tz.gettz())),
         ["wakeup", "reset_last_chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 22, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 23, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     service.asleep = False
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 0, 0, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 7, 0, 0, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 0, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 30, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 1, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 6, 0, tzinfo=tz.gettz())),
         ["reset_last_chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 22, 0, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 23, 0, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     config.wakeup_hour = 22
     config.wakeup_min = 0
     config.sleep_hour = 7
     config.sleep_min = 0
     config.chime_hour = True
     config.save()
     reload_task = this_loop.create_task(service.reload_config())
     this_loop.run_until_complete(reload_task)
     service.asleep = True
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 0, 0, 0, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 1, 0, 30, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 1, 6, 0, tzinfo=tz.gettz())),
         ["wakeup", "reset_last_chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 7, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 1, 0, tzinfo=tz.gettz())),
         [],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 22, 0, 0, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 23, 0, 0, tzinfo=tz.gettz())),
         ["wakeup", "chime"],
     )
     service.asleep = False
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 0, 0, 0, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 1, 0, 30, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 1, 6, 0, tzinfo=tz.gettz())),
         ["reset_last_chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 7, 0, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 0, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 8, 1, 0, tzinfo=tz.gettz())),
         ["sleep"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 22, 0, 0, tzinfo=tz.gettz())),
         ["chime"],
     )
     self.assertEqual(
         service.clock_response(
             datetime.datetime(2018, 11, 2, 23, 0, 0, tzinfo=tz.gettz())),
         ["chime"],
     )