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

No Home Assistant URL found in config or detected; forcing user form #1727

Closed
he4th3n opened this issue Sep 14, 2022 · 15 comments · Fixed by #1769
Closed

No Home Assistant URL found in config or detected; forcing user form #1727

he4th3n opened this issue Sep 14, 2022 · 15 comments · Fixed by #1769

Comments

@he4th3n
Copy link

he4th3n commented Sep 14, 2022

Describe the bug
Cannot setup the integration (via the Integrations GUI)

To Reproduce

  1. Open Integrations tab
  2. Click on 'Add integration'
  3. Fill all configuration fields as expected
  4. No login; see logs (nothing happens when pressing the "Enter" button)

Expected behavior

Integration should be setup

Screenshots

immagine

System details

  • Home-assistant (version): 2022.9.1 (Supervisor 2022.08.6 / OS 8.5)
  • alexa_media (version from const.py or HA startup): 4.1.2
  • alexapy (version from pip show alexapy or HA startup): 1.26.3
  • Amazon 2FA is enabled (y/n). Yes

Logs
Please provide logs.

2022-09-14 23:19:25.400 DEBUG (MainThread) [custom_components.alexa_media.config_flow] Creating new login
2022-09-14 23:19:25.401 DEBUG (MainThread) [custom_components.alexa_media.helpers] e*********n@g*******m: Returning uuid {'uuid': 'ae41f049eaa2ae22754a4f0a2d891a33', 'index': 0}
2022-09-14 23:19:25.417 DEBUG (MainThread) [alexapy.alexalogin] Creating TOTP for R************************************************IFA
2022-09-14 23:19:25.417 DEBUG (MainThread) [alexapy.alexalogin] Generating OTP [REDACTED]
2022-09-14 23:19:25.417 DEBUG (MainThread) [alexapy.alexalogin] Login created for e[REDACTED]n@g[REDACTED]m - amazon.it
2022-09-14 23:19:25.417 DEBUG (MainThread) [custom_components.alexa_media.config_flow] No Home Assistant URL found in config or detected; forcing user form

Additional context
Even if debug is enabled in GUI, no additional log (alexa_media.(email).get.html nor alexa_media.(email).post.html) is output inside the configuration directory
The URL entered in the configuration window is a duckdns .org URL, with https enabled.

@alandtse
Copy link
Owner

The error appears if you don't enter any value in the HA url and HA cannot determine it's own url. You can try to use an internal url or you can fix your Settings -> Network.
image

