krahabb / meross_lan

Home Assistant integration for Meross devices
MIT License
450 stars 47 forks source link

2024.5.0 - blocking call to import_module detected #427

Closed RobertD502 closed 6 months ago

RobertD502 commented 7 months ago

Version of the custom_component

5.0.4

Configuration


Logger: homeassistant.util.loop
Source: util/loop.py:99
First occurred: 2:49:51 PM (4 occurrences)
Last logged: 2:49:51 PM

Detected blocking call to import_module inside the event loop by custom integration 'meross_lan' at custom_components/meross_lan/meross_device.py, line 472: module = import_module( (offender: /config/custom_components/meross_lan/meross_device.py, line 472: module = import_module(), please create a bug report at https://github.com/krahabb/meross_lan/issues

Describe the bug

Starting with Home Assistant 2024.5.0 beta, the warning seen above is being logged. It is referring to the following code in meross_device.py:

        for namespace, init_descriptor in MerossDevice.ENTITY_INITIALIZERS.items():
            if namespace in ability:
                with self.exception_warning("initializing namespace:%s", namespace):
                    module = import_module(
                        init_descriptor[0], "custom_components.meross_lan"
                    )
                    getattr(module, init_descriptor[1])(self)

Related Home Assistant Core PR

Debug log


N/A
krahabb commented 6 months ago

Thank you for signaling..I cannot see the reason behind that (maybe performance) but..that's it, HA core devs know their stuff better ;)

psteemson commented 6 months ago

I'm also seeing this. 152 occurrences in last set of debug logs. Don't know if related or not but all mss110 devices now taking several seconds to respond, if they respond at all (about 50% success rate). They all work fine from Apple Homekit and Meross App on IOS. All other Meross devices working fine. Only mss110 affected. They're on firmware v 7.3.37. Never had a problem with any Meross devices until now.

Joo01 commented 6 months ago

I have a msg100 (HW: 3.5.0, FW: 3.2.7) and getting same warnings since the update to HA 2024.5

2024-05-02 19:53:02.106 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module inside the event loop by custom integration 'meross_lan' at custom_components/meross_lan/__init__.py, line 566: module = import_module( (offender: /config/custom_components/meross_lan/__init__.py, line 566: module = import_module(), please create a bug report at https://github.com/krahabb/meross_lan/issues

But other than the warning, I don't see any change in functionality...

krahabb commented 6 months ago

The issue itself is 'not an issue' since this is just a warning (by the HA core devs) to 'speed up' a better approach to component initialization. The new implementation has already been integrated in current development and I hope to release a new version in the coming days. @psteemson : I dont' think this is related to the mss110 stalling you're experiencing..maybe that's another issue.

psteemson commented 6 months ago

Thanks @krahabb, I guess so. No problems with any other Meross devices, only mss110 - all 16 of them. They all work fine in Apple Homekit but all my automations are managed in HASS so this is a pain. Happy to provide some log data if you might have any suggestions...?

haty1 commented 6 months ago

me too, I have 4 MSS210s and 1 MSS210p. Running HASSOS 2024.5 2024-05-06 12:17:32.104 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module inside the event loop by custom integration 'meross_lan' at custom_components/meross_lan/meross_device.py, line 472: module = import_module( (offender: /config/custom_components/meross_lan/meross_device.py, line 472: module = import_module(), please create a bug report at https://github.com/krahabb/meross_lan/issues

ollo69 commented 6 months ago

@krahabb

I think you should move long initialization steps on a separate thread to fix this problem, with something like:

await asyncio.to_thread(...)

The problem is that probably you are running time consuming activities in main loop and this is temporary blocking HA to complete other actions. I had the same issue on my integration SmartThinq sensors and I solved in this way.

sven-debug commented 6 months ago

I have the issue as well. Those are the log entries: