epaulsen / energytariff

HACS Integration for monitoring Norwegian grid tariff level
MIT License
28 stars 1 forks source link

Error message - AttributeError: 'NoneType' object has no attribute 'create_task' #9

Closed ruant closed 1 year ago

ruant commented 1 year ago

Getting this error in the logs after upgrading to HA 2023.6.0

2023-06-08 17:28:19.315 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform energytariff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 849, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/energytariff/sensor.py", line 323, in async_added_to_hass
    self.calculate_level()
  File "/config/custom_components/energytariff/sensor.py", line 367, in calculate_level
    self._coordinator.thresholddata.on_next(
  File "/usr/local/lib/python3.11/site-packages/rx/subject/subject.py", line 55, in on_next
    super().on_next(value)
  File "/usr/local/lib/python3.11/site-packages/rx/core/observer/observer.py", line 26, in on_next
    self._on_next_core(value)
  File "/usr/local/lib/python3.11/site-packages/rx/subject/behaviorsubject.py", line 52, in _on_next_core
    observer.on_next(value)
  File "/usr/local/lib/python3.11/site-packages/rx/core/observer/autodetachobserver.py", line 26, in on_next
    self._on_next(value)
  File "/config/custom_components/energytariff/sensor.py", line 683, in _threshold_state_change
    self.schedule_update_ha_state(True)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 724, in schedule_update_ha_state
    self.hass.create_task(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'create_task'
epaulsen commented 1 year ago

Seems like a breaking change in HA, needs investigation.

epaulsen commented 1 year ago

Not able to reproduce this in my development environment, energytariff loads without any issues after upgrading to 2023.6.0.
I have yet to upgrade my production environment to 2023.6.x, will try that later this week.

ruant commented 1 year ago

Yeah, not sure what happened here. Might just be a single error that happened to me. Sorry.

ruant commented 1 year ago

Not sure what I've done. But got this error again :/

Swoop86 commented 1 year ago

Getting the same issue here, after newly starting to use energy tariff. HA 2023.7.2.

Source: helpers/entity.py:880
Integration: sensor (documentation, issues)
First occurred: 21. juli 2023 kl. 02:06:27 (2 occurrences)
Last logged: 21. juli 2023 kl. 02:06:27

Error adding entities for domain sensor with platform energytariff
Error while setting up energytariff platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 504, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 788, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/energytariff/sensor.py", line 323, in async_added_to_hass
    self.calculate_level()
  File "/config/custom_components/energytariff/sensor.py", line 367, in calculate_level
    self._coordinator.thresholddata.on_next(
  File "/usr/local/lib/python3.11/site-packages/rx/subject/subject.py", line 55, in on_next
    super().on_next(value)
  File "/usr/local/lib/python3.11/site-packages/rx/core/observer/observer.py", line 26, in on_next
    self._on_next_core(value)
  File "/usr/local/lib/python3.11/site-packages/rx/subject/behaviorsubject.py", line 52, in _on_next_core
    observer.on_next(value)
  File "/usr/local/lib/python3.11/site-packages/rx/core/observer/autodetachobserver.py", line 26, in on_next
    self._on_next(value)
  File "/config/custom_components/energytariff/sensor.py", line 683, in _threshold_state_change
    self.schedule_update_ha_state(True)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 880, in schedule_update_ha_state
    self.hass.create_task(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'create_task'
hansahell commented 1 year ago

I have the same error and have had it for a few months. HA 2023.7.3

2023-08-02 11:00:41.403 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform energytariff Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 504, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 788, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in add_to_platform_finish await self.async_added_to_hass() File "/config/custom_components/energytariff/sensor.py", line 323, in async_added_to_hass self.calculate_level() File "/config/custom_components/energytariff/sensor.py", line 367, in calculate_level self._coordinator.thresholddata.on_next( File "/usr/local/lib/python3.11/site-packages/rx/subject/subject.py", line 55, in on_next super().on_next(value) File "/usr/local/lib/python3.11/site-packages/rx/core/observer/observer.py", line 26, in on_next self._on_next_core(value) File "/usr/local/lib/python3.11/site-packages/rx/subject/behaviorsubject.py", line 52, in _on_next_core observer.on_next(value) File "/usr/local/lib/python3.11/site-packages/rx/core/observer/autodetachobserver.py", line 26, in on_next self._on_next(value) File "/config/custom_components/energytariff/sensor.py", line 683, in _threshold_state_change self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 880, in schedule_update_ha_state self.hass.create_task( ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'create_task' 2023-08-02 11:00:41.405 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up energytariff platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 504, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 788, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in add_to_platform_finish await self.async_added_to_hass() File "/config/custom_components/energytariff/sensor.py", line 323, in async_added_to_hass self.calculate_level() File "/config/custom_components/energytariff/sensor.py", line 367, in calculate_level self._coordinator.thresholddata.on_next( File "/usr/local/lib/python3.11/site-packages/rx/subject/subject.py", line 55, in on_next super().on_next(value) File "/usr/local/lib/python3.11/site-packages/rx/core/observer/observer.py", line 26, in on_next self._on_next_core(value) File "/usr/local/lib/python3.11/site-packages/rx/subject/behaviorsubject.py", line 52, in _on_next_core observer.on_next(value) File "/usr/local/lib/python3.11/site-packages/rx/core/observer/autodetachobserver.py", line 26, in on_next self._on_next(value) File "/config/custom_components/energytariff/sensor.py", line 683, in _threshold_state_change self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 880, in schedule_update_ha_state self.hass.create_task( ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'create_task'

ruant commented 1 year ago

@epaulsen Any idea what could cause this?

epaulsen commented 1 year ago

Not sure. I am on vacation until sunday, so not able to investigate until then.

Might be some breaking changes in entity setup in the latest HA releases, I haven't updated HA since may.

epaulsen commented 1 year ago

Finally able to reproduce this in my setup. Race condition during startup. Should have a fix within an hour or so.

epaulsen commented 1 year ago

Fixed in release 0.2.3.

Sorry that it took so long to hunt down this bug!