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

Integration no more loaded after reinstallation: KeyError: 'public_url' #2479

Closed
protege323 opened this issue Aug 21, 2024 · 23 comments
Closed

Comments

@protege323
Copy link

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Alexa integration will be not loaded after installation

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

image

System details

  • Home-assistant (version): 2024.8.2
  • alexa_media (version from const.py or HA startup): 4.12.10
  • alexapy (version from pip show alexapy or HA startup): 1.28.2
  • Amazon 2FA is enabled (y/n).: yes

Logs
Logger: homeassistant.setup
Source: setup.py:416
First occurred: 7:28:08 AM (1 occurrences)
Last logged: 7:28:08 AM

Error during setup of component alexa_media
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/alexa_media/init.py", line 188, in async_setup
CONF_PUBLIC_URL: account[CONF_PUBLIC_URL],
~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'public_url'

Who can help?

Thanks

@1242scooter
Copy link

following

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Aug 21, 2024

Did you just upgrade Alexa Media Player? If so, from what version?

Do you have an Internet URL configured in HA Settings > System > Network?

Can you view /config/.storage/core.config_entries, search for alexa_media and post the contents of that config_entry?
It looks like this:

      {
        "created_at": "2024-08-21T08:21:34.897280+00:00",
        "data": {
          "otp_secret": "<redacted>",
          "email": "<redacted>",
          "password": "<redacted>",
          "url": "amazon.com",
          "public_url": " ",
          "scan_interval": 60,
          "queue_delay": 1.5,
          "include_devices": "",
          "exclude_devices": "Bedroom,Daniel's Fire,Echo Auto,Mach-E SYNC,Living Room,Main floor,Norton Court,Office,This Device",
          "extended_entity_discovery": true,
          "debug": false,
          "oauth": {
            "access_token": "<redacted>
            "refresh_token": "<redacted>
            "expires_in": 1724232095.47634,
            "mac_dms": {
              "device_private_key": "<redacted>
              "adp_token": "{enc:<redacted>
            },
            "code_verifier": "-<redacted>",
            "authorization_code": "<redacted>"
          }
        },
        "disabled_by": null,
        "domain": "alexa_media",
        "entry_id": "01J5T0DSHHWJKKTDCZCD375A49",
        "minor_version": 1,
        "modified_at": "2024-08-21T08:21:45.985888+00:00",
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "title": "<redacted>- amazon.com",
        "unique_id": "<redacted>- amazon.com",
        "version": 1
      }

@protege323
Copy link
Author

protege323 commented Aug 21, 2024

I think the version which was running before was 4.12.6 or .7

Yes Internet URL is configured --> Nabu Casa

 "created_at": "2024-08-21T05:24:29.884934+00:00",
        "data": {
          "otp_secret": "< redacted>",
          "email": "< redacted>",
          "password": "< redacted>",
          "url": "amazon.de",
          "public_url": "< redacted>",
          "scan_interval": 60,
          "queue_delay": 1.5,
          "include_devices": "",
          "exclude_devices": "",
          "extended_entity_discovery": false,
          "debug": false,
          "oauth": {
            "access_token": "< redacted>",
            "refresh_token": "< redacted>",
            "expires_in": 1724221467.591467,
            "mac_dms": {
              "device_private_key": "< redacted>",
              "adp_token": "< redacted>"
            },
            "code_verifier": "< redacted>",
            "authorization_code": "< redacted>"
          }
        },
        "disabled_by": null,
        "domain": "alexa_media",
        "entry_id": "01J5SP9HHW09ZQE3GHWN1RHNJT",
        "minor_version": 1,
        "modified_at": "2024-08-21T05:24:29.884941+00:00",
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "title": "< redacted> - amazon.de",
        "unique_id": "< redacted> - amazon.de",
        "version": 1

@emufan
Copy link

emufan commented Aug 22, 2024

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

image **System details**
  • Home-assistant (version): 2024.8.2
  • alexa_media (version from const.py or HA startup): 4.12.10
  • alexapy (version from pip show alexapy or HA startup): 1.28.2
  • Amazon 2FA is enabled (y/n).: yes

