hultenvp / solis-sensor

HomeAssistant integration for the SolisCloud PV Monitoring portal via SolisCloud API
Apache License 2.0
190 stars 41 forks source link

Detected blocking call to open inside the event loop by custom integration solis #377

Open Dino0005 opened 3 weeks ago

Dino0005 commented 3 weeks ago

Describe the bug Detected blocking call to open inside the event loop by custom integration solis

Versions Lo HACS Version: None (manual installation of Solis integration) Integration version: 3.5.2

Logs:

2024-06-06 00:03:36.169 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'solis' at custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file: (offender: /config/custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:), please create a bug report at https://github.com/hultenvp/solis-sensor/issues
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
sys.exit(main())
File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
exit_code = runner.run(runtime_conf)
File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
self._run_once()
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once
handle._run()
File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component
result = await _async_setup_component(hass, domain, config)
File "/usr/src/homeassistant/homeassistant/setup.py", line 447, in _async_setup_component
await asyncio.gather(
File "/usr/src/homeassistant/homeassistant/setup.py", line 449, in <genexpr>
create_eager_task(
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked
await self.async_setup(hass, integration=integration)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
result = await component.async_setup_entry(hass, self)
File "/config/custom_components/solis/__init__.py", line 82, in async_setup_entry
portal_config = SoliscloudConfig(
File "/config/custom_components/solis/soliscloud_api.py", line 185, in __init__
with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:

Screenshots

Screenshot 2024-06-05 alle 21 43 07
alanglund commented 3 weeks ago

Not sure if this is related to the above, apologies I am not an expert in this area.

Logger: homeassistant.helpers.typing Source: helpers/deprecation.py:197 First occurred: 09:43:46 (2 occurrences) Last logged: 09:43:46

HomeAssistantType was used from solis, this is a deprecated alias which will be removed in HA Core 2025.5. Use homeassistant.core.HomeAssistant instead, please report it to the author of the 'solis' custom integration ServiceCallType was used from solis, this is a deprecated alias which will be removed in HA Core 2025.5. Use homeassistant.core.ServiceCall instead, please report it to the author of the 'solis' custom integration

Dino0005 commented 3 weeks ago

Not sure if this is related to the above, apologies I am not an expert in this area.

Logger: homeassistant.helpers.typing Source: helpers/deprecation.py:197 First occurred: 09:43:46 (2 occurrences) Last logged: 09:43:46

HomeAssistantType was used from solis, this is a deprecated alias which will be removed in HA Core 2025.5. Use homeassistant.core.HomeAssistant instead, please report it to the author of the 'solis' custom integration ServiceCallType was used from solis, this is a deprecated alias which will be removed in HA Core 2025.5. Use homeassistant.core.ServiceCall instead, please report it to the author of the 'solis' custom integration

No, that's another issue... Try looking here https://github.com/hultenvp/solis-sensor/issues/369

changeofaspect commented 3 weeks ago

I have the same issue and it started with the update to HA 2024.6.0.

Logger: homeassistant.util.loop
Source: util/loop.py:84
First occurred: 13:31:53 (3 occurrences)
Last logged: 13:39:02

Detected blocking call to open inside the event loop by custom integration 'solis' at custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file: (offender: /config/custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:), please create a bug report at https://github.com/hultenvp/solis-sensor/issues Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/usr/src/homeassistant/homeassistant/setup.py", line 447, in _async_setup_component await asyncio.gather( File "/usr/src/homeassistant/homeassistant/setup.py", line 449, in <genexpr> create_eager_task( File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/solis/__init__.py", line 82, in async_setup_entry portal_config = SoliscloudConfig( File "/config/custom_components/solis/soliscloud_api.py", line 185, in __init__ with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:
Detected blocking call to open inside the event loop by custom integration 'solcast_solar' at custom_components/solcast_solar/solcastapi.py, line 230: with open(self._filename) as data_file: (offender: /config/custom_components/solcast_solar/solcastapi.py, line 230: with open(self._filename) as data_file:), please create a bug report at https://github.com/BJReplay/ha-solcast-solar/issues Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/solcast_solar/__init__.py", line 110, in async_setup_entry await solcast.load_saved_data() File "/config/custom_components/solcast_solar/solcastapi.py", line 230, in load_saved_data with open(self._filename) as data_file:
Detected blocking call to open inside the event loop by custom integration 'solcast_solar' at custom_components/solcast_solar/solcastapi.py, line 97: with open(self._filename, "w") as f: (offender: /config/custom_components/solcast_solar/solcastapi.py, line 97: with open(self._filename, "w") as f:), please create a bug report at https://github.com/BJReplay/ha-solcast-solar/issues Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call response_data = await coro File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service return await target(service_call) File "/config/custom_components/solcast_solar/__init__.py", line 140, in handle_service_update_forecast await coordinator.service_event_update() File "/config/custom_components/solcast_solar/coordinator.py", line 67, in service_event_update await self.solcast.http_data(dopast=False) File "/config/custom_components/solcast_solar/solcastapi.py", line 543, in http_data await self.serialize_data() File "/config/custom_components/solcast_solar/solcastapi.py", line 97, in serialize_data with open(self._filename, "w") as f:

My Solcast integration seems to be affected at the same time with a similar warning and they are referencing a link to handling time zones: https://developers.home-assistant.io/blog/2024/05/19/fix_zoneinfo_blocking_io/

pivlersmom commented 2 weeks ago

Same issue here. Integration is not loading anymore

dpgh947 commented 2 weeks ago

I am getting this since updating to 2024.6.2 - I also had the same for the alexa_media integration, but that has already been fixed. I get the error at HA restart, but the solis integration does seem to load and work OK after that.

changeofaspect commented 2 weeks ago

I had similar with the Solcast integration which generated a message at start up and a slightly different message every time I polled the Solcast server. The warning message for the Solis integration points to Line 185 of the soliscloudapi.py file which is with open('/config/custom_components/solis/workarounds.yaml', 'r') and seems to be trying to open a file in the event loop.

The Solcast integration has now been fixed by using 'async with aiofiles.open' instead of 'with open' but it was not quite as simple as that. I am not a Python coder but I noted that other changes were required to be made to make it all work. It will need a Python expert to work through it and make the changes - I am definitely not a Python expert. Also, the reference above to the zoneinfo blocking turned out to be a bit of a red herring, yes, it needed sorting, but it was not the cause of the warning messages which were caused by the 'with open'.

cfarm31 commented 1 week ago

Hi all

I'm getting the same error and notes on work grounds or anything like that? Below is my error

Logger: homeassistant.util.loop Source: util/loop.py:84 First occurred: 23:06:31 (3 occurrences) Last logged: 23:07:06

Detected blocking call to open inside the event loop by custom integration 'solis' at custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file: (offender: /config/custom_components/solis/soliscloud_api.py, line 185: with open('/config/custom_components/solis/workarounds.yaml', 'r') as file:), please create a bug report at https://github.com/hultenvp/solis-sensor/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, self._args) File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/usr/src/homeassistant/homeassistant/setup.py", line 447, in _async_setup_component await asyncio.gather( File "/usr/src/homeassistant/homeassistant/setup.py", line 449, in create_eagertask( File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/solis/init.py", line 82, in async_setup_entry portal_config = SoliscloudConfig( File "/config/custom_components/solis/soliscloud_api.py", line 185, in init with open('/config/custom_components/solis/workarounds.yaml', 'r') as file: Detected blocking call to open inside the event loop by custom integration 'solcast_solar' at custom_components/solcast_solar/solcastapi.py, line 230: with open(self._filename) as data_file: (offender: /config/custom_components/solcast_solar/solcastapi.py, line 230: with open(self._filename) as data_file:), please create a bug report at https://github.com/oziee/ha-solcast-solar/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/solcast_solar/init.py", line 109, in async_setup_entry await solcast.load_saved_data() File "/config/custom_components/solcast_solar/solcastapi.py", line 230, in load_saved_data with open(self._filename) as data_file: Detected blocking call to open inside the event loop by custom integration 'solax_modbus' at custom_components/solax_modbus/init.py, line 332: fp = open(self._hass.config.path(f"{self.name}_data.json")) (offender: /config/custom_components/solax_modbus/init.py, line 332: fp = open(self._hass.config.path(f"{self.name}_data.json"))), please create a bug report at https://github.com/wills106/homsassistant-solax-modbus/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/config/custom_components/solax_modbus/init.py", line 377, in _refresh await self.async_refresh_modbus_data(grp, _now) File "/config/custom_components/solax_modbus/init.py", line 403, in async_refresh_modbus_data update_result = await self.async_read_modbus_data(group) File "/config/custom_components/solax_modbus/init.py", line 619, in async_read_modbus_data res = await self.async_read_modbus_registers_all(group) File "/config/custom_components/solax_modbus/init.py", line 795, in async_read_modbus_registers_all self.loadLocalData() File "/config/custom_components/solax_modbus/init.py", line 332, in loadLocalData fp = open(self._hass.config.path(f"{self.name}_data.json"))