def test_done_close_tilt_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Tilt(blind).do() self.assertEqual(1, device.tilt_counter) self.assertEqual(State.TILT, device.stats()) close = Close(blind) self.assertFalse(close.done())
def test_done_pretilt_open_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Open(blind).do() self.assertEqual(1, device.open_counter) self.assertEqual(State.OPEN, device.stats()) prepare = PreTilt(blind) self.assertFalse(prepare.done())
def test_done_tilt_close_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Close(blind).do() self.assertEqual(1, device.close_counter) self.assertEqual(State.CLOSED, device.stats()) tilt = Tilt(blind) self.assertFalse(tilt.done())
def test_done_close_close_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Close(blind).do() self.assertEqual(1, device.close_counter) self.assertEqual(State.CLOSED, device.stats()) close = Close(blind) self.assertTrue(close.done())
def test_done_pretilt_tilt_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Tilt(blind).do() self.assertEqual(1, device.tilt_counter) self.assertEqual(State.TILT, device.stats()) prepare = PreTilt(blind) self.assertTrue(prepare.done())
def test_done_open_tilt_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Tilt(blind).do() self.assertEqual(1, device.tilt_counter) self.assertEqual(State.TILT, device.stats()) task = Open(blind) self.assertFalse(task.done())
def test_done_open_open_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Open(blind).do() self.assertEqual(1, device.open_counter) self.assertEqual(State.OPEN, device.stats()) task = Open(blind) self.assertTrue(task.done())
def test_done_close_open_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Open(blind).do() self.assertEqual(1, device.open_counter) self.assertEqual(State.OPEN, device.stats()) close = Close(blind) self.assertFalse(close.done())
def test_done_tilt_different_tilt_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) Tilt(blind, 45).do() self.assertEqual(1, device.tilt_counter) self.assertEqual(State.TILT, device.stats()) tilt = Tilt(blind) self.assertFalse(tilt.done())
def test_tilt_calculation_close(self): mock = DeviceMock('👨🏫') blind = Blind('👨🎓', 10, 20, mock, [], []) blind.override_tilt_duration( 90) # Makes calculation for checks much more easy =) blind.close() self.assertEqual(State.CLOSED, mock.stats()) blind.tilt(0) self.assertEqual(90, mock.time) self.assertEqual('open', mock.direction)
def test_tilt_calculation_60_30(self): mock = DeviceMock('👨🏫') blind = Blind('👨🎓', 10, 20, mock, [], []) blind.override_tilt_duration( 90) # Makes calculation for checks much more easy =) # starting from 90 blind.tilt(60) self.assertEqual(30, mock.time) self.assertEqual('open', mock.direction) blind.tilt(30) self.assertEqual(30, mock.time) self.assertEqual('open', mock.direction)
def test_parallel_tasks_triggers_extract(self): blinds = [ Blind('A', 0, 0, TestDevice('A'), ['SUNRISE'], []), Blind('B', 0, 0, TestDevice('B'), ['SUNRISE'], []) ] api = SunAPIMock() api.fetch_sundata(None) for blind in blinds: triggers = trigger.extract_triggers(blind, api.sundata) print(triggers) manager.add(Job(triggers[0], blind)) print(manager) manager.prepare() print(manager) manager.run() self.assertEqual(1, blinds[1].device.counter, '{} was called'.format(blinds[1].name)) self.assertEqual(1, blinds[0].device.counter, '{} was called'.format(blinds[0].name))
def blind(triggers: []) -> Blind: return Blind('test', 10, 20, None, triggers, [])
def test_done_close_moved_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) device.move(50) close = Close(blind) self.assertFalse(close.done())
def blind(events: []) -> Blind: return Blind('test', 10, 20, DeviceMock('YOLO'), [], events)
def get_blind(name: str = 'Test') -> Blind: return Blind(name, 10, 20, DeviceMock(name), [], [])
def test_done_open_moved_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) device.move(50) task = Open(blind) self.assertFalse(task.done())
def test_done_pretilt_moved_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) device.move(50) prepare = PreTilt(blind) self.assertFalse(prepare.done())
def test_done_tilt_moved_state(self): device = DeviceMock('TestDevice') blind = Blind('Test', 0, 0, device, [], []) device.move(50) tilt = Tilt(blind) self.assertFalse(tilt.done())