Esempio n. 1
0
 def test_receive_switches(self) -> None:
     q: Queue[LightSwitch] = Queue()
     lc = LightController(q, [], Color(0, 0, 0))
     c = Color(1, 2, 3)
     exp = 0
     q.put(LightSwitch(exp, 40, c))
     q.put(LightSwitch(exp, 41, c))
     q.put(LightSwitch(exp, 42, c))
     lc.receive_switches()
     assert len(lc._switches) == 3
Esempio n. 2
0
 def test_get_highest_priority(self) -> None:
     lc = LightController(Queue(), [], Color(0, 0, 0))
     c = Color(1, 2, 3)
     exp = 0
     lc._switches = [
         LightSwitch(exp, 40, c),
         LightSwitch(exp + 1, 50, c),
         LightSwitch(exp + 2, 40, c),
         LightSwitch(exp + 3, 40, c)
     ]
     assert lc.get_highest_priority() == LightSwitch(exp + 1, 50, c)
Esempio n. 3
0
 def test_remove_expired(self) -> None:
     lc = LightController(Queue(), [], Color(0, 0, 0))
     c = Color(1, 2, 3)
     exp = datetime.now().timestamp()
     lc._switches = [
         LightSwitch(exp, 40, c),
         LightSwitch(exp - 1, 50, c),
         LightSwitch(exp - 2, 40, c),
         LightSwitch(exp + 3, 40, c),
         LightSwitch(exp - 10000, 40, c)
     ]
     lc.remove_expired()
     assert len(lc._switches) == 2
Esempio n. 4
0
    def test_send_message(self) -> None:
        queue: Queue[LightSwitch] = Queue()
        blp = BluetoothProximity(queue, -50, timedelta(seconds=3), 50,
                                 Color(1, 2, 3))
        blp.flick_light_switch("fa:ke:ad:dr", -42)

        assert queue.qsize() == 1
        actual = queue.get()
        assert actual == LightSwitch(
            datetime(2020, 1, 1, 12, 0, 5).timestamp(), 50, Color(1, 2, 3))
Esempio n. 5
0
 def test_equal(self) -> None:
     now = datetime.now().timestamp()
     assert LightSwitch(now, 50, Color(1, 2, 3)) == LightSwitch(now, 50, Color(1, 2, 3))
Esempio n. 6
0
 def test_not_expired(self) -> None:
     assert not LightSwitch(datetime.now().timestamp() + 1, 42, Color(1, 2, 3)).expired()
Esempio n. 7
0
 def flick_light_switch(self, address: str, rssi: int) -> None:
     logging.info(f"Device {address} in range ({rssi})")
     expiry = (datetime.now() + self._detection_duration).timestamp()
     flick = LightSwitch(expiry, self._priority, self._color)
     logging.debug(f"Sending message {flick}")
     self._switch_queue.put(flick)