Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Failed to set up" integration when HA is restarted #317

Closed
ben-willmore opened this issue Oct 25, 2022 · 18 comments
Closed

"Failed to set up" integration when HA is restarted #317

ben-willmore opened this issue Oct 25, 2022 · 18 comments

Comments

@ben-willmore
Copy link

This was discussed on the forum thread, but now seems to happen reliably on restart for me. The integration is unavailable on restart, and the integrations page in HA says "Failed to set up" for the Wiser integration. I seem to be able to get it to work by going to the 3-dot menu for the integration, then Reload, then 3-dot menu again, System options, Update.

2022-10-25 20:34:35.405 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry WiserHeat043089 for wiser
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 357, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/wiser/__init__.py", line 60, in async_setup_entry
    await async_update_device_registry(hass, config_entry)
  File "/config/custom_components/wiser/__init__.py", line 80, in async_update_device_registry
    (CONNECTION_NETWORK_MAC, data.wiserhub.system.network.mac_address)
AttributeError: 'NoneType' object has no attribute 'network'
@msp1974
Copy link
Collaborator

msp1974 commented Oct 25, 2022

Can you provide a diagnostic output please as have not been able to create this issue.

@thecem
Copy link

thecem commented Oct 26, 2022

For me the same since the last update, beside the reload do not solve the problem. I only have a floorheating system with 4 Thermostats and the bridge version 1. Logs:

A9849823-02FE-4D76-B9B2-A1CE6FCFBF02

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: homeassistant.config_entries
Source: custom_components/wiser/helpers.py:6 
Integration: Drayton Wiser Integration for Home Assistant (documentation, issues) 
First occurred: 25. Oktober 2022 um 09:03:50 (5 occurrences) 
Last logged: 08:33:22

Error setting up entry WiserHeat02E4DA for wiser
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 365, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/wiser/__init__.py", line 60, in async_setup_entry
    await async_update_device_registry(hass, config_entry)
  File "/config/custom_components/wiser/__init__.py", line 82, in async_update_device_registry
    identifiers={(DOMAIN, get_identifier(data, 0))},
  File "/config/custom_components/wiser/helpers.py", line 69, in get_identifier
    return f"{data.wiserhub.system.name} {get_device_name(data, id, type)}"
  File "/config/custom_components/wiser/helpers.py", line 6, in get_device_name
    device = data.wiserhub.devices.get_by_id(id)
AttributeError: 'NoneType' object has no attribute 'get_by_id'

Logger: homeassistant.config_entries
Source: helpers/entity_component.py:160 
First occurred: 08:32:59 (32 occurrences) 
Last logged: 08:33:22

Error setting up entry WiserHeat02E4DA for select
Error setting up entry WiserHeat02E4DA for button
Error setting up entry WiserHeat02E4DA for number
Error setting up entry WiserHeat02E4DA for light
Error setting up entry WiserHeat02E4DA for cover
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 365, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 195, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 160, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!


Logger: homeassistant.components.sensor
Source: custom_components/wiser/sensor.py:46 
Integration: Sensor (documentation, issues) 
First occurred: 25. Oktober 2022 um 09:03:50 (1 occurrences) 
Last logged: 25. Oktober 2022 um 09:03:50

Error while setting up wiser platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/wiser/sensor.py", line 46, in async_setup_entry
    hub_devices = data.wiserhub.devices.all
AttributeError: 'NoneType' object has no attribute 'all'

If you need more logs let me wich one and where.
Thx!

@ben-willmore
Copy link
Author

Here are the diagnostics. I had to go through the reload-update cycle (so that the integration was functioning) before I had the option to download them. I hope that doesn't make them useless! Happy to provide any more info, or to dig around myself if helpful (I am competent with python etc but new to HA). Thanks for all your work!

config_entry-wiser-2f19cc38495459ad1d8a320c7774cfbe.json-5.txt

@ben-willmore
Copy link
Author

I meant to say that it’s not perfectly reliable. After a handful of restarts it’s perhaps 50/50 for me.

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

