basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.9k stars 136 forks source link

Error doing job: Task exception was never retrieved when setting max_sunset_time #714

Closed manuelh19 closed 1 year ago

manuelh19 commented 1 year ago

If you need help with using or configuring Adaptive Lighting, please open a Q&A discussion thread here instead.

Before submitting a bug report, please follow these troubleshooting steps:

Please confirm that you have completed the following steps:

  1. Debug logs captured while the issue occurred. See here for instructions on enabling debug logging:
2023-08-07 00:13:07.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] AL Flur Normal: Set switch settings for lights '['light.flurspiegel', 'light.tur']'. now using data: '{'lights': ['light.flurspiegel', 'light.tur'], 'interval': datetime.timedelta(seconds=90), 'transition': 45.0, 'initial_transition': 1.0, 'min_brightness': 10, 'max_brightness': 100, 'min_color_temp': 2000, 'max_color_temp': 5500, 'prefer_rgb_color': False, 'sleep_brightness': 1, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': None, 'min_sunrise_time': None, 'max_sunrise_time': None, 'sunrise_offset': datetime.timedelta(0), 'sunset_time': None, 'min_sunset_time': datetime.time(18, 0), 'max_sunset_time': '21:00:00', 'sunset_offset': datetime.timedelta(0), 'brightness_mode': 'linear', 'brightness_mode_time_dark': datetime.timedelta(seconds=3600), 'brightness_mode_time_light': datetime.timedelta(seconds=3600), 'take_over_control': True, 'detect_non_ha_changes': True, 'autoreset_control_seconds': 0, 'only_once': False, 'adapt_only_on_bare_turn_on': False, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': False, 'multi_light_intercept': True, 'include_config_in_attributes': False, 'name': 'AL Flur Normal'}'
2023-08-07 00:13:07.947 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] AL Flur Normal: Setting up with '['light.flurspiegel', 'light.tur']', config_entry.data: '{'name': 'AL Flur Normal', 'lights': ['light.flurspiegel', 'light.tur'], 'max_brightness': 100, 'min_brightness': 10, 'detect_non_ha_changes': True, 'brightness_mode': 'linear', 'max_sunset_time': '21:00:00', 'min_sunset_time': '18:00:00', 'brightness_mode_time_dark': 3600.0, 'include_config_in_attributes': False, 'take_over_control': True, 'max_color_temp': 5500, 'adapt_delay': 0.0, 'adapt_only_on_bare_turn_on': False, 'transition_until_sleep': False, 'initial_transition': 1.0, 'separate_turn_on_commands': False, 'sleep_transition': 1.0, 'prefer_rgb_color': False, 'multi_light_intercept': True, 'sleep_brightness': 1, 'skip_redundant_commands': False, 'brightness_mode_time_light': 3600.0, 'transition': 45.0, 'sleep_rgb_color': [255, 56, 0], 'send_split_delay': 0, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'min_color_temp': 2000, 'sunrise_offset': 0.0, 'autoreset_control_seconds': 0, 'only_once': False, 'interval': 90.0, 'sunset_offset': 0.0}', config_entry.options: '{}', converted to '{'lights': ['light.flurspiegel', 'light.tur'], 'interval': datetime.timedelta(seconds=90), 'transition': 45.0, 'initial_transition': 1.0, 'min_brightness': 10, 'max_brightness': 100, 'min_color_temp': 2000, 'max_color_temp': 5500, 'prefer_rgb_color': False, 'sleep_brightness': 1, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': None, 'min_sunrise_time': None, 'max_sunrise_time': None, 'sunrise_offset': datetime.timedelta(0), 'sunset_time': None, 'min_sunset_time': datetime.time(18, 0), 'max_sunset_time': '21:00:00', 'sunset_offset': datetime.timedelta(0), 'brightness_mode': 'linear', 'brightness_mode_time_dark': datetime.timedelta(seconds=3600), 'brightness_mode_time_light': datetime.timedelta(seconds=3600), 'take_over_control': True, 'detect_non_ha_changes': True, 'autoreset_control_seconds': 0, 'only_once': False, 'adapt_only_on_bare_turn_on': False, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': False, 'multi_light_intercept': True, 'include_config_in_attributes': False, 'name': 'AL Flur Normal'}'.
  1. Your Adaptive Lighting configuration:
- name: AL Flur Normal
  lights:
    - light.flurspiegel
    - light.tur
  max_brightness: 100 
  min_brightness: 10
  detect_non_ha_changes: true
  brightness_mode: linear
  min_sunset_time: '18:00:00'
  max_sunset_time: '21:00:00'
  brightness_mode_time_dark: 3600
  1. Describe the bug and how to reproduce it:

After updating and wanting to try the new features, I noticed my adaptive lighting stopped working with the new config. In the logs I am getting following error, I have attached the component debug logs above as well.

Now to my understanding and investigation, it seems the max_sunset_time is not converted properly. All other time variables get converted to datetime.timedelta, this is still a string.

Logger: homeassistant
Source: custom_components/adaptive_lighting/switch.py:1662
Integration: Adaptive Lighting (documentation, issues)
First occurred: 00:14:50 (114 occurrences)
Last logged: 00:41:59

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/adaptive_lighting/switch.py", line 1137, in _async_update_at_interval_action
    await self._update_attrs_and_maybe_adapt_lights(
  File "/config/custom_components/adaptive_lighting/switch.py", line 1368, in _update_attrs_and_maybe_adapt_lights
    self._sun_light_settings.get_settings(
  File "/config/custom_components/adaptive_lighting/switch.py", line 1847, in get_settings
    self.calc_percent(transition)
  File "/config/custom_components/adaptive_lighting/switch.py", line 1738, in calc_percent
    today = self.relevant_events(target_time)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 1723, in relevant_events
    events = [
             ^
  File "/config/custom_components/adaptive_lighting/switch.py", line 1726, in <listcomp>
    for event in self.get_sun_events(now + timedelta(days=days))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 1687, in get_sun_events
    sunset = self.sunset(date)
             ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 1655, in sunset
    max_sunset = self._replace_time(date, "max_sunset")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/switch.py", line 1662, in _replace_time
    date_time = datetime.datetime.combine(date, time)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: combine() argument 2 must be datetime.time, not str
manuelh19 commented 1 year ago

Update, I have commented out the lines for max_sunset_time and it works properly again

basnijholt commented 1 year ago

Thanks a lot for reporting!

I have pushed a fix in https://github.com/basnijholt/adaptive-lighting/pull/717.

I have released 1.19.0b4: https://github.com/basnijholt/adaptive-lighting/releases/tag/1.19.0b4

Let me know if it works for you 😄

manuelh19 commented 1 year ago

Thank you for the quick fix, I can confirm that it works again!

basnijholt commented 1 year ago

Awesome! Thanks for reporting back.