Exemplo n.º 1
0
    def test_create_thread__should_create_thread_with_stop_event(
            self, mock_thread, mock_event):
        event = Mock()
        mock_event.return_value = event
        create_thread(self.FUNCT)

        mock_thread.assert_called_with(event, ANY, ANY)
Exemplo n.º 2
0
    def test_create_thread__should_return_thread(self, mock_thread,
                                                 mock_event):
        thread = Mock()
        mock_thread.return_value = thread
        actual = create_thread(self.FUNCT)

        assert actual == thread
 def add_light_alarm(self, task_id, light_group_id, alarm_time, alarm_days,
                     task_type):
     if not any(alarm.THREAD_ID == task_id for alarm in self.LIGHT_ALARMS):
         if task_type == Automation.LIGHT.SUNRISE:
             alarm = LightAlarmState(task_id, alarm_time, alarm_days)
             alarm.ACTIVE_THREAD = create_thread(
                 lambda: light_alarm_program(alarm, self.get_light_api_key(
                 ), light_group_id), Automation.TIME.SEVEN_SECONDS)
             alarm.ACTIVE_THREAD.start()
             self.LIGHT_ALARMS.append(alarm)
         elif task_type == Automation.LIGHT.TURN_ON:
             alarm = LightOnOffState(task_id, alarm_time, alarm_days)
             alarm.ACTIVE_THREAD = create_thread(
                 lambda: light_on_program(alarm, self.get_light_api_key(
                 ), light_group_id), Automation.TIME.TEN_SECONDS)
             alarm.ACTIVE_THREAD.start()
             self.LIGHT_ALARMS.append(alarm)
         elif task_type == Automation.LIGHT.TURN_OFF:
             alarm = LightOnOffState(task_id, alarm_time, alarm_days)
             alarm.ACTIVE_THREAD = create_thread(
                 lambda: light_off_program(alarm, self.get_light_api_key(
                 ), light_group_id), Automation.TIME.TEN_SECONDS)
             alarm.ACTIVE_THREAD.start()
             self.LIGHT_ALARMS.append(alarm)
Exemplo n.º 4
0
    def test_create_thread__should_create_thread_with_overridden_delay_value(self, mock_thread, mock_event):
        create_thread(self.FUNCT, Automation.TIMING.TEN_MINUTE)

        mock_thread.assert_called_with(ANY, ANY, Automation.TIMING.TEN_MINUTE)
Exemplo n.º 5
0
    def test_create_thread__should_create_thread_with_default_delay(self, mock_thread, mock_event):
        create_thread(self.FUNCT)

        mock_thread.assert_called_with(ANY, ANY, Automation.TIMING.FIVE_SECONDS)
Exemplo n.º 6
0
    def test_create_thread__should_create_thread_with_provided_function(self, mock_thread, mock_event):
        create_thread(self.FUNCT)

        mock_thread.assert_called_with(ANY, self.FUNCT, ANY)
Exemplo n.º 7
0
    def test_create_thread__should_execute_function_initially(self, mock_event):
        mock_func = Mock()
        create_thread(mock_func)

        mock_func.assert_called()
Exemplo n.º 8
0
    def test_create_thread__should_set_stop_event(self, mock_event):
        event = Event()
        mock_event.return_value = event
        actual = create_thread(self.FUNCT)

        assert actual.stopped == event
Exemplo n.º 9
0
def create_status_app():
    state = GarageState.get_instance()
    if state.ACTIVE_THREAD is None:
        state.ACTIVE_THREAD = create_thread(monitor_status)
        state.ACTIVE_THREAD.start()
Exemplo n.º 10
0
import logging

from svc.constants.home_automation import Automation
from svc.services.light_service import create_light_alarm
from svc.utilities.event_utils import create_thread

logging.basicConfig(filename='sunriseAlarm.log', level=logging.INFO)

try:
    logging.info('Application started!')
    thread = create_thread(create_light_alarm, Automation.TIME.ONE_MINUTE)
    thread.start()
except Exception:
    logging.error('Application interrupted by user')