TheBrain8791 / ha_awattar

Adds Awattar energy cost data to Home Assistant.
Other
11 stars 1 forks source link

Failed to setup (awattar (at)) - 2024.2.1 #8

Open nuki47 opened 6 months ago

nuki47 commented 6 months ago

Home Assistant 2024.2.1

` Logger: homeassistant.config_entries Source: config_entries.py:444 First occurred: February 13, 2024 at 10:34:25 (8 occurrences) Last logged: 15:51:39

Error setting up entry Awattar (at) for awattar_energy_cost Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 444, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/awattar_energy_cost/init.py", line 24, in async_setup_entry shell.add_entry(entry) File "/config/custom_components/awattar_energy_cost/init.py", line 69, in add_entry self._hass.add_job(source.fetch) ^^^^^^ UnboundLocalError: cannot access local variable 'source' where it is not associated with a value `

bernibaer commented 6 months ago

I have the same problem since I updated to HA 2024.2.2. But the fix seams to be simple. The call to async_setup_platformsin custom_components/awattar_energy_cost/__init__.py needs to be replaced by async_forward_entry_setups:

index a54a9b2..cb0dbe6 100644
--- a/custom_components/awattar_energy_cost/__init__.py
+++ b/custom_components/awattar_energy_cost/__init__.py
@@ -23,7 +23,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
     # add market area to shell
     shell.add_entry(entry)

-    hass.config_entries.async_setup_platforms(entry, PLATFORMS)
+    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

     return True

It looks like async_setup_platforms was removed in recent release. I added the await statement like in this change:

https://community.home-assistant.io/t/async-forward-entry-setups-this-will-fail-in-version-2023-3/533293/5

After restart of homeassistant i got some errors because state was still unavailable and conversion to double failed. But this healed itself after the first state was retrieved after some minutes.