betaboon / philips-airpurifier-coap

💨 Philips AirPurifier custom component for Home Assistant. With support for new Devices with CoAP protocol. Tested on AC2729/10 (bought early 2020)
70 stars 31 forks source link

Reconnect #57

Closed mhetzi closed 2 years ago

mhetzi commented 3 years ago

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.

SamJongenelen commented 2 years ago

@betaboon could we review and merge this?

SamJongenelen commented 2 years ago

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 commented 2 years ago

@SamJongenelen did you mean like this? https://github.com/betaboon/philips-airpurifier-coap/pull/57/commits/9b6e3e964613886ec33d84b44ea077039048d3cd

SamJongenelen commented 2 years ago

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

SamJongenelen commented 2 years ago

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 commented 2 years ago

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, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

SamJongenelen commented 2 years ago

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

ronaldt80 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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/aioairctrl@v0.2.1"
  ]
}
ronaldt80 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I havent had any choke issues on HA lately

kongo09 commented 2 years ago

@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 commented 2 years ago

@kongo09 How can i help you?

kongo09 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

mhetzi commented 2 years ago

ok