kongo09 / philips-airpurifier-coap

💨 Philips AirPurifier custom component for Home Assistant. Supports local CoAP protocol.
165 stars 25 forks source link

aiocoap AttributeError #27

Closed kongo09 closed 7 months ago

kongo09 commented 2 years ago

Sometimes, aiocoap reports some errors:

2022-05-03 17:36:35 ERROR (Recorder) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiocoap/tokenmanager.py", line 57, in shutdown
    await self.token_interface.shutdown()
  File "/usr/local/lib/python3.9/site-packages/aiocoap/transports/tcp.py", line 407, in shutdown
    del self._tokenmanager
AttributeError: _tokenmanager
2022-05-03 17:36:35 ERROR (Recorder) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiocoap/tokenmanager.py", line 57, in shutdown
    await self.token_interface.shutdown()
  File "/usr/local/lib/python3.9/site-packages/aiocoap/messagemanager.py", line 67, in shutdown
    for messageerror_monitor, cancellable in self._active_exchanges.values():
AttributeError: 'NoneType' object has no attribute 'values'
kongo09 commented 2 years ago

Do you get this at startup or shutdown or out of the blue?

mhetzi commented 2 years ago

@kongo09 do you think, using a fixed timeout value is a problem? We have a maximum update time in the library ( i used this field to get value of 180 seconds, 60 seconds * 3 missed updates)

kongo09 commented 2 years ago

I'm getting a lot of these:

These are not errors but just debug output in loglevel info. You can ignore that. Eventually, we can tidy this up.

kongo09 commented 2 years ago

do you think, using a fixed timeout value is a problem

I was wondering that, too. Also, 180s is quite long. In my experience the device either comes back rather quickly or it is gone for good. Do you see an alternative? Or just a reduction?

kongo09 commented 2 years ago

Look how excessive the startup time is compared to the rest..

Yes, that happens when there is no connection to the device. Also see: https://github.com/kongo09/philips-airpurifier-coap/issues/25

I was wondering if the setup can be put into the background. The shelly integration does that for battery powered devices that are not always online. And then uses a callback to complete the setup once data comes in

mhetzi commented 2 years ago

@kongo09 https://github.com/kongo09/aioairctrl/pull/1 https://github.com/kongo09/philips-airpurifier-coap/pull/29

These changes would use the max_age value from the device, a far a i understand the device ensures to send at this intervall if no sensor values changed

you can change the missed package multiplier here: in file custom_components/philips_airpurifier_coap/philips.py on line 34: MISSED_PACKAGE_COUNT = 3

kongo09 commented 2 years ago

@mhetzi I've done a new beta with your changes: v0.10.1-beta

kongo09 commented 2 years ago

Hm, I must have made an error, or the library didn't update properly: image

2022-05-08 16:55:00 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Failed to connect: too many values to unpack (expected 2)
2022-05-08 16:55:00 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/philips_airpurifier_coap/config_flow.py", line 76, in async_step_dhcp
    status, _ = await client.get_status()
ValueError: too many values to unpack (expected 2)

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/discovery_flow.py", line 74, in _async_process_pending_flows
    await gather_with_concurrency(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 192, in gather_with_concurrency
    return await gather(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 190, in sem_task
    return await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 205, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 232, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/philips_airpurifier_coap/config_flow.py", line 91, in async_step_dhcp
    raise exceptions.ConfigEntryNotReady from ex
homeassistant.exceptions.ConfigEntryNotReady: too many values to unpack (expected 2)
2022-05-08 16:55:03 WARNING (MainThread) [custom_components.philips_airpurifier_coap] Failed to connect to host 192.168.179.7: 
mhetzi commented 2 years ago

Most likely the lib. do you see the max_age log? something like this:

`Mai 08 08:21:26 xeon python3[450813]: 2022-05-08 08:21:26 ERROR (MainThread) [aioairctrl.coap.client] response = <aiocoap.Message at 0x7f87646bfd30: Type.NON 2.05 Content (MID 8913, token fc04) remote <UDP6EndpointAddress 192.168.57.91 (locally 192.168.57.219%bond0_iot)>, 3 option(s), 1480 byte(s) payload>

Mai 08 08:21:26 xeon python3[450813]: 2022-05-08 08:21:26 ERROR (MainThread) [aioairctrl.coap.client] response.opt = <aiocoap.options.Options at 0x7f87507b6740: OBSERVE: 8912, CONTENT_FORMAT: 50, MAX_AGE: 60>

Mai 08 08:21:26 xeon python3[450813]: 2022-05-08 08:21:26 ERROR (MainThread) [aioairctrl.coap.client] response.opt.max_age = 60`

i made these debug messages, error messages so the stand out.

mhetzi commented 2 years ago

Beta release works, with modified lib, updating via hacs did not update the lib only the component

kongo09 commented 2 years ago

I'm struggling with the correct requirements line to update the lib. Sorry, not enough experience. Any idea?

Updating it by hand leads to new errors in the HA log:

2022-05-08 22:39:53 ERROR (MainThread) [custom_components.philips_airpurifier_coap.philips] _reconnect error
Traceback (most recent call last):
  File "/config/custom_components/philips_airpurifier_coap/philips.py", line 90, in _reconnect
    self.client = await CoAPClient.create(self._host)
  File "/usr/local/lib/python3.9/site-packages/aioairctrl/coap/client.py", line 38, in create
    await obj._init()
  File "/usr/local/lib/python3.9/site-packages/aioairctrl/coap/client.py", line 33, in _init
    await self._sync()
  File "/usr/local/lib/python3.9/site-packages/aioairctrl/coap/client.py", line 54, in _sync
    response = await self._client_context.request(request).response
asyncio.exceptions.CancelledError

and

2022-05-08 22:39:56 ERROR (SyncWorker_2) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiocoap/tokenmanager.py", line 57, in shutdown
    await self.token_interface.shutdown()
  File "/usr/local/lib/python3.9/site-packages/aiocoap/messagemanager.py", line 67, in shutdown
    for messageerror_monitor, cancellable in self._active_exchanges.values():
AttributeError: 'NoneType' object has no attribute 'values'
2022-05-08 22:39:56 ERROR (SyncWorker_2) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiocoap/tokenmanager.py", line 57, in shutdown
    await self.token_interface.shutdown()
  File "/usr/local/lib/python3.9/site-packages/aiocoap/transports/tcp.py", line 407, in shutdown
    del self._tokenmanager
AttributeError: _tokenmanager
2022-05-08 22:39:56 ERROR (SyncWorker_2) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiocoap/tokenmanager.py", line 57, in shutdown
    await self.token_interface.shutdown()
  File "/usr/local/lib/python3.9/site-packages/aiocoap/messagemanager.py", line 67, in shutdown
    for messageerror_monitor, cancellable in self._active_exchanges.values():
AttributeError: 'NoneType' object has no attribute 'values'

do you see those as well?

mhetzi commented 2 years ago

Sadly never played with custom integration, until this reconnect problem really got on my nerves, sorry.

The first comes from the cancelling we do in case of timeout. the second one comes from time to time, even without my changes. had them since the integration came out (betaboon not yours).

so no new errors, for me at least....

kongo09 commented 2 years ago

I'll just merge it into main

But if you could help eliminating these errors, that would be great. I just lack the experience

kongo09 commented 2 years ago

It's getting a bit messy here with a number of error reports that might or might not be related.

kongo09 commented 1 year ago

please try v0.11.1 which now comes with the latest aiocoap 0.4.5 and let me know if the problem still exists

kongo09 commented 7 months ago

the aiocoap Attribute error seems to have disappeared and as there is no further discussion here, I'll close this issue.