thomluther / ha-anker-solix

Home Assistant integration for Anker Solix Power devices
MIT License
294 stars 4 forks source link

HA 2024.6 Warning: Detected blocking call to open inside the event loop #71

Closed thomluther closed 5 months ago

thomluther commented 5 months ago

System Health details

see below

Checklist

Describe the issue

HA 2024.6 reports Warnings for integration: Detected blocking call to open inside the event loop by custom integration 'anker_solix' at custom_components/anker_solix/solixapi/api.py, line 595: with open(filename, encoding="utf-8") as file:

Reproduction steps

Warnings after upgrading to HA 2024.06

Debug logs

Logger: homeassistant.util.loop
Quelle: util/loop.py:84
Erstmals aufgetreten: 18:05:53 (781 Vorkommnisse)
Zuletzt protokolliert: 18:06:26

    Detected blocking call to open inside the event loop by custom integration 'anker_solix' at custom_components/anker_solix/solixapi/api.py, line 595: with open(filename, encoding="utf-8") as file: (offender: /config/custom_components/anker_solix/solixapi/api.py, line 595: with open(filename, encoding="utf-8") as file:), please create a bug report at https://github.com/thomluther/hacs-anker-solix/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/anker_solix/__init__.py", line 84, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh await self._async_refresh( File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() File "/config/custom_components/anker_solix/coordinator.py", line 50, in _async_update_data return await self.client.async_get_data() File "/config/custom_components/anker_solix/api_client.py", line 206, in async_get_data await self.api.update_sites(fromFile=self._testmode) File "/config/custom_components/anker_solix/solixapi/api.py", line 1259, in update_sites sites = await self.get_site_list(fromFile=fromFile) File "/config/custom_components/anker_solix/solixapi/api.py", line 1609, in get_site_list resp = await self.request("post", _API_ENDPOINTS["site_list"]) File "/config/custom_components/anker_solix/solixapi/api.py", line 1094, in request await self.async_authenticate() File "/config/custom_components/anker_solix/solixapi/api.py", line 992, in async_authenticate data = self._loadFromFile(self._authFile) File "/config/custom_components/anker_solix/solixapi/api.py", line 595, in _loadFromFile with open(filename, encoding="utf-8") as file:

Diagnostics dump

No response

thomluther commented 5 months ago

Changed all file read and write IO of the Api library to async IO using the aiofiles library. Added aiofiles to integration requirements to have it installed by Core