home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.65k stars 30.41k forks source link

asyncio.exceptions.CancelledError streaming when Wiz lights turned off #110647

Closed ratsputin closed 3 months ago

ratsputin commented 8 months ago

The problem

Wiz lights that are turned off at the switch but retain an "on" status in HA are streaming errors in HA logs when services like light.turn_on are called against the light. My current syslog file is 7.1G due to these errors.

A solution to the issue would be to simply flag the device as unavailable the first time a timeout occurs attempting to control the light.

What version of Home Assistant Core has the issue?

core 2024.2.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Wiz

Link to integration documentation on our website

https://www.home-assistant.io/integrations/wiz/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-02-15 06:50:55.702 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140636752609600]
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 758, in send
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/wiz/light.py", line 127, in async_turn_on
    await self._device.turn_on(_async_pilot_builder(**kwargs))
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 657, in turn_on
    await self.send(pilot_builder.set_pilot_message())
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 762, in send
    raise WizLightConnectionError(str(ex)) from ex
pywizlight.exceptions.WizLightConnectionError
2024-02-15 06:50:56.205 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140636752609600]
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 758, in send
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/homeassistant/components/wiz/light.py", line 127, in async_turn_on
    await self._device.turn_on(_async_pilot_builder(**kwargs))
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 657, in turn_on
    await self.send(pilot_builder.set_pilot_message())
  File "/srv/homeassistant/venv/lib/python3.11/site-packages/pywizlight/bulb.py", line 762, in send
    raise WizLightConnectionError(str(ex)) from ex
pywizlight.exceptions.WizLightConnectionError

Additional information

The Wiz integration doesn't seem to handle lights being turned on/off at the switch properly. The integration setup page shows "failed setup" repeatedly for lights that are currently off but have been previously configured. Devices that have been turned off take a significant amount of time to become unavailable, and attempts to control them (as they still show on) stream errors in the logs rather than simply switching them to unavailable.

home-assistant[bot] commented 8 months ago

Hey there @sbidy, mind taking a look at this issue as it has been labeled with an integration (wiz) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `wiz` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign wiz` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


wiz documentation wiz source (message by IssueLinks)

Sythsaz commented 6 months ago

I think i'm having a similar issue with my wiz lights. Idk how long it's been now but they have been having issues timeing out when they are attemted to turn off or on.

Logger: homeassistant.components.automation.bedroom_closet_off
Source: components/automation/__init__.py:666
integration: Automation (documentation, issues)
First occurred: 2:38:43 PM (1 occurrences)
Last logged: 2:38:43 PM

While executing automation automation.bedroom_closet_off
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 758, in send
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 666, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 970, in _async_if_step
    await self._async_run_script(if_data["if_then"])
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1100, in _async_run_script
    result = await self._async_run_long_action(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 639, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/wiz/entity.py", line 69, in async_turn_off
    await self._device.turn_off()
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 630, in turn_off
    await self.send({"method": "setPilot", "params": {"state": False}})
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 762, in send
    raise WizLightConnectionError(str(ex)) from ex
pywizlight.exceptions.WizLightConnectionError 

Another one:

 Logger: homeassistant.core
Source: core.py:2335
First occurred: March 23, 2024 at 5:38:17 PM (11 occurrences)
Last logged: 2:42:45 PM

Error executing service: <ServiceCall light.turn_on (c:01HSQCQ8YQ:al:KN2G:ntrv:LM): entity_id=['light.stovetop'], params=brightness=60>
Error executing service: <ServiceCall light.turn_on (c:01HSQZEQVC:al:J52X:ntrv:52): entity_id=['light.outside'], params=brightness=57>
Error executing service: <ServiceCall light.turn_on (c:01HSS2VNXR:al:KN2G:ntrv:37): entity_id=['light.stovetop'], params=color_temp=184, color_temp_kelvin=5410>
Error executing service: <ServiceCall light.turn_on (c:01HSS36QEA:al:IJSW:ntrv:3I): entity_id=['light.bedroom_closet'], params=color_temp=185, color_temp_kelvin=5390>
Error executing service: <ServiceCall light.turn_on (c:01HSS36QEC:al:KN2G:ntrv:3B): entity_id=['light.stovetop'], params=color_temp=185, color_temp_kelvin=5390>
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 758, in send
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 2335, in _run_service_call_catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/adaptive_lighting/hass_utils.py", line 61, in service_func_proxy
    await existing_service.job.target(call)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/wiz/light.py", line 129, in async_turn_on
    await self._device.turn_on(_async_pilot_builder(**kwargs))
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 657, in turn_on
    await self.send(pilot_builder.set_pilot_message())
  File "/usr/local/lib/python3.12/site-packages/pywizlight/bulb.py", line 762, in send
    raise WizLightConnectionError(str(ex)) from ex
pywizlight.exceptions.WizLightConnectionError 

I stumbled across this and figured it may help and just enabled debug logging. Hope it helps, new to this lol

issue-triage-workflows[bot] commented 3 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.