But there's literally no further debugging I can provide as it's literally looking up the the form value (which you've hidden), not finding any input, and then asking HA to self discover it's URL. Then HA is returning an error that no URL is configured or detectable.

https://github.com/custom-components/alexa_media_player/blob/dev/custom_components/alexa_media/config_flow.py#L247-L257

@alandtse alandtse changed the title No login from integrations GUI (No Home Assistant URL found in config or detected; forcing user form) No Home Assistant URL found in config or detected; forcing user form Sep 15, 2022
@he4th3n
Copy link
Author

he4th3n commented Sep 15, 2022

Well, this is quite funny... You are right, the Settings -> Network URL was not set correctly.
However, as I said in additional context above, my URL was already correctly entered in the GUI form for the configuration flow. Just adding the same URL to the Settings -> Network field too, made the configuration flow proceed. Thus, both seem to be needed.

So I would say it is a bit unexpected/misleading that the configuration flow does not proceed even if the correct URL was provided in the GUI (but not in Settings -> Network), isn't it? At a minimum, I would say this requirement should be explicitly stated in the documentation, as it seems the GUI field for Home Assistant URL is not effective by itself.

Does this make sense? Or did I miss something?

@alandtse
Copy link
Owner

I'm saying there's no code I can change to pull the data from the GUI differently. HA doesn't think you entered anything into the form so fell back to the auto discover settings which were also missing. There's literally nothing I can do to solve this problem because I don't have any form processing code. It's all HA's.

Perhaps there's a bug for Italian language in how HA handles forms. I really don't know as you're the only person who has reported this condition. Regardless, I'm glad you managed to log in.

@he4th3n
Copy link
Author

he4th3n commented Sep 15, 2022

I see; thanks for clarifying. Maybe adding this weird corner case to the FAQs could help other users, in the future.

Thanks for helping!

@String-656
Copy link

I had this exact issue, and had defined "homeassistant:" in the config. As a result, I did not have external_url: and internal_url: defined, which resulted in the Settings -> Network being blank.

I was also entering the correct url in the form, yet it just looped, and I received identical debug logs above. Seems it's taking the URL from Home assistant field, not the GUI form... odd

I received the "cannot connect to URL, but if certain you can ignore this message" - worked a treat and all working again. Very odd, but I appreciate the comments, I've been at this for hours!

@alandtse
Copy link
Owner

alandtse commented Nov 1, 2022

What HA language? Maybe it's related to a language setting.

@String-656
Copy link

HA language is user specific I think? Under administrator user, I have "English (GB)" selected.

@String-656
Copy link

I did a test,

I modified the try statement at line 248 in config_flow.py from this...

        try:
            hass_url: str = user_input.get(
                CONF_HASS_URL, get_url(self.hass, prefer_external=True)
            )

to this, and it worked / took the user input.. I hope that helps.

        try:
            hass_url: str = user_input.get(CONF_HASS_URL)

@alandtse
Copy link
Owner

alandtse commented Nov 2, 2022

I modified the try statement at line 248 in config_flow.py from this...

        try:
            hass_url: str = user_input.get(
                CONF_HASS_URL, get_url(self.hass, prefer_external=True)
            )

to this, and it worked / took the user input.. I hope that helps.

        try:
            hass_url: str = user_input.get(CONF_HASS_URL)

That change shouldn't do anything. The second parameter for get is the default value if CONF_HASS_URL isn't in user_input. See https://python-reference.readthedocs.io/en/latest/docs/dict/get.html. You can try attaching a debugger or printing user_input before this point to see what it has.

@String-656
Copy link

I agree, I had a read of the .get function, it should not default unless the key is not found... I will add some debug outputs before and after.. standby.

@alandtse
Copy link
Owner

alandtse commented Nov 2, 2022

Thanks. The only thing I can think of is perhaps user_input is being modified by something else? In which case it should be saved in the config and we could access it from there.
https://github.com/custom-components/alexa_media_player/blob/dev/custom_components/alexa_media/config_flow.py#L684-L685

@String-656
Copy link

String-656 commented Nov 2, 2022

The exception I believe is being thrown when it evaluates the default value, even though it's not needed, it seems it is evaluated, creates an exception and thus never uses the user input, as the catch exception code then runs.

Test code, and resulting logs, it never ran the remaining log entry (I never received "String_656 Log End"), as the exception was already thrown at get_url.

     try:
            _LOGGER.debug("String_656 Logs Start")
            _LOGGER.debug(user_input.get(CONF_HASS_URL))
            _LOGGER.debug(get_url(self.hass, prefer_external=True))
            _LOGGER.debug("String_656 Logs End") 
            
            hass_url: str = user_input.get(
                CONF_HASS_URL, get_url(self.hass, prefer_external=True)
            )
            

Logs

@alandtse
Copy link
Owner

alandtse commented Nov 2, 2022

Damn. I know what is happening. You're right. The get_url is being evaluated first and throwing the exception before user input. This would only happen if Network Settings is wrong. Ok. I know how to fix it (or if you feel confident, I'd also appreciate a PR). Thanks for doing the testing with your system to show the reason.

@alandtse alandtse reopened this Nov 2, 2022
@String-656
Copy link

No problem. Thanks for the custom component!

I've never coded python, (other languages yes) I don't think I can pull off a PR.

@alandtse
Copy link
Owner

alandtse commented Nov 2, 2022

No biggie. You helped enough. I'll post the fix and tag you so you can see the changes made. It'll be obvious once you see it.

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

Successfully merging a pull request may close this issue.

3 participants