Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 def test_done_open_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())
     task = Open(blind)
     self.assertFalse(task.done())
Exemplo n.º 3
0
 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_blocking(self):
     # Setup
     e = CloudsEvent()
     b, trigger = self.__prepare([e], 804, percentage=100)
     # Test
     b.update(trigger)
     # Check
     self.assertEqual(1, b.device.open_counter)
     self.assertTrue(b.blocked)
     Close(b).do()
     Open(b).do()
     self.assertEqual(0, b.device.close_counter)
     self.assertEqual(1, b.device.open_counter)
     self.assertEqual(Open.type(), b._blocker.last.type())
Exemplo n.º 5
0
 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())
Exemplo n.º 6
0
 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())
Exemplo n.º 7
0
 def test_extract_workingdays(self):
     triggers = [{'SUNRISE': {'at': ['WORKINGDAY']}}]
     result = trigger.extract_triggers(blind(triggers), sundata())
     self.assertEqual(1, len(result))
     self.assertEqual(Open.type(), result[0].task().type())
     self.assertEqual(5, len(result[0]._on))
     for day in result[0]._on:
         self.assertTrue(day in ['MO', 'TU', 'WE', 'TH', 'FR'], 'Day {} not in list {}'.format(day, result[0]._on))
Exemplo n.º 8
0
 def test_extract_sunout(self):
     triggers = ['SUNOUT', {'SUNOUT': {'task': 'TILT'}}]
     result = trigger.extract_triggers(blind(triggers), sundata())
     self.assertEqual(2, len(result))
     self.assertEqual(Open.type(), result[0].task().type())
     self.assertEqual(Tilt.type(), result[1].task().type())
     for item in result:
         self.assertEqual(SunOutTrigger.type(), item.type())
         self.assertEqual('2020-07-27T07:59:00+02:00', item.time().isoformat())
Exemplo n.º 9
0
 def test_applies_not(self):
     triggers = [{'SUNRISE': {'at': ['TU']}}]
     result = trigger.extract_triggers(blind(triggers), sundata())
     self.assertEqual(1, len(result))
     self.assertEqual(Open.type(), result[0].task().type())
     for item in result:
         self.assertEqual(SunriseTrigger.type(), item.type())
         self.assertEqual('2020-07-27T05:59:00+02:00', item.time().isoformat())
         self.assertFalse(item.applies())
 def test_multi_sub(self):
     events = [{'CLOUDY': {'intensity': ['SCATTERED', 'OVERCAST']}}]
     b = blind(events)
     event.apply_weather_events(b)
     result = b.events[0]
     self.assertEqual(1, len(b._events))
     self.assertEqual(Open.type(), result._task.type())
     self.assertEqual(CloudsEvent.type(), result.type())
     self.assertEqual(WeatherConditionEnum.CLOUDS, result._main)
     self.assertEqual(2, len(result._sub))
     self.assertEqual(WeatherSubConditionEnum.SCATTERED, result._sub[0])
     self.assertEqual(WeatherSubConditionEnum.OVERCAST, result._sub[1])
 def test_unblocking(self):
     # Setup
     e = CloudsEvent()
     b, trigger = self.__prepare([e], 804, percentage=100)
     # Test
     b.update(trigger)
     # Check
     self.assertEqual(1, b.device.open_counter)
     self.assertTrue(b.blocked)
     Close(b).do()
     Open(b).do()
     self.assertEqual(0, b.device.close_counter)
     self.assertEqual(1, b.device.open_counter)
     self.assertEqual(Open.type(), b._blocker.last.type())
     release = self.__create_trigger(803, percentage=93)
     b.update(release)
     self.assertFalse(b.blocked, 'Blocking should be released')
     self.assertEqual(1, b.device.close_counter,
                      'Last blocked Task should be applied')
     Close(b).do()
     self.assertEqual(2, b.device.close_counter,
                      'Further task shouldn\'t be blocked')
 def test_clouds(self):
     events = ['CLOUDY', {'CLOUDY': {'task': 'TILT', 'coverage': 93}}]
     b = blind(events)
     event.apply_weather_events(b)
     result = b.events
     self.assertEqual(2, len(result))
     self.assertEqual(Open.type(), result[0]._task.type())
     self.assertEqual(Tilt.type(), result[1]._task.type())
     item = result[0]
     self.assertEqual(CloudsEvent.type(), item.type())
     self.assertEqual(WeatherConditionEnum.CLOUDS, item._main)
     self.assertEqual(0, len(item._sub))
     self.assertEqual(100, item.percentage)
     item = result[1]
     self.assertEqual(CloudsEvent.type(), item.type())
     self.assertEqual(WeatherConditionEnum.CLOUDS, item._main)
     self.assertEqual(0, len(item._sub))
     self.assertEqual(93, item.percentage)
Exemplo n.º 13
0
 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())