home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.37k stars 30.64k forks source link

Error since 2023.2.0 - Platform kef not ready yet: Cannot get the ip address of kef speaker #87146

Closed mark007 closed 1 year ago

mark007 commented 1 year ago

The problem

Since the 2023.2.0 update, the kef integration no longer can access my kef speaker, no matter how many times I reboot each. The speaker itself is pingable and connectable from the kef app, just not HA since the upgrade.

What version of Home Assistant Core has the issue?

2023.2.0

What was the last working version of Home Assistant Core?

2023.1.7

What type of installation are you running?

Home Assistant OS

Integration causing the issue

kef

Link to integration documentation on our website

https://www.home-assistant.io/integrations/kef/

Diagnostics information

No response

Example YAML snippet

media_player:
 - platform: kef
   host: 192.168.8.162
   type: LS50
   supports_on: false
   inverse_speaker_mode: true
   standby_time: 60
   maximum_volume: 1
   name: Living Room Speakers

Anything in the logs that might be useful for us?

The error I see in the logs at HA reboot time is

Platform kef not ready yet: Cannot get the ip address of kef speaker.; Retrying in background in 30 seconds

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @basnijholt, mind taking a look at this issue as it has been labeled with an integration (kef) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `kef` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign kef` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


kef documentation kef source (message by IssueLinks)

mark007 commented 1 year ago

After rolling back to 2023.1.7 it's back working. Hopefully a fix can be found.

jlpouffier commented 1 year ago

Hello

I just want to inform that this issue is not isolated to one user. I am experiencing the exact same problem.

checkiecheck commented 1 year ago

Using the integration on LSX speakers result in same error. I've seen some deprecation of 'async setup' in other integrations, but this error doesnt show here on KEF code. The step the kef log comes from is when it tries to get the MAC adress of the speakers, not sure why its failing now, as ip comes from config. So maybe config reading is broken. and indeed the core .1.7 does not give the error and the integration works. Should be fixable enough to me. Let me know if there is anything to test or provide.

VitaminTe commented 1 year ago

Exact same issue here. Thanks in advance for looking at it, I'm so grateful to this community of developers!!

rajeshshu commented 1 year ago

Having the same issue with Kef LS50 W speakers

leeuw207 commented 1 year ago

Same problem here with my LSX speakers, rolled back to 2023.1.7 to maintain control of speakers

tomroeleveld commented 1 year ago

Same issue for me. Kef LSX remains unavailable after 2023.2.0 update.

basnijholt commented 1 year ago

Unfortunately, I do not own the KEF speakers anymore so I cannot test this.

I assume this is a change that is unrelated to the direct KEF code.

Does anyone know more details about changes in HA core that might cause this problem?

jlpouffier commented 1 year ago

Everything seems to be listed here. https://www.home-assistant.io/changelogs/core-2023.2

If it's a matter of putting my HA instance in debug level for the logs and providing you what I see I can do that.

If you walk me through how to best catch all the logs at once, I'll be OK to help you ;)

basnijholt commented 1 year ago

I believe it is because of the switch to Python 3.10 (https://github.com/home-assistant/core/pull/85456).

Perhaps this code works differently in Python 3.10:

https://github.com/home-assistant/core/blob/e53de2742cbd0c6e772b44597708cb9ad5fbb5dd/homeassistant/components/kef/media_player.py#L78-L85

Could anyone try to change that to:

def get_ip_mode(host):
    return "ip"
basnijholt commented 1 year ago

I just verified that the behavior of ipaddress.ip_address is unchanged in Python 3.10, however, there are some changes to the code (https://github.com/python/cpython/commits/main/Lib/ipaddress.py).

And also Home Assistant seems to have already been using Python 3.10 before the deprecation, so this is probably not the issue.

VitaminTe commented 1 year ago

I'm also on standby to troubleshoot if needed

checkiecheck commented 1 year ago

I just verified that the behavior of ipaddress.ip_address is unchanged in Python 3.10, however, there are some changes to the code (https://github.com/python/cpython/commits/main/Lib/ipaddress.py).

And also Home Assistant seems to have already been using Python 3.10 before the deprecation, so this is probably not the issue.

agree.. the january version of core already ran on 3.10 here, so still suspect a 'config construct' change somewhere which fails to pickup the ip address.. I'll try to run a few PY tests outside HA today, not a developer myself, but ruling out a few things is bit in my capacity.

checkiecheck commented 1 year ago

from debug i only get one line extra in the logs btw:

2023-02-07 09:20:56.906 DEBUG (MainThread) [homeassistant.components.kef.media_player] Setting up kef with host: 192.168.1.xxx, port: 50001, name: kef native, sources: ['Wifi', 'Bluetooth', 'Aux', 'Opt'] so it has the IP adress value anyway.

mark007 commented 1 year ago

Has anyone tried the code change locally to

def get_ip_mode(host):
    return "ip"

I wanted to ask before I update HA and try it. If it already is known to not work, I won't bother trying.

checkiecheck commented 1 year ago

i didnt as i dont know where to get to the files for normal HA included integrations. I know to edit custom components files. If you point me where the file is in an HASSOS installation , i'll be ok to make the edit. If you have a 'outside HA python script' that i can run in a PY environment, that i can do too.

mark007 commented 1 year ago

I created a kef custom_integration directory, copied the 4 kef integration files into it, added a version key to the manifest.json (otherwise the custom integration won't load). Changing the get_ip_mode function didn't help. It seems to be the getmac library having issues. There are other issues written like this one. https://github.com/home-assistant/core/issues/87623

Hopefully a fix for getmac can be added to the next HA version. For now I replaced the following line

https://github.com/home-assistant/core/blob/94519de8dd9fcac684b510904a38c2269c27a042/homeassistant/components/kef/media_player.py#L120

with my speakers mac, in lowercase, like

mac = '84:17:15:00:xx:xx'

and rebooted HA and its back online. Using uppercase resulted in a second media_player entity being created so using lowercase solved that. At least its a temporary workaround.

mark007 commented 1 year ago

I used some code suggestions from the https://github.com/home-assistant/core/issues/87623 issue and it worked. Hoping someone can review the changes, or let me know what the normal expectation is with this integration in terms of tests / code styles etc. It works for me anyways. Here's the pull request. https://github.com/home-assistant/core/pull/87712

checkiecheck commented 1 year ago

Dont get it on this context as in previous 2023.1.x version, this is no issue. Did I miss a python bump in .02.x release?

mark007 commented 1 year ago

The only thing I can think of is if HA changed something on the networking side of things that causes the default getmac mode to no longer work? Anyone know? Because the manifest for the kef integration has the same, fixed version of the getmac library for some time.

checkiecheck commented 1 year ago

I created a kef custom_integration directory, copied the 4 kef integration files into it, added a version key to the manifest.json (otherwise the custom integration won't load). Changing the get_ip_mode function didn't help. It seems to be the getmac library having issues. There are other issues written like this one. #87623

Hopefully a fix for getmac can be added to the next HA version. For now I replaced the following line

https://github.com/home-assistant/core/blob/94519de8dd9fcac684b510904a38c2269c27a042/homeassistant/components/kef/media_player.py#L120

with my speakers mac, in lowercase, like

mac = '84:17:15:00:xx:xx'

and rebooted HA and its back online. Using uppercase resulted in a second media_player entity being created so using lowercase solved that. At least its a temporary workaround.

did so too, wil remember this trick. happy to have the speakers back. Now i hope the fix proposed will do the same.

mark007 commented 1 year ago

Does anyone know what the homeassistant 'DEFAULT_VERSION' does. It changed from 3.9 to 3.10 when comparing 2023.1.7 to 2023.2.0 in the builder.yml file

https://github.com/home-assistant/core/compare/2023.1.7...2023.2.0

Could that have broken getmac as its changelog recently refers to 'tentative' support for python 3.10 https://github.com/GhostofGoes/getmac/blob/56412aab460e73304b59c3dc8fb5520ce39f7ef7/CHANGELOG.md?

mark007 commented 1 year ago

As requested by the getmac developer I have created an issue here as he thinks he might know the cause and a quick fix.

https://github.com/GhostofGoes/getmac/issues/83

checkiecheck commented 1 year ago

Cool, then it should be sorted there Indeed

mark007 commented 1 year ago

@ManneW this and a few other HA issues seem to be caused by the fact that there are two getmac libraries (an old get-mac one and a new getmac one). Both can't be installed at the same time because internally they both have a 'getmac' python package inside. A ticket is open with the getmac developer to see if theres an elegant way out of this problem but the only integration I see in the core / homeassistant container is the vilfo integration via its manifest here. The version of the vilfo python package it references, uses the old get-mac package, but I see the latest vilfo python package now points to the new getmac package.

https://github.com/home-assistant/core/blob/dev/homeassistant/components/vilfo/manifest.json

https://github.com/ManneW/vilfo-api-client-python/commit/d659c10338c37bbde5a9e1ae0c7a9978a4c7ae9b

Is it possible to uplift the version of the vilfo python client in the homeassistant core? That to me would at least mean all core integrations that I can see within the HA container (checking with the pipdeptree command, are using getmac and not get-mac anymore.

checkiecheck commented 1 year ago

some other question in this integration , but helpful in current state: is it possible to add the 'reload' this integration. When issues arise i have to completely restart HA, a reload of a specific integration like this would be very helpful.

bobokun commented 1 year ago

Is there any alternative temporary fix while being on the latest 2023.3.1 version or is the only option to downgrade to version 2023.1.7?

mark007 commented 1 year ago

Yes you can create a copy of the integration following the steps here if you wish which works around it for me and others while we wait for the fix to be reviewed and merged.

https://github.com/home-assistant/core/issues/87146#issuecomment-1422710364

jlpouffier commented 1 year ago

Any news on an official fix ☺️ ? It's starting to be a bit long

mark007 commented 1 year ago

Any news on an official fix ☺️ ? It's starting to be a bit long

One CI job was failing so with a small change today I hope that passes. We are waiting for a review / verification from another dev, as another integration required an update so as not to conflict with the kef integration. We are also awaiting that review / verification so it's unclear when they will be able to perform that test on their side. Hopefully soon.

jlpouffier commented 1 year ago

In fact, I saw! I discovered your work here #87712 Amazing !! Thx for the status

checkiecheck commented 1 year ago

nice.. progress :)

checkiecheck commented 1 year ago

still stuck in review? although i still have local fix, i would prefer this integration to be active again :)

gcmilo704 commented 1 year ago

I created a kef custom_integration directory, copied the 4 kef integration files into it, added a version key to the manifest.json (otherwise the custom integration won't load). Changing the get_ip_mode function didn't help. It seems to be the getmac library having issues. There are other issues written like this one. #87623 Hopefully a fix for getmac can be added to the next HA version. For now I replaced the following line https://github.com/home-assistant/core/blob/94519de8dd9fcac684b510904a38c2269c27a042/homeassistant/components/kef/media_player.py#L120

with my speakers mac, in lowercase, like mac = '84:17:15:00:xx:xx' and rebooted HA and its back online. Using uppercase resulted in a second media_player entity being created so using lowercase solved that. At least its a temporary workaround.

did so too, wil remember this trick. happy to have the speakers back. Now i hope the fix proposed will do the same.

Sorry, may i know more details that how to apply this workaround? thanks

jlpouffier commented 1 year ago

That's basically it. In layman's terms

AiCocina commented 1 year ago

The fix functions flawlessly. I hope its inclusion in the official release soon.

birdc006 commented 1 year ago

That's basically it. In layman's terms

  • download the content of the kef integration (4 files)
  • copy them in the directory custom_components (the same where HACS integrations are installed)
  • edit the manifest.json file to add a version number like "version": "0.0.1"
  • Hardcode the Mac address of your kef in media_player.py line 120
  • restart and enjoy

I think I'm being an idiot.. I've downloaded the files from here. Uploaded directly with custom_components, edited manifest.json to include the version number and replaced line 120 with my mac address, restarted, but the LSX's are still unavailable?!

checkiecheck commented 1 year ago

you'll need subbfolder for the files, not in custom_components direcly. mine:

image

image

birdc006 commented 1 year ago

you'll need subbfolder for the files, not in custom_components direcly. mine:

image

image

Amazing! Thank you!

AiCocina commented 1 year ago

If have issues with downloading from GIT. You could use the below steps

  1. Go to https://download-directory.github.io/
  2. Paste URL: https://github.com/home-assistant/core/tree/dev/homeassistant/components/kef
  3. Press Enter, this will download the folder to your local directory
  4. Rename the Folder to kef, make changes as shown above
  5. Upload to folder to custom_components within your HA installation.
trungitaly commented 1 year ago

you'll need subbfolder for the files, not in custom_components direcly. mine:

image

image

Hi, I'm new to Home Assistant and I'm trying to add my KEF LS50W to HA.

I've tried the fix as @checkiecheck suggested here, but after that I can't get my speaker to show up in devices. I've edited the configuration.yaml as follow, but when I restarted HA nothing happened, no notification.

 media_player:
  - platform: kef
    host: 192.168.x.xxx 
    type: LS50
    name: KEF LS50W 
    maximum_volume: 0.6 
    volume_step: 0.05
checkiecheck commented 1 year ago

if you did literaly, then it need to be

i specifically did that to see the original component start working again when fixed in some release.