def test_wind(self): events = [ 'WIND', { 'WIND': { 'task': 'TILT', 'speed': 100, 'direction': { 'from': 100, 'to': 200 } } } ] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual('WIND', e.type()) self.assertEqual(120.0, result[0].speed) self.assertEqual(100, result[1].speed) self.assertIsNone(result[0].direction[0]) self.assertIsNone(result[0].direction[1]) self.assertEqual((100, 200), result[1].direction) self.assertEqual(Tilt.type(), result[1]._task.type())
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())
def test_extract_sunin(self): triggers = ['SUNIN', {'SUNIN': {'task': 'CLOSE'}}] result = trigger.extract_triggers(blind(triggers), sundata()) self.assertEqual(2, len(result)) self.assertEqual(Tilt.type(), result[0].task().type()) self.assertEqual(Close.type(), result[1].task().type()) for item in result: self.assertEqual(SunInTrigger.type(), item.type()) self.assertEqual('2020-07-27T07:59:00+02:00', item.time().isoformat())
def test_clear(self): events = ['CLEAR', {'CLEAR': {'task': 'TILT'}}] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual(WeatherConditionEnum.CLEAR, e._main) self.assertEqual('CLEAR', e.type()) self.assertEqual(Tilt.type(), result[1]._task.type())
def test_rain(self): events = ['RAIN', {'RAIN': {'task': 'TILT', 'intensity': ['HEAVY']}}] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual(WeatherConditionEnum.RAIN, e._main) self.assertEqual('RAIN', e.type()) self.assertEqual(1, len(result[1]._sub)) self.assertEqual(WeatherSubConditionEnum.HEAVY, result[1]._sub[0]) self.assertEqual(Tilt.type(), result[1]._task.type())
def test_snow(self): events = ['SNOW', {'SNOW': {'task': 'TILT', 'intensity': ['SLEET']}}] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual(WeatherConditionEnum.SNOW, e._main) self.assertEqual('SNOW', e.type()) self.assertEqual(1, len(result[1]._sub)) self.assertEqual(WeatherSubConditionEnum.SLEET, result[1]._sub[0]) self.assertEqual(Tilt.type(), result[1]._task.type())
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_drizzle(self): events = [ 'DRIZZLE', { 'DRIZZLE': { 'task': 'TILT', 'intensity': ['SHOWER'] } } ] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual(WeatherConditionEnum.DRIZZLE, e._main) self.assertEqual('DRIZZLE', e.type()) self.assertEqual(1, len(result[1]._sub)) self.assertEqual(WeatherSubConditionEnum.SHOWER, result[1]._sub[0]) self.assertEqual(Tilt.type(), result[1]._task.type())
def test_special_weather(self): events = [ 'SPECIAL', { 'SPECIAL': { 'task': 'TILT', 'events': ['TORNADO'] } } ] b = blind(events) event.apply_weather_events(b) result = b.events self.assertEqual(2, len(result)) for e in result: self.assertEqual(WeatherConditionEnum.ATMOSPHERE, e._main) self.assertEqual('SPECIAL', e.type()) self.assertEqual(1, len(result[1]._sub)) self.assertEqual(WeatherSubConditionEnum.TORNADO, result[1]._sub[0]) self.assertEqual(Tilt.type(), result[1]._task.type())