Skip to content

Commit

Permalink
Better logging and prevent KeyError in state_changed_event_listener (#…
Browse files Browse the repository at this point in the history
…650)

* Better logging

* Remove useless and erroneous logging statement

* Bump to 1.16.3
  • Loading branch information
basnijholt authored Jul 22, 2023
1 parent db40b9a commit fee9025
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion custom_components/adaptive_lighting/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues",
"requirements": ["ulid-transform"],
"version": "1.16.2"
"version": "1.16.3"
}
24 changes: 9 additions & 15 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,10 +1212,8 @@ async def _adapt_light( # noqa: C901
async def _execute_adaptation_calls(self, data: AdaptationData):
"""Executes a sequence of adaptation service calls for the given service datas."""

index = 0
while True:
for index in range(data.max_length):
is_first_call = index == 0
index += 1

# Sleep between multiple service calls.
if not is_first_call or data.initial_sleep:
Expand Down Expand Up @@ -1257,13 +1255,9 @@ async def execute_cancellable_adaptation_calls(
listener = self.turn_on_off_listener
listener.cancel_ongoing_adaptation_calls(data.entity_id, which=data.which)
_LOGGER.debug(
"%s: execute_cancellable_adaptation_calls with data: %s"
"adaptation_tasks_brightness: %s"
"adaptation_tasks_color: %s",
"%s: execute_cancellable_adaptation_calls with data: %s",
self._name,
data,
listener.adaptation_tasks_brightness,
listener.adaptation_tasks_color,
)
# Execute adaptation calls within a task
try:
Expand All @@ -1290,9 +1284,13 @@ async def _update_attrs_and_maybe_adapt_lights(
) -> None:
assert context is not None
_LOGGER.debug(
"%s: '_update_attrs_and_maybe_adapt_lights' called with context.id='%s'",
"%s: '_update_attrs_and_maybe_adapt_lights' called with context.id='%s'"
" lights: '%s', transition: '%s', force: '%s'",
self._name,
context.id,
lights,
transition,
force,
)
assert self.is_on
self._settings.update(
Expand Down Expand Up @@ -1919,8 +1917,8 @@ async def _service_interceptor_turn_on_handler(
adapt_brightness,
adapt_color,
)
# if adaptation_data is None:
# return
if adaptation_data is None:
return

# Take first adaptation item to apply it to this service call
first_service_data = await adaptation_data.next_service_call_data()
Expand Down Expand Up @@ -2193,10 +2191,6 @@ async def state_changed_event_listener(self, event: Event) -> None:
entity_id,
)
self.last_state_change[entity_id] = [new_state]
_LOGGER.debug(
"Last transition: %s",
self.last_service_data[entity_id].get(ATTR_TRANSITION),
)
self.start_transition_timer(entity_id)
elif old_state is not None:
self.last_state_change[entity_id].append(new_state)
Expand Down

0 comments on commit fee9025

Please sign in to comment.