alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.44k stars 277 forks source link

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

Open protege323 opened 3 weeks ago

protege323 commented 3 weeks ago

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

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 commented 3 weeks ago

following

danielbrunt57 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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 https://github.com/alandtse/alexa_media_player/issues/2469 that I wasn't able to set up the integration anymore in total.

voyagerft commented 3 weeks ago

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

anthonyCarigny commented 2 weeks ago

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

luizcarlosnery commented 2 weeks ago

Parou aqui também... erroalexa

danielbrunt57 commented 2 weeks ago

Parou aqui também...

Samahani, sielewi...

danielbrunt57 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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

danielbrunt57 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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