def test_clouds_not_applying(self):
     # Setup
     e = CloudsEvent()
     b, trigger = self.__prepare([e], 804, percentage=94)
     # Test
     b.update(trigger)
     # Check
     self.assertEqual(0, b.device.open_counter)
 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)
 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_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())
 def test_event_reverse(self):
     # Setup
     c = CloudsEvent()
     r = RainEvent()
     b, trigger = self.__prepare([r, c], 804, percentage=100)
     print(b)
     # Test
     b.update(trigger)
     print(b)
     self.assertTrue(b.blocked)
     # Check
     rain_trigger = self.__create_trigger(504, percentage=93)
     b.update(rain_trigger)
     self.assertTrue(b.blocked)
     # Unblocks first event and then blocks with second event
     self.assertEqual(2, b.device.open_counter)
 def test_only_one_active_event(self):
     # Setup
     c = CloudsEvent()
     r = RainEvent()
     b, trigger = self.__prepare([r, c], 804, percentage=100)
     print(b)
     # Test
     b.update(trigger)
     print(b)
     self.assertTrue(b.blocked)
     # Check
     rain_trigger = self.__create_trigger(504, percentage=100)
     rain_trigger.trigger.conditions.append(trigger.trigger.conditions[0])
     b.update(rain_trigger)
     self.assertTrue(b.blocked)
     self.assertTrue(c.active, 'Clouds should still be active')
     self.assertFalse(r.active, 'Rain should not get activated')
 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')