Ben, your diagnostic file was perfect. I use this to emulate your hub in my mock hub server to make sure there is no data related issue that we do not catch. This worked perfectly and loaded and functioned fine.

As such, I can only think that for some reason, it is failing getting an update from the hub at startup. We have suppressed a lot of this but if you know how to pull a version from the dev branch and run that in your HA environment then, I can enable some logging and we can see better what is happening. Let me know.

I also have a couple of questions if you can provide answers:

  1. Did you run any of the 3.2.0beta versions or migrate from 3.1.7 to 3.2.0?
  2. Have you tried removing and re-adding the integration?

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

@thecem - can you also please answer the 2 questions above plus:

What version of HA are you running?
I presume you can not get it running at all on v3.2.0? Is it ok if you go back to 3.1.7?
Can you provide a diagnostic output (from v3.1.7 or v3.2.0)

Thanks

@thecem
Copy link

thecem commented Oct 26, 2022

HA Version:
Uploading 524F922B-2BF5-41E5-89B0-4AD49037F314.jpeg…

@thecem
Copy link

thecem commented Oct 26, 2022

3687B8FA-34EC-40F5-9944-75E66F214DE3

@thecem
Copy link

thecem commented Oct 26, 2022

Going back to 3.1.7 is directly working.

@ben-willmore
Copy link
Author

Yes I’m very happy to try a dev version.

  • Did you run any of the 3.2.0beta versions or migrate from 3.1.7 to 3.2.0?

Yes, I ran most of the betas but not sure exactly which.

  • Have you tried removing and re-adding the integration?

No, I was afraid of breaking automations etc. but perhaps I don’t need to be?

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

OK, Ben if you want to update form the dev branch and see if the logs show any better errors when you restart.

@thecem
Copy link

thecem commented Oct 26, 2022

In 3.2.0 there is no diagnostic information button. In 3.1.7 it is:

config_entry-wiser-71de748eec083b56f128f048f9ba6ada.json.txt

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

@thecem - ok this is a different issue. Running your hub diagnostics on my emulator showed an issue with the UFH controller code. I will transfer this to another issue and provide a fix in the next couple of days (once I know what this issue with Ben's is).

@ben-willmore
Copy link
Author

I installed the dev branch, and couldn't reproduce the problem across 6 restarts. Instead, in the 'Integrations' page, I initially get "Retrying setup: None". Then, after HA has finished starting up, this switches to the normal success card.

In the logs, I get:

$ grep wiser home-assistant.log
2022-10-26 18:17:48.869 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration wiser which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2022-10-26 18:18:37.053 ERROR (MainThread) [custom_components.wiser.coordinator] Connection timeout trying to communicate with Wiser Hub 192.168.178.170.  Error is 
2022-10-26 18:18:37.068 WARNING (MainThread) [homeassistant.config_entries] Config entry 'WiserHeat043089' for wiser integration not ready yet: None; Retrying in background

I then reinstalled 3.2.0 from HACS and got "Failed to set up" again (which doesn't resolve itself) in one of two restarts.

TLDR: dev branch seems to fix the problem for me

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

Hmm. It looks like your hub does not respond to the initial request within 10s.

I made a couple of changes to both improve logging but also fail the setup and retry if no data from the hub has been retrieved. That is the integration not ready message.

Not sure why it does not update on first request. I would have thought timeout this is plenty long enough as mine responds in a few hundred ms. I'll think a bit more if there is anything that might cause this problem with a slow responding hub but for now, I'll push a v3.2.1 version from the dev branch so at least it works more reliably and fixes thecem's issue also.

@ben-willmore
Copy link
Author

Could the slowness be on the HA end? I'm running on a Pi Zero which is usually fine but it does take a long time to start up.

@msp1974
Copy link
Collaborator

msp1974 commented Oct 26, 2022

That could be the issue - we did have a different retry strategy in 3.1.7 but all 3.2beta versions were the same.

Anyway, v3.2.1 is now available to download via HACs which should now work although you may get the setup retry on each restart.

@ben-willmore
Copy link
Author

Yes, v3.2.1 works great for me. Thanks for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants