dlarrick / hass-kumo

Home Assistant module interfacing with Mitsubishi mini-split units
MIT License
96 stars 21 forks source link

Blocking call to putrequest inside the event loop #85

Closed danielgoepp closed 2 years ago

danielgoepp commented 2 years ago

Is anyone else seeing this in their logs after upgrading to the 2022.8.2? Everything seems to be working okay, just seeing these

2022-08-08 05:11:45 2022-08-08 05:11:45.875 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to putrequest inside the event loop. This is causing stability issues. Please report issue to the custom integration author for kumo doing blocking calls at custom_components/kumo/climate.py, line 198: success = self._pykumo.update_status()
2022-08-08 05:11:45 2022-08-08 05:11:45.875 WARNING (MainThread) [pykumo.py_kumo_base] Error issuing request http://10.1.1.43/api: Blocking calls must be done in the executor or a separate thread; Use `await hass.async_add_executor_job()`; at custom_components/kumo/climate.py, line 198: success = self._pykumo.update_status()
2022-08-08 05:11:45 2022-08-08 05:11:45.876 WARNING (MainThread) [pykumo.py_kumo] Error retrieving status
danielgoepp commented 2 years ago

Sorry, not new to 2022.8.2, I'm not sure when this started.

dlarrick commented 2 years ago

Yes I'm seeing this too. I suspect it's improved detection in HA because I don't think this code has substantially changed recently.

Does changing line 184 to be something like await self._update_property(prop) and changing the function it's in to be called async_update fix it? That seems to be what some other integrations are doing. We're in a heat wave in Boston and I'm unwilling to test this out myself until the weather breaks.

danielgoepp commented 2 years ago

@dlarrick I can try that out. I live in Western Mass, so we are getting the same thing ;) I'll try this when I can though and I'll let you know what happens. Thanks.

omriasta commented 2 years ago

Yep, this definitely started with the last PR https://github.com/dlarrick/hass-kumo/pull/67 Look at the last comments

danielgoepp commented 2 years ago

Ah, missed that, thanks @omriasta.

dlarrick commented 2 years ago

Aha, I may be on to something. This line adds self.update to the coordinator as an additional update step. https://github.com/dlarrick/hass-kumo/blob/master/custom_components/kumo/climate.py#L132

The coordinator does its own update, then calls back to this method: https://github.com/dlarrick/hass-kumo/blob/master/custom_components/kumo/coordinator.py#L50-L58

But the coordinator has just refreshed the state from pykumo, so there's no need to do it again in climate.py. So delete or comment out lines 198-200 should fix this. https://github.com/dlarrick/hass-kumo/blob/master/custom_components/kumo/climate.py#L198-L200

I tested this briefly on my dev instance and it seems to be working. I'll run it on the main instance for a while and make sure it works as intended.

danielgoepp commented 2 years ago

Thanks @dlarrick! I'll try this out this evening.