Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Reconnect #57

Closed
wants to merge 4 commits into from
Closed

Reconnect #57

wants to merge 4 commits into from

Conversation

mhetzi
Copy link

@mhetzi mhetzi commented Aug 17, 2021

Hi,
Implementing Timers like this, fixes (at least with my model AC3829), #15 and #28.

Connection is currently 1 day stable, instead of 30 minutes.

Reconnect if no observation since 67 Seconds.
Reconnect if connection is not complettely ready in 20 Seconds.
@SamJongenelen
Copy link

@betaboon could we review and merge this?

@SamJongenelen
Copy link

SamJongenelen commented Oct 13, 2021

I tested this, and it indeed reconnects.

However, it does not recognize disconnects. Could this also be added? I power toggle the purifier during the day using sonoffs

@mhetzi
Copy link
Author

mhetzi commented Oct 14, 2021

@SamJongenelen did you mean like this?
9b6e3e9

@SamJongenelen
Copy link

SamJongenelen commented Oct 15, 2021

Yes! I've tested the #9b6e3e9 fan.py and it indeed returns to 'unavailable' after the timeout, thank you!
image
image

@SamJongenelen
Copy link

Well I have some errors which I think are related

2021-10-15 17:08:50 ERROR (SyncWorker_2) [homeassistant] Error doing job: Task was destroyed but it is pending!
2021-10-15 17:08:50 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
RuntimeError: aclose(): asynchronous generator is already running
2021-10-15 17:08:50 ERROR (MainThread) [coap] Connection loss was not expected.

@ronaldt80
Copy link

ronaldt80 commented Oct 15, 2021 via email

@SamJongenelen
Copy link

SamJongenelen commented Oct 15, 2021

Good catch no I didnt, will install fully when on pc again

Try to get rid of a few errors, while trying to reconnect
@ronaldt80
Copy link

thanks @mhetzi ; solved my issues it seems. With the new aioairctrl and your changes the integration is working again (AC2889/10; FW 64.3)

Seeing @betaboon is no longer maintaining this fork; would it not be easier to move over to your fork as "main" coap version?

@ronaldt80
Copy link

whilst the airpurifier is running i do get flooded with errors - my line numbers deviate but its around these two pieces of code

    async def reset_connection(self, endIt=False):
        try:
            if self._observer_task is not None:
                self._observer_task.cancel()
                await self._observer_task
            if self._client is not None:
                await self._client.shutdown()
        except:
            _LOGGER.exception("Reset Connection: Cleanup of old connection failed!")
        if not endIt:
            await self.init()
            await self.async_added_to_hass()
    async def _observe_status(self) -> None:
        async for status in self._client.observe_status():
            self._device_status = status
            self.schedule_update_ha_state()
            self._timer.reset()

which generates the following error:

Logger: custom_components.philips_airpurifier_coap.fan
Source: custom_components/philips_airpurifier_coap/fan.py:363
Integration: philips_airpurifier_coap (documentation)
First occurred: 16:55:40 (50 occurrences)
Last logged: 20:37:00

Reset Connection: Cleanup of old connection failed!
Traceback (most recent call last):
  File "/config/custom_components/philips_airpurifier_coap/fan.py", line 439, in _observe_status
    async for status in self._client.observe_status():
  File "/usr/local/lib/python3.9/site-packages/aioairctrl/coap/client.py", line 92, in observe_status
    async for response in requester.observation:
  File "/usr/local/lib/python3.9/site-packages/aiocoap/protocol.py", line 1083, in __anext__
    result = await self._future
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/philips_airpurifier_coap/fan.py", line 363, in reset_connection
    await self._observer_task
asyncio.exceptions.CancelledError

and

Logger: coap
Source: /usr/local/lib/python3.9/site-packages/aiocoap/transports/udp6.py:525
First occurred: 16:56:07 (245 occurrences)
Last logged: 20:37:21

Connection loss was not expected.

@ronaldt80
Copy link

Note, the purifier was on between 16.55 and 18:26 and has been off ever since. Behaviour takes place both in on and off state.

@mhetzi
Copy link
Author

mhetzi commented Oct 17, 2021

@ronaldt80
The first exception should be history with this change.
Connection loss was not expected. is from the COAP API, dont know what to do about this one. Sorry

About switching branches/forks, who will maintain this integration in the long run?

@ronaldt80
Copy link

thanks - the COAP API error persists indeed, but only when the purifier is off. The other errors are gone now. Side effect, when restarting HA whilst the purifier is off it now takes longer for the purfier to become available (ca. 3minutes in my case). Will test some more over the coming days. Thanks!

As for the ownership of the branches / forks - good point, unfortunately my python skills are limited to some cutting and pasting so not the ideal candidate myself I fear.

@SamJongenelen
Copy link

SamJongenelen commented Oct 18, 2021

Did you update aioairctrl? I changed my manifest settings referring to an updated version. No issues since 72 hrs

