def test_light_alarm_program__should_not_call_set_light_group_if_after_end_time(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = datetime.datetime(
            2020, 11, 2, 7, 41, 0)
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_not_called()
    def test_light_alarm_program__should_reset_brightness_when_between_4000_and_4100(
            self, mock_api, mock_date, mock_time):
        self.ALARM.HUE = 125
        self.ALARM.BRIGHTNESS = 10
        mock_date.datetime.now.return_value = self.MONDAY
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        assert self.ALARM.BRIGHTNESS == 40
    def test_light_alarm_program__should_reset_the_light_state_value_back_to_zero(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = datetime.datetime(
            2020, 11, 2, 7, 41, 0)
        self.ALARM.ALARM_CURRENT_STATE = 203
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_not_called()
        assert self.ALARM.BRIGHTNESS == 0
    def test_light_alarm_program__should_max_out_brightness_at_255(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = self.MONDAY
        self.ALARM.BRIGHTNESS = 212
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_called_with(self.API_KEY,
                                    self.GROUP_ID,
                                    255,
                                    hue=3008,
                                    sat=255)
    def test_light_alarm_program__should_increment_the_light_brightness(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = self.MONDAY
        self.ALARM.BRIGHTNESS = 4
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_called_with(self.API_KEY,
                                    self.GROUP_ID,
                                    16,
                                    hue=3008,
                                    sat=255)
    def test_light_alarm_program__should_call_set_light_group_if_equal_start_time(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = datetime.datetime(
            2020, 11, 2, 7, 30, 0)
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_called_with(self.API_KEY,
                                    self.GROUP_ID,
                                    0,
                                    hue=3008,
                                    sat=255)
    def test_light_alarm_program__should_call_set_light_when_greater_than_4100(
            self, mock_api, mock_date, mock_time):
        self.ALARM.HUE = 140
        mock_date.datetime.now.return_value = self.MONDAY
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_called_with(self.API_KEY,
                                    self.GROUP_ID,
                                    self.ALARM.BRIGHTNESS,
                                    temp=2700,
                                    trans=4)
    def test_light_alarm_program__should_call_set_light_group_with_increased_bri_after_first_time_if_after_start_time(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = datetime.datetime(
            2020, 11, 2, 7, 31, 0)
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_any_call(self.API_KEY,
                                 self.GROUP_ID,
                                 4,
                                 hue=3016,
                                 sat=255)
    def test_light_alarm_program__should_decrement_saturation_when_between_4000_and_4100(
            self, mock_api, mock_date, mock_time):
        self.ALARM.HUE = 125
        self.ALARM.BRIGHTNESS = 10
        mock_date.datetime.now.return_value = self.MONDAY
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_called_with(self.API_KEY,
                                    self.GROUP_ID,
                                    255,
                                    hue=(126 * 8) + 3000,
                                    sat=250,
                                    trans=4)
 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)
    def test_light_alarm_program__should_not_call_set_light_group_when_wed(
            self, mock_api, mock_date, mock_time):
        mock_date.datetime.now.return_value = self.WEDNESDAY
        light_alarm_program(self.ALARM, self.API_KEY, self.GROUP_ID)

        mock_api.assert_not_called()