KartoffelToby / better_thermostat

This custom component for Home Assistant will add crucial features to your climate-controlling TRV (Thermostatic Radiator Valves) to save you the work of creating automations to make it smart. It combines a room-temperature sensor, window/door sensors, weather forecasts, or an ambient temperature probe to decide when it should call for heat and automatically calibrate your TRVs to fix the imprecise measurements taken in the radiator's vicinity.
https://better-thermostat.org
GNU Affero General Public License v3.0
727 stars 123 forks source link

Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/adapters/delegate.py #1363

Open NikDevx opened 1 month ago

NikDevx commented 1 month ago

HA v. 2024.5.4

Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/adapters/delegate.py, line 16: self.adapter = import_module( (offender: /config/custom_components/better_thermostat/adapters/delegate.py, line 16: self.adapter = import_module(), please create a bug report at https://github.com/KartoffelToby/better_thermostat/issues
Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/adapters/delegate.py, line 27: self.adapter = import_module( (offender: /config/custom_components/better_thermostat/adapters/delegate.py, line 27: self.adapter = import_module(), please create a bug report at https://github.com/KartoffelToby/better_thermostat/issues
Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/model_fixes/model_quirks.py, line 14: self.model_quirks = import_module( (offender: /config/custom_components/better_thermostat/model_fixes/model_quirks.py, line 14: self.model_quirks = import_module(), please create a bug report at https://github.com/KartoffelToby/better_thermostat/issues
Detected blocking call to import_module inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/model_fixes/model_quirks.py, line 25: self.model_quirks = import_module( (offender: /config/custom_components/better_thermostat/model_fixes/model_quirks.py, line 25: self.model_quirks = import_module(), please create a bug report at https://github.com/KartoffelToby/better_thermostat/issues
LeoCal commented 1 month ago

seeing the same issue here

Wazbat commented 4 weeks ago

Also seeing this. I tried creating my first thermostat and I'm getting this in the logs

This was also followed by the following log entry:

Logger: homeassistant
Source: components/zha/core/cluster_handlers/__init__.py:82
First occurred: 1 July 2024 at 20:19:32 (4 occurrences)
Last logged: 00:56:13

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/better_thermostat/climate.py", line 853, in startup
    await control_trv(self, trv)
  File "/config/custom_components/better_thermostat/utils/controlling.py", line 260, in control_trv
    await set_offset(self, heater_entity_id, _calibration)
  File "/config/custom_components/better_thermostat/adapters/delegate.py", line 91, in set_offset
    return await self.real_trvs[entity_id]["adapter"].set_offset(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/better_thermostat/adapters/generic.py", line 146, in set_offset
    await self.hass.services.async_call(
  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 "/usr/src/homeassistant/homeassistant/helpers/service.py", line 977, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 121, in async_set_value
    await entity.async_set_native_value(native_value)
  File "/usr/src/homeassistant/homeassistant/components/zha/number.py", line 468, in async_set_native_value
    await self._cluster_handler.write_attributes_safe(
  File "/usr/src/homeassistant/homeassistant/components/zha/core/cluster_handlers/__init__.py", line 539, in write_attributes_safe
    res = await self.write_attributes(attributes, manufacturer=manufacturer)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/zha/core/cluster_handlers/__init__.py", line 82, in wrapper
    return await RETRYABLE_REQUEST_DECORATOR(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/util.py", line 131, in retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zhaquirks/tuya/__init__.py", line 764, in write_attributes
    manufacturer_attrs.update(new_attrs)
TypeError: 'NoneType' object is not iterable

My TRV valve is connected via ZHA, if that helps

jamesonuk commented 3 weeks ago

Fix is documented https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module however the helper doesn't implement the optional package parameter that is used here

https://github.com/home-assistant/core/blob/6ab6ce30efea9e342d34ffcd68edae2210f0bd37/homeassistant/helpers/importlib.py#L30

chlctt commented 1 week ago

I do also see this. My HomeAssistant instance stopped working and I had to find out why. I could narrow it down to this.

This is from my home-assistant.log file when activating one of my Better Thermostats again.

2024-07-18 14:25:28.539 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('custom_components.better_thermostat.adapters.fritzbox',) inside the event loop by custom integration 'better_thermostat' at custom_components/better_thermostat/adapters/delegate.py, line 16: self.adapter = import_module( (offender: /config/custom_components/better_thermostat/adapters/delegate.py, line 16: self.adapter = import_module(), please create a bug report at https://github.com/KartoffelToby/better_thermostat/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
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 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, 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 734, in async_setup_locked
    await self.async_setup(hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/better_thermostat/__init__.py", line 35, in async_setup_entry
    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2059, in async_forward_entry_setups
    await self._async_forward_entry_setups_locked(entry, platforms)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2070, in _async_forward_entry_setups_locked
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2072, 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 2152, in _async_forward_entry_setup
    await entry.async_setup(self.hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 221, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 195, in async_setup_entry
    return await self._platforms[key].async_setup_entry(config_entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 331, in async_setup_entry
    return await self._async_setup_platform(async_create_setup_awaitable)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform
    awaitable = create_eager_task(awaitable, loop=hass.loop)
  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 "/config/custom_components/better_thermostat/climate.py", line 135, in async_setup_entry
    async_add_devices(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 513, in _async_schedule_add_entities_for_entry
    task = self.config_entry.async_create_task(
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1126, in async_create_task
    task = hass.async_create_task_internal(
  File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  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/helpers/entity_platform.py", line 647, in async_add_entities
    await add_func(coros, entities, timeout)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/better_thermostat/climate.py", line 335, in async_added_to_hass
    _adapter = load_adapter(self, trv["integration"], trv["trv"])
  File "/config/custom_components/better_thermostat/adapters/delegate.py", line 16, in load_adapter
    self.adapter = import_module(