Had this as well after updating to 2024.8.2 and AMP to 4.12.10 (coming from 4.12.7.

I then deleted the integration to have a clean start and ended up in problem #2469 that I wasn't able to set up the integration anymore in total.

@voyagerft
Copy link

in Italy it doesn't work, the reconfiguration pop up appears continuously
IMG_3799

@anthonyCarigny
Copy link

anthonyCarigny commented Aug 24, 2024

I confirm experiencing the same as @protege323 with amazon.fr

@luizcarlosnery
Copy link

Parou aqui também...
erroalexa

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Aug 27, 2024

Parou aqui também...

Samahani, sielewi...

@danielbrunt57 danielbrunt57 changed the title Integration no more loaded after reinstallation Integration no more loaded after reinstallation: KeyError: 'public_url' Aug 27, 2024
@danielbrunt57
Copy link
Collaborator

Please try editing __init__.py lines 151-177 and insert CONF_PUBLIC_URL as follows:

                    _LOGGER.debug("Updating existing entry")
                    hass.config_entries.async_update_entry(
                        entry,
                        data={
                            CONF_EMAIL: account[CONF_EMAIL],
                            CONF_PASSWORD: account[CONF_PASSWORD],
                            CONF_URL: account[CONF_URL],
                            CONF_PUBLIC_URL: account[CONF_PUBLIC_URL],
                            CONF_INCLUDE_DEVICES: account[CONF_INCLUDE_DEVICES],
                            CONF_EXCLUDE_DEVICES: account[CONF_EXCLUDE_DEVICES],
                            CONF_SCAN_INTERVAL: account[
                                CONF_SCAN_INTERVAL
                            ].total_seconds(),
                            CONF_QUEUE_DELAY: account[CONF_QUEUE_DELAY],
                            CONF_OAUTH: account.get(
                                CONF_OAUTH, entry.data.get(CONF_OAUTH, {})
                            ),
                            CONF_OTPSECRET: account.get(
                                CONF_OTPSECRET, entry.data.get(CONF_OTPSECRET, "")
                            ),
                            CONF_EXTENDED_ENTITY_DISCOVERY: account[
                                CONF_EXTENDED_ENTITY_DISCOVERY
                            ],
                            CONF_DEBUG: account[CONF_DEBUG],
                        },
                    )
                    entry_found = True
                    break

Then remove integration config entry, restart HA and re-add integration.

@anthonyCarigny
Copy link

Hello @danielbrunt57
I tried what you suggested and added CONF_PUBLIC_URL: account[CONF_PUBLIC_URL], on line 158.
But I still have the same issue as @protege323
logs still say

Error during setup of component alexa_media
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/alexa_media/__init__.py", line 189, in async_setup
    CONF_PUBLIC_URL: account[CONF_PUBLIC_URL],
                     ~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'public_url'

(Just now line 189 instead of 188 of course.)

@protege323
Copy link
Author

Hi @danielbrunt57
those lines were already represent in the init.py. However I've pasted your lines into mine config, removed integration, removed HACS intergration, performed a full restart of HA but issue still persist.

Logger: homeassistant.setup
Source: setup.py:416
First occurred: 4:10:58 PM (1 occurrences)
Last logged: 4:10:58 PM

Error during setup of component alexa_media
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/alexa_media/init.py", line 188, in async_setup
CONF_PUBLIC_URL: account[CONF_PUBLIC_URL],
~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'public_url'

@anthonyCarigny
Copy link

anthonyCarigny commented Aug 28, 2024

I worked around the issue by providing a default value for account[CONF_PUBLIC_URL] on line 189.
That allowed me configure and load the integration

                        CONF_PUBLIC_URL: account.get(CONF_PUBLIC_URL, 'https://my.domain/'),

@popy2k14
Copy link

Nice find!!!!!!!!
Could you please make a PR if fix is working for others here?
This would help many others.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Aug 28, 2024

Nice find!!!!!!!! Could you please make a PR if fix is working for others here? This would help many others.

That can't be a PR as he has hard coded his own public URL and his public URL won't work on your system!
Check if that key:value pair exists in your /config/.storage/core.config_entries in the alexa_media entry block. If it's missing, CAREFULLY add it and restart HA. Warning: if you induce an error in that file, HA will not start normally and will rename that file and create a new minimal one that allows it to start in recovery mode. You can then fix the error in the renamed one, copy it back to core.config_entries and restart, but most custom edits to entities will be gone. Ask me how I know! Safest is to backup HA core before editing it so you can do full HA core restore!
The entry will look like:

    "public_url":"_your_public_url_here_",

@luizcarlosnery
Copy link

Exato @danielbrunt57 Aqui no meu funcionou, porém só depois de incluir minha URL público... eu uso redirecionamento via noip.com depois de fazer isto e usar a chave gerada em amazon.com tudo voltou a funcionar.

@elchanly
Copy link

I worked around the issue by providing a default value for account[CONF_PUBLIC_URL] on line 189. That allowed me configure and load the integration

                        CONF_PUBLIC_URL: account.get(CONF_PUBLIC_URL, 'https://my.domain/'),

THIS WORKED, THANKS @anthonyCarigny !!!!!!!!!!!

@elchanly
Copy link

I worked around the issue by providing a default value for account[CONF_PUBLIC_URL] on line 189. That allowed me configure and load the integration

                        CONF_PUBLIC_URL: account.get(CONF_PUBLIC_URL, 'https://my.domain/'),

THIS WORKED, THANKS @anthonyCarigny !!!!!!!!!!!

24h later.... It crashed again

@1242scooter
Copy link

1242scooter commented Oct 22, 2024 via email

@danielbrunt57
Copy link
Collaborator

No issues observed here after several dozens of remove/re-add

image

@1242scooter
Copy link

1242scooter commented Oct 22, 2024 via email

@danielbrunt57
Copy link
Collaborator

Remove and re add AMP? Then re add all your AMP announcements too?

I'm not sure what you're actually referring to when you say announcements. Removing Alexa Media Player in HA only removes the Alexa devices and services (notify, media_player, alexa_media) that it created. It doesn't remove any corresponding actions or entities that you have in your scripts and automations.

@1242scooter
Copy link

1242scooter commented Oct 22, 2024 via email

@danielbrunt57
Copy link
Collaborator

I only use HA to make announcements on my echo devices from my Reolink cameras if they detect a person or vehicle. I’m not sure if you know, but if I removed Alexa media player and then reinstall, would I have to re-add all my automations using AMP to my echo’s?

No. Removing AMP does not alter any code that's in automations/scripts.
The automations/scripts are unaltered and will continue to try and run while AMP is removed but they will fail and log an error that they could not find a particular service/entity/device which now does not exist. The will resume working once AMP is reinstalled and the services/entities/devices that they reference are re-created.

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

9 participants