def test_pause_period_before_off(self): # setup airily_dao = AirlyDao('url', 'key', 28) airily_dao.caqi = MagicMock(return_value=80) calendar_dao = CalendarDao('url') air_purifier = AirPurifier(ConfigMock()) air_purifier.turn_off = MagicMock() air_purifier.get_state = MagicMock(return_value=AirPurifierState.OFF) cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00') clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao, air_purifier) # test clean_airtomation_service.clean_polluted_air() # verify airily_dao.caqi.assert_not_called() air_purifier.turn_off.assert_not_called()
def test_pause_edge_right(self): # setup airily_dao = AirlyDao('url', 'key', 28) airily_dao.caqi = MagicMock(return_value=10) calendar_dao = CalendarDao('url') air_purifier = AirPurifier(ConfigMock()) air_purifier.turn_off = MagicMock() air_purifier.turn_on = MagicMock() air_purifier.get_state = MagicMock(return_value=AirPurifierState.ON) cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00') clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao, air_purifier) # test result = clean_airtomation_service._is_not_in_pause_time() # verify self.assertFalse(result)
def test_air_purifier_not_touched_on_airly_error(self): # setup airily_dao = AirlyDao('url', 'key', 28) airily_dao.caqi = MagicMock(return_value=None) calendar_dao = CalendarDao('url') air_purifier = AirPurifier(ConfigMock()) air_purifier.turn_off = MagicMock() air_purifier.turn_on = MagicMock() cleaning_pause = self.get_cleaning_pause(['Monday', 'Tuesday', 'Wednesday'], '8:00', '16:00') clean_airtomation_service = CleanAirtomationService(70, cleaning_pause, airily_dao, calendar_dao, air_purifier) # test clean_airtomation_service.clean_polluted_air() # verify airily_dao.caqi.assert_called_once() air_purifier.turn_off.assert_not_called() air_purifier.turn_on.assert_not_called()
def test_switch_off_success_switch_on_failure(self): air_purifier = AirPurifier(MockedConfig()) self.assertTrue(air_purifier.turn_off()) self.assertEqual(AirPurifierState.OFF, air_purifier.get_state()) self.assertFalse(air_purifier.turn_on()) self.assertEqual(AirPurifierState.OFF, air_purifier.get_state())
def test_switch_on_success(self): air_purifier = AirPurifier(MockedConfig()) self.assertTrue(air_purifier.turn_on()) self.assertEqual(AirPurifierState.ON, air_purifier.get_state())
import time from clean_airtomation.air_purifier import AirPurifier from clean_airtomation.airly_dao import AirlyDao from clean_airtomation.calendar_dao import CalendarDao from clean_airtomation.clean_airtomation_service import CleanAirtomationService from clean_airtomation.config import Config config = Config() conf = config.read_config() airly_dao = AirlyDao(conf['airlyUrl'], conf['apikey'], conf['installationId']) air_purifier = AirPurifier(config) calendar_dao = CalendarDao(conf['calendarUrl']) cleanAirtomationService = CleanAirtomationService(conf['caqiTreshold'], conf['cleaningPause'], airly_dao, calendar_dao, air_purifier) while True: cleanAirtomationService.clean_polluted_air() time.sleep(conf['checkIntervalInMinutes'] * 60)