-------- Original Message --------
On 15 Oct 2021, 17:51, Sam Jongenelen wrote: Well I have some errors which I think are related > 2021-10-15 17:08:50 ERROR (SyncWorker_2) [homeassistant] Error doing job: Task was destroyed but it is pending! 2021-10-15 17:08:50 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved RuntimeError: aclose(): asynchronous generator is already running 2021-10-15 17:08:50 ERROR (MainThread) [coap] Connection loss was not expected. — You are receiving this because you are subscribed to this thread. Reply to this email directly, [view it on GitHub](#57 (comment)), or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

@ronaldt80
I checked my manifest (this branch version), its using v0.2.1 - you too?


{
  "domain": "philips_airpurifier_coap",
  "name": "Philips AirPurifier (with CoAP)",
  "version": "0.7.0",
  "documentation": "https://github.com/betaboon/philips-airpurifier-coap",
  "dependencies": [],
  "codeowners": ["@betaboon"],
  "requirements": [
    "aioairctrl @ git+https://github.com/betaboon/[email protected]"
  ]
}

@ronaldt80
Copy link

@SamJongenelen I am on HASS OS so cannot manually install different aioairctrl versions- to achieve the same I changed my manifest to ensure it references the updated file - a full OS reboot was required to pull the new file (in my case), code is as follows:

{
  "domain": "philips_airpurifier_coap",
  "name": "Philips AirPurifier (with CoAP)",
  "version": "0.7.0",
  "documentation": "https://github.com/betaboon/philips-airpurifier-coap",
  "dependencies": [],
  "codeowners": ["@betaboon"],
  "requirements": [
    "aioairctrl @ git+https://github.com/Peter-J/aioairctrl"
  ]
}

@SamJongenelen
Copy link

@SamJongenelen I am on HASS OS so cannot manually install different aioairctrl versions- to achieve the same I changed my manifest to ensure it references the updated file - a full OS reboot was required to pull the new file (in my case), code is as follows:

{
  "domain": "philips_airpurifier_coap",
  "name": "Philips AirPurifier (with CoAP)",
  "version": "0.7.0",
  "documentation": "https://github.com/betaboon/philips-airpurifier-coap",
  "dependencies": [],
  "codeowners": ["@betaboon"],
  "requirements": [
    "aioairctrl @ git+https://github.com/Peter-J/aioairctrl"
  ]
}

Me too homeassistantOs. I small try the peter j airctrl

@ronaldt80
Copy link

Any one else experience the coap connection loss error after incorporating the changes which otherwise solve the disconnect issue?

Logger: coap
Source: /usr/local/lib/python3.9/site-packages/aiocoap/transports/udp6.py:525
First occurred: 07:42:44 (66 occurrences)
Last logged: 08:17:20

Connection loss was not expected.

I have thousands a day, think after a while it chokes HA Core

@SamJongenelen
Copy link

SamJongenelen commented Oct 31, 2021

You are right. The logging expands when running for a long time. Exact same log timestamps, see beneith after ~12h uptime

2021-10-31 13:23:26 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:23:26 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:23:26 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:23:26 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:32:48 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:32:48 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:32:48 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:36:49 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:39:50 ERROR (MainThread) [coap] Connection loss was not expected.
2021-10-31 13:39:50 ERROR (MainThread) [coap] Connection loss was not expected.

@kongo09
Copy link

kongo09 commented Dec 7, 2021

About switching branches/forks, who will maintain this integration in the long run?

At the moment, nobody really does. It would be great to have someone take over who at least occasionally could take a brief look at stuff with more than rookie skills.

@betaboon Or is there hope that you find some time after Christmas, just like you did last year?

@SamJongenelen
Copy link

I havent had any choke issues on HA lately

@kongo09
Copy link

kongo09 commented Apr 7, 2022

@mhetzi As the integration seems unmaintained here, I've attempted a bit of a rewrite based on a fork of this. It's now quite comprehensive in terms of features, but my Python skills are acquired on the way, so I struggle a bit with integrating your timer approach. Do you think you could help out?

@mhetzi
Copy link
Author

mhetzi commented Apr 8, 2022

@kongo09 How can i help you?

@kongo09
Copy link

kongo09 commented Apr 8, 2022

@kongo09 How can i help you?

Maybe you can take a look at the rewrite and suggest how to integrate the Timer? I've put your timer code into a separate file for clarity, but it is not integrated. I'm not sure if it should deal with the coordinator, or maybe it is even better placed in the aioairctrl library? What's your suggestion?

@mhetzi
Copy link
Author

mhetzi commented Apr 8, 2022

I think putting it in Coordinator would be the easiest.
On my last experiments killing and recreating the client was the most stable solution.
The library sometimes thinks its connected, but it´s not.

@kongo09
Copy link

kongo09 commented Apr 8, 2022

Do you think you could help out with a pull request?

@mhetzi
Copy link
Author

mhetzi commented Apr 8, 2022

ok

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants